#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2010 Pierre Clarenc , # Samuel Renard , # Étienne Loks # 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 . # See the file COPYING for details. """ Views of the project """ import datetime from django.shortcuts import render_to_response from django.template import loader from django.http import HttpResponseRedirect, HttpResponse from django.core import serializers from chimere import settings from chimere.main.actions import actions from chimere.main.models import Category, SubCategory, PropertyModel, Marker, \ Route, News, Area, Color # Pierre CLARENC : 19/01/2010 : Add AreaWidget from chimere.main.widgets import getMapJS, PointChooserWidget, \ RouteChooserWidget, URL_OSM_JS, URL_OSM_CSS, AreaWidget # Pierre CLARENC : 19/01/2010 : End # Pierre CLARENC : 19/01/2010 : Add AreaAdminForm from chimere.main.forms import MarkerForm, RouteForm, AreaForm, notifyStaff # Pierre CLARENC : 19/01/2010 : End def rss(request): ''' Redirect to RSS subscription page ''' # 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 = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'extra_url':settings.EXTRA_URL, 'category_rss_feed':'category', 'sub_categories':SubCategory.getAvailable(['M', 'B']) } 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() response_dct = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'extra_url':settings.EXTRA_URL, '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) # Error when submitting the form else: error = _("Error - Please choose a correct choice in the list") response_dct = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'extra_url':settings.EXTRA_URL, 'error_message':error, 'category_rss_feed':'category', 'sub_categories':SubCategory.getAvailable(['M', 'B']) } 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 = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'extra_url':settings.EXTRA_URL, 'category_rss_feed':'category', '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 = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'extra_url':settings.EXTRA_URL, '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: response_dct = {'actions':actions, 'action_selected':'rss', 'media_path':settings.MEDIA_URL, 'category_rss_feed':'', 'extra_url':settings.EXTRA_URL } return render_to_response('rss.html', response_dct)