示例#1
0
def index(request):
    template = 'pages/index.html'

    past = request.GET.get('past', 'no')

    user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
                            remote=request.META.get('REMOTE_ADDR'))
    country = get_country_from_user_ip(user_ip)

    try:
        lan_lon = get_lat_lon_from_user_ip(user_ip) or (58.08695, 5.58121)
    except GeoIPException:
        lan_lon = (58.08695, 5.58121)

    ambassadors = get_ambassadors(country['country_code'])
    all_countries = list_active_countries()

    return render_to_response(
        template, {
            'lan_lon': lan_lon,
            'country': country,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            'all_countries': all_countries,
            'past': past,
            'ambassadors': ambassadors,
        },
        context_instance=RequestContext(request))
示例#2
0
def index(request):
    template = 'pages/index.html'

    past = request.GET.get('past', 'no')

    user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
                            remote=request.META.get('REMOTE_ADDR'))
    country = get_country_from_user_ip(user_ip)

    try:
        lan_lon = get_lat_lon_from_user_ip(user_ip) or (58.08695, 5.58121)
    except GeoIPException:
        lan_lon = (58.08695, 5.58121)

    ambassadors = get_ambassadors(country['country_code'])
    all_countries = list_active_countries(with_past_events=(past == 'yes'))

    return render_to_response(
        template,
        {
            'lan_lon': lan_lon,
            'country': country,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            'all_countries': all_countries,
            'past': past,
            'ambassadors': ambassadors,
        },
        context_instance=RequestContext(request))
示例#3
0
def test_list_active_countries(admin_user, db):
    """
    Verifies that only the countries with event which date is gte
    2014 are returned from the list_active_countries() function
    """

    events = [
        {
            # this country should be returned
            # because event is APPROVED and after 2014
            'location':
            u'Ljubljana, Slovenia',
            'country':
            'SI',
            'organizer':
            u'testko',
            "creator":
            admin_user,
            'start_date':
            datetime.datetime.now(),
            'end_date':
            datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title':
            u'Test Approved Event',
            'status':
            "APPROVED",
        },
        {
            # this country should be returned
            # for the same reasons
            'location':
            u'Paris, France',
            'country':
            'FR',
            'organizer':
            u'testko',
            "creator":
            admin_user,
            'start_date':
            datetime.datetime.now(),
            'end_date':
            datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title':
            u'Test Pending Event',
            'status':
            "APPROVED",
        },
        {
            # the same country should be returned only once
            'location':
            u'Ljubljana, Slovenia',
            'country':
            'SI',
            'organizer':
            u'testko',
            "creator":
            admin_user,
            'start_date':
            datetime.datetime.now(),
            'end_date':
            datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title':
            u'Test Pending Event',
            'status':
            "APPROVED",
        },
        {
            # this country shouldn't be returned
            # because event start_date is < 2014
            'location':
            u'Rome, Italy',
            'country':
            'IT',
            'organizer':
            u'testko',
            "creator":
            admin_user,
            'start_date':
            datetime.datetime(2013, 1, 1, 12, 00),
            'end_date':
            datetime.datetime(2013, 1, 1, 12, 00) +
            datetime.timedelta(days=3, hours=3),
            'title':
            u'Test Approved Event in other country',
            'status':
            "APPROVED",
        }
    ]

    # insert the listed events
    for event_data in events:
        create_or_update_event(event_id=None, **event_data)

    # retrieve the active countries from db
    active_countries = list_active_countries()

    # there should be only two active countries
    assert len(active_countries) == 2

    # and should be those two
    assert ('Slovenia', 'SI') in active_countries
    assert ('France', 'FR') in active_countries

    # if listing works, results are tuples ('country_name', 'country_code')
    # country_code should be a string with 2 characters
    for country in active_countries:
        assert len(country[1]) == 2
def test_list_active_countries(admin_user, db):
    """
    Verifies that only the countries with event which date is gte
    2014 are returned from the list_active_countries() function
    """

    events = [
        {
            # this country should be returned
            # because event is APPROVED and after 2014
            'location': u'Ljubljana, Slovenia',
            'country': 'SI',
            'organizer': u'testko',
            "creator": admin_user,
            'start_date': datetime.datetime.now(),
            'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title': u'Test Approved Event',
            'status': "APPROVED",
        },
        {
            # this country should be returned
            # for the same reasons
            'location': u'Paris, France',
            'country': 'FR',
            'organizer': u'testko',
            "creator": admin_user,
            'start_date': datetime.datetime.now(),
            'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title': u'Test Pending Event',
            'status': "APPROVED",
        },
        {
            # the same country should be returned only once
            'location': u'Ljubljana, Slovenia',
            'country': 'SI',
            'organizer': u'testko',
            "creator": admin_user,
            'start_date': datetime.datetime.now(),
            'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            'title': u'Test Pending Event',
            'status': "APPROVED",
        },
        {
            # this country shouldn't be returned
            # because event start_date is < 2014
            'location': u'Rome, Italy',
            'country': 'IT',
            'organizer': u'testko',
            "creator": admin_user,
            'start_date': datetime.datetime(2013, 1, 1, 12, 00),
            'end_date': datetime.datetime(2013, 1, 1, 12, 00) + datetime.timedelta(days=3, hours=3),
            'title': u'Test Approved Event in other country',
            'status': "APPROVED",
        }
    ]

    # insert the listed events
    for event_data in events:
        create_or_update_event(event_id=None, **event_data)

    # retrieve the active countries from db
    active_countries = list_active_countries()

    # there should be only two active countries
    assert len(active_countries) == 2

    # and should be those two
    assert ('Slovenia', 'SI') in active_countries
    assert ('France', 'FR') in active_countries

    # if listing works, results are tuples ('country_name', 'country_code')
    # country_code should be a string with 2 characters
    for country in active_countries:
        assert len(country[1]) == 2