added allergens and prices to db (view todo)

This commit is contained in:
Hofmann 2017-10-26 00:50:10 +02:00
parent ae7370a899
commit 2fa2da64b8
21 changed files with 161 additions and 375 deletions

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-03 22:01
# Generated by Django 1.11.6 on 2017-10-25 21:40
from __future__ import unicode_literals
from django.db import migrations, models
@ -17,13 +17,25 @@ class Migration(migrations.Migration):
name='Room',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('key', models.CharField(max_length=60)),
('address', models.CharField(max_length=60)),
('building_key', models.CharField(max_length=60)),
('floor', models.CharField(max_length=60)),
('name', models.CharField(max_length=60)),
('orgname', models.CharField(max_length=60)),
('short', models.CharField(max_length=60)),
('key', models.CharField(default='', max_length=60)),
('address', models.CharField(default='', max_length=60)),
('building_key', models.CharField(default='', max_length=60)),
('floor', models.CharField(default='', max_length=60)),
('name', models.CharField(default='', max_length=60)),
('orgname', models.CharField(default='', max_length=60)),
('short', models.CharField(max_length=60, unique=True)),
('size', models.CharField(default='', max_length=60)),
('description', models.CharField(default='', max_length=200)),
],
),
migrations.CreateModel(
name='VGN_Coords',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=60, unique=True)),
('coords', models.CharField(max_length=60, unique=True)),
('longitude', models.CharField(max_length=60, unique=True)),
('latitude', models.CharField(max_length=60, unique=True)),
],
),
]

View File

@ -1,55 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-04 00:11
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('donar', '0002_auto_20171004_0016'),
]
operations = [
migrations.AddField(
model_name='room',
name='description',
field=models.CharField(default='', max_length=200),
),
migrations.AddField(
model_name='room',
name='size',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='address',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='building_key',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='floor',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='key',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='name',
field=models.CharField(default='', max_length=60),
),
migrations.AlterField(
model_name='room',
name='orgname',
field=models.CharField(default='', max_length=60),
),
]

View File

@ -1,23 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-17 13:34
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('donar', '0003_auto_20171004_0211'),
]
operations = [
migrations.CreateModel(
name='VGN_Coords',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(default='', max_length=60, unique=True)),
('coords', models.CharField(default='', max_length=60, unique=True)),
],
),
]

View File

@ -1,37 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-17 14:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('donar', '0004_vgn_coords'),
]
operations = [
migrations.AddField(
model_name='vgn_coords',
name='latitude',
field=models.CharField(default=0, max_length=60, unique=True),
preserve_default=False,
),
migrations.AddField(
model_name='vgn_coords',
name='longitude',
field=models.CharField(default=0, max_length=60, unique=True),
preserve_default=False,
),
migrations.AlterField(
model_name='vgn_coords',
name='coords',
field=models.CharField(max_length=60, unique=True),
),
migrations.AlterField(
model_name='vgn_coords',
name='name',
field=models.CharField(max_length=60, unique=True),
),
]

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-02 20:56
# Generated by Django 1.11.6 on 2017-10-25 21:40
from __future__ import unicode_literals
from django.db import migrations, models
@ -20,14 +20,28 @@ class Migration(migrations.Migration):
('id', models.AutoField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=60)),
('category', models.CharField(max_length=60)),
('link', models.CharField(max_length=60)),
('location', models.CharField(max_length=60)),
('time', models.TimeField(default=django.utils.timezone.now)),
('link', models.CharField(blank=True, max_length=60)),
('date', models.DateField(default=django.utils.timezone.now)),
('time', models.TimeField(default=django.utils.timezone.now)),
('presenter', models.CharField(blank=True, max_length=60)),
('orgname', models.CharField(blank=True, max_length=60)),
],
),
migrations.CreateModel(
name='Location',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('key', models.CharField(blank=True, max_length=60)),
('name', models.CharField(max_length=60, unique=True)),
],
),
migrations.AddField(
model_name='event',
name='locations',
field=models.ManyToManyField(to='events.Location'),
),
migrations.AlterUniqueTogether(
name='event',
unique_together=set([('date', 'location')]),
unique_together=set([('date', 'time', 'title')]),
),
]

