def test_headers_col2_asc(self):
     """
     If the second column is sorted asc, set it up to be sorted desc.
     """
     request = Mock(GET=QueryDict('ot=asc&o=1'))
     sort_headers = SortHeaders(request, self.header_list)
     headers = list(sort_headers.headers())
     eq_(
         headers[0], {
             'url': '&ot=asc&o=0',
             'text': 'Title 1',
             'class_attr': {
                 'class': 'orderable'
             },
             'sortable': True
         })
     eq_(
         headers[1], {
             'url': '&ot=desc&o=1',
             'text': 'Title 2',
             'class_attr': {
                 'class': 'orderable sorted asc'
             },
             'sortable': True
         })
 def test_get_order_by_default(self):
     """
     Default order by is first field ascending.
     """
     request = Mock(GET=QueryDict(''))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), 'field_1')
 def test_headers_default(self):
     """
     If no related query params exist, the first column is sorted ascending.
     """
     request = Mock(GET=QueryDict(''))
     sort_headers = SortHeaders(request, self.header_list)
     headers = list(sort_headers.headers())
     eq_(
         headers[0], {
             'url': '&ot=desc&o=0',
             'text': 'Title 1',
             'class_attr': {
                 'class': 'orderable sorted asc'
             },
             'sortable': True
         })
     eq_(
         headers[1], {
             'url': '&ot=asc&o=1',
             'text': 'Title 2',
             'class_attr': {
                 'class': 'orderable'
             },
             'sortable': True
         })
 def test_get_order_by_default(self):
     """
     Default order by is first field ascending.
     """
     request = Mock(GET=QueryDict(''))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), 'field_1')
 def test_get_order_by_col1_desc(self):
     """
     If first field descending is selected, return first field name
     with a minus sign.
     """
     request = Mock(GET=QueryDict('ot=desc&o=0'))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), '-field_1')
 def test_get_order_by_col2_asc(self):
     """
     If second field ascending is selected, return second field name
     without a minus sign.
     """
     request = Mock(GET=QueryDict('ot=asc&o=1'))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), 'field_2')
 def test_get_order_by_col2_asc(self):
     """
     If second field ascending is selected, return second field name
     without a minus sign.
     """
     request = Mock(GET=QueryDict('ot=asc&o=1'))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), 'field_2')
 def test_get_order_by_col1_desc(self):
     """
     If first field descending is selected, return first field name
     with a minus sign.
     """
     request = Mock(GET=QueryDict('ot=desc&o=0'))
     sort_headers = SortHeaders(request, self.header_list)
     eq_(sort_headers.get_order_by(), '-field_1')
Exemple #9
0
 def get_queryset(self):
     self.sort_headers = SortHeaders(self.request, self.list_headers)
     qs = TaskAttempt.objects.extra(
         select={
             'state_display': TaskAttempt.choice_display_extra_expression('state'),
             'elapsed_time':
                 'EXTRACT(EPOCH FROM (tasks_taskattempt.modified - tasks_taskattempt.created))'
         })
     return qs.order_by(self.sort_headers.get_order_by())
Exemple #10
0
 def get_queryset(self):
     self.sort_headers = SortHeaders(self.request, self.list_headers)
     qs = TaskAttempt.objects.extra(
         select={
             'state_display':
             TaskAttempt.choice_display_extra_expression('state'),
             'elapsed_time':
             'TIMESTAMPDIFF(SECOND, tasks_taskattempt.created, tasks_taskattempt.modified)'
         })
     return qs.order_by(self.sort_headers.get_order_by())
Exemple #11
0
class ActivityView(LoginRequiredMixin, MyStaffUserRequiredMixin, FilterView):
    list_headers = (
        (_lazy(u'Task'), 'task__name'),
        (_lazy(u'User'), 'user__profile__name'),
        (_lazy(u'Status'), 'state_display'),
        (_lazy(u'Time'), 'elapsed_time'),
    )
    context_object_name = 'attempts'
    template_name = 'tasks/activity.html'
    paginate_by = 20
    filterset_class = ActivityFilterSet

    def get_context_data(self, *args, **kwargs):
        ctx = super(ActivityView, self).get_context_data(*args, **kwargs)
        ctx['headers'] = self.sort_headers
        return ctx

    def get_queryset(self):
        self.sort_headers = SortHeaders(self.request, self.list_headers)
        qs = TaskAttempt.objects.extra(
            select={
                'state_display':
                TaskAttempt.choice_display_extra_expression('state'),
                'elapsed_time':
                'TIMESTAMPDIFF(SECOND, tasks_taskattempt.created, tasks_taskattempt.modified)'
            })
        return qs.order_by(self.sort_headers.get_order_by())
Exemple #12
0
class ActivityView(LoginRequiredMixin, MyStaffUserRequiredMixin, FilterView):
    list_headers = (
        (_lazy(u"Task"), "task__name"),
        (_lazy(u"User"), "user__profile__name"),
        (_lazy(u"Status"), "state_display"),
        (_lazy(u"Time"), "elapsed_time"),
    )
    context_object_name = "attempts"
    template_name = "tasks/activity.html"
    paginate_by = 20
    filterset_class = ActivityFilterSet

    def get_context_data(self, *args, **kwargs):
        ctx = super(ActivityView, self).get_context_data(*args, **kwargs)
        ctx["headers"] = self.sort_headers
        return ctx

    def get_queryset(self):
        self.sort_headers = SortHeaders(self.request, self.list_headers)
        qs = TaskAttempt.objects.extra(
            select={
                "state_display": TaskAttempt.choice_display_extra_expression("state"),
                "elapsed_time": "EXTRACT(EPOCH FROM (tasks_taskattempt.modified - tasks_taskattempt.created))",
            }
        )
        return qs.order_by(self.sort_headers.get_order_by())
