Beispiel #1
0
 def test_selection_privileged_user(self):
     """User is admin and they selected "not assigned to anyone". Actually
     for privileged user any selection should make through."""
     request = self.factory.get('/', {'assigned_to': 'noone'})
     request.user = self.admin
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'noone')
     self.assertTrue(is_admin)
Beispiel #2
0
 def test_no_selection_normal_user(self):
     """User is normal user and they selected nothing. The result should be
     default value for this kind of a user."""
     request = self.factory.get('/')
     request.user = self.normal_user
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'all')
     self.assertFalse(is_admin)
Beispiel #3
0
 def test_selection_privileged_user(self):
     """User is admin and they selected "not assigned to anyone". Actually
     for privileged user any selection should make through."""
     request = self.factory.get('/', {'assigned_to': 'noone'})
     request.user = self.admin
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'noone')
     self.assertTrue(is_admin)
Beispiel #4
0
 def test_no_selection_admin(self):
     """User is admin and they selected nothing. The result should be
     default value for this kind of a user."""
     request = self.factory.get('/')
     request.user = self.admin
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'me')
     self.assertTrue(is_admin)
Beispiel #5
0
 def test_no_selection_normal_user(self):
     """User is normal user and they selected nothing. The result should be
     default value for this kind of a user."""
     request = self.factory.get('/')
     request.user = self.normal_user
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'all')
     self.assertFalse(is_admin)
Beispiel #6
0
 def test_no_selection_admin(self):
     """User is admin and they selected nothing. The result should be
     default value for this kind of a user."""
     request = self.factory.get('/')
     request.user = self.admin
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'me')
     self.assertTrue(is_admin)
Beispiel #7
0
 def test_selection_normal_user(self):
     """User is normal user and they selected self-assigned. This is invalid
     selection (normal user cannot select anything), so the default option
     should be returned."""
     request = self.factory.get('/', {'assigned_to': 'me'})
     request.user = self.normal_user
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'all')
     self.assertFalse(is_admin)
Beispiel #8
0
 def test_selection_normal_user(self):
     """User is normal user and they selected self-assigned. This is invalid
     selection (normal user cannot select anything), so the default option
     should be returned."""
     request = self.factory.get('/', {'assigned_to': 'me'})
     request.user = self.normal_user
     assignment, is_admin = assignment_selection(request)
     self.assertEqual(assignment, 'all')
     self.assertFalse(is_admin)
Beispiel #9
0
def admin_dashboard(request):
    """Home page for admins."""

    current_events = (
        Event.objects.upcoming_events()
        | Event.objects.ongoing_events()).active().prefetch_related('tags')

    # This annotation may produce wrong number of instructors when
    # `unpublished_events` filters out events that contain a specific tag.
    # The bug was fixed in #1130.
    unpublished_events = Event.objects \
        .active().unpublished_events().select_related('host').annotate(
            num_instructors=Count(
                Case(
                    When(task__role__name='instructor', then=Value(1)),
                    output_field=IntegerField()
                )
            ),
        )

    assigned_to, is_admin = assignment_selection(request)

    if assigned_to == 'me':
        current_events = current_events.filter(assigned_to=request.user)
        unpublished_events = unpublished_events.filter(
            assigned_to=request.user)

    elif assigned_to == 'noone':
        current_events = current_events.filter(assigned_to__isnull=True)
        unpublished_events = unpublished_events.filter(
            assigned_to__isnull=True)

    elif assigned_to == 'all':
        # no filtering
        pass

    else:
        # no filtering
        pass

    # assigned events that have unaccepted changes
    updated_metadata = Event.objects.active() \
                                    .filter(assigned_to=request.user) \
                                    .filter(metadata_changed=True) \
                                    .count()

    context = {
        'title': None,
        'is_admin': is_admin,
        'assigned_to': assigned_to,
        'current_events': current_events,
        'unpublished_events': unpublished_events,
        'updated_metadata': updated_metadata,
        'main_tags': Tag.objects.main_tags(),
    }
    return render(request, 'dashboard/admin_dashboard.html', context)
Beispiel #10
0
def admin_dashboard(request):
    """Home page for admins."""

    current_events = (
        Event.objects.upcoming_events() | Event.objects.ongoing_events()
    ).active().prefetch_related('tags')

    # This annotation may produce wrong number of instructors when
    # `unpublished_events` filters out events that contain a specific tag.
    # The bug was fixed in #1130.
    unpublished_events = Event.objects \
        .active().unpublished_events().select_related('host').annotate(
            num_instructors=Count(
                Case(
                    When(task__role__name='instructor', then=Value(1)),
                    output_field=IntegerField()
                )
            ),
        )

    assigned_to, is_admin = assignment_selection(request)

    if assigned_to == 'me':
        current_events = current_events.filter(assigned_to=request.user)
        unpublished_events = unpublished_events.filter(
            assigned_to=request.user)

    elif assigned_to == 'noone':
        current_events = current_events.filter(assigned_to__isnull=True)
        unpublished_events = unpublished_events.filter(
            assigned_to__isnull=True)

    elif assigned_to == 'all':
        # no filtering
        pass

    else:
        # no filtering
        pass

    # assigned events that have unaccepted changes
    updated_metadata = Event.objects.active() \
                                    .filter(assigned_to=request.user) \
                                    .filter(metadata_changed=True) \
                                    .count()

    context = {
        'title': None,
        'is_admin': is_admin,
        'assigned_to': assigned_to,
        'current_events': current_events,
        'unpublished_events': unpublished_events,
        'updated_metadata': updated_metadata,
        'main_tags': Tag.objects.main_tags(),
    }
    return render(request, 'dashboard/admin_dashboard.html', context)
