Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit 40d05ac

Browse files
committed
fix merge conflict
2 parents cf2dd9e + c8b3f30 commit 40d05ac

File tree

8 files changed

+195
-166
lines changed

8 files changed

+195
-166
lines changed

static/js/endless_pagination/custom-endless-pagination.js

Lines changed: 0 additions & 118 deletions
This file was deleted.

static/js/faceted-search-events.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,16 @@ var Codeweek = window.Codeweek || {};
1818
var data = $('#faceted-search-events').serialize();
1919
var url = $('#faceted-search-events').attr('action');
2020

21-
$.post(url, data, function(fragment) {
21+
22+
if (!Modernizr.history) {
23+
document.getElementById('faceted-search-events').submit();
24+
} else {
25+
$.get(url, data, function(fragment) {
26+
history.replaceState({}, document.title, '?' + data);
2227
container.empty();
2328
container.html(fragment);
24-
});
29+
});
30+
}
2531
});
2632
});
2733
};

web/forms/event_form.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,16 @@ class SearchEventForm(forms.Form):
164164
if not 'Kosovo' in list(dict(countries._countries).values()):
165165
countries._countries.append((u'XK', u'Kosovo'))
166166

167-
search = forms.CharField(
167+
168+
q = forms.CharField(
168169
required=False,
169170
widget=forms.TextInput(attrs={'placeholder': 'Search for event name or tag', 'class': 'form-control'})
170171
)
171-
past_events = forms.BooleanField(
172+
past = forms.ChoiceField(
172173
label='Include past events',
173174
required=False,
174-
widget=forms.CheckboxInput(attrs={'class': 'search-form-element'}),
175-
#choices=countries
175+
choices=(('yes', 'yes'),('no', 'no')),
176+
widget=forms.RadioSelect(attrs={'class': 'search-form-element'}),
176177
)
177178
country = forms.ChoiceField(
178179
label='Select country',
@@ -196,14 +197,20 @@ class SearchEventForm(forms.Form):
196197

197198
def __init__(self, *args, **kwargs):
198199
country_code = kwargs.pop('country_code', None)
199-
past_events = kwargs.pop('past_events', False)
200+
past_events = kwargs.pop('past_events')
200201
search_query = kwargs.pop('search', None)
202+
theme = kwargs.pop('theme', None)
203+
audience = kwargs.pop('audience', None)
201204
super(SearchEventForm, self).__init__(*args, **kwargs)
202205
if country_code:
203206
self.fields['country'].initial = country_code
204-
self.fields['past_events'].initial = past_events
207+
self.fields['past'].initial = past_events
205208
if search_query:
206-
self.fields['search'].initial = search_query
209+
self.fields['q'].initial = search_query
210+
if theme:
211+
self.fields['theme'].initial = theme
212+
if audience:
213+
self.fields['audience'].initial = audience
207214

208215

209216

web/templates/pages/search_events.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,24 @@
1111
<div class="container">
1212
<div class="search-page">
1313
<div class="search-options">
14-
<form id="faceted-search-events" method="post" action="{% url 'web.search_events' %}" enctype="multipart/form-data">{% csrf_token %}
14+
<form id="faceted-search-events" method="get" action="{% url 'web.search_events' %}" enctype="multipart/form-data">
1515
{{ form.non_field_errors }}
1616
<div class="row">
1717
<div class="form-group col-md-9">
18-
{{ form.search }}
18+
{{ form.q }}
1919
</div>
2020
<div class="col-md-3"><input type="submit" class="btn btn-primary btn-lg" value="Search" /></div>
2121
<div class="col-md-12"><hr></div>
2222
</div>
2323
<div class="row">
2424
<div class="col-md-4">
25-
<label for="id_country">{{ form.fields.country.label }}</label>
25+
<label for="{{ form.country.id_for_label }}">{{ form.fields.country.label }}</label>
2626
{{ form.country }}
2727

2828
<div class="search-checkbox">
2929
<hr>
30-
{{ form.past_events }}
31-
<label for="id_include_past">{{ form.past_events.label }}</label>
30+
<label for="{{ form.past.id_for_label }}">{{ form.past.label }}</label>
31+
{{ form.past}}
3232
</div>
3333

3434
<div class="search-checkbox">
@@ -57,7 +57,7 @@
5757

5858
{% block custom_js %}
5959
{{ block.super }}
60-
<script type="text/javascript" src="{% static "js/endless_pagination/custom-endless-pagination.js" %}" ></script>
60+
<script type="text/javascript" src="{% static "js/endless_pagination/endless-pagination.js" %}" ></script>
6161
<script type="text/javascript" src="{% static "js/faceted-search-events.js" %}" ></script>
6262
<script type="text/javascript">
6363
Codeweek.FacetedSearch.init();

web/tests/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Meta:
1010
model = Event
1111

1212
organizer="Event Organizer"
13-
creator=factory.LazyAttribute(lambda n: User.objects.get(pk=1))
13+
creator=factory.LazyAttribute(lambda n: User.objects.get_or_create(username='test_user')[0])
1414
title="My Coding Event"
1515
description="Some description"
1616
location="Nonexisting location"
@@ -20,6 +20,9 @@ class Meta:
2020
country="SI"
2121
tags=["tag1", "tag2"]
2222

23+
audience =[1]
24+
theme=[1]
25+
2326
start_date=factory.LazyAttribute(lambda n: datetime.datetime.now() + datetime.timedelta(days=1, hours=3) )
2427
end_date=factory.LazyAttribute(lambda n: datetime.datetime.now() + datetime.timedelta(days=3, hours=3) )
2528

web/tests/test_event_search.py

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# -*- coding: utf-8 -*-
2+
import pytest
3+
from django.core.urlresolvers import reverse
4+
5+
from web.tests import EventFactory, ApprovedEventFactory, PastEventFactory
6+
7+
@pytest.mark.django_db
8+
def test_search_show_only_approved(db, client):
9+
approved_event = ApprovedEventFactory.create()
10+
unapproved_event = EventFactory.create()
11+
12+
response = client.get('/search/')
13+
14+
assert approved_event.get_absolute_url() in response.content
15+
assert unapproved_event.get_absolute_url() not in response.content
16+
17+
map(lambda x: x.delete(), [approved_event, unapproved_event])
18+
19+
def test_search_do_not_show_past_events(db, client):
20+
future_event = ApprovedEventFactory.create()
21+
past_event = PastEventFactory.create(status='APPROVED')
22+
23+
response = client.get('/search/')
24+
25+
assert future_event.get_absolute_url() in response.content
26+
assert past_event.get_absolute_url() not in response.content
27+
28+
map(lambda x: x.delete(), [future_event, past_event])
29+
30+
31+
def test_search_show_past_events(db, client):
32+
future_event = ApprovedEventFactory.create()
33+
past_event = PastEventFactory.create(status='APPROVED')
34+
35+
response = client.get('/search/?past=yes')
36+
37+
assert future_event.get_absolute_url() in response.content
38+
assert past_event.get_absolute_url() in response.content
39+
40+
map(lambda x: x.delete(), [future_event, past_event])
41+
42+
43+
def test_search_events_with_search_query_all_countries_multiple_results(db, client):
44+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
45+
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT")
46+
47+
response = client.get(reverse('web.search_events'), {'q':'arglebargle', 'country':'00'}, REMOTE_ADDR='93.103.53.11')
48+
49+
assert approved1.get_absolute_url() in response.content
50+
assert approved2.get_absolute_url() in response.content
51+
52+
map(lambda x: x.delete(), [approved1, approved2])
53+
54+
55+
def test_search_events_with_search_query(db, client):
56+
approved1 = ApprovedEventFactory.create(title='Event Arglebargle - Approved')
57+
response = client.get(reverse('web.search_events'), {'q':'arglebargle'}, REMOTE_ADDR='93.103.53.11')
58+
59+
assert approved1.get_absolute_url() in response.content
60+
61+
approved1.delete()
62+
63+
64+
65+
def test_search_events_with_unicode_tag_in_search_query(db, client):
66+
approved1 = ApprovedEventFactory.create(tags=[u"jabolčna čežana",u"José", "Django"])
67+
response = client.get(reverse('web.search_events'), {'q':'čežana'}, REMOTE_ADDR='93.103.53.11')
68+
69+
assert approved1.get_absolute_url() in response.content
70+
71+
approved1.delete()
72+
73+
74+
def test_search_events_with_search_query_multiple_events_current_country_only(db, client):
75+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
76+
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT")
77+
78+
response = client.get(reverse('web.search_events'), {'q':'arglebargle'}, REMOTE_ADDR='93.103.53.11')
79+
80+
assert approved1.get_absolute_url() in response.content
81+
assert approved2.get_absolute_url() not in response.content
82+
83+
map(lambda x: x.delete(), [approved1, approved2])
84+
85+
86+
def test_search_with_audience(db, client):
87+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
88+
response = client.get(reverse('web.search_events'), {'audience':1}, REMOTE_ADDR='93.103.53.11')
89+
90+
assert approved1.get_absolute_url() in response.content
91+
92+
approved1.delete()
93+
94+
95+
def test_search_with_audience_multiple_events(db, client):
96+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI") #default audience 1
97+
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI", audience=[1,2])
98+
approved3 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT", audience=[1,2])
99+
approved4 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI", audience=[3])
100+
response = client.get(reverse('web.search_events'), {'audience':1}, REMOTE_ADDR='93.103.53.11')
101+
102+
assert approved1.get_absolute_url() in response.content
103+
assert approved2.get_absolute_url() in response.content
104+
assert approved3.get_absolute_url() not in response.content
105+
assert approved4.get_absolute_url() not in response.content
106+
107+
map(lambda x: x.delete(), [approved1, approved2, approved3, approved4])
108+
109+
110+
111+
def test_search_with_theme(db, client):
112+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI", theme=[2])
113+
response = client.get(reverse('web.search_events'), {'theme':2}, REMOTE_ADDR='93.103.53.11')
114+
115+
assert approved1.get_absolute_url() in response.content
116+
117+
approved1.delete()
118+
119+
120+
def test_search_with_theme_multiple_events(db, client):
121+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
122+
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI", theme=[2])
123+
response = client.get(reverse('web.search_events'), {'theme':1}, REMOTE_ADDR='93.103.53.11')
124+
125+
assert approved1.get_absolute_url() in response.content
126+
assert approved2.get_absolute_url() not in response.content
127+
128+
map(lambda x: x.delete(), [approved1, approved2])
129+
130+
131+
132+
def test_search_with_theme_multiple_events_all_countries(db, client):
133+
approved1 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="SI")
134+
approved2 = ApprovedEventFactory.create(title="Event Arglebargle - Approved", country="AT")
135+
response = client.get(reverse('web.search_events'), {'country':'00', 'theme':1}, REMOTE_ADDR='93.103.53.11')
136+
137+
assert approved1.get_absolute_url() in response.content
138+
assert approved2.get_absolute_url() in response.content
139+
140+
map(lambda x: x.delete(), [approved1, approved2])

0 commit comments

Comments
 (0)