diff options
Diffstat (limited to 'chimere/views.py')
-rw-r--r-- | chimere/views.py | 126 |
1 files changed, 124 insertions, 2 deletions
diff --git a/chimere/views.py b/chimere/views.py index 371731d..891078e 100644 --- a/chimere/views.py +++ b/chimere/views.py @@ -1,6 +1,9 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2008-2012 Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> +# +# RSS : Copyright (C) 2010 Pierre Clarenc <pierre.crc_AT_gmailDOTcom>, +# Samuel Renard <renard.samuel_AT_gmailDOTcom>, # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as @@ -41,10 +44,10 @@ from chimere.models import Category, SubCategory, PropertyModel, \ Marker, Route, News, SimpleArea, Area, Color, TinyUrl, RouteFile from chimere.widgets import getMapJS, PointChooserWidget, \ - RouteChooserWidget + RouteChooserWidget, AreaWidget from chimere.forms import MarkerForm, RouteForm, ContactForm, FileForm, \ FullFileForm, MultimediaFileFormSet, PictureFileFormSet, notifySubmission,\ - notifyStaff + notifyStaff, AreaForm #TODO: convert to requestcontext def get_base_response(area_name=""): @@ -592,3 +595,122 @@ def redirectFromTinyURN(request, area_name='', tiny_urn=''): if redir: return redir return HttpResponseRedirect(response_dct['extra_url'] + parameters) + +def rss(request, area_name=''): + ''' + Redirect to RSS subscription page + ''' + response_dct, redir = get_base_response(area_name) + if redir: + return redir + response_dct.update({'actions':actions, '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 + if request.POST['rss_category'] == 'global': + feeds_link = reverse('chimere:feeds-global') + return redirect(feeds_link) + # User wants to follow all the new POI by category or subcategory + 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)) + # 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 + }) + 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)) + + # 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 : + cat_id = cat_id.split('_')[1] + feeds_link = reverse('chimere:feeds-cat', + kwargs={'category_id':cat_id}) + return redirect(feeds_link) + + else: + feeds_link = reverse('chimere:feeds-subcat', + 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']}) + 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) + elif 'upper_left_lat' in request.POST and \ + request.POST['upper_left_lat'] != '' and \ + 'upper_left_lon' in request.POST and \ + request.POST['upper_left_lon'] != '' and \ + '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'] != '' : + coords = request.POST['upper_left_lat'] + '_' + \ + request.POST['upper_left_lon'] + '_' + \ + request.POST['lower_right_lat'] + '_' + \ + request.POST['lower_right_lon'] + feeds_link = reverse('chimere:feeds-area', + kwargs={'area':coords}) + return redirect(feeds_link) + + # GET method is used for linking with the RSS icon in the browser when user + # wants to choose a category to follow + elif request.method == "GET" and 'rss_category' in request.GET: + if request.GET['rss_category'] == 'global': + feeds_link = reverse('chimere:feeds-global') + return redirect(feeds_link) + if request.GET['rss_category'] == 'poi': + response_dct['category_rss_feed'] = 'category' + 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)}) + return render_to_response('chimere/feeds/rss.html', response_dct, + context_instance=RequestContext(request)) + + # User access to the RSS tab + else: + return render_to_response('chimere/feeds/rss.html', response_dct, + context_instance=RequestContext(request)) |