예제 #1
0
def map(request):
    template = 'pages/map.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_countries()

    return render_to_response(
        template, {
            'lan_lon': lan_lon,
            'country': country,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            'all_countries': all_countries[2:],
            'past': past,
            'ambassadors': ambassadors,
        },
        context_instance=RequestContext(request))
예제 #2
0
def ambassadors(request):
    try:
        user_ip = get_client_ip(
            forwarded=request.META.get("HTTP_X_FORWARDED_FOR"), remote=request.META.get("REMOTE_ADDR")
        )
        user_country = get_country_from_user_ip(user_ip)

    except:
        user_country = None

    countries_ambassadors = get_ambassadors_for_countries()
    all_countries = list_countries()

    if not user_country:
        position = 2
    else:
        position = get_country_pos(unicode(user_country["country_name"]))

    return render_to_response(
        "pages/ambassadors.html",
        {
            "user_country": user_country,
            "countries": countries_ambassadors,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            "all_countries": all_countries[2:],
            "country_pos": position,
        },
        context_instance=RequestContext(request),
    )
예제 #3
0
def index(request, country_code=None):
    template = 'pages/index.html'
    events = get_approved_events()
    map_events = serializers.serialize('json',
                                       events,
                                       fields=('geoposition', 'title', 'pk',
                                               'slug', 'description',
                                               'picture'))
    user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
                            remote=request.META.get('REMOTE_ADDR'))

    country = get_country(country_code, user_ip)

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

    events = get_approved_events(order='pub_date',
                                 country_code=country.get(
                                     'country_code', None))

    all_countries = list_countries()
    return render_to_response(template, {
        'latest_events': events,
        'map_events': map_events,
        'lan_lon': lan_lon,
        'country': country,
        'all_countries': all_countries,
    },
                              context_instance=RequestContext(request))
예제 #4
0
def ambassadors(request):
    try:
        user_ip = get_client_ip(
            forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
            remote=request.META.get('REMOTE_ADDR'))
        user_country = get_country_from_user_ip(user_ip)

    except:
        user_country = None

    countries_ambassadors = get_ambassadors_for_countries()
    all_countries = list_countries()

    if not user_country:
        position = 2
    else:
        position = get_country_pos(unicode(user_country['country_name']))

    return render_to_response(
        'pages/ambassadors.html',
        {
            'user_country': user_country,
            'countries': countries_ambassadors,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            'all_countries': all_countries[2:],
            'country_pos': position,
        },
        context_instance=RequestContext(request))
예제 #5
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)
    except GeoIPException:
        lan_lon = (58.08695, 5.58121)

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

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

	past = request.GET.get('past', 'no')
	if past == 'yes':
		events = get_approved_events(past=True)
	else:
		events = get_approved_events()

	map_events = serializers.serialize('json', events, fields=('geoposition', 'title', 'pk', 'slug', 'description', 'picture'))
	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)
	except GeoIPException:
		lan_lon = (58.08695, 5.58121)
	
	ambassadors = get_ambassadors(country['country_code'])
	all_countries = list_countries()
	
	return render_to_response(
		template, {
			'map_events': map_events,
			'lan_lon': lan_lon,
			'country': country,
			# all_countries minus two CUSTOM_COUNTRY_ENTRIES
			'all_countries': all_countries[2:],
			'past': past,
			'ambassadors': ambassadors,
		},
		context_instance=RequestContext(request))
예제 #7
0
def ambassadors(request):
    try:
        user_ip = get_client_ip(
            forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
            remote=request.META.get('REMOTE_ADDR'))
        user_country = get_country_from_user_ip(user_ip)

    except:
        user_country = None

    countries_ambassadors = get_ambassadors_for_countries()
    all_countries = list_countries()

    if not user_country:
        position = 2
    else:
        position = get_country_pos(unicode(user_country['country_name']))

    return render_to_response(
        'pages/ambassadors.html', {
            'user_country': user_country,
            'countries': countries_ambassadors,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            'all_countries': all_countries[2:],
            'country_pos': position,
        },
        context_instance=RequestContext(request))
def test_create_event_in_each_listed_country(admin_user, db):
    all_countries = list_countries()

    for country in all_countries[2:]:
        country_code = country[1]
        country_name = country[0]

        event_data = {
            "audience": [3],
            "theme": [1, 2],
            "contact_person": u"*****@*****.**",
            "country": country_code,
            "description": u"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
            "event_url": u"",
            "location": country_name,
            "organizer": u"RailsGirls " + country_name,
            "creator": admin_user,
            "start_date": datetime.datetime.now(),
            "end_date": datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
            "tags": [u"css", u"html", u"web"],
            "title": u"RailsGirls " + country_name,
        }

        test_event = create_or_update_event(event_id=None, **event_data)

        assert country_code == test_event.country.code

        test_event.delete()
예제 #9
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_countries()

    return render_to_response(
        template,
        {
            "lan_lon": lan_lon,
            "country": country,
            # all_countries minus two CUSTOM_COUNTRY_ENTRIES
            "all_countries": all_countries[2:],
            "past": past,
            "ambassadors": ambassadors,
        },
        context_instance=RequestContext(request),
    )
