aboutsummaryrefslogtreecommitdiff
path: root/mensa/frontends/html.py
diff options
context:
space:
mode:
Diffstat (limited to 'mensa/frontends/html.py')
-rw-r--r--mensa/frontends/html.py53
1 files changed, 24 insertions, 29 deletions
diff --git a/mensa/frontends/html.py b/mensa/frontends/html.py
index c23d27c..f3bf065 100644
--- a/mensa/frontends/html.py
+++ b/mensa/frontends/html.py
@@ -3,38 +3,33 @@ from yapsy.IPlugin import IPlugin
from xml.sax.saxutils import escape as esc
class HTMLRenderer(IPlugin) :
+ def format_line(self, item) :
+ vegkeys = [ "", "Vegetarian", "Vegan" ]
+ if self.options.get("only_veggie",0) > item.veggie :
+ return ""
+ if item.desc :
+ desc = "<div class=\"description\">"+esc(item.desc)+"</div>\n"
+ else :
+ desc = ""
+ return"<li class=\"fooditem\" ><span class=\"name\">" + esc(item.name) + "</span><span class=\"price\">"+ esc(item.price) + "</span><span class=\"veggie\">"+ esc(vegkeys[item.veggie])+"</span>\n"+ desc
+
+ def format_category(self, category, items) :
+ return "<h4>%s</h4></h4><ul class=\"food-by-cat\">\n%s</ul>" % (esc(category), "".join([self.format_line(i) for i in items]))
+ def format_restaurant(self, restaurant, food) :
+ if not food :
+ return ""
+ st = "<div class=\"restaurant\"><h3>%s</h3>\n" % esc(restaurant.human_name)
+ dist = ""
+ if "pos" in self.options and restaurant.pos and self.options.get("dist") :
+ dist = "<div class=\"distance\">Distance: %.2f km</div>\n" % base.dist(options["pos"], restaurant.pos)
+ body = "\n".join([self.format_category(cat, it) for cat,it in food.items()])
+ return st+dist+body+"</div>"
def render (self, foods, **options) :
## Expects list of tuples with (Restaurant, Foodlist)
- r = ""
- vegkeys = [ "", "Vegetarian", "Vegan" ]
- for restaurant, food in foods :
- cat = []
- if not food :
- continue
- r = r+"<div class=\"restaurant\"><h3>"+esc(restaurant.human_name)+"</h3>"+"\n"#+base.formt(food)
- if "pos" in options and restaurant.pos and "dist" in options :
- ## display distance to restaurant
- r=r+"<div class=\"distance\">Distance: %.2f km</div>\n" % base.dist(options["pos"], restaurant.pos)
+ self.options = options
+
+ r = "\n".join([self.format_restaurant(restaurant, food) for restaurant, food in foods ])
- food.sort(key=lambda foo: foo.category)
- for i in food:
- if options["only_student_prices"] :
- price = base.only_student_prices(i.price)
- else:
- price = i.price
- if options["only_veggie"] and options["only_veggie"] > i.veggie :
- continue
- if not i.category in cat :
- if cat :
- r = r + "</ul>"
- cat.append(i.category)
- if not i.category == None :
- r=r+ "<h4>"+esc(i.category)+"</h4><ul class=\"food-by-cat\">\n"
- r=r+"<li class=\"fooditem\" ><span class=\"name\">" + esc(i.name) + "</span><span class=\"price\">"+ esc(price) + "</span><span class=\"veggie\">"+ esc(vegkeys[i.veggie])+"</span>\n"
- if i.desc :
- r = r+"<div class=\"description\">"+esc(i.desc)+"</div>\n"
- r = r+"</ul></div>"
- r = r
print(r)
def register_renderer(self) :