コード例 #1
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def deleteVariant(cls, variantID):
        session      = Session()
        variantIndex = CommandVariants.getIndexFromVariantID(variantID)
        result       = session.query(CommandVariants).filter(CommandVariants.i == variantIndex).first()

        if result is None:
            session.close()
            return {'id':variantID}

        session.delete(result)

        session.commit()
        session.close()

        return {'id':variantID}
コード例 #2
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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
コード例 #3
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def reorderVariants(cls, variantIDs):
        session = Session()
        index   = 0
        out     = []
        for varID in variantIDs:
            varIndex = CommandVariants.getIndexFromVariantID(varID)
            variant  = session.query(CommandVariants).filter(CommandVariants.i == varIndex).first()
            if not variant:
                continue

            variant.row = index
            out.append(variant.variantID)
            index  += 1

        session.commit()
        session.close()
        return out
コード例 #4
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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
コード例 #5
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def reorderColumn(cls, column, commandIDs):
        session = Session()
        index   = 0
        out     = []
        for cmdID in commandIDs:
            cmdIndex = UserCommands.getIndexFromCommandID(cmdID)
            cmd      = session.query(UserCommands).filter(UserCommands.i == cmdIndex).first()
            if not cmd:
                continue

            cmd.column = column
            cmd.row    = index
            out.append(cmd.commandID)
            index  += 1

        session.commit()
        session.close()
        return out
コード例 #6
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def modifyVariant(cls, variantID, **kwargs):
        session      = Session()
        variantIndex = CommandVariants.getIndexFromVariantID(variantID)
        result       = session.query(CommandVariants).filter(CommandVariants.i == variantIndex).first()

        if result is None:
            session.close()
            return {'error':'No Such Variant'}

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

        session.commit()

        out = result.toButtonDict()
        session.close()
        return out
コード例 #7
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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
コード例 #8
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def deleteCommand(cls, commandID):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(UserCommands).filter(UserCommands.i == commandIndex).first()

        if result is None:
            session.close()
            return {'id':commandID}

        session.delete(result)

        result = session.query(CommandVariants).filter(CommandVariants.usrcmdfk == commandIndex).all()
        for r in result:
            session.delete(result)

        session.commit()
        session.close()

        return {'id':commandID}
コード例 #9
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    def modifyCommand(cls, commandID, **kwargs):
        session      = Session()
        commandIndex = UserCommands.getIndexFromCommandID(commandID)
        result       = session.query(UserCommands).filter(UserCommands.i == commandIndex).first()

        if result is None:
            session.close()
            return {'error':'No Such Command'}

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

        session.commit()

        out = result.toButtonDict()
        session.close()
        return out
コード例 #10
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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}
コード例 #11
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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
コード例 #12
0
ファイル: AlloyData.py プロジェクト: Gorfaal/Alloy
    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