예제 #10
0
def index(request, country_code=None):
	template = 'pages/index.html'
	events = get_approved_events()
	map_events = serializers.serialize('json', events, fields=('geoposition', 'title', 'pk', 'slug', 'description', 'picture'))
	user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
	                        remote=request.META.get('REMOTE_ADDR'))

	country = get_country(country_code, user_ip)

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

	events = get_approved_events(order='pub_date', country_code=country.get('country_code', None))

	all_countries = list_countries()
	return render_to_response(
		template, {
			'latest_events': events,
			'map_events': map_events,
			'lan_lon': lan_lon,
			'country': country,
			'all_countries': all_countries,
		},
		context_instance=RequestContext(request))
def test_create_event_in_each_listed_country(admin_user, db):
	all_countries = list_countries()

	for country in all_countries[2:]:
		country_code = country[1]
		country_name = country[0]

		event_data = {
			'audience': [3],
			'theme': [1,2],
			'contact_person': u'*****@*****.**',
			'country': country_code,
			'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
			'event_url': u'',
			'location': country_name,
			'organizer': u'RailsGirls ' + country_name,
			"creator": admin_user,
			'start_date': datetime.datetime.now(),
			'end_date': datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
			'tags': [u'css', u'html', u'web'],
			'title': u'RailsGirls ' + country_name,
		}

		test_event = create_or_update_event(event_id=None, **event_data)

		assert country_code == test_event.country.code

		test_event.delete()
def test_list_countries():
    # a function we use a lot to get all countries, so let's check it's returning expected results
    all_countries = list_countries()

    # Austria should be the first country after two custom entries (All countries)
    assert "Austria" == all_countries[2][0]

    # checking two random countries - our own and Kosovo, which is a special case
    assert ("Slovenia", "SI") in all_countries
    assert ("Kosovo", "XK") in all_countries

    # United Kingdom should be last
    assert "United Kingdom" == all_countries[-1][0]

    # if listing works, results are tuples ('country_name', 'country_code')
    # country_code should be a string with 2 characters
    for country in all_countries[2:]:
        assert len(country[1]) == 2
예제 #13
0
def test_list_countries():
    # a function we use a lot to get all countries, so let's check it's returning expected results
    all_countries = list_countries()

    # Austria should be the first country after two custom entries (All countries)
    assert "Austria" == all_countries[2][0]

    # checking two random countries - our own and Kosovo, which is a special case
    assert ('Slovenia', 'SI') in all_countries
    assert ('Kosovo', 'XK') in all_countries

    # United Kingdom should be last
    assert "United Kingdom" == all_countries[-1][0]

    # if listing works, results are tuples ('country_name', 'country_code')
    # country_code should be a string with 2 characters
    for country in all_countries[2:]:
        assert len(country[1]) == 2
def test_list_countries():
    # a function we use a lot to get all countries, so let's check it's
    # returning expected results
    all_countries = list_countries()

    # Afghanistan should be the first country after two custom entries (All
    # countries)
    assert "Afghanistan" == all_countries[2][0]

    # checking two random countries - our own and Kosovo, which is a special
    # case
    assert ('Slovenia', 'SI') in all_countries
    assert ('Kosovo', 'XK') in all_countries

    # Aland Islands should be last
    assert "land Islands" in all_countries[-1][0]

    # if listing works, results are tuples ('country_name', 'country_code')
    # country_code should be a string with 2 characters
    for country in all_countries[2:]:
        assert len(country[1]) == 2
예제 #15
0
def index(request, country_code=None):
	template = 'pages/index.html'
	events = get_approved_events()
	map_events = serializers.serialize('json', events, fields=('geoposition', 'title', 'pk', 'slug'))
	user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
	                        remote=request.META.get('REMOTE_ADDR'))

	if country_code and 'media' not in country_code:
		country_name = unicode(dict(countries)[country_code])
		country = {'country_name': country_name, 'country_code': country_code}
	else:
		country = get_country_from_user_ip(user_ip)

	if request.is_ajax():
		if request.META.get('HTTP_X_PJAX', None):
			template = 'pages/pjax_index.html'
		else:
			template = 'layout/all_events.html'

	try:
		lan_lon = get_lat_lon_from_user_ip(user_ip)
	except GeoIPException:
		lan_lon = (46.0608144, 14.497165600000017)

	events = get_approved_events(order='pub_date', country_code=country.get('country_code', None))

	all_countries = list_countries()
	return render_to_response(
		template, {
			'latest_events': events,
			'map_events': map_events,
			'lan_lon': lan_lon,
			'country': country,
			'all_countries': all_countries,
		},
		context_instance=RequestContext(request))
