Ejemplo n.º 1
0
def view_dashboard(self, request):
    """ The dashboard view (for editors).

    Shows the drafted, submitted and rejected notices, shows warnings and
    allows to create a new notice.

    """
    layout = Layout(self, request)

    user_ids, group_ids = get_user_and_group(request)
    collection = GazetteNoticeCollection(request.session,
                                         user_ids=user_ids,
                                         group_ids=group_ids)

    # rejected
    rejected = collection.for_state('rejected').query().all()
    if rejected:
        request.message(_("You have rejected messages."), 'warning')

    # drafted
    drafted = collection.for_state('drafted').query().all()
    now = utcnow()
    limit = now + timedelta(days=2)
    past_issues_selected = False
    deadline_reached_soon = False
    for notice in drafted:
        for issue in notice.issue_objects:
            if issue.deadline < now:
                past_issues_selected = True
            elif issue.deadline < limit:
                deadline_reached_soon = True
    if past_issues_selected:
        request.message(_("You have drafted messages with past issues."),
                        'warning')
    if deadline_reached_soon:
        request.message(
            _("You have drafted messages with issues close to the deadline."),
            'warning')

    # submitted
    submitted = collection.for_state('submitted').query().all()

    new_notice = request.link(collection.for_state('drafted'),
                              name='new-notice')

    return {
        'layout': layout,
        'title': _("Dashboard"),
        'rejected': rejected,
        'drafted': drafted,
        'submitted': submitted,
        'new_notice': new_notice,
        'current_issue': layout.current_issue
    }
Ejemplo n.º 2
0
def test_notice_collection_count_by_organization(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_organization() == []

    organizations = OrganizationCollection(session)
    organizations.add_root(name='1', title='A')
    organizations.add_root(name='2', title='B')
    organizations.add_root(name='3', title='C')
    for organization, count in (('1', 2), ('2', 4), ('3', 10)):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id=organization,
                           category_id='',
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=None)
    assert collection.count_by_organization() == [
        ('A', 1),
        ('B', 6),
        ('C', 45),
    ]

    assert collection.count_by_organization() == \
        collection.for_state('drafted').count_by_organization()

    collection.issues = ['2017-1', '2017-4']
    assert collection.count_by_organization() == [('B', 2), ('C', 13)]
Ejemplo n.º 3
0
def test_notice_collection_count_by_group(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_group() == []

    groups = UserGroupCollection(session)
    group_a = groups.add(name='A')
    group_b = groups.add(name='B')
    groups.add(name='C')

    users = UserCollection(session)
    user_a = users.add('*****@*****.**', 'pw', 'editor', group=group_a)
    user_b = users.add('*****@*****.**', 'pw', 'editor', group=group_a)
    user_c = users.add('*****@*****.**', 'pw', 'admin')
    user_d = users.add('*****@*****.**', 'pw', 'publisher')
    user_e = users.add('*****@*****.**', 'pw', 'publisher', group=group_b)
    user_f = users.add('*****@*****.**', 'pw', 'publisher')
    user_g = users.add('*****@*****.**', 'pw', 'publisher')
    user_h = users.add('*****@*****.**', 'pw', 'publisher')

    for user, count in (
        (user_a, 2),
        (user_b, 4),
        (user_c, 1),
        (user_d, 7),
        (user_e, 2),
        (user_f, 3),
        (user_g, 6),
        (user_h, 2),
    ):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id='',
                           category_id='',
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=user)
    assert collection.count_by_group() == [('A', 7), ('B', 1)]

    assert collection.count_by_group() == \
        collection.for_state('drafted').count_by_group()

    collection.issues = ['2017-2', '2017-4']
    assert collection.count_by_group() == [('A', 1)]
Ejemplo n.º 4
0
def test_notice_collection_count_by_category(session):
    collection = GazetteNoticeCollection(session)
    assert collection.count_by_category() == []

    categories = CategoryCollection(session)
    categories.add_root(name='1', title='A')
    categories.add_root(name='2', title='B')
    categories.add_root(name='3', title='C')
    for category, count in (('1', 2), ('2', 4), ('3', 1)):
        for x in range(count):
            collection.add(title='',
                           text='',
                           organization_id=None,
                           category_id=category,
                           issues=['2017-{}'.format(y) for y in range(x)],
                           user=None)
    assert collection.count_by_category() == [('A', 1), ('B', 6)]

    assert collection.count_by_category() == \
        collection.for_state('drafted').count_by_category()

    collection.issues = ['2017-0', '2017-2']
    assert collection.count_by_category() == [('A', 1), ('B', 4)]