View File

@ -1,36 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-05 14:55
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('key', models.CharField(max_length=60)),
('name', models.CharField(max_length=60)),
],
),
migrations.AlterUniqueTogether(
name='event',
unique_together=set([]),
),
migrations.RemoveField(
model_name='event',
name='location',
),
migrations.AddField(
model_name='event',
name='location',
field=models.ManyToManyField(to='events.Location'),
),
]

View File

@ -1,39 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-05 16:07
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0002_auto_20171005_1655'),
]
operations = [
migrations.AddField(
model_name='event',
name='orgname',
field=models.CharField(blank=True, max_length=60),
),
migrations.AddField(
model_name='event',
name='presenter',
field=models.CharField(blank=True, max_length=60),
),
migrations.AlterField(
model_name='event',
name='link',
field=models.CharField(blank=True, max_length=60),
),
migrations.AlterField(
model_name='location',
name='key',
field=models.CharField(blank=True, max_length=60),
),
migrations.AlterUniqueTogether(
name='event',
unique_together=set([('date', 'time', 'title')]),
),
]

View File

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-05 17:23
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0003_auto_20171005_1807'),
]
operations = [
migrations.AlterField(
model_name='location',
name='name',
field=models.CharField(max_length=60, unique=True),
),
]

View File

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-05 18:04
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('events', '0004_auto_20171005_1923'),
]
operations = [
migrations.RenameField(
model_name='event',
old_name='location',
new_name='locations',
),
]

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-02 20:56
# Generated by Django 1.11.6 on 2017-10-25 21:40
from __future__ import unicode_literals
from django.db import migrations, models
@ -14,13 +14,20 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='Allergene',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=60, unique=True)),
],
),
migrations.CreateModel(
name='HappyHour',
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('date', models.DateField(default=django.utils.timezone.now)),
('starttime', models.DateField(default=django.utils.timezone.now)),
('endtime', models.DateField(default=django.utils.timezone.now)),
('starttime', models.TimeField(default=django.utils.timezone.now)),
('endtime', models.TimeField(default=django.utils.timezone.now)),
('location', models.CharField(max_length=60)),
('description', models.CharField(max_length=60)),
],
@ -38,6 +45,17 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(primary_key=True, serialize=False)),
('name', models.CharField(max_length=60, unique=True)),
('price_student', models.CharField(max_length=10)),
('price_employee', models.CharField(max_length=10)),
('price_guest', models.CharField(max_length=10)),
('image', models.ImageField(blank=True, upload_to='food/%Y/%m/')),
('rating', models.FloatField(default=0)),
('first_star', models.SmallIntegerField(default=0)),
('second_star', models.SmallIntegerField(default=0)),
('third_star', models.SmallIntegerField(default=0)),
('fourth_star', models.SmallIntegerField(default=0)),
('fifth_star', models.SmallIntegerField(default=0)),
('allergens', models.ManyToManyField(to='food.Allergene')),
],
),
migrations.AddField(
@ -47,7 +65,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name='happyhour',
unique_together=set([('date', 'location')]),
unique_together=set([('date', 'location', 'starttime', 'endtime')]),
),
migrations.AlterUniqueTogether(
name='menu',

View File

@ -1,26 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-08 09:02
from __future__ import unicode_literals
from django.db import migrations, models
import django.utils.timezone
class Migration(migrations.Migration):
dependencies = [
('food', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='happyhour',
name='endtime',
field=models.TimeField(default=django.utils.timezone.now),
),
migrations.AlterField(
model_name='happyhour',
name='starttime',
field=models.TimeField(default=django.utils.timezone.now),
),
]

View File

@ -0,0 +1,35 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-25 22:33
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('food', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='singlefood',
name='allergens',
field=models.ManyToManyField(blank=True, null=True, to='food.Allergene'),
),
migrations.AlterField(
model_name='singlefood',
name='price_employee',
field=models.CharField(blank=True, max_length=10, null=True),
),
migrations.AlterField(
model_name='singlefood',
name='price_guest',
field=models.CharField(blank=True, max_length=10, null=True),
),
migrations.AlterField(
model_name='singlefood',
name='price_student',
field=models.CharField(blank=True, max_length=10, null=True),
),
]

