Merge branch 'master' of /media/data_1/www/gogs/gogs-repositories/michigg/ofu-app

This commit is contained in:
michigg 2017-10-26 02:15:09 +02:00
commit a749532ba9
25 changed files with 179 additions and 393 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,20 +0,0 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-10-03 22:16
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('donar', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='room',
name='short',
field=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.2 on 2017-10-25 23:47
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(blank=True, max_length=10, null=True)),
('price_employee', models.CharField(blank=True, max_length=10, null=True)),
('price_guest', models.CharField(blank=True, max_length=10, null=True)),
('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(blank=True, 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

@ -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,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

@ -33,12 +33,12 @@ urlpatterns = [
url(r'^all/$', views.food, name='all-food'),
url(r'^daily/rating/$', views.food_rating, name='rating-food'),
url(r'^weekly/rating/$', views.food_rating, name='rating-food'),
url(r'^api/', include(router.urls)),
url(r'^api/(?P<location>[a-zA-Z]+)/$', views.FoodList.as_view(), name='rating-food'),
url(r'^api/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.FoodList.as_view(),
name='rating-food'),
url(r'^api/(?P<location>[a-zA-Z]+)/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.FoodList.as_view(),
url(r'^api/(?P<location>[a-zA-Z]+)/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$',
views.FoodList.as_view(),
name='rating-food'),
url(r'^detail/(?P<id>[0-9]+)/$', views.food_detail, name='food-detail')
]

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

@ -53,6 +53,11 @@ def weekly_food(request):
})
def food_detail(request, id):
food = SingleFood.objects.get(id=id)
return render(request, "food/detailed_food.jinja", {'food': food})
def all_food(request):
menus = Menu.objects.all()
feki_menu = menus.filter(location__contains="Feldkirchenstraße")

View File

@ -0,0 +1,31 @@
{% extends 'food/food_wrapper.jinja' %}
{% import '/macros/food_macros.jinja' as macros %}
{% block headline %}
<h1 class="text-center">Food </h1>
{% endblock %}
{% block content %}
<div class="container">
<div class="row p-3 border border-dark rounded bg-light text-dark">
<div id="title" class="col-12"><h4>{{ food.name }}</h4></div>
<div class="col-8 mt-2">
<div class="col-12"><h5>Allergene</h5></div>
<ul>
{% for alergen in food.allergens.all() %}
<li>{{ alergen }}</li>
{% endfor %}
</ul>
</div>
<div class="col-4 mt-2">
<div id="prices" class="">
<div><strong>Preise</strong></div>
<div class="student">Student: {{ food.price_student }}</div>
<div class="price-employee">Employee: {{ food.price_employee }}</div>
<div class="price-guest">Guest: {{ food.price_guest }}</div>
</div>
<div id="rating" class="mt-3"><strong>Rating:</strong> {{ food.rating }}</div>
</div>
</div>
</div>
</div>
{% endblock %}

View File

@ -35,6 +35,7 @@
{% for single_food in menu %}
<li data-food="{{ single_food.id }}" data-rating="{{ single_food.rating }}" class="food-item">
<div class="row">
<<<<<<< HEAD
<div class="food-name col-8"><p>{{ single_food.name }}</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>#}
@ -51,6 +52,25 @@
id="upload-photo" style="display: none !important;"/>
</div>
</div>#}
=======
<div class="food-name col-8"><a href="{{ url('food-detail', args=[single_food.id]) }}"><p>{{ single_food.name }}</p></a></div>
<div class="col-4"><span class="float-right">{{ single_food.price_student}}</span></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>
<div class="row">
<div class="rating-wrapper col-6 text-left"></div>
<div class="col-6 text-right">
{# <label for="pic-upload-{{ single_food.id }}" class="custom-pic-upload">
<i class="fa fa-camera" aria-hidden="true"></i>
</label>
<div class="pic-input-wrapper">
TODO: extract style to external css file
<input id="pic-upload-{{ single_food.id }}" class="pic-upload" type="file" name="photo"
id="upload-photo" style="display: none !important;"/>
</div> #}
</div>
>>>>>>> develop
</div>
</li>
{% endfor %}