• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

akvo / akvo-rsr / 36d6dc01-6726-4ee7-a9dd-ce35c506949e

pending completion
36d6dc01-6726-4ee7-a9dd-ce35c506949e

push

semaphore-ci

web-flow
Merge pull request #5298 from akvo/cleanup-rest-endpoints

Cleanup REST endpoints

34 of 34 new or added lines in 11 files covered. (100.0%)

17025 of 25071 relevant lines covered (67.91%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.47
/akvo/rsr/models/country.py
1
# -*- coding: utf-8 -*-
2

3
# Akvo RSR is covered by the GNU Affero General Public License.
4
# See more details in the license.txt file located at the root folder of the Akvo RSR module.
5
# For additional details on the GNU license please see < http://www.gnu.org/licenses/agpl.html >.
6

7

8
from django.db import models
1✔
9
from django.core.validators import MaxValueValidator, MinValueValidator
1✔
10
from django.utils.translation import ugettext_lazy as _
1✔
11

12
from ..fields import ValidXMLCharField
1✔
13
from ..iso3166 import ISO_3166_COUNTRIES, CONTINENTS, COUNTRY_CONTINENTS
1✔
14

15
from akvo.codelists import models as codelist_models
1✔
16
from akvo.codelists.store.default_codelists import COUNTRY
1✔
17
from akvo.utils import codelist_choices, codelist_value
1✔
18

19

20
class Country(models.Model):
1✔
21
    name = ValidXMLCharField(_('country name'), max_length=50, unique=True, db_index=True)
1✔
22
    iso_code = ValidXMLCharField(
1✔
23
        _('ISO 3166 code'), max_length=2, unique=True, db_index=True, choices=ISO_3166_COUNTRIES
24
    )
25
    continent = ValidXMLCharField(_('continent name'), max_length=20, db_index=True)
1✔
26
    continent_code = ValidXMLCharField(
1✔
27
        _('continent code'), max_length=2, db_index=True, choices=CONTINENTS
28
    )
29

30
    def __str__(self):
31
        return self.name
32

33
    @classmethod
1✔
34
    def fields_from_iso_code(cls, iso_code):
1✔
35
        continent_code = COUNTRY_CONTINENTS[iso_code]
×
36
        name = dict(ISO_3166_COUNTRIES)[iso_code]
×
37
        continent = dict(CONTINENTS)[continent_code]
×
38
        return dict(
×
39
            iso_code=iso_code, name=name, continent=continent, continent_code=continent_code
40
        )
41

42
    class Meta:
1✔
43
        app_label = 'rsr'
1✔
44
        verbose_name = _('country')
1✔
45
        verbose_name_plural = _('countries')
1✔
46
        ordering = ['name']
1✔
47

48

49
class RecipientCountry(models.Model):
1✔
50
    project = models.ForeignKey(
1✔
51
        'Project', on_delete=models.CASCADE, verbose_name=_('project'), related_name='recipient_countries'
52
    )
53
    country = ValidXMLCharField(
1✔
54
        _('recipient country'), blank=True, max_length=2, choices=codelist_choices(COUNTRY, show_code=False),
55
        help_text=_('The country that benefits from the project.')
56
    )
57
    percentage = models.DecimalField(
1✔
58
        _('recipient country percentage'), blank=True, null=True, max_digits=4, decimal_places=1,
59
        validators=[MaxValueValidator(100), MinValueValidator(0)],
60
        help_text=_('The percentage of total commitments or total activity budget allocated to '
61
                    'this country. Content must be a positive decimal number between 0 and 100, '
62
                    'with no percentage sign. Percentages for all reported countries and regions '
63
                    'MUST add up to 100%. Use a period to denote decimals.')
64
    )
65
    text = ValidXMLCharField(
1✔
66
        _('recipient country description'), blank=True, max_length=50,
67
        help_text=_('Enter additional information about the recipient country, if necessary.')
68
    )
69

70
    def __str__(self):
71
        if self.country:
72
            try:
73
                country_unicode = self.iati_country().name
74
            except (AttributeError, codelist_models.Country.DoesNotExist):
75
                country_unicode = self.country
76
        else:
77
            country_unicode = '%s' % _('No country specified')
78

79
        if self.percentage:
80
            country_unicode += ' (%s%%)' % str(self.percentage)
81

82
        return country_unicode
83

84
    def iati_country(self):
1✔
85
        return codelist_value(codelist_models.Country, self, 'country')
1✔
86

87
    def iati_country_unicode(self):
1✔
88
        return str(self.iati_country())
1✔
89

90
    class Meta:
1✔
91
        app_label = 'rsr'
1✔
92
        verbose_name = _('recipient country')
1✔
93
        verbose_name_plural = _('recipient countries')
1✔
94
        ordering = ('-percentage', 'country')
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc