Beispiel #1
0
 def add_arguments(self, parser):
     parser.add_argument("filename",
                         nargs="+",
                         help="Excel file(s) to import")
     parser.add_argument("--global",
                         action="store_true",
                         help="Coverage is global")
     parser.add_argument(
         "--region",
         action="store",
         dest="region",
         help="Import historical data for a region. One of: {}".format(
             ", ".join(sorted(REGION_COUNTRY_MAP.keys()))),
     )
     parser.add_argument(
         "--country",
         action="store",
         dest="country",
         help="Import historical data for a country. One of: {}".format(
             ", ".join(sorted(c[0] for c in get_countries()))),
     )
     parser.add_argument(
         "--year",
         action="store",
         dest="year",
         help=
         "Historical GMMP year the Excel file(s) belongs to. One of:  2010, 2015",
     )
Beispiel #2
0
class CountryForm(forms.Form):
    # Only show countries for which data has been submitted
    COUNTRIES = get_countries()

    country = forms.ChoiceField(label='Country', choices=COUNTRIES)

    def filter_countries(self):
        if self.cleaned_data['country'] == 'ALL':
            return get_countries()
        else:
            return [(code, country) for code, country in get_countries()
                    if code == self.cleaned_data['country']]
Beispiel #3
0
    def handle(self, *args, **options):
        historical = Historical()
        coverage = None
        region = None
        country = None
        year = options["year"] or settings.REPORTS_HISTORICAL_YEAR
        filenames = options["filename"]

        if year not in ["2010", "2015"]:
            raise ValueError("Invalid historical GMMP year: {}".format(year))

        if options["global"]:
            coverage = "global"
        elif options["region"]:
            coverage = "region"
            region = options["region"]
            if region not in REGION_COUNTRY_MAP:
                raise ValueError("Unknown region: %s" % region)
        elif options["country"]:
            coverage = "country"
            country = options["country"]
            countries = {c: n for c, n in get_countries()}
            if not country.upper() in countries:
                for code, name in countries.items():
                    if name.upper() == country:
                        country = code
                        break
                if not country in countries:
                    raise ValueError("Unknown country: %s" % country)
        else:
            raise CommandError("Must specify --global or --region")

        for fname in filenames:
            historical.import_from_file(fname,
                                        coverage,
                                        region=region,
                                        country=country,
                                        year=year)

        historical.save()
Beispiel #4
0
    def handle(self, *args, **options):
        historical = Historical()
        coverage = None
        region = None
        country = None

        if options['global']:
            coverage = 'global'
        elif options['region']:
            coverage = 'region'
            region = options['region']

            if region not in REGION_COUNTRY_MAP:
                raise ValueError("Unknown region: %s" % region)

        elif options['country']:
            coverage = 'country'
            country = options['country']

            countries = {c: n for c, n in get_countries()}

            if not country.upper() in countries:
                for code, name in countries.items():
                    if name.upper() == country:
                        country = code
                        break

                if not country in countries:
                    raise ValueError("Unknown country: %s" % country)

        else:
            raise CommandError("Must specify --global or --region")

        for fname in args:
            historical.import_from_file(fname, coverage, region=region, country=country)

        historical.save()
    def handle(self, *args, **options):
        historical = Historical()
        coverage = None
        region = None
        country = None

        if options['global']:
            coverage = 'global'
        elif options['region']:
            coverage = 'region'
            region = options['region']

            if region not in REGION_COUNTRY_MAP:
                raise ValueError("Unknown region: %s" % region)

        elif options['country']:
            coverage = 'country'
            country = options['country']

            countries = {c: n for c, n in get_countries()}

            if not country.upper() in countries:
                for code, name in countries.iteritems():
                    if name.upper() == country:
                        country = code
                        break

                if not country in countries:
                    raise ValueError("Unknown country: %s" % country)

        else:
            raise CommandError("Must specify --global or --region")

        for fname in args:
            historical.import_from_file(fname, coverage, region=region, country=country)

        historical.save()
Beispiel #6
0
 def filter_countries(self):
     if self.cleaned_data['country'] == 'ALL':
         return get_countries()
     else:
         return [(code, country) for code, country in get_countries() if code == self.cleaned_data['country']]
Beispiel #7
0
class Command(BaseCommand):
    help = 'Import historical GMMP data from an XLSX file'
    option_list = BaseCommand.option_list + (
        make_option('--global',
            action='store_true',
            help='Coverage is global'),
        make_option('--region REGION',
            action='store',
            dest='region',
            help='Import historical data for a region. One of: %s' % ', '.join(sorted(REGION_COUNTRY_MAP.keys()))),
        make_option('--country COUNTRY',
            action='store',
            dest='country',
            help='Import historical data for a country. One of: %s' % ', '.join(sorted(c[0] for c in get_countries()))),
    )

    def handle(self, *args, **options):
        historical = Historical()
        coverage = None
        region = None
        country = None

        if options['global']:
            coverage = 'global'
        elif options['region']:
            coverage = 'region'
            region = options['region']

            if region not in REGION_COUNTRY_MAP:
                raise ValueError("Unknown region: %s" % region)

        elif options['country']:
            coverage = 'country'
            country = options['country']

            countries = {c: n for c, n in get_countries()}

            if not country.upper() in countries:
                for code, name in countries.items():
                    if name.upper() == country:
                        country = code
                        break

                if not country in countries:
                    raise ValueError("Unknown country: %s" % country)

        else:
            raise CommandError("Must specify --global or --region")

        for fname in args:
            historical.import_from_file(fname, coverage, region=region, country=country)

        historical.save()
Beispiel #8
0
 def filter_countries(self):
     if self.cleaned_data['country'] == 'ALL':
         return get_countries()
     else:
         return [(code, country) for code, country in get_countries()
                 if code == self.cleaned_data['country']]
Beispiel #9
0
 def get_form_countries(self):
     return get_countries()