Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[enh] import all vegoresto tags and display them in another manner #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions restaurant/management/commands/import-vegoresto.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.core.management.base import BaseCommand

from restaurant.models import Restaurant
from restaurant.utils import VG_TAGS
from BeautifulSoup import BeautifulSoup
import urllib2
from dateutil.parser import parse
Expand All @@ -10,22 +11,14 @@

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

VG_TAGS = {
'sans_gluten': 'gluten-free',
'vege': 'vegetarian',
'vegan': 'vegan',
'vegan_friendly': 'vegan-friendly'
}


def parse_vg_tags(tags):
result = set()

for t in filter(None, map(lambda x: x.strip(), tags.split('|'))):
try:
result.add(VG_TAGS[t])
except KeyError:
print "WARNING: Unknown tag %s" % t
result.add(t)

return result

Expand Down
2 changes: 1 addition & 1 deletion restaurant/templates/restopopup.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
{{#resto.website}} <a href="{{ resto.website }}">{{ resto.website }}</a><br> {{/resto.website}}
<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 -->
<i><a href="restaurant/{{ resto.id }}/">Plus d'informations</a></i>
<p>{{#resto.tags}}<span class="label label-success">{{.}}</span> {{/resto.tags}}</p>
<p>{{#resto.tags}}<span class="label label-success">{{.}}</span> {{/resto.tags}} {{#resto.other_tags}}<span class="label label-info">{{.}}</span> {{/resto.other_tags}}</p>
6 changes: 6 additions & 0 deletions restaurant/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
VG_TAGS = {
'sans_gluten': 'gluten-free',
'vege': 'vegetarian',
'vegan': 'vegan',
'vegan_friendly': 'vegan-friendly'
}
4 changes: 3 additions & 1 deletion restaurant/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.http import HttpResponse

from .models import Restaurant
from .utils import VG_TAGS


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

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