Esempio n. 1
0
def search_events(request):

		country_filter = request.GET.get('country_code', None)
		if not country_filter:
			user_ip = get_client_ip(forwarded=request.META.get('HTTP_X_FORWARDED_FOR'),
		                        remote=request.META.get('REMOTE_ADDR'))
			country = get_country(country_filter, user_ip)
			country_filter = country['country_code']

		past = request.GET.get('past', None)
		past_events = True if past and past=='yes' else False

		search_query = request.GET.get('q', '')
		page = request.GET.get('page', None)

		template = 'pages/search_events.html'
		page_template = 'pages/ajax_faceted_search_events.html'

		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)
		else:
			form = SearchEventForm(country_code=country_filter, past_events=past_events, search=search_query)
			events = get_filtered_events(search_filter=search_query, country_filter=country_filter, past_events=past_events)


		if request.is_ajax():
			return render_to_response(
				page_template, 
				{
				'events':events,
				'page': page
				},
				context_instance=RequestContext(request))

		return render_to_response(
			template,
			{
				'page_template': page_template,
				'events': events,
				'form': form,
				'country': country_filter,
			},
			context_instance=RequestContext(request))
Esempio n. 2
0
	def test_get_filtered_events_with_search_filter_and_more_past_approved_events(self):
		event = Event.objects.create(
			organizer='CodeCatz',
			creator=User.objects.filter(pk=1)[0],
			title='Programming for dummies asdasd',
			description='Learn basics about programming in python',
			location='Ljubljana',
			start_date=datetime.datetime.now() - datetime.timedelta(days=2, hours=3),
			end_date=datetime.datetime.now() - datetime.timedelta(days=1, hours=1),
			event_url='http://example.com',
			contact_person='[email protected]',
			country='SI',
			pub_date=datetime.datetime.now() - datetime.timedelta(days=2, hours=1))
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.status = 'APPROVED'
		event.save()

		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		search_filter = "asdasd"
		events = get_filtered_events(search_filter=search_filter, past_events=True)
		self.assertEquals(2, events.count())
