From 3ce01e79c559cf38abe382106d4e1376b265230b Mon Sep 17 00:00:00 2001 From: tomtom5152 Date: Thu, 5 Mar 2015 18:20:43 +0000 Subject: [PATCH] Readded start>end checking. Template improvements Added descritpions of all error for the user as well as the image. Added contextual alert boxes for messages in base. If start>end start<=>end. Very simple fix, thanks Charlie. --- RIGS/rigboard.py | 20 +++++++++++++++++--- templates/400.html | 1 + templates/401.html | 1 + templates/403.html | 1 + templates/404.html | 8 ++++++-- templates/500.html | 1 + templates/base.html | 6 +++++- 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/RIGS/rigboard.py b/RIGS/rigboard.py index 7c5c305c..737b7dc9 100644 --- a/RIGS/rigboard.py +++ b/RIGS/rigboard.py @@ -6,11 +6,12 @@ import urllib2 from django.views import generic from django.core.urlresolvers import reverse_lazy from django.shortcuts import get_object_or_404 -from django.template import Context, RequestContext +from django.template import RequestContext from django.template.loader import get_template from django.conf import settings -from django.http import HttpResponse, HttpResponseBadRequest +from django.http import HttpResponse from django.db.models import Q +from django.contrib import messages from z3c.rml import rml2pdf from PyPDF2 import PdfFileMerger, PdfFileReader @@ -125,6 +126,13 @@ class EventArchive(generic.ArchiveIndexView): def get_queryset(self): start = self.request.GET.get('start', None) end = self.request.GET.get('end', datetime.date.today()) + + # Assume idiots, always check + if start and start > end: + messages.add_message(self.request, messages.INFO, + "Muppet! Check the dates, it has been fixed for you.") + start, end = end, start # Stop the impending fail + filter = False if end != "": filter = Q(start_date__lte=end) @@ -139,4 +147,10 @@ class EventArchive(generic.ArchiveIndexView): else: qs = self.model.objects.all() - return qs.select_related('person', 'organisation', 'venue', 'mic') \ No newline at end of file + # Preselect related for efficiency + qs.select_related('person', 'organisation', 'venue', 'mic') + + if len(qs) == 0: + messages.add_message(self.request, messages.WARNING, "No events have been found matching those criteria.") + + return qs \ No newline at end of file diff --git a/templates/400.html b/templates/400.html index 69c93032..5dd0c30b 100644 --- a/templates/400.html +++ b/templates/400.html @@ -4,6 +4,7 @@ {% block content %}
+

400: Bad Request

{% endblock %} diff --git a/templates/401.html b/templates/401.html index 6d930f91..9b9b019f 100644 --- a/templates/401.html +++ b/templates/401.html @@ -4,6 +4,7 @@ {% block content %}
+

401: Unauthorized

{% endblock %} diff --git a/templates/403.html b/templates/403.html index 2bae9f1f..5f59c351 100644 --- a/templates/403.html +++ b/templates/403.html @@ -4,6 +4,7 @@ {% block content %}
+

403: Forbidden

{% endblock %} diff --git a/templates/404.html b/templates/404.html index 81dc065f..5b347c1b 100644 --- a/templates/404.html +++ b/templates/404.html @@ -3,7 +3,11 @@ {% block title %}Page Not Found{% endblock %} {% block content %} -
- +
+

404: Not Found

+ +
+ +
{% endblock %} diff --git a/templates/500.html b/templates/500.html index 3d93d52c..c135cd4c 100644 --- a/templates/500.html +++ b/templates/500.html @@ -4,6 +4,7 @@ {% block content %}
+

500: Server error

{% endblock %} diff --git a/templates/base.html b/templates/base.html index d952fbc3..a2f9af04 100644 --- a/templates/base.html +++ b/templates/base.html @@ -110,7 +110,11 @@
{{ info }}
{% endif %} {% if messages %} {% for message in messages %} -
{{ message }}
+ {% endfor %} {% endif %} {% endblock %}