Exemplo 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
Exemplo n.º 2
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
Exemplo n.º 3
0
    def createVariant(cls, commandID, row =None, **kwargs):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)

        if row is None or row < 0:
            row = session.query(CommandVariants).filter(
                CommandVariants.usrcmdfk == commandIndex
            ).count()

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

        variant = CommandVariants(usrcmdfk=commandIndex, row=row, **kwargs)
        session.add(variant)
        session.commit()

        out = variant.toButtonDict()
        session.close()
        return out
Exemplo n.º 4
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