示例#1
0
def setup():
    """
    Called at the end of CKAN setup.

    Create issue and issue_category tables in the database.
    Prepopulate issue_category table with default categories.
    """
    if issue_table is None:
        define_issue_tables()
        report_tables = define_report_tables([Issue, IssueComment])
        log.debug('Issue tables defined in memory')

    if not model.package_table.exists():
        # during tests?
        return

    if not issue_table.exists():
        issue_category_table.create(checkfirst=True)
        issue_table.create(checkfirst=True)
        issue_comment_table.create(checkfirst=True)

        if report_tables:
            for table in report_tables:
                table.create(checkfirst=True)
        log.debug('Issue tables created')

        # add default categories if they don't already exist
        session = model.meta.Session()
        for category_name, category_desc in DEFAULT_CATEGORIES.iteritems():
            if not category_name:
                continue

            category = IssueCategory.get(category_name)
            if not category:
                category = IssueCategory(category_name)
                category.description = category_desc
                session.add(category)
        if session.new:
            log.debug('Issue categories created')
            session.commit()
    else:
        log.debug('Issue tables already exist')
示例#2
0
        'resource': relation(
            model.Resource,
            backref=backref('issues', cascade='all'),
            primaryjoin=foreign(issue_table.c.resource_id) == remote(Resource.id)
        ),
    }
)

meta.mapper(IssueCategory, issue_category_table)

meta.mapper(
    IssueComment,
    issue_comment_table,
    properties={
        'user': relation(
            model.User,
            backref=backref('issue_comments',
                            cascade='all, delete-orphan',
                            single_parent=True),
            primaryjoin=foreign(issue_comment_table.c.user_id) == remote(User.id)
        ),
        'issue': relation(
            Issue,
            backref=backref('comments', cascade='all, delete-orphan'),
            primaryjoin=issue_comment_table.c.issue_id.__eq__(Issue.id)
        ),
    }
)

report_tables = define_report_tables([Issue, IssueComment])
        'resource': relation(
            model.Resource,
            backref=backref('issues', cascade='all'),
            primaryjoin=foreign(issue_table.c.resource_id) == remote(Resource.id)
        ),
    }
)

meta.mapper(IssueCategory, issue_category_table)

meta.mapper(
    IssueComment,
    issue_comment_table,
    properties={
        'user': relation(
            model.User,
            backref=backref('issue_comments',
                            cascade='all, delete-orphan',
                            single_parent=True),
            primaryjoin=foreign(issue_comment_table.c.user_id) == remote(User.id)
        ),
        'issue': relation(
            Issue,
            backref=backref('comments', cascade='all, delete-orphan'),
            primaryjoin=issue_comment_table.c.issue_id.__eq__(Issue.id)
        ),
    }
)

report_tables = define_report_tables([Issue, IssueComment])