View File

@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-13 17:02
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('food', '0002_auto_20171008_1102'),
]
operations = [
migrations.AlterUniqueTogether(
name='happyhour',
unique_together=set([('date', 'location', 'starttime', 'endtime')]),
),
]

View File

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-03 22:16
# Generated by Django 1.11.6 on 2017-10-25 22:40
from __future__ import unicode_literals
from django.db import migrations, models
@ -8,13 +8,13 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('donar', '0001_initial'),
('food', '0002_auto_20171026_0033'),
]
operations = [
migrations.AlterField(
model_name='room',
name='short',
field=models.CharField(max_length=60, unique=True),
model_name='singlefood',
name='allergens',
field=models.ManyToManyField(blank=True, to='food.Allergene'),
),
]

View File

@ -1,25 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-19 23:46
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('food', '0003_auto_20171013_1902'),
]
operations = [
migrations.AddField(
model_name='singlefood',
name='image',
field=models.ImageField(blank=True, upload_to='food/%Y/%m/'),
),
migrations.AddField(
model_name='singlefood',
name='rating',
field=models.FloatField(default=0),
),
]

View File

@ -1,40 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-20 03:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('food', '0004_auto_20171020_0146'),
]
operations = [
migrations.AddField(
model_name='singlefood',
name='fifth_star',
field=models.SmallIntegerField(default=0),
),
migrations.AddField(
model_name='singlefood',
name='first_star',
field=models.SmallIntegerField(default=0),
),
migrations.AddField(
model_name='singlefood',
name='fourth_star',
field=models.SmallIntegerField(default=0),
),
migrations.AddField(
model_name='singlefood',
name='second_star',
field=models.SmallIntegerField(default=0),
),
migrations.AddField(
model_name='singlefood',
name='third_star',
field=models.SmallIntegerField(default=0),
),
]

View File

