1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
#!/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.
from django.contrib.syndication.feeds import Feed
from django.contrib.syndication.feeds import FeedDoesNotExist
from chimere.main.models import Category, SubCategory, Marker, Area
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.gis.geos import *
from chimere import settings
class LatestPOIsByCategory(Feed):
'''
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):
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):
return "Chimere - %s" % obj.name
# Define the link of the feed. Feeds agregators update at this link
def link(self, obj):
if not obj:
raise FeedDoesNotExist
return settings.BASE_URL + 'rss/category/' + str(obj.id)
# Description of the feed
def description(self, obj):
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)
return settings.BASE_URL + '?zoom=16&lat=' + str(coord.y) + '&lon=' + str(coord.x) + '&layers=BTT&checked_categories=1&display_submited=false'
# Date of the Marker when it has been available
def item_pubdate(self,item):
return item.avail_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(subcategory__category__id__exact=obj.id, status__exact='A').order_by('-avail_date')[:15]
class LatestPOIsBySubCategory(Feed):
'''
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 + "Chimere - %s" % 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.avail_date
def items(self, obj):
return Marker.objects.filter(subcategory__id__exact=obj.id, status__exact='A').order_by('-avail_date')[:15]
class LatestPOIs(Feed):
'''
Last Points of interests
'''
title_template = "rss_title.html"
description_template = "rss_descr.html"
def title(self):
return "Chimere - Last POIs"
def link(self):
return settings.BASE_URL + 'rss/categories/'
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.avail_date
def items(self):
return Marker.objects.filter(status__exact='A').order_by('-avail_date')[:15]
class LatestPOIsByZone(Feed):
'''
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):
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(',')
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
# 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)
return areaBox
def title(self, obj):
return "Chimere - Last POIs by area"
# Define the link of the feed. It's the same url as we get in the method get_object
def link(self, obj):
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.avail_date
# 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('-avail_date')[:15]
class LatestPOIsByZoneID(Feed):
'''
Last Points of interests by zone by id
'''
title_template = "rss_title.html"
description_template = "rss_descr.html"
def get_object(self, bits):
if len(bits) != 1:
raise ObjectDoesNotExist
return Area.objects.get(id__exact=bits[0])
def title(self, obj):
return "Chimere - Last POIs of %s" % obj.name
def link(self, obj):
if not obj:
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.avail_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)
|