Python django_countries.countries() Examples

The following are 11 code examples of django_countries.countries(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django_countries , or try the search function .
Example #1
Source File: base.py    From pasportaservo with GNU Affero General Public License v3.0 6 votes vote down vote up
def handle_label(self, country, **options):
        self.country = country.upper()
        if self.country == 'ALL':
            self.countries = sorted(set(
                Place.objects
                .filter(in_book=True, visibility__visible_in_book=True, checked=True)
                .values_list('country', flat=True)
            ))
            for country in self.countries[:8]:
                print(country)
                self.country = country
                self.make()
            return
        if self.country not in countries:
            raise CommandError("Unknown country: {}".format(self.country))
        self.make() 
Example #2
Source File: events.py    From coding-events with MIT License 6 votes vote down vote up
def list_pending_events(request, country_code):
    """
    Display a list of pending events.
    """

    active_page = request.GET.get('page', '')

    if request.user.is_staff:
        event_list = get_pending_events(past=True)
        event_list = sorted(event_list, key=lambda a: a.country.code)
    else:
        event_list = get_pending_events(country_code=country_code, past=True)

    country_name = unicode(dict(countries)[country_code])

    return render_to_response(
        'pages/list_events.html', {
            'event_list': event_list,
            'status': 'pending',
            'country_code': country_code,
            'country_name': country_name,
            'active_page': active_page
        }, context_instance=RequestContext(request)) 
Example #3
Source File: user.py    From coding-events with MIT License 6 votes vote down vote up
def get_ambassadors_for_countries():
    ambassadors = get_ambassadors()
    countries_ambassadors = []
    # list countries minus two CUSTOM_COUNTRY_ENTRIES
    for code, name in list(countries)[2:]:
        readable_name = unicode(name)
        country_ambassadors = [ambassador for ambassador in ambassadors if ambassador.country == code]
        # load main ambassadors
        main_ambassadors = [ambassador for ambassador in country_ambassadors if ambassador.is_main_contact]
        # exclude main ambassadors
        supporting_ambassadors = [ambassador for ambassador in country_ambassadors if not ambassador.is_main_contact]
        countries_ambassadors.append(
            (code, readable_name, supporting_ambassadors, main_ambassadors, facebook(readable_name)))

    countries_ambassadors.sort(key=lambda country: country[1], reverse=False)

    return countries_ambassadors 
Example #4
Source File: initial_data.py    From normandy with Mozilla Public License 2.0 5 votes vote down vote up
def add_countries(self):
        self.stdout.write("Adding Countries...", ending="")
        for code, name in countries:
            Country.objects.update_or_create(code=code, defaults={"name": name})
        self.stdout.write("Done") 
Example #5
Source File: country.py    From edx-analytics-data-api with GNU Affero General Public License v3.0 5 votes vote down vote up
def _get_country_property(code, property_name):
    return six.text_type(getattr(countries, property_name)(code)) 
Example #6
Source File: events.py    From coding-events with MIT License 5 votes vote down vote up
def list_approved_events(request, country_code):
    """
    Display a list of approved events.
    """

    event_list = get_approved_events(country_code=country_code, past=True)

    country_name = unicode(dict(countries)[country_code])

    return render_to_response('pages/list_events.html', {
        'event_list': event_list,
        'status': 'approved',
        'country_code': country_code,
        'country_name': country_name
    }, context_instance=RequestContext(request)) 
Example #7
Source File: event.py    From coding-events with MIT License 5 votes vote down vote up
def list_countries():
    all_countries = []
    for code, name in list(countries):
        readable_name = unicode(name)
        all_countries.append((readable_name, code))
    all_countries.sort()
    return all_countries 
Example #8
Source File: event.py    From coding-events with MIT License 5 votes vote down vote up
def list_active_countries(with_past_events=False):
    """ List countries with at least an Event associated """
    start_year = 2014 if with_past_events else datetime.datetime.now().year
    events_countries = Event.objects.filter(
            start_date__gte=datetime.date(start_year, 1, 1),
            status='APPROVED'
        ).values_list('country').order_by().distinct()

    active_countries = [(unicode(name), code) for code, name in list(countries) if (code,) in events_countries]

    return active_countries 
Example #9
Source File: event.py    From coding-events with MIT License 5 votes vote down vote up
def \
        count_approved_events_for_country(past=True):
    """
    Count the number of approved events and score for each country
    """

    all_events = Event.objects.filter(status='APPROVED')

    country_count = []

    # not including the first two fake countries in the list
    for country in list(countries)[2:]:
        country_code = country[0]
        country_name = country[1]
        number_of_events = all_events.filter(
            country=country_code).filter(
            start_date__gte=datetime.date(
                datetime.datetime.now().year, 1, 1)).count()
        population = Country.objects.get(iso=country_code).population
        country_score = 0
        if number_of_events > 0 and population > 0 and population != "":
            country_score = 1. * number_of_events / population
        country_entry = {'country_code': country_code,
                         'country_name': country_name,
                         'events': number_of_events,
                         'score': country_score}
        if number_of_events > 0:
            country_count.append(country_entry)

    sorted_count = sorted(
        country_count,
        key=lambda k: k['score'],
        reverse=True)
    return sorted_count 
Example #10
Source File: event.py    From coding-events with MIT License 5 votes vote down vote up
def get_country_pos(item):
    """
    Return country position
    """
    pos = 1
    # not including the first two fake countries in the list
    for country in list(countries)[2:]:
        country_name = country[1]
        if item == country_name:
            break
        else:
            pos = pos + 1

    return pos 
Example #11
Source File: ProjectList.py    From cadasta-platform with GNU Affero General Public License v3.0 4 votes vote down vote up
def check_project_list(self, projects):
        """This verifies that the supplied list of projects
        and only these projects are visible on the page """

        rows = self.browser.find_elements_by_xpath(
            "//table[@id='DataTables_Table_0']/tbody/tr"
        )
        assert len(rows) == len(projects)
        for row in rows:
            onclick_items = row.get_attribute('onclick').split('/')
            project_slug = onclick_items[4]

            cells = row.find_elements_by_tag_name('td')
            actual_org_slug = onclick_items[2]
            try:
                img = cells[2].find_element_by_tag_name('img')
                actual_org_logo = img.get_attribute('src')
                actual_org_name = img.get_attribute('alt')
            except NoSuchElementException:
                actual_org_logo = None
                alt = cells[2].find_elements_by_class_name('org-name-alt')
                actual_org_name = alt[0].text
            actual_project_name = (
                cells[1].find_element_by_tag_name('h4').text
            )
            actual_project_description = (
                cells[1].find_element_by_tag_name('p').text
            )
            actual_country = cells[3].text

            target_project = None
            for project in projects:
                if project['slug'] == project_slug:
                    target_project = project
                    break
            assert target_project

            assert actual_org_slug == target_project['_org_slug']
            assert actual_org_name == target_project['_org_name']
            expected_org_logo = (
                target_project['_org_logo']
                if target_project['_org_logo']
                else None
            )
            assert actual_org_logo == expected_org_logo
            assert actual_project_name == target_project['name']
            assert actual_project_description == target_project['description']
            expected_country = (
                dict(countries)[target_project['country']]
                if target_project['country'] else ''
            )
            assert actual_country == expected_country

            # TODO Check also last updated column