Exemple #13
0
class ActivityView(LoginRequiredMixin, MyStaffUserRequiredMixin, FilterView):
    list_headers = (
        (_lazy(u'Task'), 'task__name'),
        (_lazy(u'User'), 'user__profile__name'),
        (_lazy(u'Status'), 'state_display'),
        (_lazy(u'Time'), 'elapsed_time'),
    )
    context_object_name = 'attempts'
    template_name = 'tasks/activity.html'
    paginate_by = 20
    filterset_class = ActivityFilterSet

    def get_context_data(self, *args, **kwargs):
        ctx = super(ActivityView, self).get_context_data(*args, **kwargs)
        ctx['headers'] = self.sort_headers
        return ctx

    def get_queryset(self):
        self.sort_headers = SortHeaders(self.request, self.list_headers)
        qs = TaskAttempt.objects.extra(
            select={
                'state_display': TaskAttempt.choice_display_extra_expression('state'),
                'elapsed_time': 'TIMESTAMPDIFF(SECOND, tasks_taskattempt.created, tasks_taskattempt.modified)'
            })
        return qs.order_by(self.sort_headers.get_order_by())
Exemple #14
0
class MetricsView(LoginRequiredMixin, MyStaffUserRequiredMixin, generic.ListView):
    list_headers = (
        (_lazy(u'Task'), 'task__name'),
        (_lazy(u'Users Completed'), 'completed_users',
         _lazy(u'Number of unique users who completed the task')),
        (_lazy(u'Users Abandoned'), 'abandoned_users',
         _lazy(u'Number of unique users who explicitly abandoned the task')),
        (_lazy(u'Users Did Not Complete'), 'incomplete_users',
         _lazy(u'Number of unique users who took but never completed the task')),
        (_lazy(u'Moves on to Another'), 'user_completes_then_takes_another_count',
         _lazy(u'Number of times the task was completed and the the same user takes another task')),
        (_lazy(u'Takes No Further Tasks'), 'user_takes_then_quits_count',
         _lazy(u'Number of times the task was taken and then the same user takes no further tasks')),
    )
    context_object_name = 'metrics'
    template_name = 'tasks/metrics.html'
    paginate_by = 20

    def get_context_data(self, *args, **kwargs):
        ctx = super(MetricsView, self).get_context_data(*args, **kwargs)
        ctx['headers'] = self.sort_headers
        return ctx

    def get_queryset(self):
        self.sort_headers = SortHeaders(self.request, self.list_headers,
                                        default_order_field=1,
                                        default_order_type='desc')
        qs = TaskMetrics.objects.all()
        return qs.order_by(self.sort_headers.get_order_by())
Exemple #15
0
 def get_queryset(self):
     self.sort_headers = SortHeaders(self.request, self.list_headers)
     qs = TaskAttempt.objects.extra(
         select={
             'state_display': TaskAttempt.choice_display_extra_expression('state'),
             'elapsed_time': 'TIMESTAMPDIFF(SECOND, tasks_taskattempt.created, tasks_taskattempt.modified)'
         })
     return qs.order_by(self.sort_headers.get_order_by())
 def test_headers_col2_asc(self):
     """
     If the second column is sorted asc, set it up to be sorted desc.
     """
     request = Mock(GET=QueryDict('ot=asc&o=1'))
     sort_headers = SortHeaders(request, self.header_list)
     headers = list(sort_headers.headers())
     eq_(headers[0], {
         'url': '&ot=asc&o=0',
         'text': 'Title 1',
         'class_attr': {'class': 'orderable'},
         'sortable': True})
     eq_(headers[1], {
         'url': '&ot=desc&o=1',
         'text': 'Title 2',
         'class_attr': {'class': 'orderable sorted asc'},
         'sortable': True})
 def test_headers_default(self):
     """
     If no related query params exist, the first column is sorted ascending.
     """
     request = Mock(GET=QueryDict(''))
     sort_headers = SortHeaders(request, self.header_list)
     headers = list(sort_headers.headers())
     eq_(headers[0], {
         'url': '&ot=desc&o=0',
         'text': 'Title 1',
         'class_attr': {'class': 'orderable sorted asc'},
         'sortable': True})
     eq_(headers[1], {
         'url': '&ot=asc&o=1',
         'text': 'Title 2',
         'class_attr': {'class': 'orderable'},
         'sortable': True})
Exemple #18
0
 def get_queryset(self):
     self.sort_headers = SortHeaders(self.request, self.list_headers)
     qs = TaskAttempt.objects.extra(
         select={
             'state_display': TaskAttempt.choice_display_extra_expression('state'),
             'elapsed_time': 'EXTRACT(EPOCH FROM (tasks_taskattempt.modified - tasks_taskattempt.created))'
         })
     return qs.order_by(self.sort_headers.get_order_by())
Exemple #19
0
 def get_queryset(self):
     self.sort_headers = SortHeaders(self.request, self.list_headers,
                                     default_order_field=1,
                                     default_order_type='desc')
     qs = TaskMetrics.objects.all()
     return qs.order_by(self.sort_headers.get_order_by())