@ -23,6 +23,9 @@ class Menu(models.Model):
class SingleFood(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(unique=True, max_length=MAX_LENGTH)
price_student = models.CharField(max_length=10, blank=True, null=True)
price_employee = models.CharField(max_length=10, blank=True, null=True)
price_guest = models.CharField(max_length=10, blank=True, null=True)
image = models.ImageField(upload_to='food/%Y/%m/', blank=True)
rating = models.FloatField(default=0)
first_star = models.SmallIntegerField(default=0)
@ -30,9 +33,10 @@ class SingleFood(models.Model):
third_star = models.SmallIntegerField(default=0)
fourth_star = models.SmallIntegerField(default=0)
fifth_star = models.SmallIntegerField(default=0)
allergens = models.ManyToManyField("Allergene", blank=True)
def __str__(self):
return "%s Rating: %f" % (self.name, self.rating)
return "%s - Rating: %f - Student Price: %s" % (self.name, self.rating, self.price_student)
class Allergene(models.Model):

View File

@ -2,7 +2,7 @@ import json
from datetime import datetime
from pprint import pprint
from django.db.utils import IntegrityError
from apps.food.models import SingleFood, Menu, HappyHour
from apps.food.models import SingleFood, Menu, HappyHour, Allergene
from apps.food.utils.parser import mensa_page_parser, fekide_happyhour_page_parser, cafete_page_parser
# CONFIG SERVICE LINKS
@ -21,12 +21,37 @@ def getJsonFromFile(path):
def writeStudentenwerkDataInDB(data):
data = json.loads(data)
for menu in data['weekmenu']:
foodlist = []
for single_food in menu['menu']:
if 'allergens' in single_food:
allergens = []
for allergen in single_food['allergens']:
try:
allergens.append(Allergene.objects.create(name=allergen))
except IntegrityError:
allergens.append(Allergene.objects.get(name=allergen))
try:
foodlist.append(SingleFood.objects.create(name=single_food))
if 'prices' in single_food:
db_single_food = SingleFood.objects.create(name=single_food['title'],
price_student=single_food['prices']['price_student'],
price_employee=single_food['prices']['price_employee'],
price_guest=single_food['prices']['price_guest'])
else:
db_single_food = SingleFood.objects.create(name=single_food['title'])
if 'allergens' in locals():
db_single_food.allergens = allergens
foodlist.append(db_single_food)
except IntegrityError:
foodlist.append(SingleFood.objects.get(name=single_food))
db_single_food = SingleFood.objects.get(name=single_food['title'])
if 'prices' in single_food:
db_single_food.price_student = single_food['prices']['price_student'],
db_single_food.price_employee = single_food['prices']['price_employee'],
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'],

View File

@ -34,8 +34,10 @@ def getFoodPerDay(soup):
dayObj = {}
day = str(food).split()[0]
foodName = str(food).replace(day, "").strip()
singleFoodObj = {}
singleFoodObj['title'] = foodName
dayObj['date'] = day
dayObj['menu'] = [foodName]
dayObj['menu'] = [singleFoodObj]
days.append(dayObj)
return days

View File

@ -15,17 +15,30 @@ def getMenuDay(soup):
def getFoodPerDay(soup):
days = []
week_menus = []
for day in soup.select('.currentweek .day'):
dayObj = {}
menu = {}
daysoup = BeautifulSoup(str(day), "lxml")
day = getMenuDay(daysoup)
dayMenu = [e.getText() for e in daysoup.select('.menuwrap .menu .left .title')]
day_menu = []
for singleFood in daysoup.select('.menuwrap .menu'):
singleFoodObj = {}
singleFoodSoup = BeautifulSoup(str(singleFood), "lxml")
title = singleFoodSoup.find('div', {'class': 'title'}).getText()
allergens = [e.getText() for e in singleFoodSoup.select('.left .additnr .toggler ul li')]
prices = {}
prices['price_student'] = singleFoodSoup.select('.price')[0]['data-default']
prices['price_employee'] = singleFoodSoup.select('.price')[0]['data-bed']
prices['price_guest'] = singleFoodSoup.select('.price')[0]['data-guest']
singleFoodObj['title'] = title
singleFoodObj['allergens'] = allergens
singleFoodObj['prices'] = prices
day_menu.append(singleFoodObj)
dayObj['date'] = str(day).split(" ")[1]
dayObj['menu'] = dayMenu
days.append(dayObj)
return days
menu['date'] = str(day).split(" ")[1]
menu['menu'] = day_menu
week_menus.append(menu)
return week_menus
def parsePage(url: str):
@ -50,4 +63,6 @@ def parsePage(url: str):
def getFoodplanName(soup):
foodplan_name = soup.select('.mensamenu h2')[0].getText()
return foodplan_name
# parsePage(FEKI_URL)
parsePage(FEKI_URL)

View File

@ -36,6 +36,7 @@
<li data-food="{{ single_food.id }}" data-rating="{{ single_food.rating }}" class="food-item">
<div class="row">
<div class="food-name col-8"><p>{{ single_food.name }}</p></div>
<div class="food-name col-8"><p>{{ single_food.price_student }}</p></div>
<div class="image-wrapper col-4"><img src="" class="img-rounded img" alt="" width="1024"
height="800"><i class="img-placeholder fa fa-cutlery text-right"></i></div>
</div>