diff options
author | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-20 01:06:27 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@peacefrogs.net> | 2010-11-20 01:06:27 +0100 |
commit | 3dbeb807a29da66717796bde667528aef423c40f (patch) | |
tree | 9d42d4094e5c9f087c0c19dc8c37e3300666cf31 | |
parent | 992d117bd212e487f040227be111709ca7d50c48 (diff) | |
download | Chimère-3dbeb807a29da66717796bde667528aef423c40f.tar.bz2 Chimère-3dbeb807a29da66717796bde667528aef423c40f.zip |
Make the feeds work (refs #65)
-rw-r--r-- | chimere/main/admin.py | 3 | ||||
-rw-r--r-- | chimere/main/views.py | 1 | ||||
-rw-r--r-- | chimere/rss/feeds.py | 211 | ||||
-rw-r--r-- | chimere/rss/templates/rss.html | 4 | ||||
-rw-r--r-- | chimere/rss/urls.py | 2 | ||||
-rw-r--r-- | chimere/rss/views.py | 4 | ||||
-rw-r--r-- | chimere/urls.py | 2 |
7 files changed, 99 insertions, 128 deletions
diff --git a/chimere/main/admin.py b/chimere/main/admin.py index 30ea716..ea79f7a 100644 --- a/chimere/main/admin.py +++ b/chimere/main/admin.py @@ -21,6 +21,7 @@ Settings for administration pages """ +from chimere import settings from chimere.main.models import Category, Icon, SubCategory, Marker, \ PropertyModel, News, Route, Area, ColorTheme, Color from chimere.main.forms import MarkerAdminForm, RouteAdminForm, AreaAdminForm,\ @@ -50,6 +51,8 @@ class MarkerAdmin(admin.ModelAdmin): list_display = ('name', 'status') list_filter = ('status', 'categories') exclude = ['height', 'width'] + if 'chimere.rss' in settings.INSTALLED_APPS: + exclude.append('available_date') form = MarkerAdminForm def queryset(self, request): diff --git a/chimere/main/views.py b/chimere/main/views.py index be9b64b..b74a472 100644 --- a/chimere/main/views.py +++ b/chimere/main/views.py @@ -312,7 +312,6 @@ def getGeoObjects(request, area_name, category_ids, status): try: q = checkDate(Q(status__in=status, categories__in=category_ids)) query = Marker.objects.filter(q) - print query.query except: return HttpResponse('no results') category_ids = [int(cat_id) for cat_id in category_ids] diff --git a/chimere/rss/feeds.py b/chimere/rss/feeds.py index 1c4e015..870d00c 100644 --- a/chimere/rss/feeds.py +++ b/chimere/rss/feeds.py @@ -27,87 +27,100 @@ from django.contrib.gis.geos import * from chimere import settings +class BaseFeed(Feed): + """ + Base feed for Chimere objects + """ + def item_link(self, item): + ''' Return POI permalink ''' + coord = item.point + return settings.BASE_URL + '?zoom=16&lat=%d&lon=%d¤t_feature=%d&\ +checked_categories=%d' % (coord.y, coord.x, item.id, + item.categories.all()[0].id) + + def item_pubdate(self, item): + """ + Date of the Marker when it has been available + """ + return item.available_date -class LatestPOIsByCategory(Feed): + def description(self, obj): + return "" + +class LatestPOIsByCategory(BaseFeed): ''' Last Points of interests by category in Feeds ''' title_template = "rss_title.html" description_template = "rss_descr.html" - # Get extra url, after rss/category/ -> bits[0]=id of category + def get_object(self, bits): + """ + Get extra url, after rss/category/ id of category + """ if len(bits) != 1: raise ObjectDoesNotExist return Category.objects.get(id__exact=bits[0]) - # Define the title of the feed, here The name of the category + def title(self, obj): + """ + Define the title of the feed + """ return u"%s - %s" % (settings.PROJECT_NAME, obj.name) - # Define the link of the feed. Feeds agregators update at this link + def link(self, obj): + """ + Define the link of the feed. + """ if not obj: raise FeedDoesNotExist return settings.BASE_URL + 'rss/category/' + str(obj.id) - # Description of the feed + def description(self, obj): + """ + Description of the feed + """ return obj.description - # Link of the item/POI. Here the link is the permalink of the marker/POI - def item_link(self, item): - # Return the permalink of the POI : - # Get thirst the attribute point of the marker - # Then we had to transform this to the good system metric. From srid=4326 to srid=900913 - coord = item.point - #coord.transform(settings.EPSG_PROJECTION) - lnk = settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + \ -str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false' - return lnk - # Date of the Marker when it has been available - def item_pubdate(self,item): - return item.available_date - # Requests to marker where its category match the category is requested AND its status is available - # This returns a list of the 15 last markers/POIs ordering by date + def items(self, obj): - return Marker.objects.filter(status__exact='A', - categories__subcategory__category__id__exact=obj.id).order_by( - '-available_date')[:15] + """ + Requests to marker where its category match the category is requested + and its status is available + This returns a list of the 15 last markers/POIs ordering by date + """ + q = Marker.objects.filter(status__exact='A', + categories__subcategory__category__id__exact=obj.id, + available_date__isnull=False).order_by('-available_date')[:15] + return q -class LatestPOIsBySubCategory(Feed): +class LatestPOIsBySubCategory(BaseFeed): ''' Last Points of interests by SubCategory in Feeds ''' title_template = "rss_title.html" description_template = "rss_descr.html" + def get_object(self, bits): if len(bits) != 1: raise ObjectDoesNotExist return SubCategory.objects.get(id__exact=bits[0]) def title(self, obj): - return obj.category.name + u"%s - %s" % (settings.PROJECT_NAME, - obj.name) + return u"%s - %s - %s" % (settings.PROJECT_NAME, obj.category.name, + obj.name) def link(self, obj): if not obj: raise FeedDoesNotExist return settings.BASE_URL + 'rss/subcategory/' + str(obj.id) - def description(self, obj): - return "" - - def item_link(self, item): - # Renvoyer le permalink du POI : - coord = item.point - #coord.transform(settings.EPSG_PROJECTION) - return settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + \ -str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false' - - def item_pubdate(self,item): - return item.available_date - def items(self, obj): - return Marker.objects.filter(categories_subcategory__id__exact=obj.id, - status__exact='A').order_by('-available_date')[:15] + q = Marker.objects.filter(categories__id__exact=obj.id, + available_date__isnull=False, status__exact='A').order_by( + '-available_date')[:15] + return q -class LatestPOIs(Feed): +class LatestPOIs(BaseFeed): ''' Last Points of interests ''' @@ -123,96 +136,74 @@ class LatestPOIs(Feed): def description(self): return "Latest POIs from Chimere" - def item_link(self, item): - # Renvoyer le permalink du POI : - coord = item.point - #coord.transform(settings.EPSG_PROJECTION) - return settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + \ -str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false' - - def item_pubdate(self,item): - return item.available_date - def items(self): - return Marker.objects.filter(status__exact='A' - ).order_by('-available_date')[:15] - + q = Marker.objects.filter(status__exact='A', + available_date__isnull=False).order_by('-available_date')[:15] + return q -class LatestPOIsByZone(Feed): +class LatestPOIsByZone(BaseFeed): ''' Last Points of interests by zone by coordinates ''' title_template = "rss_title.html" description_template = "rss_descr.html" - # Attributes which store coordinates of the requested zone upper_left_lat = 0 upper_left_lon = 0 lower_right_lat = 0 lower_right_lon = 0 def get_object(self, bits): + """ + Get the extra url. Parameters are the coordinates of the zone (the + upper left and lower right points) + """ if len(bits) != 1: raise ObjectDoesNotExist - # Get the extra url. Parameters are the coordinates of the zone (the - # upper left and lower right points) # Then define the upper right and lower left points - coordinates = str(bits[0]).split(',') + coordinates = str(bits[0]).split('_') upper_left_lat = float(coordinates[0]) upper_left_lon = float(coordinates[1]) lower_right_lat = float(coordinates[2]) lower_right_lon = float(coordinates[3]) - """ upper_right_lat = upper_left_lat upper_right_lon = lower_right_lon lower_left_lat = lower_right_lat - lower_left_lon = upper_left_lon""" + lower_left_lon = upper_left_lon # Define a Polygon with the 4 points of the zone. - # Cordinates are define with a srid=900913, use by google, yahoo but no OpenStreeMap areaBox = Polygon(((upper_left_lon, upper_left_lat), (upper_right_lon, upper_right_lat), (lower_right_lon, lower_right_lat), (lower_left_lon, lower_left_lat), (upper_left_lon, upper_left_lat)), - srid=settings.EPSG_PROJECTION) - # OSM uses the standard srid=4326, wich uses the real pairs latitude/longitude in degrees. - #areaBox.transform(settings.EPSG_DISPLAY_PROJECTION) - + srid=settings.EPSG_DISPLAY_PROJECTION) return areaBox def title(self, obj): return u"%s - Last POIs by area" % settings.PROJECT_NAME - # Define the link of the feed. It's the same url as we get in the method get_object + def link(self, obj): + """ + Define the link of the feed. It's the same url as we get in the method + get_object + """ if not obj: raise FeedDoesNotExist return settings.BASE_URL + 'rss/area/' \ - + str(self.upper_left_lat) + ',' + str(self.upper_left_lon) + \ - ',' + str(self.lower_right_lat) + ',' + str(self.lower_right_lon) - - def description(self, obj): - return "" - - # Link of the item/POI. Here the link is the permalink of the marker/POI - def item_link(self, item): - # Return the permalink of the POI : - # Get thirst the attribute point of the marker - # Then we had to transform this to the good system metric. From srid=4326 to srid=900913 - coord = item.point - #coord.transform(settings.EPSG_PROJECTION) - return settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + \ -str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false' - - # Return the date of the Marker - def item_pubdate(self,item): - return item.available_date + + str(self.upper_left_lat) + '_' + str(self.upper_left_lon) + \ + '_' + str(self.lower_right_lat) + '_' + str(self.lower_right_lon) - # Request to return Markers WHERE there points are containes in the zone which is requested. - # This returns a list of the 15 last markers/POIs ordering by date def items(self, obj): - return Marker.objects.filter(point__contained=obj, status__exact='A' - ).order_by('-available_date')[:15] + """ + Request to return Markers WHERE there points are containes in the zone + which is requested. + This returns a list of the 15 last markers/POIs ordering by date + """ + print obj + q = Marker.objects.filter(point__contained=obj, status__exact='A', + available_date__isnull=False).order_by('-available_date')[:15] + return q -class LatestPOIsByZoneID(Feed): +class LatestPOIsByZoneID(BaseFeed): ''' Last Points of interests by zone by id ''' @@ -232,34 +223,10 @@ class LatestPOIsByZoneID(Feed): raise FeedDoesNotExist return settings.BASE_URL + 'rss/areaid/' + str(obj.id) - def description(self, obj): - return "" - - def item_link(self, item): - coord = item.point - coord.transform(settings.EPSG_PROJECTION) - return settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + \ -str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false' - - def item_pubdate(self,item): - return item.available_date - def items(self, obj): - upper_left_lat = float(obj.upper_left_corner.x) - upper_left_lon = float(obj.upper_left_corner.y) - lower_right_lat = float(obj.lower_right_corner.x) - lower_right_lon = float(obj.lower_right_corner.y) - ''' - upper_right_lat = upper_left_lat - upper_right_lon = lower_right_lon - lower_left_lat = lower_right_lat - lower_left_lon = upper_left_lon - ''' - areaBox = Polygon(((upper_left_lon, upper_left_lat), - (upper_right_lon, upper_right_lat), - (lower_right_lon, lower_right_lat), - (lower_left_lon, lower_left_lat), - (upper_left_lon, upper_left_lat)), - srid=settings.EPSG_PROJECTION) - #areaBox.transform(settings.EPSG_DISPLAY_PROJECTION) - return Marker.objects.filter(point__contained=areaBox) + sql = 'select * from "main_marker" where ' + obj.getIncludeSql() + sql += ' and "main_marker".available_date is not null' + sql += ' and "main_marker".status=\'A\'' + sql += ' order by "main_marker".available_date desc limit 15' + q = Marker.objects.raw(sql) + return q diff --git a/chimere/rss/templates/rss.html b/chimere/rss/templates/rss.html index bb656e3..52f118e 100644 --- a/chimere/rss/templates/rss.html +++ b/chimere/rss/templates/rss.html @@ -18,9 +18,9 @@ <label for="rss_category">{% trans "Category of RSS feeds" %} *</label> <select name='rss_category' id='rss_category'> <option value="">---------</option> - <option value="global">All the new POIs</option> + <option value="global">All the new POIs</option> <option value="poi">Category of POI</option> - <option value="area">Area</option> + <option value="area">Area</option> </select> </div> {% endif %} diff --git a/chimere/rss/urls.py b/chimere/rss/urls.py index 9c841c8..e5e9a24 100644 --- a/chimere/rss/urls.py +++ b/chimere/rss/urls.py @@ -24,7 +24,7 @@ from django.conf.urls.defaults import * from chimere.rss.feeds import LatestPOIsByCategory, LatestPOIsBySubCategory, \ LatestPOIs, LatestPOIsByZone, LatestPOIsByZoneID -from chimere.urls import BASE, EXTRA +from chimere.urls import EXTRA_NO_AREA as EXTRA feeds = { 'category': LatestPOIsByCategory, diff --git a/chimere/rss/views.py b/chimere/rss/views.py index 305d255..b82d3ae 100644 --- a/chimere/rss/views.py +++ b/chimere/rss/views.py @@ -123,8 +123,8 @@ def rss(request, area_name=''): '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'] +request.POST['upper_left_lat'] + '_' + request.POST['upper_left_lon'] + '_' + \ +request.POST['lower_right_lat'] + '_' + request.POST['lower_right_lon'] return HttpResponseRedirect(feeds_link) diff --git a/chimere/urls.py b/chimere/urls.py index 7b9b3c7..5788c43 100644 --- a/chimere/urls.py +++ b/chimere/urls.py @@ -57,7 +57,9 @@ for area in url_areas: EXTRA = "|".join([area.urn for area in url_areas]) default_dct = {} +EXTRA_NO_AREA = EXTRA if EXTRA: + EXTRA_NO_AREA = "(%s)?/?" % EXTRA EXTRA = "(?P<area_name>%s)?/?" % EXTRA else: default_dct = {'area_name':''} |