コード例 #1
0
class TG_Group(InheritableSQLObject):
    """An ultra-simple group definition."""
    class sqlmeta:
        table = "tg_group"

    group_name = UnicodeCol(length=16,
                            alternateID=True,
                            alternateMethodName="by_group_name")
    display_name = UnicodeCol(length=255)
    created = DateTimeCol(default=datetime.now)

    # Old names
    groupId = DeprecatedAttr("groupId", "group_name")
    displayName = DeprecatedAttr("displayName", "display_name")

    # collection of all users belonging to this group
    users = RelatedJoin("TG_User",
                        intermediateTable="tg_user_group",
                        joinColumn="group_id",
                        otherColumn="user_id")

    # collection of all permissions for this group
    permissions = RelatedJoin("TG_Permission",
                              joinColumn="group_id",
                              intermediateTable="tg_group_permission",
                              otherColumn="permission_id")
コード例 #2
0
class Group(SQLObject):
    """
    An ultra-simple group definition.
    """

    # names like "Group", "Order" and "User" are reserved words in SQL
    # so we set the name to something safe for SQL
    class sqlmeta:
        table = 'tg_group'

    group_name = UnicodeCol(length=16,
                            alternateID=True,
                            alternateMethodName='by_group_name')
    display_name = UnicodeCol(length=255)
    created = DateTimeCol(default=datetime.now)

    # collection of all users belonging to this group
    users = RelatedJoin('User',
                        intermediateTable='user_group',
                        joinColumn='group_id',
                        otherColumn='user_id')

    # collection of all permissions for this group
    permissions = RelatedJoin('Permission',
                              joinColumn='group_id',
                              intermediateTable='group_permission',
                              otherColumn='permission_id')
コード例 #3
0
class Dataset(SQLObject):
    class sqlmeta:
        table = 'ons_dataset'
    uri = StringCol(alternateID=True, length=511)
    title = StringCol()
    summary = StringCol()
    keywords = RelatedJoin('Keyword')
    distributions = RelatedJoin('Distribution')
コード例 #4
0
    class Journal(SQLObject):
        timestamp = DateTimeCol(default=datetime.now, notNone=True)
        level = IntCol(notNone=True)
        level_index = DatabaseIndex('level')
        text = UnicodeCol(length=255, notNone=True)
        text_index = DatabaseIndex('text')

        parent = ForeignKey('Journal', default=None)
        children = MultipleJoin('Journal')
        related = RelatedJoin('Journal', joinColumn='journal_id', otherColumn='journal_from_id')
        related_from = RelatedJoin('Journal', joinColumn='journal_from_id', otherColumn='journal_id', createRelatedTable=False)
コード例 #5
0
class Course(SQLObject):
    name = StringCol(length=64)
    enrolled = RelatedJoin('Student',
        intermediateTable="enrolled_assc",
        joinColumn="courseID",
        otherColumn="studentID",
        addRemoveName="Enrolled")
    completed = RelatedJoin('Student',
        intermediateTable="completed_assc",
        joinColumn="courseID",
        otherColumn="studentID",
        addRemoveName="Completed")
コード例 #6
0
class Student(SQLObject):
    fullName = StringCol(length=64)
    username = StringCol(length=16, default=None)
    emails = MultipleJoin('Email')
    enrolled = RelatedJoin('Course',
        intermediateTable="enrolled_assc",
        joinColumn="studentID",
        otherColumn="courseID",
        addRemoveName="Enrolled")
    completed = RelatedJoin('Course',
        intermediateTable="completed_assc",
        joinColumn="studentID",
        otherColumn="courseID",
        addRemoveName="Completed")
コード例 #7
0
class Dataset(SQLObject):
    class sqlmeta:
        table = 'wh_dataset'

    whitehall_id = IntCol(alternateID=True)
    stats_type = EnumCol(enumValues=[
        'Official Statistics', 'National Statistics', 'Statistical data set',
        None
    ],
                         default=None)
    title = StringCol()
    url = StringCol(alternateID=True, length=255)
    orgs = RelatedJoin('Organisation')
    publication_date = DateTimeCol()
    government_name = StringCol()
    collections = RelatedJoin('Collection')
