Ejemplo n.º 1
0
    def getCategories(cls):
        session = Session()
        result  = session.query(CommandCategories).all()

        if not result:
            category = CommandCategories()
            session.add(category)
            session.commit()
            out = [category.toDict()]
        else:
            out = []
            for r in result:
                out.append(r.toDict())

        session.close()
        return out
Ejemplo n.º 2
0
    def getColumns(cls, categoryID):
        session       = Session()
        categoryIndex = CommandCategories.getIndexFromCategoryID(categoryID)

        category = session.query(CommandCategories).filter(
            CommandCategories.i == categoryIndex
        ).first()

        out = []
        for i in range(1, 5):
            name = u'column' + unicode(i)
            out.append({
                'label':getattr(category, name) if category else (u'Column ' + unicode(i)),
                'commands':[]
            })

        session.close()

        if not category:
            return out

        for cmd in cls.getCommands(categoryID):
            out[cmd['column']]['commands'].append(cmd)

        return out
Ejemplo n.º 3
0
    def createCategory(cls, label):
        """ Creates a new category with the specified label and returns the dictionary
            representation of the newly created category, including its id.

            @@@param label:string
                The display label for the new category.

            @@@return dict
                The dictionary representation of the newly created category.
        """

        session  = Session()
        category = CommandCategories(label=unicode(label))
        session.add(category)
        session.commit()

        out = category.toDict()
        session.close()
        return out
Ejemplo n.º 4
0
 def toButtonDict(self):
     return {
         'id':self.commandID,
         'column':self.column,
         'row':self.row,
         'categoryID':CommandCategories.getCategoryIDFromIndex(self.categoryfk),
         'label':self.label,
         'info':self.info,
         'icon':self.icon,
         'hasVariants':len(self.variants) > 0
     }
Ejemplo n.º 5
0
 def toDict(self):
     return {
         'id':self.commandID,
         'column':self.column,
         'row':self.row,
         'categoryID':CommandCategories.getCategoryIDFromIndex(self.categoryfk),
         'label':self.label,
         'info':self.info,
         'icon':self.icon,
         'language':self.language,
         'location':self.location,
         'script':self.script,
         'variants':self.variants
     }
Ejemplo n.º 6
0
    def modifyCategory(cls, categoryID, **kwargs):
        session = Session()
        result = session.query(CommandCategories).filter(
            CommandCategories.i == CommandCategories.getIndexFromCategoryID(categoryID)
        ).first()

        if result is None:
            return {'error':'No Such Category'}

        for n,v in kwargs.iteritems():
            if isinstance(v, str):
                v = unicode(v)
            setattr(result, n, v)
            session.commit()

        out = result.toDict()
        session.close()
        return out
Ejemplo n.º 7
0
    def getCommands(cls, categoryID):
        session         = Session()
        categoryIndex   = CommandCategories.getIndexFromCategoryID(categoryID)
        result          = session.query(UserCommands) \
            .filter(UserCommands.categoryfk == categoryIndex) \
            .order_by(UserCommands.row.asc()) \
            .all()

        if not result:
            session.close()
            return []

        out = []
        for r in result:
            out.append(r.toButtonDict())

        session.close()
        return out
Ejemplo n.º 8
0
    def deleteCategory(cls, categoryID):
        session       = Session()
        categoryIndex = CommandCategories.getIndexFromCategoryID(categoryID)
        result = session.query(CommandCategories).filter(CommandCategories.i == categoryIndex).first()

        if result:
            session.delete(result)

        result = session.query(UserCommands).filter(UserCommands.categoryfk == categoryIndex).all()
        for r in result:
            session.delete(r)

            variants = session.query(CommandVariants).filter(CommandVariants.usrcmdfk == r.i).all()
            for v in variants:
                session.delete(v)

        session.commit()
        session.close()

        return {'id':categoryID}
Ejemplo n.º 9
0
    def createCommand(cls, categoryID, column, row =None, **kwargs):
        session       = Session()
        categoryIndex = CommandCategories.getIndexFromCategoryID(categoryID)

        if row is None or row < 0:
            row = session.query(UserCommands).filter(
                and_(
                    UserCommands.categoryfk == categoryIndex,
                    UserCommands.column == column
                )
            ).count()

        for n,v in kwargs.iteritems():
            if isinstance(v, str):
                kwargs[n] = unicode(v)

        command = UserCommands(categoryfk=categoryIndex, column=column, row=row, **kwargs)
        session.add(command)
        session.commit()

        out = command.toButtonDict()
        session.close()
        return out