Skip to content

Commit b4aad47

Browse files
committed
[enh] import all vegoresto tags and display them in another manner
1 parent 0d59c44 commit b4aad47

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

restaurant/management/commands/import-vegoresto.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.core.management.base import BaseCommand
33

44
from restaurant.models import Restaurant
5+
from restaurant.utils import VG_TAGS
56
from BeautifulSoup import BeautifulSoup
67
import urllib2
78
from dateutil.parser import parse
@@ -10,22 +11,14 @@
1011

1112
source_url = 'http://vegoresto.fr/restos-fichier-xml/'
1213

13-
VG_TAGS = {
14-
'sans_gluten': 'gluten-free',
15-
'vege': 'vegetarian',
16-
'vegan': 'vegan',
17-
'vegan_friendly': 'vegan-friendly'
18-
}
19-
20-
2114
def parse_vg_tags(tags):
2215
result = set()
2316

2417
for t in filter(None, map(lambda x: x.strip(), tags.split('|'))):
2518
try:
2619
result.add(VG_TAGS[t])
2720
except KeyError:
28-
print "WARNING: Unknown tag %s" % t
21+
result.add(t)
2922

3023
return result
3124

restaurant/templates/restopopup.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
{{#resto.website}} <a href="{{ resto.website }}">{{ resto.website }}</a><br> {{/resto.website}}
55
<a href="https://maps.google.com/maps?saddr=&daddr={{ resto.lat }},{{ resto.lon }}" target="_blank">Itinéraire (via Google Maps)</a><br> <!-- keep in sync with the resto detail page -->
66
<i><a href="restaurant/{{ resto.id }}/">Plus d'informations</a></i>
7-
<p>{{#resto.tags}}<span class="label label-success">{{.}}</span> {{/resto.tags}}</p>
7+
<p>{{#resto.tags}}<span class="label label-success">{{.}}</span> {{/resto.tags}} {{#resto.other_tags}}<span class="label label-info">{{.}}</span> {{/resto.other_tags}}</p>

restaurant/utils.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VG_TAGS = {
2+
'sans_gluten': 'gluten-free',
3+
'vege': 'vegetarian',
4+
'vegan': 'vegan',
5+
'vegan_friendly': 'vegan-friendly'
6+
}

restaurant/views.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.http import HttpResponse
33

44
from .models import Restaurant
5+
from .utils import VG_TAGS
56

67

78
def restaurants_json(request):
@@ -15,7 +16,8 @@ def restaurants_json(request):
1516
"id": x.id,
1617
"national_phone_number": x.get_national_phone_number(),
1718
"international_phone_number": x.get_international_phone_number(),
18-
"tags": [tag["name"] for tag in x.tags.all().values("name")],
19+
"tags": [tag["name"] for tag in x.tags.all().values("name") if tag["name"] in VG_TAGS.values()],
20+
"other_tags": [tag["name"] for tag in x.tags.all().values("name") if tag["name"] not in VG_TAGS.values()],
1921
} for x in Restaurant.objects.filter(lat__isnull=False, lon__isnull=False, active=True)], indent=4))
2022

2123
# optimisation note: .prefetch_related("tags") makes request slower here

0 commit comments

Comments
 (0)