コード例 #8
0
class Artist(SQLObject):

    tableversion = 1
    canonicalName = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    name = UnicodeCol()
    cards = RelatedJoin('AbstractCard', intermediateTable='abs_artist_map',
                        createRelatedTable=False)
コード例 #9
0
class Tourtment(SQLObject):
    class sqlmeta:
        table = 'competition'  # test on a non-standard way

    name = StringCol()
    fightersAsList = RelatedJoin('Fighter')
    fightersAsSResult = SQLRelatedJoin('Fighter')
コード例 #10
0
class PrintingProperty(SQLObject):

    tableversion = 1
    canonicalValue = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    value = UnicodeCol(length=MAX_ID_LENGTH)
    printings = RelatedJoin('Printing', intermediateTable='printing_data_map',
                            createRelatedTable=False)
コード例 #11
0
class Contact(SQLObject):
    class sqlmeta:
        table = 'ons_contact'
    email = StringCol()
    name = StringCol()
    telephone = StringCol()
    datasets = RelatedJoin('Distribution')
コード例 #12
0
class Organisation(SQLObject):
    class sqlmeta:
        table = 'wh_organisation'

    uri = StringCol(alternateID=True, length=255)
    label = StringCol()
    datasets = RelatedJoin('Dataset')
コード例 #13
0
class Collection(SQLObject):
    class sqlmeta:
        table = 'wh_collection'

    uri = StringCol()
    label = StringCol()
    datasets = RelatedJoin('Dataset')
コード例 #14
0
class Ruling(SQLObject):

    tableversion = 2
    text = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    code = UnicodeCol()
    url = UnicodeCol(default=None)
    cards = RelatedJoin('AbstractCard', intermediateTable='abs_ruling_map',
                        createRelatedTable=False)
コード例 #15
0
class Title(SQLObject):

    tableversion = 2
    name = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    cards = RelatedJoin('SutekhAbstractCard',
                        intermediateTable='abs_title_map',
                        otherColumn="abstract_card_id",
                        createRelatedTable=False)
コード例 #16
0
class RarityPair(SQLObject):
    tableversion = 1
    expansion = ForeignKey('Expansion')
    rarity = ForeignKey('Rarity')
    cards = RelatedJoin('AbstractCard',
                        intermediateTable='abs_rarity_pair_map',
                        createRelatedTable=False)
    expansionRarityIndex = DatabaseIndex(expansion, rarity, unique=True)
コード例 #17
0
class Task(SQLObject):
    title = UnicodeCol()
    creationDate = DateTimeCol(notNone=True)
    dueDate = DateTimeCol(default=None)
    doneDate = DateTimeCol(default=None)
    description = UnicodeCol(default="", notNone=True)
    urgency = IntCol(default=0, notNone=True)
    status = EnumCol(enumValues=['new', 'started', 'done'])
    project = ForeignKey("Project")
    keywords = RelatedJoin("Keyword",
                           createRelatedTable=False,
                           intermediateTable="task_keyword",
                           joinColumn="task_id",
                           otherColumn="keyword_id")
    recurrence = ForeignKey("Recurrence", default=None)

    def setKeywordDict(self, dct):
        """
        Defines keywords of a task.
        Dict is of the form: keywordName => value
        """
        for taskKeyword in TaskKeyword.selectBy(task=self):
            taskKeyword.destroySelf()

        for name, value in dct.items():
            keyword = Keyword.selectBy(name=name)[0]
            TaskKeyword(task=self, keyword=keyword, value=value)

    def getKeywordDict(self):
        """
        Returns all keywords of a task as a dict of the form:
        keywordName => value
        """
        dct = {}
        for keyword in TaskKeyword.selectBy(task=self):
            dct[keyword.keyword.name] = keyword.value
        return dct

    def getKeywordsAsString(self):
        """
        Returns all keywords as a string like "key1=value1, key2=value2..."
        """
        return ", ".join(
            list(("%s=%s" % k for k in self.getKeywordDict().items())))

    def getUserKeywordsNameAsString(self):
        """
        Returns all keywords keys as a string like "key1, key2, key3...".
        Internal keywords (starting with _) are ignored.
        """
        keywords = [
            k for k in self.getKeywordDict().keys() if not k.startswith("_")
        ]
        keywords.sort()
        if keywords:
            return ", ".join(keywords)
        else:
            return ""
