Beispiel #1
0
 def query_used_organizations(cls, session, issue):
     query = session.query(GazetteNotice._organizations.keys())
     query = query.filter(
         GazetteNotice._issues.has_key(issue.name),  # noqa
         GazetteNotice.state == 'published',
         bool_is(GazetteNotice.meta['print_only'], True))
     return set([result[0][0] for result in query if result[0]])
Beispiel #2
0
 def query_excluded_notices_count(cls, session, issue):
     query = session.query(GazetteNotice)
     query = query.filter(
         GazetteNotice._issues.has_key(issue.name),  # noqa
         GazetteNotice.state == 'published',
         bool_is(GazetteNotice.meta['print_only'], True))
     return query.count()
Beispiel #3
0
def test_bool_is(session):
    session.add(GazetteNotice(title='F.1'))
    session.add(GazetteNotice(title='F.2', meta={'y': 1}))
    session.add(GazetteNotice(title='F.3', meta={'x': None}))
    session.add(GazetteNotice(title='F.4', meta={'x': None, 'y': 1}))
    session.add(GazetteNotice(title='F.5', meta={'x': False}))
    session.add(GazetteNotice(title='F.6', meta={'x': False, 'y': 1}))
    session.add(GazetteNotice(title='T.1', meta={'x': True}))
    session.add(GazetteNotice(title='T.2', meta={'x': True, 'y': 1}))
    session.flush()

    query = session.query(GazetteNotice)
    assert sorted([
        r.title for r in query.filter(bool_is(GazetteNotice.meta['x'], True))
    ]) == ['T.1', 'T.2']
    assert sorted([
        r.title for r in query.filter(bool_is(GazetteNotice.meta['x'], False))
    ]) == ['F.1', 'F.2', 'F.3', 'F.4', 'F.5', 'F.6']
Beispiel #4
0
    def query_notices(session, issue, organization, category):
        """ Queries all notices with the given values, ordered by publication
        number.

        """

        notices = session.query(GazetteNotice.id)
        notices = notices.filter(
            GazetteNotice._issues.has_key(issue),  # noqa
            GazetteNotice.state == 'published',
            GazetteNotice._organizations.has_key(organization),
            GazetteNotice._categories.has_key(category),
            bool_is(GazetteNotice.meta['print_only'], True))
        notices = notices.order_by(GazetteNotice._issues[issue],
                                   GazetteNotice.title)
        return [notice[0] for notice in notices]