Пример #1
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))
Пример #2
0
def search_events(request):
		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)
		events = get_approved_events(country_code=country)

		if request.method == 'POST':
			form = SearchEventForm(request.POST)

			if form.is_valid():
				search_filter = form.cleaned_data.get('search', None)
				country_filter = form.cleaned_data.get('country', None)
				theme_filter = form.cleaned_data.get('theme', None)
				audience_filter = form.cleaned_data.get('audience', None)

				events = get_filtered_events(search_filter, country_filter, theme_filter, audience_filter)
		else:
			form = SearchEventForm(country_code=country['country_code'])
			events = get_approved_events(country_code=country['country_code'])

		return render_to_response(
			'pages/search_events.html', {
				'events': events,
				'form': form,
			}, 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 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))
Пример #5
0
def search_events(request):
    user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
                            remote=request.META.get('REMOTE_ADDR'))
    country_code = request.GET.get('country_code', None)
    country = get_country(country_code, user_ip)
    events = get_approved_events(country_code=country)

    if request.method == 'POST':
        form = SearchEventForm(request.POST)

        if form.is_valid():
            search_filter = form.cleaned_data.get('search', None)
            country_filter = form.cleaned_data.get('country', None)
            theme_filter = form.cleaned_data.get('theme', None)
            audience_filter = form.cleaned_data.get('audience', None)

            events = get_filtered_events(search_filter, country_filter,
                                         theme_filter, audience_filter)
            country = {'country_code': country_filter}
    else:
        form = SearchEventForm(country_code=country['country_code'])
        events = get_approved_events(country_code=country['country_code'])

    return render_to_response('pages/search_events.html', {
        'events': events,
        'form': form,
        'country': country['country_code'],
    },
                              context_instance=RequestContext(request))
Пример #6
0
def view_event_by_country(request, country_code):
    event_list = get_approved_events(country_code=country_code)

    return render_to_response('pages/list_events.html', {
        'event_list': event_list,
    },
                              context_instance=RequestContext(request))
Пример #7
0
def view_event_by_country(request, country_code):
	event_list = get_approved_events(country_code=country_code)

	return render_to_response(
		'pages/list_events.html', {
			'event_list': event_list,
		}, context_instance=RequestContext(request))
    def test_get_approved_event_with_filter_country_code_and_order_and_limit__with_approved_event(
            self):
        countries = ["IS", "DK", "FI", "FI", "FI"]
        for index, country in enumerate(countries):
            self.create_event(
                title="Testing event" +
                str(
                    index +
                    1),
                country_code=country,
                status="APPROVED",
                start_date=datetime.datetime.now() +
                datetime.timedelta(
                    days=0,
                    hours=index +
                    1),
                end_date=datetime.datetime.now() +
                datetime.timedelta(
                    days=1,
                    hours=index +
                    1))

        events = get_approved_events(
            order="start_date", limit=2, country_code="FI")
        self.assertEqual(2, len(events))
        self.assertEqual("Testing event3", events[0].title)
        self.assertEqual("Testing event4", events[1].title)
 def test_get_approved_event_without_filter_with_approved_event_but_passed_date(self):
     self.create_event(
         start_date=datetime.datetime.now() - datetime.timedelta(days=1, hours=3),
         end_date=datetime.datetime.now() - datetime.timedelta(days=2, hours=3),
         status="APPROVED",
     )
     events = get_approved_events()
     self.assertEqual(0, len(events))
Пример #10
0
def view_event_by_country(request, country_code):
    event_list = get_approved_events(country_code=country_code)

    return render_to_response(
        "pages/list_events.html",
        {"event_list": event_list, "country_code": country_code},
        context_instance=RequestContext(request),
    )
Пример #11
0
    def get_queryset(self):
        params = {
            'limit': self.request.GET.get('limit', None),
            'order': self.request.GET.get('order', None),
            'country_code': self.request.GET.get('country_code', None),
            'past': self.request.GET.get('past', False)
        }

        return get_approved_events(**params)