コード例 #18
0
ファイル: models.py プロジェクト: Kludex/orm-benchmarks
    class Journal(SQLObject):
        timestamp = DateTimeCol(default=datetime.now, notNone=True)
        level = IntCol(notNone=True)
        level_index = DatabaseIndex("level")
        text = UnicodeCol(length=255, notNone=True)
        text_index = DatabaseIndex("text")

        parent = ForeignKey("Journal", default=None)
        children = MultipleJoin("Journal")
        related = RelatedJoin("Journal",
                              joinColumn="journal_id",
                              otherColumn="journal_from_id")
        related_from = RelatedJoin(
            "Journal",
            joinColumn="journal_from_id",
            otherColumn="journal_id",
            createRelatedTable=False,
        )
コード例 #19
0
class PhysicalCard(SQLObject):

    tableversion = 3
    abstractCard = ForeignKey('AbstractCard')
    abstractCardIndex = DatabaseIndex(abstractCard)
    # Explicitly allow None as expansion
    printing = ForeignKey('Printing', notNull=False)
    sets = RelatedJoin('PhysicalCardSet', intermediateTable='physical_map',
                       createRelatedTable=False)
コード例 #20
0
class Clan(SQLObject):

    tableversion = 3
    name = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    shortname = UnicodeCol(default=None)
    cards = RelatedJoin('SutekhAbstractCard',
                        intermediateTable='abs_clan_map',
                        otherColumn="abstract_card_id",
                        createRelatedTable=False)
コード例 #21
0
class Distribution(SQLObject):
    class sqlmeta:
        table = 'ons_distribution'
    uri = StringCol()
    national_statistic = BoolCol()
    version = StringCol()
    edition = StringCol()
    release_date = DateTimeCol()
    next_release = DateCol()
    contacts = RelatedJoin('Contact')
コード例 #22
0
class DisciplinePair(SQLObject):

    tableversion = 1
    discipline = ForeignKey('Discipline')
    level = EnumCol(enumValues=['inferior', 'superior'])
    disciplineLevelIndex = DatabaseIndex(discipline, level, unique=True)
    cards = RelatedJoin('SutekhAbstractCard',
                        intermediateTable='abs_discipline_pair_map',
                        otherColumn="abstract_card_id",
                        createRelatedTable=False)
コード例 #23
0
ファイル: db.py プロジェクト: phdru/m_librarian
class Genre(SQLObject):
    name = UnicodeCol(notNull=True, unique=True)
    title = UnicodeCol(notNull=True)
    count = IntCol(notNull=True)
    books = RelatedJoin('Book',
                        otherColumn='book_id',
                        intermediateTable='book_genre',
                        createRelatedTable=False)
    title_idx = DatabaseIndex(title)
    count_idx = DatabaseIndex(count)
コード例 #24
0
class Keyword(SQLObject):

    # For sanity, avoid keywords with commas since this is the preferred
    # character for separating lists of keywords when displaying them
    # to a user in a compact way.

    tableversion = 1
    keyword = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    cards = RelatedJoin('AbstractCard', intermediateTable='abs_keyword_map',
                        createRelatedTable=False)
コード例 #25
0
class PhysicalCardSet(SQLObject):
    tableversion = 7
    name = UnicodeCol(alternateID=True, length=MAX_ID_LENGTH)
    author = UnicodeCol(default='')
    comment = UnicodeCol(default='')
    annotations = UnicodeCol(default='')
    inuse = BoolCol(default=False)
    parent = ForeignKey('PhysicalCardSet', default=None)
    cards = RelatedJoin('PhysicalCard', intermediateTable='physical_map',
                        createRelatedTable=False)
    parentIndex = DatabaseIndex(parent)
