diff options
Diffstat (limited to 'chimere_rss/views.py')
| -rw-r--r-- | chimere_rss/views.py | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/chimere_rss/views.py b/chimere_rss/views.py new file mode 100644 index 0000000..1d6381d --- /dev/null +++ b/chimere_rss/views.py @@ -0,0 +1,140 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Pierre Clarenc <pierre.crc_AT_gmailDOTcom>, +# Samuel Renard <renard.samuel_AT_gmailDOTcom>, +# Étienne Loks <etienne.loks_AT_peacefrogsDOTnet> + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# See the file COPYING for details. + +""" +Views of the project +""" + +from django.shortcuts import render_to_response +from django.http import HttpResponseRedirect +from django.utils.translation import ugettext as _ + +from chimere import settings +from chimere.main.views import get_base_response +from chimere.main.actions import actions +from chimere.main.models import SubCategory,Area +from chimere.main.forms import AreaForm +from chimere.main.widgets import AreaWidget + +def rss(request, area_name=''): + ''' + Redirect to RSS subscription page + ''' + response_dct = get_base_response() + 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 = '/' + settings.EXTRA_URL + 'rss/global/' + return HttpResponseRedirect(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('rss.html', response_dct) + # 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.MAP_LAYER, + 'extra_head':form.media, + 'form':form, + 'category_rss_feed':'area', + 'area_id':Area.getAvailable(), + 'area_widget':area_widget + }) + return render_to_response('rss.html', response_dct) + # 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('rss.html', response_dct) + + # 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'] != '': + idCat = request.POST['subcategory'] + if idCat.find("cat_") != -1 : + list_Cat = idCat.split('_') + feeds_link = '/' + settings.EXTRA_URL + 'rss/category/' + feeds_link += list_Cat[1] + return HttpResponseRedirect(feeds_link) + + else: + feeds_link = '/' + settings.EXTRA_URL + 'rss/subcategory/' + \ + idCat + return HttpResponseRedirect(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 = '/' + settings.EXTRA_URL + 'rss/areaid/' \ + + request.POST['id_area'] + return HttpResponseRedirect(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'] != '' : + feeds_link = '/' + settings.EXTRA_URL + 'rss/area/' + \ +request.POST['upper_left_lat'] + '_' + request.POST['upper_left_lon'] + '_' + \ +request.POST['lower_right_lat'] + '_' + request.POST['lower_right_lon'] + return HttpResponseRedirect(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 = '/' + settings.EXTRA_URL + 'rss/global/' + return HttpResponseRedirect(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('rss.html', response_dct) + 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('rss.html', response_dct) + + # User access to the RSS tab + else: + return render_to_response('rss.html', response_dct) |