Пример #12
0
    def get_queryset(self):
        params = {
            'limit': self.request.GET.get('limit', None),
            'order': self.request.GET.get('order', None),
            'country_code': self.request.GET.get('country_code', None),
            'past': self.request.GET.get('past', False)
        }

        return get_approved_events(**params)
 def test_get_approved_event_without_filter_with_approved_event_but_passed_date(
         self):
     self.create_event(start_date=datetime.datetime.now() -
                       datetime.timedelta(days=1, hours=3),
                       end_date=datetime.datetime.now() -
                       datetime.timedelta(days=2, hours=3),
                       status="APPROVED")
     events = get_approved_events()
     self.assertEqual(0, len(events))
 def test_get_approved_event_without_filter_with_pending_event(self):
     self.create_event(
         start_date=datetime.datetime.now() +
         datetime.timedelta(days=0, hours=3),
         end_date=datetime.datetime.now() +
         datetime.timedelta(days=1, hours=3),
         status="APPROVED",
     )
     events = get_approved_events()
     self.assertEqual(1, len(events))
	def test_get_approved_event_with_filter_country_code_and_order_and_limit__with_approved_event(self):
		countries = ["IS", "DK", "FI", "FI", "FI"]
		for index, country in enumerate(countries):
			self.create_event(title="Testing event" + str(index + 1), country_code=country, status="APPROVED",
			                  start_date=datetime.datetime.now() + datetime.timedelta(days=0, hours=index + 1),
			                  end_date=datetime.datetime.now() + datetime.timedelta(days=1, hours=index + 1))

		events = get_approved_events(order="start_date", limit=2, country_code="FI")
		self.assertEqual(2, len(events))
		self.assertEqual("Testing event3", events[0].title)
		self.assertEqual("Testing event4", events[1].title)
Пример #16
0
def search_events(request):
		user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
		                        remote=request.META.get('REMOTE_ADDR'))
		country_code = request.GET.get('country_code', None)
		country = get_country(country_code, user_ip)
		events = get_approved_events(country_code=country)
		
		is_it_past = request.GET.get('past', 'no')
		if is_it_past == 'yes':
			past = True
		else:
			past = False

		if request.method == 'POST':
			form = SearchEventForm(request.POST)

			if form.is_valid():
				search_filter = form.cleaned_data.get('search', None)
				country_filter = form.cleaned_data.get('country', None)
				theme_filter = form.cleaned_data.get('theme', None)
				audience_filter = form.cleaned_data.get('audience', None)
				past_events = form.cleaned_data.get('past_events',None)

				events = get_filtered_events(search_filter, country_filter, theme_filter, audience_filter, past_events)
				country = {'country_code': country_filter}

				if past_events:
					past = True
				
		else:
			form = SearchEventForm(country_code=country['country_code'],initial={'past_events': past})
			events = get_approved_events(country_code=country['country_code'],past=past)

		return render_to_response(
			'pages/search_events.html', {
				'events': events,
				'form': form,
			    'country': country['country_code'],
			    'past': past,
			}, context_instance=RequestContext(request))
Пример #17
0
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),
    )
Пример #18
0
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))
Пример #19
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))
Пример #20
0
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))
 def test_get_approved_event_with_filter_country_code_with_approved_event(
         self):
     self.create_event(country_code="IS", status="APPROVED")
     events = get_approved_events(country_code="IS")
     self.assertEqual(1, len(events))
     self.assertEqual("IS", events[0].country.code)
    def test_get_approved_event_without_filter_returns_zero(self):

        events = get_approved_events()
        self.assertQuerysetEqual([], events)
Пример #23
0
	def test_get_approved_event_without_filter_returns_zero(self):

		events = get_approved_events()
		self.assertQuerysetEqual([], events)
Пример #24
0
	def test_get_approved_event_with_filter_country_code_with_approved_event(self):
		self.create_event(country_code="IS", status="APPROVED")
		events = get_approved_events(country_code="IS")
		self.assertEqual(1, len(events))
		self.assertEqual("IS", events[0].country.code)