Beispiel #1
0
 def test_rating_without_parameters(self, rating_type):
     # WHEN function calls without parameters
     tasks, avg = rating(self.monitoring, rating_type=rating_type)
     # THEN function returns expected results
     self.assertEqual(avg['openness'], 83.75)
     self.assertEqual(avg['openness_initial'], 83.75)
     self.assertEqual(avg['openness_delta'], 0.0)
     self.assertEqual(avg['total_tasks'], len(self.tasks))
Beispiel #2
0
 def test_rating_with_parameters(self, rating_type):
     # WHEN function calls only for the first parameter
     parameters = [self.parameters[0].pk]
     tasks, avg = rating(self.monitoring, parameters, rating_type=rating_type)
     # THEN function returns expected results
     self.assertEqual(avg['openness'], 75.0)
     self.assertEqual(avg['openness_initial'], 75.0)
     self.assertEqual(avg['openness_delta'], 0.0)
     self.assertEqual(avg['total_tasks'], len(self.tasks))
     # WHEN function calls only for the second parameter
     parameters = [self.parameters[1].pk]
     tasks, avg = rating(self.monitoring, parameters, rating_type=rating_type)
     # THEN function returns expected results
     self.assertEqual(avg['openness'], 92.5)
     self.assertEqual(avg['openness_initial'], 92.5)
     self.assertEqual(avg['openness_delta'], 0.0)
     self.assertEqual(avg['total_tasks'], len(self.tasks))
Beispiel #3
0
 def test_rating_without_openness(self, parameters, rating_type):
     # WHEN function calls for parameter with negative weight
     parameters = [self.parameter.pk] if parameters else []
     tasks, avg = rating(self.monitoring2, parameters, rating_type=rating_type)
     # THEN function returns expected results
     self.assertEqual(avg['openness'], None)
     self.assertEqual(avg['openness_initial'], None)
     self.assertEqual(avg['openness_delta'], None)
     self.assertEqual(avg['total_tasks'], 0)
Beispiel #4
0
 def test_organizations_count(self):
     # WHEN function accepts monitoring and parameters data
     rating_list, avg = rating(self.monitoring, [self.parameter])
     text = _total_orgs_translate(avg, rating_list, '')
     # THEN expected text and organization count exist in returned text
     expected_text = ungettext(
     'Altogether, there is %(count)d organization in the monitoring cycle',
     'Altogether, there are %(count)d organizations in the monitoring cycle',
     avg['total_tasks']
     ) % {'count': 1}
     self.assertTrue(expected_text in text)
Beispiel #5
0
    def get_context_data(self, form, **kwargs):
        context = super(CertificateOrderView, self).get_context_data(form=form, **kwargs)
        first_step = self.steps.first
        request = self.request
        rating_type = request.GET.get('type', 'all')

        if self.steps.current == first_step:
            context_data = {}
            organizations = request.user.profile.organization.filter(monitoring__status=MONITORING_PUBLISHED)
            tasks = Task.objects.filter(organization__in=organizations, status=Task.TASK_APPROVED)

            if tasks.exists():
                has_npa = organizations.filter(monitoring__parameter__npa=True)

                name_filter = request.GET.get('name_filter')
                if name_filter:
                    tasks = tasks.filter(organization__name__icontains=name_filter)
                    has_npa = has_npa.filter(name__icontains=name_filter)

                if rating_type in ['npa', 'other']:
                    tasks = tasks.filter(organization__monitoring__parameter__npa=True).distinct()

                object_list = OrderedDict()

                for task in tasks:
                    monitoring = task.organization.monitoring
                    rating_type, parameter_list, form = _rating_type_parameter(request, monitoring, monitoring.has_npa)
                    rating_list, avg = rating(monitoring, parameters=parameter_list, rating_type=rating_type)
                    place = {t.pk: t.place for t in rating_list}.get(task.pk, None)

                    object_list[task.pk] = {
                        'openness': task.openness,
                        'org_name': task.organization.name,
                        'place': place,
                        'publish_date': task.organization.monitoring.publish_date,
                        'url': task.organization.url,
                    }

                context_data = {
                    'has_npa': has_npa,
                    'object_list': object_list,
                    'rating_type': rating_type,
                }

                self.storage.extra_data = {'object_list': object_list}

        else:
            by_type = {
                'all': _('by all'),
                'npa': _('by normative'),
                'other': _('by recommendatory'),
            }

            form_data = self.get_cleaned_data_for_step(first_step)
            task = self.storage.extra_data['object_list'].get(form_data['task_id'])

            description = _('For %(name)s organization, which took %(place)d place with %(openness).3f%% openness in '
                            'rating %(type)s parameters, which published %(date)s.') %\
                {
                    'name': task['org_name'],
                    'place': task['place'],
                    'openness': task['openness'],
                    'type': by_type[rating_type],
                    'date': dateformat.format(task['publish_date'], "j E Y"),
                }

            if form_data['delivery_method'] == "1":
                on_address = _('On address %(zip_code)s, %(address)s, %(for_whom)s.') % \
                    {
                        'zip_code': form_data['zip_code'],
                        'address': form_data['address'],
                        'for_whom': form_data['for_whom'],
                    }
            else:
                on_address = _('On email address %s.') % form_data['email']

                context_data = {
                    'description': description,
                    'on_address': on_address,
                    'special_wishes': form_data['wishes'],
                    'breadcrumbs': [{'url': reverse('exmo2010:index')},
                                    {'url': reverse('exmo2010:certificate_order'), 'title': _('Openness certificate')},
                                    {'title': _('Confirmation of a certificate ordering')}]
                }

            if form_data['certificate_for'] == "1":
                prepare_for = _('Prepare a certificate in the name of %s.') % form_data['name']
                context_data.update({'prepare_for': prepare_for})

        title = _('Openness certificate')

        if self.steps.current != first_step:
            self.storage.extra_data.update({'email_context': context_data})
            title = _('Confirmation of a certificate ordering')

        context_data.update({
            'title': title,
        })
        context.update(context_data)

        return context