Ejemplo n.º 1
0
    def _load_collection (self):
        """Load the collection from the database."""

        assert(type(self['id']) == int)
        if self._db.get('id'):
            sql = "SELECT * FROM collections WHERE id=%d;" % self['id']
        elif self._db.get('name'):
            sql = "SELECT * FROM collections "\
                  "WHERE name='%s' ORDER BY id DESC "\
                  "LIMIT 1;" % self['name']
        else:
            raise Error.Invalid

        q = Query(sql)
        if not q['id']:
            self['id'] = None
            return False

        for key in q.get_headers():
            self._db[key] = q[key][0]

        sql = "SELECT id FROM assets " +\
              "WHERE collections_id=%d;" % self['id']
        q = Query(sql)
        if len(q):
            self._assets = [q[x]['id'] for x in q]
Ejemplo n.º 2
0
    def _load_collection(self):
        """Load the collection from the database."""

        assert (type(self['id']) == int)
        if self._db.get('id'):
            sql = "SELECT * FROM collections WHERE id=%d;" % self['id']
        elif self._db.get('name'):
            sql = "SELECT * FROM collections "\
                  "WHERE name='%s' ORDER BY id DESC "\
                  "LIMIT 1;" % self['name']
        else:
            raise Error.Invalid

        q = Query(sql)
        if not q['id']:
            self['id'] = None
            return False

        for key in q.get_headers():
            self._db[key] = q[key][0]

        sql = "SELECT id FROM assets " +\
              "WHERE collections_id=%d;" % self['id']
        q = Query(sql)
        if len(q):
            self._assets = [q[x]['id'] for x in q]
Ejemplo n.º 3
0
    def _lookup_file (self):
        sql = "SELECT * FROM files "+\
              "WHERE id=%d;" % self['id']

        q = Query(sql)
        if len(q):
            for x in q.get_headers():
                self._file[x] = q[x][0]
Ejemplo n.º 4
0
def get_files_by_flag (flag):
    q = "SELECT * "\
        "FROM files "\
        "WHERE queue_flag = %s;" % flag

    query = Query(q)

    if len(query) == 0:
        return []

    files = []
    for x in query:
        f = {}
        for key in query.get_headers():
            f[key]= query[x][key]
        files.append(f)
    return files
Ejemplo n.º 5
0
def get_files_by_flag(flag):
    q = "SELECT * "\
        "FROM files "\
        "WHERE queue_flag = %s;" % flag

    query = Query(q)

    if len(query) == 0:
        return []

    files = []
    for x in query:
        f = {}
        for key in query.get_headers():
            f[key] = query[x][key]
        files.append(f)
    return files
Ejemplo n.º 6
0
def get_user (username = None):
    if username == None:
        username = CTK.cookie['user']

    if not username:
        return {}

    q = "SELECT * FROM users WHERE username='******';" % username

    query = Query(q)
    user = {}
    try:
        for key in query.get_headers():
            user[key] = query[0][key]
    except:
        pass

    return user
Ejemplo n.º 7
0
def get_user(username=None):
    if username == None:
        username = CTK.cookie['user']

    if not username:
        return {}

    q = "SELECT * FROM users WHERE username='******';" % username

    query = Query(q)
    user = {}
    try:
        for key in query.get_headers():
            user[key] = query[0][key]
    except:
        pass

    return user
Ejemplo n.º 8
0
def get_files_by_name (filenames):
    assert type(filenames) == list

    names = ','.join(["'%s'"% f for f in filenames])
    q = "SELECT * "\
        "FROM files "\
        "WHERE filename IN (%s);" % names

    query = Query(q)
    if len(query) == 0:
        return []

    files = []
    for x in query:
        f = {}
        for key in query.get_headers():
            if query[x][key]:
                f[key]= query[x][key]
        files.append(f)
    return files
Ejemplo n.º 9
0
def get_files_by_name(filenames):
    assert type(filenames) == list

    names = ','.join(["'%s'" % f for f in filenames])
    q = "SELECT * "\
        "FROM files "\
        "WHERE filename IN (%s);" % names

    query = Query(q)
    if len(query) == 0:
        return []

    files = []
    for x in query:
        f = {}
        for key in query.get_headers():
            if query[x][key]:
                f[key] = query[x][key]
        files.append(f)
    return files
Ejemplo n.º 10
0
    def _load_asset (self):
        assert(type(self['id']) == int)
        sql = "SELECT assets.* FROM assets "\
              "LEFT JOIN files ON assets.id=files.id "\
              "WHERE assets.id=%d" % self['id']

        q = Query(sql)

        if not q['id']:
            self['id'] = None
            return False

        for key in q.get_headers():
            self._db[key] = q[key][0]

        self._lookup_parent()
        self._lookup_children()
        self._lookup_versions()
        self._lookup_formats()
        self._lookup_parts()
        self._lookup_replacements()
        self._lookup_collection()
        self._lookup_file()
        self._compile_tags()