コード例 #26
0
class Project(SQLObject):
    class sqlmeta:
        defaultOrder = "name"

    name = UnicodeCol(alternateID=True, notNone=True)
    active = BoolCol(default=True)
    keywords = RelatedJoin("Keyword",
                           createRelatedTable=False,
                           intermediateTable="project_keyword",
                           joinColumn="project_id",
                           otherColumn="keyword_id")

    def __unicode__(self):
        keywords = self.getKeywordsAsString()
        if keywords:
            return "%s (%s)" % (self.name, keywords)
        else:
            return self.name

    def setKeywordDict(self, dct):
        """
        Defines keywords of a project.
        Dict is of the form: keywordName => value
        """
        for projectKeyword in ProjectKeyword.selectBy(project=self):
            projectKeyword.destroySelf()

        for name, value in dct.items():
            keyword = Keyword.selectBy(name=name)[0]
            ProjectKeyword(project=self, keyword=keyword, value=value)

    def getKeywordDict(self):
        """
        Returns all keywords of a project as a dict of the form:
        keywordName => value
        """
        dct = {}
        for keyword in ProjectKeyword.selectBy(project=self):
            dct[keyword.keyword.name] = keyword.value
        return dct

    def getKeywordsAsString(self):
        """
        Returns all keywords as a string like "key1=value1, key2=value2..."
        Value is not displayed if none
        """
        result = []
        for key, value in self.getKeywordDict().items():
            if value:
                result.append("%s=%s" % (key, value))
            else:
                result.append(key)
        return ", ".join(result)
コード例 #27
0
ファイル: MemberModel.py プロジェクト: tstachl/Phoenix
class Member(SQLObject):
    username = StringCol(alternateID=True, length=20)
    email = StringCol(alternateID=True, length=254)
    name = StringCol(length=255, default=None)
    ownedroles = MultipleJoin("Role")
    roles = RelatedJoin("Role")
    repositories = MultipleJoin("Repository")
    privileges = MultipleJoin("Privilege")
    keys = MultipleJoin("Key")

    def addRepository(self, name, path=None):
        from Phoenix.Models import Repository
        repo = Repository(member=self, name=name, path=path)
        return repo

    def addRole(self, name):
        from Phoenix.Models import Role
        role = Role(name=name, member=self)
        return role

    def addKey(self, key):
        from Phoenix.Models import Key
        key = Key(member=self, pubkey=key)
        return key

    def removeKey(self, key):
        key.destroySelf()

    def repositoryByName(self, name):
        from Phoenix.Models import Repository
        try:
            return Repository.selectBy(member=self, name=name)[0]
        except IndexError:
            return None

    def repositoryByPath(self, path):
        from Phoenix.Models import Repository
        try:
            return Repository.selectBy(member=self, path=path)[0]
        except IndexError:
            return None

    @classmethod
    def _beforedestroy(cls, member, *a):
        for role in member.ownedroles:
            role.destroySelf()

        for repository in member.repositories:
            repository.destroySelf()

        for key in member.keys:
            key.destroySelf()
コード例 #28
0
class Keyword(SQLObject):
    class sqlmeta:
        defaultOrder = "name"

    name = UnicodeCol(alternateID=True, notNone=True)
    tasks = RelatedJoin("Task",
                        createRelatedTable=False,
                        intermediateTable="task_keyword",
                        joinColumn="keyword_id",
                        otherColumn="task_id")

    def __unicode__(self):
        return self.name
コード例 #29
0
class Permission(SQLObject):
    """
    A relationship that determines what each Group can do
    """
    permission_name = UnicodeCol(length=16,
                                 alternateID=True,
                                 alternateMethodName='by_permission_name')
    description = UnicodeCol(length=255)

    groups = RelatedJoin('Group',
                         intermediateTable='group_permission',
                         joinColumn='permission_id',
                         otherColumn='group_id')
コード例 #30
0
class PhysicalCard_v2(SQLObject):
    """Table used to upgrade PhysicalCard from v2"""
    class sqlmeta:
        """meta class used to set the correct table"""
        table = PhysicalCard.sqlmeta.table
        cacheValues = False

    abstractCard = ForeignKey('AbstractCard')
    # Explicitly allow None as expansion
    expansion = ForeignKey('Expansion_v4', notNull=False)
    sets = RelatedJoin('PhysicalCardSet',
                       intermediateTable='physical_map',
                       createRelatedTable=False)