Beispiel #1
0
    def apply_transition(self, request, *args, **kwargs):
        """ Applies a specific transition and redirects the user to the success URL. """
        self.object = self.get_object()
        success_url = self.get_success_url()

        old_status = self.object.status

        # Applies the transition
        transition = getattr(self.object, self.transition_name)
        transition()
        self.object.save()

        # Saves a potential comment if applicable
        if self.use_comment_form:
            form = IssueSubmissionTransitionCommentForm(data=request.POST)
            comment = form.cleaned_data.get('comment', None) if form.is_valid() else None
            if comment:
                track = self.object.last_status_track
                track.comment = comment
                track.save()

        # Capture a metric when the status changes
        if self.object.status != old_status:
            metric(
                'erudit__issuesubmission__change_status',
                tags={'old_status': old_status, 'new_status': self.object.status},
                author_id=self.request.user.id, submission_id=self.object.id)

        # Send a signal in order to notify the update of the issue submission's status
        self.transition_signal.send(
            sender=self, issue_submission=self.object, transition_name=self.transition_name,
            request=request)

        return HttpResponseRedirect(success_url)
 def dispatch(self, request, *args, **kwargs):
     self.request = request
     response = super(ArticleViewMetricCaptureMixin, self).dispatch(request, *args, **kwargs)
     if response.status_code == 200 and self.article_access_granted:
         # We register this metric only if the article can be viewed
         metric(
             self.tracking_article_view_granted_metric_name,
             tags=self.get_metric_tags(), **self.get_metric_fields())
     return response
 def test_can_increment_a_simple_metric(self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     # Run
     metric('test__metric')
     # Check
     global _test_points
     self.assertEqual(
         _test_points, [{'tags': {}, 'fields': {'num': 1}, 'measurement': 'test__metric'}])
Beispiel #4
0
 def get_redirect_url(self, *args, **kwargs):
     obj = get_object_or_404(
         self.model.objects.filter(external_url__isnull=False),
         localidentifier=kwargs['localidentifier'])
     # Tracks the redirection
     metric(
         'erudit__journal__{0}_redirect'.format(self.model._meta.model_name.lower()),
         tags={'collection': self.get_collection(obj).code, },
         **{'localidentifier': obj.localidentifier, })
     return obj.external_url
Beispiel #5
0
 def dispatch(self, request, *args, **kwargs):
     self.request = request
     response = super(ArticleViewMetricCaptureMixin,
                      self).dispatch(request, *args, **kwargs)
     if response.status_code == 200 and self.article_access_granted:
         # We register this metric only if the article can be viewed
         metric(self.tracking_article_view_granted_metric_name,
                tags=self.get_metric_tags(),
                **self.get_metric_fields())
     return response
Beispiel #6
0
 def test_do_nothing_if_the_metrics_capturing_is_deactivated(
         self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     metrics_settings.ACTIVATED = False
     # Run
     metric('test__metric')
     # Check
     global _test_points
     self.assertFalse(len(_test_points))
     metrics_settings.ACTIVATED = True
 def test_do_nothing_if_the_metrics_capturing_is_deactivated(
         self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     metrics_settings.ACTIVATED = False
     # Run
     metric('test__metric')
     # Check
     global _test_points
     self.assertFalse(len(_test_points))
     metrics_settings.ACTIVATED = True
Beispiel #8
0
 def test_can_increment_a_simple_metric_by_a_specific_number(
         self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     # Run
     metric('test__metric', num=4)
     # Check
     global _test_points
     self.assertEqual(_test_points, [{
         'tags': {},
         'fields': {
             'num': 4
         },
         'measurement': 'test__metric'
     }])
Beispiel #9
0
 def test_can_increment_a_simple_metric_by_specifying_a_specific_time(
         self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     nowd = dt.datetime.now()
     # Run
     metric('test__metric', time=nowd)
     # Check
     global _test_points
     self.assertEqual(_test_points, [{
         'tags': {},
         'fields': {
             'num': 1
         },
         'measurement': 'test__metric',
         'time': nowd,
     }])
 def test_can_increment_a_simple_metric_by_specifying_a_specific_time(
         self, mock_write_points, mock_list_db, mock_create_db):
     # Setup
     mock_write_points.side_effect = fake_write_points
     nowd = dt.datetime.now()
     # Run
     metric('test__metric', time=nowd)
     # Check
     global _test_points
     self.assertEqual(
         _test_points,
         [{
             'tags': {},
             'fields': {'num': 1},
             'measurement': 'test__metric',
             'time': nowd,
         }])
Beispiel #11
0
    def apply_transition(self, request, *args, **kwargs):
        """ Applies a specific transition and redirects the user to the success URL. """
        self.object = self.get_object()
        success_url = self.get_success_url()

        old_status = self.object.status

        # Applies the transition
        transition = getattr(self.object, self.transition_name)
        transition()
        self.object.save()

        # Saves a potential comment if applicable
        if self.use_comment_form:
            form = IssueSubmissionTransitionCommentForm(data=request.POST)
            comment = form.cleaned_data.get('comment', None) if form.is_valid() else None
            if comment:
                track = self.object.last_status_track
                track.comment = comment
                track.save()

        # Capture a metric when the status changes
        if self.object.status != old_status:
            metric(
                'erudit__issuesubmission__change_status',
                tags={'old_status': old_status, 'new_status': self.object.status},
                author_id=self.request.user.id, submission_id=self.object.id)

        logger.debug(
            '{old_status} -> {new_status}'.format(
                old_status=old_status,
                new_status=self.object.status
            ),
            extra=self.get_context_info()
        )
        # Send a signal in order to notify the update of the issue submission's status
        self.transition_signal.send(
            sender=self, issue_submission=self.object, transition_name=self.transition_name,
            request=request)

        return HttpResponseRedirect(success_url)
Beispiel #12
0
 def test_do_not_raise_in_case_of_connection_error(self):
     # Run
     metric('test__metric')
     # Check
     global _test_points
     self.assertFalse(len(_test_points))
Beispiel #13
0
 def form_valid(self, form):
     result = super().form_valid(form)
     metric(
         'erudit__issuesubmission__create',
         author_id=self.request.user.id, submission_id=form.instance.id)
     return result
 def test_do_not_raise_in_case_of_connection_error(self):
     # Run
     metric('test__metric')
     # Check
     global _test_points
     self.assertFalse(len(_test_points))
Beispiel #15
0
 def form_valid(self, form):
     result = super().form_valid(form)
     metric(
         'erudit__issuesubmission__create',
         author_id=self.request.user.id, submission_id=form.instance.id)
     return result