Beispiel #11
0
def workshop_issues(request):
    '''Display workshops in the database whose records need attention.'''

    events = Event.objects.active().past_events().annotate(
        num_instructors=Count(
            Case(
                When(
                    task__role__name='instructor',
                    then=Value(1)
                ),
                output_field=IntegerField()
            )
        )
    ).attendance()

    no_attendance = Q(attendance=None) | Q(attendance=0)
    no_location = (Q(country=None) |
                   Q(venue=None) | Q(venue__exact='') |
                   Q(address=None) | Q(address__exact='') |
                   Q(latitude=None) | Q(longitude=None))
    bad_dates = Q(start__gt=F('end'))

    events = events.filter(
        (no_attendance & ~Q(tags__name='unresponsive')) |
        no_location |
        bad_dates |
        Q(num_instructors=0)
    ).prefetch_related('task_set', 'task_set__person')

    events = events.prefetch_related(Prefetch(
        'task_set',
        to_attr='contacts',
        queryset=Task.objects.select_related('person').filter(
            # we only want hosts, organizers and instructors
            Q(role__name='host') | Q(role__name='organizer') |
            Q(role__name='instructor')
        ).filter(person__may_contact=True)
        .exclude(Q(person__email='') | Q(person__email=None))
    ))

    assigned_to, is_admin = assignment_selection(request)

    if assigned_to == 'me':
        events = events.filter(assigned_to=request.user)

    elif assigned_to == 'noone':
        events = events.filter(assigned_to=None)

    elif assigned_to == 'all':
        # no filtering
        pass

    else:
        # no filtering
        pass

    events = events.annotate(
        missing_attendance=Case(
            When(no_attendance, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
        missing_location=Case(
            When(no_location, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
        bad_dates=Case(
            When(bad_dates, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
    )

    context = {
        'title': 'Workshops with Issues',
        'events': events,
        'is_admin': is_admin,
        'assigned_to': assigned_to,
    }
    return render(request, 'reports/workshop_issues.html', context)
Beispiel #12
0
def workshop_issues(request):
    '''Display workshops in the database whose records need attention.'''

    events = Event.objects.active().past_events().annotate(
        num_instructors=Count(
            Case(
                When(
                    task__role__name='instructor',
                    then=Value(1)
                ),
                output_field=IntegerField()
            )
        )
    ).attendance().order_by('-start')

    no_attendance = Q(attendance=None) | Q(attendance=0)
    no_location = (Q(country=None) |
                   Q(venue=None) | Q(venue__exact='') |
                   Q(address=None) | Q(address__exact='') |
                   Q(latitude=None) | Q(longitude=None))
    bad_dates = Q(start__gt=F('end'))

    events = events.filter(
        (no_attendance & ~Q(tags__name='unresponsive')) |
        no_location |
        bad_dates |
        Q(num_instructors=0)
    ).prefetch_related('task_set', 'task_set__person')

    events = events.prefetch_related(Prefetch(
        'task_set',
        to_attr='contacts',
        queryset=Task.objects.select_related('person').filter(
            # we only want hosts, organizers and instructors
            Q(role__name='host') | Q(role__name='organizer') |
            Q(role__name='instructor')
        ).filter(person__may_contact=True)
        .exclude(Q(person__email='') | Q(person__email=None))
    ))

    assigned_to, is_admin = assignment_selection(request)

    if assigned_to == 'me':
        events = events.filter(assigned_to=request.user)

    elif assigned_to == 'noone':
        events = events.filter(assigned_to=None)

    elif assigned_to == 'all':
        # no filtering
        pass

    else:
        # no filtering
        pass

    events = events.annotate(
        missing_attendance=Case(
            When(no_attendance, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
        missing_location=Case(
            When(no_location, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
        bad_dates=Case(
            When(bad_dates, then=Value(1)),
            default=Value(0),
            output_field=IntegerField(),
        ),
    )

    context = {
        'title': 'Workshops with Issues',
        'events': events,
        'is_admin': is_admin,
        'assigned_to': assigned_to,
    }
    return render(request, 'reports/workshop_issues.html', context)