Esempio n. 3
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))
Esempio n. 4
0
	def test_get_filtered_events_with_country_filter_with_approved_event(self):
		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		country_filter = "SI"
		events = get_filtered_events(country_filter=country_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('asdasd', events[0].title)
Esempio n. 5
0
	def test_get_filtered_events_with_audience_filter_with_approved_event(self):
		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		audience_filter = EventAudience.objects.filter(pk=1)
		events = get_filtered_events(audience_filter=audience_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('asdasd', events[0].title)
Esempio n. 6
0
	def test_get_filtered_events_with_search_filter_and_theme_filter_with_approved_event(self):
		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		search_filter = "asd"
		theme_filter = EventTheme.objects.filter(pk=1)
		events = get_filtered_events(search_filter=search_filter, theme_filter=theme_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('asdasd', events[0].title)
Esempio n. 7
0
def search_events(request):
    country_code = request.GET.get('country_code', None)

    if not country_code:
        country_code = request.GET.get('country', None)

    if not country_code:
        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)
        country_code = country['country_code']

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

    search_query = request.GET.get('q', '')
    page = request.GET.get('page', None)

    theme_filter = request.GET.getlist('theme', None)
    audience_filter = request.GET.getlist('audience', None)

    template = 'pages/search_events.html'
    page_template = 'pages/ajax_faceted_search_events.html'
    form = SearchEventForm(
        country_code=country_code,
        past_events=past,
        search=search_query,
        audience=audience_filter,
        theme=theme_filter)
    events = get_filtered_events(
        search_query,
        country_code,
        theme_filter,
        audience_filter,
        past_events)

    if request.is_ajax():
        return render_to_response(
            page_template,
            {
                'events': events,
                'page': page
            },
            context_instance=RequestContext(request))

    return render_to_response(
        template,
        {
            'page_template': page_template,
            'events': events,
            'form': form,
            'country': country_code,
        },
        context_instance=RequestContext(request))
Esempio n. 8
0
	def test_get_filtered_events_with_search_filter_with_approved_event(self):
		event = Event.objects.get(title='asdasd')
		event.status = 'APPROVED'
		event.save()

		search_filter = "asd"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('asdasd', events[0].title)

		event.delete()
Esempio n. 9
0
	def test_get_filtered_events_with_no_search_filter(self):
		event = ApprovedEventFactory.create(title='test_get_filtered_events_with_no_search_filter')
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		events = get_filtered_events()
		self.assertEquals('test_get_filtered_events_with_no_search_filter', events[0].title)

		event.delete()
Esempio n. 10
0
	def test_get_filtered_events_with_search_filter_searching_description_and_past_events(self):
		event = PastEventFactory.create(description='Learn basics about programming in python', status='APPROVED')

		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		search_filter = "python"
		events = get_filtered_events(search_filter=search_filter, past_events=True)
		self.assertEquals(1, events.count())
		self.assertEquals(2, events[0].pk)
Esempio n. 11
0
	def test_get_filtered_events_with_search_filter_searching_description_when_no_approved_event(self):
		event = EventFactory(description='Learn basics about programming in python')
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		search_filter = "python"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(0, events.count())

		event.delete()
Esempio n. 12
0
	def test_get_filtered_events_with_search_filter_searching_title(self):
		event = ApprovedEventFactory.create(title='Programming for dummies')
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		search_filter = "dummies"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('Programming for dummies', events[0].title)

		event.delete()
Esempio n. 13
0
	def test_get_filtered_events_with_search_filter_searching_organizer(self):
		event = ApprovedEventFactory.create(organizer='CodeCatz')
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		search_filter = "Catz"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(1, events.count())
		self.assertEquals('CodeCatz', events[0].organizer)

		event.delete()
Esempio n. 14
0
	def test_get_filtered_events_with_search_filter_and_more_past_approved_events(self):
		event = PastEventFactory.create(title='Programming for dummies asdasd', status='APPROVED')

		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		search_filter = "asdasd"
		events = get_filtered_events(search_filter=search_filter, past_events=True)
		self.assertEquals(2, events.count())
Esempio n. 15
0
	def test_get_filtered_events_with_theme_filter_and_audience_filter_with_more_approved_event(self):
		event = ApprovedEventFactory.create()
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		test_event = Event.objects.get(title='asdasd')
		test_event.status = 'APPROVED'
		test_event.save()
		theme_filter = EventTheme.objects.filter(pk=1)
		audience_filter = EventAudience.objects.filter(pk=1)
		events = get_filtered_events(theme_filter=theme_filter, audience_filter=audience_filter)
		self.assertEquals(2, events.count())
Esempio n. 16
0
def search_events(request):

    country_code = request.GET.get("country_code", None)

    if not country_code:
        country_code = request.GET.get("country", None)

    if not country_code:
        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)
        country_code = country["country_code"]

    past = request.GET.get("past", "no")
    past_events = False
    if past == "yes":
        past_events = True

    search_query = request.GET.get("q", "")
    page = request.GET.get("page", None)

    theme_filter = request.GET.get("theme", None)
    audience_filter = request.GET.get("audience", None)

    template = "pages/search_events.html"
    page_template = "pages/ajax_faceted_search_events.html"

    form = SearchEventForm(country_code=country_code, past_events=past, search=search_query)
    events = get_filtered_events(search_query, country_code, theme_filter, audience_filter, past_events)

    if request.is_ajax():
        return render_to_response(
            page_template, {"events": events, "page": page}, context_instance=RequestContext(request)
        )

    return render_to_response(
        template,
        {"page_template": page_template, "events": events, "form": form, "country": country_code},
        context_instance=RequestContext(request),
    )
Esempio n. 17
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))
Esempio n. 18
0
	def test_get_filtered_events_with_search_filter_searching_description_when_no_approved_event(self):
		event = Event.objects.create(
			organizer='CodeCatz',
			creator=User.objects.filter(pk=1)[0],
			title='Programming for dummies',
			description='Learn basics about programming in python',
			location='Ljubljana',
			start_date=datetime.datetime.now() - datetime.timedelta(hours=3),
			end_date=datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
			event_url='http://example.com',
			contact_person='[email protected]',
			country='SI',
			pub_date=datetime.datetime.now() - datetime.timedelta(hours=4))
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)
		event.save()

		search_filter = "python"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(0, events.count())
Esempio n. 19
0
	def test_get_filtered_events_with_no_search_filter(self):
		event = Event.objects.create(
			organizer='asdasd1',
			creator=User.objects.filter(pk=1)[0],
			title='asdasd1',
			description='asdsad1',
			location='asdsad1',
			start_date=datetime.datetime.now() - datetime.timedelta(days=1, hours=3),
			end_date=datetime.datetime.now() + datetime.timedelta(days=3, hours=3),
			event_url='http://eee.com',
			contact_person='[email protected]',
			country='SI',
			pub_date=datetime.datetime.now())
		theme = EventTheme.objects.filter(pk=1)
		audience = EventAudience.objects.filter(pk=1)
		event.theme.add(*theme)
		event.audience.add(*audience)

		event.status = 'APPROVED'
		event.save()
		events = get_filtered_events()
		self.assertEquals('asdasd1', events[0].title)
Esempio n. 20
0
	def test_get_filtered_events_with_audience_filter_when_no_aproved_event(self):
		audience_filter = EventAudience.objects.filter(pk=1)
		events = get_filtered_events(audience_filter=audience_filter)
		self.assertEquals(0, events.count())
Esempio n. 21
0
	def test_get_filtered_events_with_theme_filter_when_no_aproved_event(self):
		theme_filter = EventTheme.objects.filter(pk=1)
		events = get_filtered_events(theme_filter=theme_filter)
		self.assertEquals(0, events.count())
Esempio n. 22
0
	def test_get_filtered_events_with_country_filter_when_no_aproved_event(self):
		country_filter = "SI"
		events = get_filtered_events(country_filter=country_filter)
		self.assertEquals(0, events.count())
Esempio n. 23
0
	def test_get_filtered_events_with_search_filter_when_no_aproved_event(self):
		search_filter = "asd"
		events = get_filtered_events(search_filter=search_filter)
		self.assertEquals(0, events.count())