예제 #16
0
def test_scoreboard_counter(admin_user, db):

    initial_counter = count_approved_events_for_country()

    # extra check to make sure the number of results matches
    # the number of listed countries minus two custom entries
    all_countries = list_countries()
    assert len(initial_counter) == len(all_countries[2:])

    counted_events_before = 0

    for country in initial_counter:
        if country['country_code'] == 'SI':
            counted_events_before = country['events']

    # Adding one approved and one pending event in same country
    # the count for events for the country should increase by 1
    event_data = {
        'audience': [3],
        'theme': [1, 2],
        'country': u'SI',
        'description':
        u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'location': u'Ljubljana, Slovenia',
        '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",
    }

    test_approved_event = create_or_update_event(event_id=None, **event_data)

    event_data = {
        'audience': [3],
        'theme': [1, 2],
        'country': u'SI',
        'description':
        u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
        'location': u'Ljubljana, Slovenia',
        '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': "PENDING",
    }

    test_pending_event = create_or_update_event(event_id=None, **event_data)

    new_counter = count_approved_events_for_country()

    counted_events_after = 0
    country_score_after = 0

    for country in new_counter:
        if country['country_code'] == 'SI':
            counted_events_after = country['events']
            country_score_after = country['score']

    # An extra check with a direct DB query
    counted_events_query = Event.objects.filter(status='APPROVED').filter(
        country='SI').count()

    assert counted_events_after == counted_events_before + 1
    assert counted_events_after == counted_events_query

    assert country_score_after > 0

    test_approved_event.delete()
    test_pending_event.delete()
def test_scoreboard_counter(admin_user, db):

    initial_counter = count_approved_events_for_country()

    # extra check to make sure the number of results matches
    # the number of listed countries minus two custom entries
    all_countries = list_countries()
    assert len(initial_counter) == len(all_countries[2:])

    counted_events_before = 0

    for country in initial_counter:
        if country["country_code"] == "SI":
            counted_events_before = country["events"]

            # Adding one approved and one pending event in same country
            # the count for events for the country should increase by 1
    event_data = {
        "audience": [3],
        "theme": [1, 2],
        "country": u"SI",
        "description": u"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
        "location": u"Ljubljana, Slovenia",
        "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",
    }

    test_approved_event = create_or_update_event(event_id=None, **event_data)

    event_data = {
        "audience": [3],
        "theme": [1, 2],
        "country": u"SI",
        "description": u"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
        "location": u"Ljubljana, Slovenia",
        "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": "PENDING",
    }

    test_pending_event = create_or_update_event(event_id=None, **event_data)

    new_counter = count_approved_events_for_country()

    counted_events_after = 0
    country_score_after = 0

    for country in new_counter:
        if country["country_code"] == "SI":
            counted_events_after = country["events"]
            country_score_after = country["score"]

            # An extra check with a direct DB query
    counted_events_query = Event.objects.filter(status="APPROVED").filter(country="SI").count()

    assert counted_events_after == counted_events_before + 1
    assert counted_events_after == counted_events_query

    assert country_score_after > 0

    test_approved_event.delete()
    test_pending_event.delete()
def test_scoreboard_counter(admin_user, db):

	initial_counter = count_approved_events_for_country()

	# extra check to make sure the number of results matches 
	# the number of listed countries minus two custom entries
	all_countries = list_countries()
	assert len(initial_counter) == len(all_countries[2:])

	counted_events_before = 0

	for country in initial_counter:
		if country['country_code'] == 'SI':
			counted_events_before = country['events']

	# Adding one approved and one pending event in same country
	# the count for events for the country should increase by 1
	event_data = {
		'audience': [3],
		'theme': [1,2],
		'country': u'SI',
		'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
		'location': u'Ljubljana, Slovenia',
		'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",
	}

	test_approved_event = create_or_update_event(event_id=None, **event_data)

	event_data = {
		'audience': [3],
		'theme': [1,2],
		'country': u'SI',
		'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
		'location': u'Ljubljana, Slovenia',
		'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':"PENDING",
	}

	test_pending_event = create_or_update_event(event_id=None, **event_data)

	# and one event from another country, which shouldn't increase the counter
	event_data = {
		'audience': [3],
		'theme': [1,2],
		'country': u'IT',
		'description': u'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod\r\ntempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,\r\nquis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo\r\nconsequat. Duis aute irure dolor in reprehenderit in voluptate velit esse\r\ncillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non\r\nproident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
		'location': u'Rome, Italy',
		'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 in other country',
		'status':"APPROVED",
	}

	test_other_country_event = create_or_update_event(event_id=None, **event_data)

	new_counter = count_approved_events_for_country()

	counted_events_after = 0
	country_score_after = 0

	for country in new_counter:
			if country['country_code'] == 'SI':
				counted_events_after = country['events']
				country_score_after = country['score']

	# An extra check with a direct DB query
	counted_events_query = Event.objects.filter(status='APPROVED').filter(country='SI').count()
	
	assert counted_events_after == counted_events_before + 1
	assert counted_events_after == counted_events_query

	assert country_score_after > 0 
	
	test_approved_event.delete()
	test_pending_event.delete()
	test_other_country_event.delete()