mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-01-17 05:22:16 +00:00
Compare commits
24 Commits
2d2df68c07
...
search
| Author | SHA1 | Date | |
|---|---|---|---|
|
4f088fb426
|
|||
|
3a7dc061bb
|
|||
| d5f54b1d88 | |||
|
3d00b935fc
|
|||
|
a3e0f3ed03
|
|||
|
724d09734b
|
|||
|
459a9b5b05
|
|||
|
9889889f9a
|
|||
|
6bcb242d6b
|
|||
|
94184a33c4
|
|||
|
a920b207c1
|
|||
|
|
db571d5df0 | ||
|
|
e35f3daa09 | ||
|
|
d2fbdd8d97 | ||
|
|
74bb5d2792 | ||
|
|
ce3acf6b76 | ||
|
|
93458ea5a9 | ||
|
|
472996545b | ||
|
|
c1b416251c | ||
|
|
03f7709769 | ||
|
|
f8afd8c1da | ||
|
|
60c7d1705f | ||
|
|
2528399bd9 | ||
|
|
9db9902bb9 |
@@ -11,6 +11,7 @@ from django.template.loader import get_template
|
||||
from django.views import generic
|
||||
from django.db.models import Q
|
||||
from z3c.rml import rml2pdf
|
||||
from django.db.models import Q
|
||||
|
||||
from RIGS import models
|
||||
|
||||
@@ -122,6 +123,34 @@ class InvoiceArchive(generic.ListView):
|
||||
template_name = 'RIGS/invoice_list_archive.html'
|
||||
paginate_by = 25
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
|
||||
filter = Q(event__name__icontains=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
filter = filter | Q(pk=val)
|
||||
filter = filter | Q(event__pk=val)
|
||||
except: # noqa
|
||||
# not an integer
|
||||
pass
|
||||
|
||||
try:
|
||||
if q[0] == "N":
|
||||
val = int(q[1:])
|
||||
filter = Q(event__pk=val) # If string is Nxxxxx then filter by event number
|
||||
elif q[0] == "#":
|
||||
val = int(q[1:])
|
||||
filter = Q(pk=val) # If string is #xxxxx then filter by invoice number
|
||||
except: # noqa
|
||||
pass
|
||||
|
||||
object_list = self.model.objects.filter(filter).order_by('-invoice_date')
|
||||
|
||||
return object_list
|
||||
|
||||
|
||||
class InvoiceWaiting(generic.ListView):
|
||||
model = models.Event
|
||||
|
||||
@@ -226,10 +226,18 @@ class EventPrint(generic.View):
|
||||
return response
|
||||
|
||||
|
||||
class EventArchive(generic.ArchiveIndexView):
|
||||
class EventArchive(generic.ListView):
|
||||
model = models.Event
|
||||
date_field = "start_date"
|
||||
paginate_by = 25
|
||||
template_name = "RIGS/event_archive.html"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
# get super context
|
||||
context = super(EventArchive, self).get_context_data(**kwargs)
|
||||
|
||||
context['start'] = self.request.GET.get('start', None)
|
||||
context['end'] = self.request.GET.get('end', datetime.date.today().strftime('%Y-%m-%d'))
|
||||
return context
|
||||
|
||||
def get_queryset(self):
|
||||
start = self.request.GET.get('start', None)
|
||||
@@ -241,19 +249,34 @@ class EventArchive(generic.ArchiveIndexView):
|
||||
"Muppet! Check the dates, it has been fixed for you.")
|
||||
start, end = end, start # Stop the impending fail
|
||||
|
||||
filter = False
|
||||
filter = Q()
|
||||
if end != "":
|
||||
filter = Q(start_date__lte=end)
|
||||
filter &= Q(start_date__lte=end)
|
||||
if start:
|
||||
if filter:
|
||||
filter = filter & Q(start_date__gte=start)
|
||||
else:
|
||||
filter = Q(start_date__gte=start)
|
||||
filter &= Q(start_date__gte=start)
|
||||
|
||||
if filter:
|
||||
qs = self.model.objects.filter(filter).order_by('-start_date')
|
||||
else:
|
||||
qs = self.model.objects.all().order_by('-start_date')
|
||||
q = self.request.GET.get('q', "")
|
||||
|
||||
if q is not "":
|
||||
qfilter = Q(name__icontains=q) | Q(description__icontains=q) | Q(notes__icontains=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
qfilter = qfilter | Q(pk=val)
|
||||
except: # noqa not an integer
|
||||
pass
|
||||
|
||||
try:
|
||||
if q[0] == "N":
|
||||
val = int(q[1:])
|
||||
qfilter = Q(pk=val) # If string is N###### then do a simple PK filter
|
||||
except: # noqa
|
||||
pass
|
||||
|
||||
filter &= qfilter
|
||||
|
||||
qs = self.model.objects.filter(filter).order_by('-start_date')
|
||||
|
||||
# Preselect related for efficiency
|
||||
qs.select_related('person', 'organisation', 'venue', 'mic')
|
||||
|
||||
@@ -5,34 +5,49 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<h2>Event Archive</h2>
|
||||
|
||||
<div class="col-sm-12 col-md-6 pagination">
|
||||
<div class="col-sm-12">
|
||||
<h2>Event Archive</h2>
|
||||
</div>
|
||||
<div class="col-sm-12">
|
||||
<form class="form-inline">
|
||||
<div class="form-group">
|
||||
<label for="start">Start</label>
|
||||
<input type="date" name="start" id="start" value="{{ request.GET.start }}" placeholder="Start" class="form-control" />
|
||||
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">Start</div>
|
||||
<input type="date" name="start" id="start" value="{{ start|default_if_none:"" }}" placeholder="Start" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="end">End</label>
|
||||
<input type="date" name="end" id="end" value="{% if request.GET.end %}{{ request.GET.end }}{% else %}{% now "Y-m-d" %}{% endif %}" placeholder="End" class="form-control" />
|
||||
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">End</div>
|
||||
<input type="date" name="end" id="end" value="{{ end|default_if_none:"" }}" placeholder="End" class="form-control" />
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<input type="submit" class="btn btn-primary" />
|
||||
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">Keyword</div>
|
||||
<input type="search" name="q" placeholder="Keyword" value="{{ request.GET.q }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
|
||||
<div class="input-group">
|
||||
<input type="submit" class="btn btn-primary" value="Search"/>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
|
||||
{% if is_paginated %}
|
||||
<div class="col-md-6 text-right">
|
||||
{% paginator %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col-sm-12">
|
||||
{% if is_paginated %}
|
||||
<div class="pull-right">
|
||||
{% paginator %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
<div class="row">
|
||||
{% with latest as events %}
|
||||
{% include 'RIGS/event_table.html' %}
|
||||
{% endwith %}
|
||||
<div class="col-sm-12">
|
||||
{% with object_list as events %}
|
||||
{% include 'RIGS/event_table.html' %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if is_paginated %}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
{% extends 'base_rigs.html' %}
|
||||
{% block title %}RIGS{% endblock %}
|
||||
|
||||
{% block js %}
|
||||
<script>
|
||||
$(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-sm-12">
|
||||
<h1>R<small>ig</small> I<small>nformation</small> G<small>athering</small> S<small>ystem</small></h1>
|
||||
@@ -36,35 +44,41 @@
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4 class="panel-title">Search Rigboard</h4>
|
||||
<h4 class="panel-title">Search Rigboard
|
||||
<a href="{% url 'search_help' %}" class="pull-right modal-href"><span class="glyphicon glyphicon-question-sign"</span></a></h4>
|
||||
</div>
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$('#search-options li a').click(function(){
|
||||
$('#searchForm').attr('action', $(this).data('action')).submit();
|
||||
});
|
||||
$('#id_search_input').keypress(function (e) {
|
||||
if (e.which == 13) {
|
||||
$('#searchForm').attr('action', $('#search-options li a').first().data('action')).submit();
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
<div class="list-group">
|
||||
<div class="list-group-item">
|
||||
<form class="form" role="form" action="{% url 'person_list' %}" method="GET">
|
||||
<div class="input-group">
|
||||
<input type="search" name="q" class="form-control" placeholder="Search People" />
|
||||
<form id="searchForm" class="form" role="form" method="GET">
|
||||
<div class="input-group" data-toggle="tooltip" title="Use the dropdown button to select what to search. The default is Event Archive.">
|
||||
<input id="id_search_input" type="search" name="q" class="form-control" placeholder="Search..." />
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
<form class="form" role="form" action="{% url 'organisation_list' %}" method="GET">
|
||||
<div class="input-group">
|
||||
<input type="search" name="q" class="form-control" placeholder="Search Organisations" />
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="list-group-item">
|
||||
<form class="form" role="form" action="{% url 'venue_list' %}" method="GET">
|
||||
<div class="input-group">
|
||||
<input type="search" name="q" class="form-control" placeholder="Search Venues" />
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
|
||||
<div class="btn-group" role="group">
|
||||
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-search"></span> Search <span class="caret"></span></button>
|
||||
<ul id="search-options" class="dropdown-menu">
|
||||
<li><a data-action="{% url 'event_archive' %}" href="#">Events</a></li>
|
||||
<li><a data-action="{% url 'person_list' %}" href="#">People</a></li>
|
||||
<li><a data-action="{% url 'organisation_list' %}" href="#">Organisations</a></li>
|
||||
<li><a data-action="{% url 'venue_list' %}" href="#">Venues</a></li>
|
||||
{% if perms.RIGS.view_invoice %}
|
||||
<li><a data-action="{% url 'invoice_archive' %}" href="#">Invoices</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
{% paginator %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% block search %}{% endblock %}
|
||||
<div class="table-responsive col-sm-12">
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
|
||||
@@ -10,4 +10,15 @@ All Invoices
|
||||
|
||||
{% block description %}
|
||||
<p>This page displays all invoices: outstanding, paid, and void</p>
|
||||
{% endblock %}
|
||||
|
||||
{% block search %}
|
||||
<div class="col-sm-3 col-sm-offset-9">
|
||||
<form class="form form-horizontal col-sm-12">
|
||||
<div class="form-group">
|
||||
<input type="search" name="q" placeholder="Search" value="{{ request.GET.q }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
70
RIGS/templates/RIGS/search_help.html
Normal file
70
RIGS/templates/RIGS/search_help.html
Normal file
@@ -0,0 +1,70 @@
|
||||
{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
|
||||
|
||||
{% block title %}Search Help{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
{% if not request.is_ajax %}
|
||||
<div class="col-sm-12">
|
||||
<h1>Search Help</h1>
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="col-sm-12">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Searching Events</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>
|
||||
Searches for entire query in:
|
||||
<button type="button" class="btn btn-default btn-xs">name</button>
|
||||
<button type="button" class="btn btn-default btn-xs">description</button> and
|
||||
<button type="button" class="btn btn-default btn-xs">notes</button>
|
||||
</p>
|
||||
<p>You can search for an event by <button type="button" class="btn btn-default btn-xs">event_id</button> by entering an integer, or using the format <code>N01234</code></p>
|
||||
<p>On the search results page you can also specify the date range for the <button type="button" class="btn btn-default btn-xs">start_date</button> of the event</p>
|
||||
<p>Events are sorted in reverse <button type="button" class="btn btn-default btn-xs">start_date</button> order (most recent events at the top)</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Searching People/Organisations/Venues</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>
|
||||
Searches for entire search phrase in:
|
||||
<button type="button" class="btn btn-default btn-xs">name</button>
|
||||
<button type="button" class="btn btn-default btn-xs">email</button>
|
||||
<button type="button" class="btn btn-default btn-xs">address</button>
|
||||
<button type="button" class="btn btn-default btn-xs">notes</button> and
|
||||
<button type="button" class="btn btn-default btn-xs">phone</button>
|
||||
</p>
|
||||
<p>You can search for an entry by <button type="button" class="btn btn-default btn-xs">id</button> by entering an integer</p>
|
||||
<p>Entries are sorted in alphabetical order by <button type="button" class="btn btn-default btn-xs">name</button></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if perms.RIGS.view_invoice %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">Searching Invoices</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>
|
||||
Searches for entire search phrase in:
|
||||
<button type="button" class="btn btn-default btn-xs">event__name</button>
|
||||
</p>
|
||||
<p>You can search for an event's invoice by entering the <button type="button" class="btn btn-default btn-xs">event_id</button> using the format <code>N01234</code></p>
|
||||
<p>You can search for an invoice by <button type="button" class="btn btn-default btn-xs">invoice_id</button> using the format <code>#01234</code></p>
|
||||
<p>Entering a raw integer will search by both <button type="button" class="btn btn-default btn-xs">invoice_id</button> and <button type="button" class="btn btn-default btn-xs">event_id</button></p>
|
||||
<p>Entries are sorted in reverse <button type="button" class="btn btn-default btn-xs">invoice_date</button> order</p>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -254,7 +254,7 @@ class EventTest(LiveServerTestCase):
|
||||
|
||||
# Slider expands and save button visible
|
||||
self.assertTrue(save.is_displayed())
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
|
||||
# For now, just check that HTML5 Client validation is in place TODO Test needs rewriting to properly test all levels of validation.
|
||||
self.assertTrue(self.browser.find_element_by_id('id_name').get_attribute('required') is not None)
|
||||
@@ -492,7 +492,7 @@ class EventTest(LiveServerTestCase):
|
||||
|
||||
save = self.browser.find_element_by_xpath(
|
||||
'(//button[@type="submit"])[3]')
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
|
||||
# Check the items are visible
|
||||
table = self.browser.find_element_by_id('item-table') # ID number is known, see above
|
||||
@@ -574,7 +574,7 @@ class EventTest(LiveServerTestCase):
|
||||
# Click Rig button
|
||||
self.browser.find_element_by_xpath('//button[.="Rig"]').click()
|
||||
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('//*[@id="content"]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
# Set title
|
||||
@@ -604,7 +604,7 @@ class EventTest(LiveServerTestCase):
|
||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||
|
||||
# Same date, end time before start time
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
@@ -623,7 +623,7 @@ class EventTest(LiveServerTestCase):
|
||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||
|
||||
# Same date, end time before start time
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
@@ -636,7 +636,7 @@ class EventTest(LiveServerTestCase):
|
||||
form.find_element_by_id('id_end_time').send_keys('06:00')
|
||||
|
||||
# No end date, end time before start time
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
@@ -655,7 +655,7 @@ class EventTest(LiveServerTestCase):
|
||||
self.assertIn("can't finish before it has started", error.find_element_by_xpath('//dd[1]/ul/li').text)
|
||||
|
||||
# 2 dates, end after start
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
self.browser.execute_script("document.getElementById('id_start_date').value='3015-04-24'")
|
||||
self.browser.execute_script("document.getElementById('id_end_date').value='3015-04-26'")
|
||||
@@ -688,7 +688,7 @@ class EventTest(LiveServerTestCase):
|
||||
# Click Rig button
|
||||
self.browser.find_element_by_xpath('//button[.="Rig"]').click()
|
||||
|
||||
form = self.browser.find_element_by_tag_name('form')
|
||||
form = self.browser.find_element_by_xpath('/html/body/div[2]/div[1]/form')
|
||||
save = self.browser.find_element_by_xpath('(//button[@type="submit"])[3]')
|
||||
|
||||
# Set title
|
||||
@@ -1222,3 +1222,47 @@ class TECEventAuthorisationTest(TestCase):
|
||||
self.assertEqual(self.event.auth_request_by, self.profile)
|
||||
self.assertEqual(self.event.auth_request_to, 'client@functional.test')
|
||||
self.assertIsNotNone(self.event.auth_request_at)
|
||||
|
||||
|
||||
class SearchTest(LiveServerTestCase):
|
||||
def setUp(self):
|
||||
self.profile = models.Profile(
|
||||
username="SearchTest", first_name="Search", last_name="Test", initials="STU", is_superuser=True)
|
||||
self.profile.set_password("SearchTestPassword")
|
||||
self.profile.save()
|
||||
|
||||
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
|
||||
|
||||
self.browser = create_browser()
|
||||
self.browser.implicitly_wait(10) # Set implicit wait session wide
|
||||
|
||||
os.environ['RECAPTCHA_TESTING'] = 'True'
|
||||
|
||||
models.Event.objects.create(name="Right Event", status=models.Event.PROVISIONAL,
|
||||
start_date=date.today(), description="This event is searched for endlessly over and over")
|
||||
models.Event.objects.create(name="Wrong Event", status=models.Event.PROVISIONAL, start_date=date.today(),
|
||||
description="This one should never be found.")
|
||||
|
||||
def tearDown(self):
|
||||
self.browser.quit()
|
||||
os.environ['RECAPTCHA_TESTING'] = 'False'
|
||||
|
||||
def test_search(self):
|
||||
self.browser.get(self.live_server_url)
|
||||
username = self.browser.find_element_by_id('id_username')
|
||||
password = self.browser.find_element_by_id('id_password')
|
||||
submit = self.browser.find_element_by_css_selector(
|
||||
'input[type=submit]')
|
||||
|
||||
username.send_keys("SearchTest")
|
||||
password.send_keys("SearchTestPassword")
|
||||
submit.click()
|
||||
|
||||
form = self.browser.find_element_by_id('searchForm')
|
||||
search_box = form.find_element_by_id('id_search_input')
|
||||
search_box.send_keys('Right')
|
||||
search_box.send_keys(Keys.ENTER)
|
||||
|
||||
event_name = self.browser.find_element_by_xpath('//*[@id="content"]/div[1]/div[4]/div/div/table/tbody/tr[1]/td[3]/h4').text
|
||||
self.assertIn('Right', event_name)
|
||||
self.assertNotIn('Wrong', event_name)
|
||||
|
||||
@@ -423,3 +423,107 @@ class TestSampleDataGenerator(TestCase):
|
||||
from django.core.management.base import CommandError
|
||||
|
||||
self.assertRaisesRegex(CommandError, ".*production", call_command, 'generateSampleRIGSData')
|
||||
|
||||
|
||||
class TestSearchLogic(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
cls.profile = models.Profile.objects.create(username="testuser1", email="1@test.com", is_superuser=True,
|
||||
is_active=True, is_staff=True)
|
||||
|
||||
cls.persons = {
|
||||
1: models.Person.objects.create(name="Right Person", phone="1234"),
|
||||
2: models.Person.objects.create(name="Wrong Person", phone="5678"),
|
||||
}
|
||||
|
||||
cls.organisations = {
|
||||
1: models.Organisation.objects.create(name="Right Organisation", email="test@example.com"),
|
||||
2: models.Organisation.objects.create(name="Wrong Organisation", email="check@fake.co.uk"),
|
||||
}
|
||||
|
||||
cls.venues = {
|
||||
1: models.Venue.objects.create(name="Right Venue", address="1 Test Street, EX1"),
|
||||
2: models.Venue.objects.create(name="Wrong Venue", address="2 Check Way, TS2"),
|
||||
}
|
||||
|
||||
cls.events = {
|
||||
1: models.Event.objects.create(name="Right Event", start_date=date.today(), person=cls.persons[1],
|
||||
organisation=cls.organisations[1], venue=cls.venues[1]),
|
||||
2: models.Event.objects.create(name="Wrong Event", start_date=date.today(), person=cls.persons[2],
|
||||
organisation=cls.organisations[2], venue=cls.venues[2]),
|
||||
}
|
||||
|
||||
def setUp(self):
|
||||
self.profile.set_password('testuser')
|
||||
self.profile.save()
|
||||
self.assertTrue(self.client.login(username=self.profile.username, password='testuser'))
|
||||
|
||||
def test_event_search(self):
|
||||
# Test search by name
|
||||
request_url = "%s?q=%s" % (reverse('event_archive'), self.events[1].name)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.events[1].name)
|
||||
self.assertNotContains(response, self.events[2].name)
|
||||
|
||||
# Test search by ID
|
||||
request_url = "%s?q=%s" % (reverse('event_archive'), self.events[1].pk)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.events[1].name)
|
||||
self.assertNotContains(response, self.events[2].name)
|
||||
|
||||
def test_people_search(self):
|
||||
# Test search by name
|
||||
request_url = "%s?q=%s" % (reverse('person_list'), self.persons[1].name)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.persons[1].name)
|
||||
self.assertNotContains(response, self.persons[2].name)
|
||||
|
||||
# Test search by ID
|
||||
request_url = "%s?q=%s" % (reverse('person_list'), self.persons[1].pk)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.persons[1].name)
|
||||
self.assertNotContains(response, self.persons[2].name)
|
||||
|
||||
# Test search by phone
|
||||
request_url = "%s?q=%s" % (reverse('person_list'), self.persons[1].phone)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.persons[1].name)
|
||||
self.assertNotContains(response, self.persons[2].name)
|
||||
|
||||
def test_organisation_search(self):
|
||||
# Test search by name
|
||||
request_url = "%s?q=%s" % (reverse('organisation_list'), self.organisations[1].name)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.organisations[1].name)
|
||||
self.assertNotContains(response, self.organisations[2].name)
|
||||
|
||||
# Test search by ID
|
||||
request_url = "%s?q=%s" % (reverse('organisation_list'), self.organisations[1].pk)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.organisations[1].name)
|
||||
self.assertNotContains(response, self.organisations[2].name)
|
||||
|
||||
# Test search by email
|
||||
request_url = "%s?q=%s" % (reverse('organisation_list'), self.organisations[1].email)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.organisations[1].email)
|
||||
self.assertNotContains(response, self.organisations[2].email)
|
||||
|
||||
def test_venue_search(self):
|
||||
# Test search by name
|
||||
request_url = "%s?q=%s" % (reverse('venue_list'), self.venues[1].name)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.venues[1].name)
|
||||
self.assertNotContains(response, self.venues[2].name)
|
||||
|
||||
# Test search by ID
|
||||
request_url = "%s?q=%s" % (reverse('venue_list'), self.venues[1].pk)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.venues[1].name)
|
||||
self.assertNotContains(response, self.venues[2].name)
|
||||
|
||||
# Test search by address
|
||||
request_url = "%s?q=%s" % (reverse('venue_list'), self.venues[1].address)
|
||||
response = self.client.get(request_url, follow=True)
|
||||
self.assertContains(response, self.venues[1].address)
|
||||
self.assertNotContains(response, self.venues[2].address)
|
||||
|
||||
@@ -21,6 +21,8 @@ urlpatterns = [
|
||||
|
||||
url(r'^user/password_reset/$', views.PasswordResetDisabled.as_view()),
|
||||
|
||||
url(r'^search_help/$', views.SearchHelp.as_view(), name='search_help'),
|
||||
|
||||
# People
|
||||
url(r'^people/$', permission_required_with_403('RIGS.view_person')(views.PersonList.as_view()),
|
||||
name='person_list'),
|
||||
|
||||
@@ -44,6 +44,10 @@ def login(request, **kwargs):
|
||||
return login(request, authentication_form=forms.CheckApprovedForm)
|
||||
|
||||
|
||||
class SearchHelp(generic.TemplateView):
|
||||
template_name = 'RIGS/search_help.html'
|
||||
|
||||
|
||||
# This view should be exempt from requiring CSRF token.
|
||||
# Then we can check for it and show a nice error
|
||||
# Don't worry, django.contrib.auth.views.login will
|
||||
@@ -86,11 +90,20 @@ class PersonList(generic.ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
if len(q) >= 3:
|
||||
object_list = self.model.objects.filter(Q(name__icontains=q) | Q(email__icontains=q))
|
||||
else:
|
||||
object_list = self.model.objects.all()
|
||||
orderBy = self.request.GET.get('orderBy', None)
|
||||
|
||||
filter = Q(name__icontains=q) | Q(email__icontains=q) | Q(address__icontains=q) | Q(notes__icontains=q) | Q(phone__startswith=q) | Q(phone__endswith=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
filter = filter | Q(pk=val)
|
||||
except: # noqa
|
||||
# not an integer
|
||||
pass
|
||||
|
||||
object_list = self.model.objects.filter(filter)
|
||||
|
||||
orderBy = self.request.GET.get('orderBy', 'name')
|
||||
if orderBy is not None:
|
||||
object_list = object_list.order_by(orderBy)
|
||||
return object_list
|
||||
@@ -140,11 +153,20 @@ class OrganisationList(generic.ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
if len(q) >= 3:
|
||||
object_list = self.model.objects.filter(Q(name__icontains=q) | Q(address__icontains=q))
|
||||
else:
|
||||
object_list = self.model.objects.all()
|
||||
orderBy = self.request.GET.get('orderBy', "")
|
||||
|
||||
filter = Q(name__icontains=q) | Q(email__icontains=q) | Q(address__icontains=q) | Q(notes__icontains=q) | Q(phone__startswith=q) | Q(phone__endswith=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
filter = filter | Q(pk=val)
|
||||
except: # noqa
|
||||
# not an integer
|
||||
pass
|
||||
|
||||
object_list = self.model.objects.filter(filter)
|
||||
|
||||
orderBy = self.request.GET.get('orderBy', "name")
|
||||
if orderBy is not "":
|
||||
object_list = object_list.order_by(orderBy)
|
||||
return object_list
|
||||
@@ -194,11 +216,20 @@ class VenueList(generic.ListView):
|
||||
|
||||
def get_queryset(self):
|
||||
q = self.request.GET.get('q', "")
|
||||
if len(q) >= 3:
|
||||
object_list = self.model.objects.filter(Q(name__icontains=q) | Q(address__icontains=q))
|
||||
else:
|
||||
object_list = self.model.objects.all()
|
||||
orderBy = self.request.GET.get('orderBy', "")
|
||||
|
||||
filter = Q(name__icontains=q) | Q(email__icontains=q) | Q(address__icontains=q) | Q(notes__icontains=q) | Q(phone__startswith=q) | Q(phone__endswith=q)
|
||||
|
||||
# try and parse an int
|
||||
try:
|
||||
val = int(q)
|
||||
filter = filter | Q(pk=val)
|
||||
except: # noqa
|
||||
# not an integer
|
||||
pass
|
||||
|
||||
object_list = self.model.objects.filter(filter)
|
||||
|
||||
orderBy = self.request.GET.get('orderBy', "name")
|
||||
if orderBy is not "":
|
||||
object_list = object_list.order_by(orderBy)
|
||||
return object_list
|
||||
|
||||
Reference in New Issue
Block a user