Fix userpicture bug, food_import bug

This commit is contained in:
michigg 2017-12-04 11:43:17 +01:00
parent f355b833fc
commit d1fc34b004
5 changed files with 16 additions and 18 deletions

View File

@ -20,10 +20,12 @@ def getJsonFromFile(path):
def writeStudentenwerkDataInDB(data):
data = json.loads(data)
pprint(data)
for menu in data['weekmenu']:
pprint(menu)
foodlist = []
for single_food in menu['menu']:
pprint(single_food)
if 'allergens' in single_food:
allergens = []
for allergen in single_food['allergens']:
@ -53,17 +55,15 @@ def writeStudentenwerkDataInDB(data):
db_single_food.price_guest = single_food['prices']['price_guest']
if 'allergens' in locals():
db_single_food.allergens = allergens
foodlist.append(db_single_food)
try:
date = datetime.strptime(str(menu['date']), "%d.%m.").replace(year=datetime.today().year)
menu = Menu.objects.create(location=data['name'],
date=date)
menu = Menu.objects.create(location=data['name'], date=date)
menu.menu = foodlist
menu.save()
except IntegrityError:
except IntegrityError as error:
# ignored
break
pass
def writeFekideDataInDB(data):

View File

@ -3,6 +3,7 @@ from bs4 import BeautifulSoup
import json
import datetime
import re
from pprint import pprint
SPEISEPLAN_NAME_SELECTOR = '.csc-default .csc-header .csc-firstHeader'
@ -64,4 +65,4 @@ def parsePage(url: str):
# LINK_ERBA_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/sonderspeiseplaene/cafeteria-erba-insel.html"
# parsePage(LINK_ERBA_CAFETE)
# pprint(parsePage(LINK_ERBA_CAFETE))

View File

@ -28,7 +28,6 @@ def getFoodPerDay(soup):
title = singleFoodSoup.find('div', {'class': 'title'}).getText()
allergens = [e.getText() for e in singleFoodSoup.select('.left .additnr .toggler ul li')]
prices = {}
print(singleFoodSoup.select('.price'))
if singleFoodSoup.select('.price'):
prices['price_student'] = singleFoodSoup.select('.price')[0]['data-default']
if singleFoodSoup.select('.price'):

View File

@ -58,8 +58,11 @@ def food_detail(request, id):
if pic_upload(request, id) == False:
return HttpResponse(status=404)
food = SingleFood.objects.get(id=id)
images = UserFoodImage.objects.filter(food=id)
if request.user.is_authenticated:
images = UserFoodImage.objects.filter(food=id, user=request.user)
return render(request, "food/detailed_food.jinja", {'food': food, 'images': images})
else:
return render(request, "food/detailed_food.jinja", {'food': food})
def all_food(request):
@ -79,8 +82,7 @@ def all_food(request):
def food(request):
return render(request, "food/home.jinja", {
})
return render(request, "food/home.jinja", {})
def food_rating(request):

View File

@ -51,12 +51,8 @@
<div class="media-body">
<div class="row">
<div class="food-name col-8">
{% if single_food.price_student %}
<a href="{{ url('food-detail', args=[single_food.id]) }}">
<p>{{ single_food.name }}</p></a>
{% else %}
<p>{{ single_food.name }}</p>
{% endif %}
</div>
{% if single_food.price_student %}
<div class="col-4"><span class="float-right">{{ single_food.price_student }}</span></div>