Example #1
0
    def set(self, owner_id, dashboard_id, old_layout_id, new_layout_id,
            new_layout_def, new_layout_props):
        with cursor() as cur:
            if old_layout_id is None:
                try:
                    cur.execute(*insert(
                        'dashboard_layout',
                        dict(
                            owner_id=owner_id,
                            dashboard_id=dashboard_id,
                            layout_def=new_layout_def,
                            layout_props=new_layout_props,
                            layout_id=new_layout_id,
                        )))
                except sqlite3.IntegrityError:
                    return False
                else:
                    return True

            cur.execute(
                """UPDATE dashboard_layout
                   SET layout_id=?, layout_def=?, layout_props=?
                   WHERE owner_id=? AND dashboard_id=? AND layout_id=?""", [
                    new_layout_id, new_layout_def, new_layout_props, owner_id,
                    dashboard_id, old_layout_id
                ])
            return cur.rowcount == 1
Example #2
0
 def insert(self, owner_id, dashboard_name, dashboard_options):
     dashboard_id = gen_uuid()
     row = dict(owner_id=owner_id,
                dashboard_id=dashboard_id,
                dashboard_name=dashboard_name,
                dashboard_options=dashboard_options)
     with cursor() as cur:
         cur.execute(*insert('dashboard', row))
     return row
Example #3
0
 def insert_multi(self, report_id, tags_series_spec_list):
     res = []
     with cursor() as cur:
         for tags, series_spec in tags_series_spec_list:
             series_id = gen_timeuuid()
             cur.execute(*insert('series_def', dict(
                 report_id=report_id,
                 tags=tags,
                 series_id=series_id,
                 series_spec=serialize.mjson(series_spec))))
             res.append(series_id)
         return res
Example #4
0
 def insert(self, email, password):
     if self.select_by_email(email) is not None:
         raise ValueError('User exists: %r' % email)
     user_id = gen_uuid()
     pw_hash = werkzeug.security.generate_password_hash(password)
     with cursor() as cur:
         cur.execute(*insert(
             'user', {
                 'user_id': user_id,
                 'email': email,
                 'password': pw_hash,
                 'created': datetime.datetime.utcnow(),
             }))
         return self.select(user_id)
Example #5
0
    def insert(self, owner_id, report_id, report_instance_id, tags, ri_data,
               input_string, extra_ri_data, custom_created):
        created = util.datetime_from_uuid1(report_instance_id)

        with cursor() as cur:
            first_row = None
            tags_powerset = util.powerset(tags[:mqeconfig.MAX_TAGS])
            for tags_subset in tags_powerset:
                row = dict(report_id=report_id,
                           tags=tags_subset,
                           report_instance_id=report_instance_id,
                           ri_data=ri_data,
                           input_string=input_string,
                           all_tags=tags,
                           extra_ri_data=extra_ri_data)
                if first_row is None:
                    first_row = row
                cur.execute(*insert('report_instance', row))

                cur.execute(
                    """INSERT OR IGNORE INTO report_instance_day (report_id, tags, day)
                               VALUES (?, ?, ?)""",
                    [report_id, tags_subset,
                     created.date()])

            if first_row:
                # report counts

                cur.execute(
                    """UPDATE report SET
                               report_instance_count = report_instance_count + 1
                               WHERE report_id=?""", [report_id])

                diskspace = self._compute_ri_diskspace(first_row)
                cur.execute(
                    """UPDATE report SET
                               report_instance_diskspace = report_instance_diskspace + ?
                               WHERE report_id=?""", [diskspace, report_id])

                # owner counts
                cur.execute(
                    """SELECT 1 FROM report_data_for_owner WHERE owner_id=?""",
                    [owner_id])
                if not cur.fetchone():
                    try:
                        cur.execute(
                            """INSERT INTO report_data_for_owner (owner_id)
                                       VALUES (?)""", [owner_id])
                    except sqlite3.IntegrityError:
                        pass

                cur.execute(
                    """UPDATE report_data_for_owner
                               SET report_instance_count=report_instance_count+1
                               WHERE owner_id=?""", [owner_id])

                cur.execute(
                    """UPDATE report_data_for_owner
                               SET report_instance_diskspace=report_instance_diskspace+?
                               WHERE owner_id=?""", [diskspace, owner_id])

                for tag in tags:
                    cur.execute(
                        """INSERT OR IGNORE INTO report_tag (report_id, tag)
                                   VALUES (?, ?)""", [report_id, tag])

            return first_row