summaryrefslogtreecommitdiff
path: root/chimere/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'chimere/views.py')
-rw-r--r--chimere/views.py121
1 files changed, 62 insertions, 59 deletions
diff --git a/chimere/views.py b/chimere/views.py
index 88619ce..562688d 100644
--- a/chimere/views.py
+++ b/chimere/views.py
@@ -27,20 +27,18 @@ Views of the project
import datetime
from itertools import groupby
import re
-import simplejson as json
from django.conf import settings
from django.contrib.gis.geos import GEOSGeometry
from django.contrib.gis.gdal.error import OGRException
from django.contrib.gis.measure import D
from django.contrib.sites.models import get_current_site
-from django.core import serializers
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Q
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.shortcuts import get_object_or_404, redirect, render_to_response
-from django.template import loader, RequestContext, defaultfilters
+from django.template import RequestContext, defaultfilters
from django.utils import simplejson as json
from django.utils.http import urlquote
from django.utils.translation import ugettext as _
@@ -48,14 +46,13 @@ from django.views.generic import TemplateView, ListView
from chimere.actions import actions
from chimere.models import Category, SubCategory, PropertyModel, Page,\
- Marker, Route, News, SimpleArea, Area, Color, TinyUrl, RouteFile,\
- AggregatedRoute
+ Marker, Route, SimpleArea, Area, Color, TinyUrl, RouteFile,\
+ AggregatedRoute
-from chimere.widgets import getMapJS, PointChooserWidget, \
- RouteChooserWidget, AreaWidget
+from chimere.widgets import PointChooserWidget, RouteChooserWidget, AreaWidget
from chimere.forms import MarkerForm, RouteForm, ContactForm, FileForm, \
- FullFileForm, MultimediaFileFormSet, PictureFileFormSet, notifySubmission,\
- notifyStaff, AreaForm, RoutingForm, getStaffEmails
+ FullFileForm, MultimediaFileFormSet, PictureFileFormSet, notifySubmission,\
+ notifyStaff, AreaForm, RoutingForm
from chimere.route import router
@@ -333,10 +330,10 @@ def edit(request, area_name="", item_id=None, submited=False):
if request.POST and request.POST.get('point'):
point_value = request.POST.get('point')
response_dct.update({
- 'actions':actions(response_dct['area_name']),
- 'action_selected':('contribute', 'edit'),
- 'map_layer':settings.CHIMERE_DEFAULT_MAP_LAYER,
- 'form':form,
+ 'actions': actions(response_dct['area_name']),
+ 'action_selected': ('contribute', 'edit'),
+ 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
+ 'form': form,
'formset_multi':formset_multi,
'formset_picture':formset_picture,
'dated':settings.CHIMERE_DAYS_BEFORE_EVENT,
@@ -935,10 +932,10 @@ def route(request, area_name, lon1, lat1, lonlat_steps, lon2, lat2,
message = ''
data = '{"properties":{"transport":%s, "total":%s, "description":%s}, '\
'"type": "FeatureCollection", "features":[%s]%s}' % (
- jsonencoder.encode(transport), total, desc, ",".join(jsons),
- message)
+ jsonencoder.encode(transport), total, desc, ",".join(jsons), message)
return HttpResponse(data)
+
def rss(request, area_name=''):
'''
Redirect to RSS subscription page
@@ -946,15 +943,15 @@ def rss(request, area_name=''):
response_dct, redir = get_base_response(request, area_name)
if redir:
return redir
- response_dct.update({'actions':actions(response_dct['area_name']),
- 'action_selected':('rss',),
- 'category_rss_feed':'',})
+ response_dct.update({'actions': actions(response_dct['area_name']),
+ 'action_selected': ('rss',),
+ 'category_rss_feed': ''})
# If the form has been submited
if request.method == "POST":
# User has defined the kind of POI he is interested in : POI in a area
# (GET method is used for the link with RSS icon in the browser)
if 'rss_category' in request.POST:
- #User wants to follow all the new POI
+ # User wants to follow all the new POI
if request.POST['rss_category'] == 'global':
feeds_link = reverse('chimere:feeds-global')
return redirect(feeds_link)
@@ -962,59 +959,60 @@ def rss(request, area_name=''):
elif request.POST['rss_category'] == 'poi':
response_dct['category_rss_feed'] = 'category'
response_dct['sub_categories'] = SubCategory.getAvailable()
- return render_to_response('chimere/feeds/rss.html',
- response_dct,
- context_instance=RequestContext(request))
+ return render_to_response(
+ 'chimere/feeds/rss.html', response_dct,
+ context_instance=RequestContext(request))
# User wants to follow all the new POI situated in a defined area
elif request.POST['rss_category'] == 'area':
# An unbound form
form = AreaForm()
area_widget = AreaWidget().render('area', None)
response_dct.update({
- 'map_layer':settings.CHIMERE_DEFAULT_MAP_LAYER,
- 'extra_head':form.media,
- 'form':form,
- 'category_rss_feed':'area',
- 'area_id':Area.getAvailable(),
- 'area_widget':area_widget
+ 'map_layer': settings.CHIMERE_DEFAULT_MAP_LAYER,
+ 'extra_head': form.media,
+ 'form': form,
+ 'category_rss_feed': 'area',
+ 'area_id': Area.getAvailable(),
+ 'area_widget': area_widget
})
- return render_to_response('chimere/feeds/rss.html',
- response_dct,
- context_instance=RequestContext(request))
+ return render_to_response(
+ 'chimere/feeds/rss.html', response_dct,
+ context_instance=RequestContext(request))
# Error when submitting the form
else:
error = _("Incorrect choice in the list")
- response_dct.update({'error_message':error,
- 'category_rss_feed':'',
- 'sub_categories':SubCategory.getAvailable()})
- return render_to_response('chimere/feeds/rss.html',
- response_dct,
- context_instance=RequestContext(request))
+ response_dct.update({
+ 'error_message':error,
+ 'category_rss_feed': '',
+ 'sub_categories': SubCategory.getAvailable()})
+ return render_to_response(
+ 'chimere/feeds/rss.html', response_dct,
+ context_instance=RequestContext(request))
# User has specified the category or subcategory he wants to follow =>
# we redirect him towards the related rss feed
if 'subcategory' in request.POST and request.POST['subcategory'] != '':
cat_id = request.POST['subcategory']
- if cat_id.find("cat_") != -1 :
+ if cat_id.find("cat_") != -1:
cat_id = cat_id.split('_')[1]
feeds_link = reverse('chimere:feeds-cat',
- kwargs={'category_id':cat_id})
+ kwargs={'category_id': cat_id})
return redirect(feeds_link)
else:
feeds_link = reverse('chimere:feeds-subcat',
- kwargs={'category_id':cat_id})
+ kwargs={'category_id': cat_id})
return redirect(feeds_link)
# User has specified the ID of the area he wants to follow
if 'id_area' in request.POST and request.POST['id_area'] != '':
feeds_link = reverse('chimere:feeds-areaid',
- kwargs={'area_id':request.POST['id_area']})
+ kwargs={'area_id': request.POST['id_area']})
return redirect(feeds_link)
# User has specified the area he wants to follow => we redirect him
# towards the related rss feed (using upper left and lower right
- # coordinates)
+ # coordinates)
elif 'upper_left_lat' in request.POST and \
request.POST['upper_left_lat'] != '' and \
'upper_left_lon' in request.POST and \
@@ -1022,13 +1020,13 @@ def rss(request, area_name=''):
'lower_right_lon' in request.POST and \
request.POST['lower_right_lon'] != '' and \
'lower_right_lat' in request.POST and \
- request.POST['lower_right_lat'] != '' :
+ request.POST['lower_right_lat'] != '':
coords = request.POST['upper_left_lat'] + '_' + \
- request.POST['upper_left_lon'] + '_' + \
- request.POST['lower_right_lat'] + '_' + \
- request.POST['lower_right_lon']
+ request.POST['upper_left_lon'] + '_' + \
+ request.POST['lower_right_lat'] + '_' + \
+ request.POST['lower_right_lon']
feeds_link = reverse('chimere:feeds-area',
- kwargs={'area':coords})
+ kwargs={'area': coords})
return redirect(feeds_link)
# GET method is used for linking with the RSS icon in the browser when user
@@ -1039,18 +1037,20 @@ def rss(request, area_name=''):
return redirect(feeds_link)
if request.GET['rss_category'] == 'poi':
response_dct['category_rss_feed'] = 'category'
- response_dct['sub_categories'] = SubCategory.getAvailable(['M','B'])
+ response_dct['sub_categories'] = SubCategory.getAvailable(
+ ['M', 'B'])
return render_to_response('chimere/feeds/rss.html', response_dct,
context_instance=RequestContext(request))
if request.GET['rss_category'] == 'area':
# An unbound form
form = AreaForm()
- response_dct.update({'map_layer':settings.MAP_LAYER,
- 'extra_head':form.media,
- 'form':form,
- 'category_rss_feed':'area',
- 'area_id':Area.getAvailable(),
- 'area_widget':AreaWidget().render('area', None)})
+ response_dct.update({
+ 'map_layer': settings.MAP_LAYER,
+ 'extra_head': form.media,
+ 'form': form,
+ 'category_rss_feed': 'area',
+ 'area_id': Area.getAvailable(),
+ 'area_widget': AreaWidget().render('area', None)})
return render_to_response('chimere/feeds/rss.html', response_dct,
context_instance=RequestContext(request))
@@ -1067,25 +1067,28 @@ if hasattr(settings, 'CHIMERE_SEARCH_ENGINE') \
and settings.CHIMERE_SEARCH_ENGINE:
from haystack.views import SearchView as HaystackSearchView
from haystack.query import SearchQuerySet
+
class SearchView(HaystackSearchView):
def extra_context(self, *args, **kwargs):
context = super(SearchView, self).extra_context(*args, **kwargs)
- context["autocomplete"] = settings.HAYSTACK_AUTOCOMPLETE \
- if hasattr(settings, 'HAYSTACK_AUTOCOMPLETE') else False
+ context["autocomplete"] = \
+ settings.HAYSTACK_AUTOCOMPLETE \
+ if hasattr(settings, 'HAYSTACK_AUTOCOMPLETE') else False
return context
+
def autocomplete(request):
sqs = SearchQuerySet().autocomplete(
- content_auto=request.GET.get('q', ''))[:5]
+ content_auto=request.GET.get('q', ''))[:5]
suggestions = [result.object.name for result in sqs if result.object]
spelling = []
if not suggestions:
spelling = SearchQuerySet().spelling_suggestion(
- request.GET.get('q', '')) or []
+ request.GET.get('q', '')) or []
# convert to list spelling...
# make sure it returns a JSON object, not a bare list.
# otherwise, it could be vulnerable to an XSS attack.
the_data = json.dumps({
'results': suggestions,
- 'spelling':spelling,
+ 'spelling': spelling,
})
return HttpResponse(the_data, content_type='application/json')