Merge branch 'develop_food'
This commit is contained in:
commit
f69561dd45
20
ofu_app/apps/donar/migrations/0003_auto_20180111_1246.py
Normal file
20
ofu_app/apps/donar/migrations/0003_auto_20180111_1246.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2018-01-11 11:46
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0002_auto_20180105_1449'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(),
|
||||
),
|
||||
]
|
||||
@ -48,7 +48,7 @@ class Lecture(models.Model):
|
||||
|
||||
class Lecture_Terms(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
starttime = models.TimeField(blank=False, default=timezone.now())
|
||||
starttime = models.TimeField(blank=False)
|
||||
room = models.ManyToManyField('Room', blank=True)
|
||||
|
||||
def __str__(self):
|
||||
|
||||
@ -27,6 +27,7 @@ class SingleFoodSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
menu = SingleFoodSerializer(many=True, read_only=True)
|
||||
location = serializers.ChoiceField(choices=Menu.LOCATION_CHOICES)
|
||||
|
||||
class Meta:
|
||||
model = Menu
|
||||
|
||||
@ -15,16 +15,17 @@ Including another URLconf
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from apps.food.api import views as api_views
|
||||
from apps.food.models import Menu
|
||||
|
||||
urlpatterns = [
|
||||
# API Version 1.1
|
||||
url(r'^food/$', api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
url(r'^food/(?P<location>feldkirchenstrasse|markusstrasse|erba|austrasse)/$',
|
||||
url(r'^food/(?P<location>' + Menu.FEKI + '|' + Menu.MARKUSPLATZ + '|' + Menu.ERBA + '|' + Menu.AUSTRASSE + ')/$',
|
||||
api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
url(r'food/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$',
|
||||
api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
url(
|
||||
r'food/(?P<location>feldkirchenstrasse|markusstrasse|erba|austrasse)/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$',
|
||||
r'food/(?P<location>' + Menu.FEKI + '|' + Menu.MARKUSPLATZ + '|' + Menu.ERBA + '|' + Menu.AUSTRASSE + ')/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$',
|
||||
api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
url(r'food/today/$', api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
url(r'food/week/$', api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||
|
||||
@ -25,18 +25,17 @@ class FoodViewSet(viewsets.ModelViewSet, ):
|
||||
queryset = Menu.objects.all()
|
||||
location = self.request.query_params.get('location')
|
||||
date = self.request.query_params.get('date')
|
||||
|
||||
print(str(location).upper() == Menu.ERBA.upper())
|
||||
if location:
|
||||
locations = ["erba", "feldkirchenstrasse", "austrasse", "markusplatz"]
|
||||
if locations.__contains__(location):
|
||||
if location == locations[0]:
|
||||
queryset = queryset.filter(location__contains="Erba")
|
||||
elif location == locations[1]:
|
||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
||||
elif location == locations[2]:
|
||||
queryset = queryset.filter(location__contains="austraße")
|
||||
elif location == locations[3]:
|
||||
queryset = queryset.filter(location__contains="markusplatz")
|
||||
print(str(location).upper() == Menu.ERBA.upper())
|
||||
if str(location).upper() is Menu.ERBA.upper():
|
||||
queryset = queryset.filter(location_contains='Erba')
|
||||
elif str(location).upper() is Menu.FEKI.upper():
|
||||
queryset = queryset.filter(location=Menu.FEKI)
|
||||
elif str(location).upper() is Menu.AUSTRASSE.upper():
|
||||
queryset = queryset.filter(location=Menu.AUSTRASSE)
|
||||
elif str(location).upper() is Menu.MARKUSPLATZ.upper():
|
||||
queryset = queryset.filter(location=Menu.MARKUSPLATZ)
|
||||
if date:
|
||||
if date == "week":
|
||||
today = datetime.now()
|
||||
@ -82,19 +81,16 @@ class FoodViewSetV1_1(viewsets.ModelViewSet, ):
|
||||
day = self.kwargs['day']
|
||||
|
||||
if location:
|
||||
# TODO better way to get location list
|
||||
locations = ["erba", "feldkirchenstrasse", "austrasse", "markusstrasse"]
|
||||
if locations.__contains__(location):
|
||||
print("Location: " + str(location))
|
||||
if location == locations[0]:
|
||||
queryset = queryset.filter(location__contains="Erba")
|
||||
elif location == locations[1]:
|
||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
||||
elif location == locations[2]:
|
||||
queryset = queryset.filter(location__contains="Austraße")
|
||||
elif location == locations[3]:
|
||||
queryset = queryset.filter(location__contains="Markusplatz")
|
||||
|
||||
if str(location).upper() == Menu.ERBA.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.ERBA)
|
||||
elif str(location).upper() == Menu.FEKI.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.FEKI)
|
||||
elif str(location).upper() == Menu.AUSTRASSE.upper():
|
||||
print("Before: " + str(queryset))
|
||||
queryset = queryset.filter(location__contains=Menu.AUSTRASSE)
|
||||
elif str(location).upper() == Menu.MARKUSPLATZ.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.MARKUSPLATZ)
|
||||
print(queryset)
|
||||
if year and month and day:
|
||||
date = '%s-%s-%s' % (year, month, day)
|
||||
queryset = queryset.filter(date=datetime.strptime(date, '%Y-%m-%d'))
|
||||
|
||||
20
ofu_app/apps/food/migrations/0003_auto_20180111_1114.py
Normal file
20
ofu_app/apps/food/migrations/0003_auto_20180111_1114.py
Normal file
@ -0,0 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2018-01-11 10:14
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0002_auto_20180105_1449'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='menu',
|
||||
name='location',
|
||||
field=models.CharField(choices=[('ERBA', 'Erba'), ('MARKUSPLATZ', 'Markusplatz'), ('FEKI', 'Feldkirchenstrasse'), ('AUSTRASSE', 'Austrasse')], max_length=60),
|
||||
),
|
||||
]
|
||||
40
ofu_app/apps/food/migrations/0004_auto_20180111_1246.py
Normal file
40
ofu_app/apps/food/migrations/0004_auto_20180111_1246.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2018-01-11 11:46
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0003_auto_20180111_1114'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='allergene',
|
||||
name='name',
|
||||
field=models.CharField(max_length=256, unique=True),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='happyhour',
|
||||
name='description',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='happyhour',
|
||||
name='location',
|
||||
field=models.CharField(max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='menu',
|
||||
name='location',
|
||||
field=models.CharField(choices=[('ERBA', 'Erba'), ('MARKUSPLATZ', 'Markusplatz'), ('FEKI', 'Feldkirchenstrasse'), ('AUSTRASSE', 'Austrasse')], max_length=256),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='singlefood',
|
||||
name='name',
|
||||
field=models.CharField(max_length=256, unique=True),
|
||||
),
|
||||
]
|
||||
@ -10,16 +10,23 @@ from django.contrib.auth.models import User
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import smart_text
|
||||
from django.utils.encoding import smart_str
|
||||
|
||||
MAX_LENGTH = 60
|
||||
MAX_LENGTH = 256
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class Menu(models.Model):
|
||||
ERBA = 'ERBA'
|
||||
MARKUSPLATZ = 'MARKUSPLATZ'
|
||||
FEKI = 'FEKI'
|
||||
AUSTRASSE = 'AUSTRASSE'
|
||||
|
||||
LOCATION_CHOICES = (
|
||||
(ERBA, 'Erba'), (MARKUSPLATZ, 'Markusplatz'), (FEKI, 'Feldkirchenstrasse'), (AUSTRASSE, 'Austrasse'))
|
||||
id = models.AutoField(primary_key=True)
|
||||
date = models.DateField(default=timezone.now)
|
||||
location = models.CharField(max_length=MAX_LENGTH)
|
||||
location = models.CharField(max_length=MAX_LENGTH, choices=LOCATION_CHOICES)
|
||||
menu = models.ManyToManyField("SingleFood", related_name="foods")
|
||||
|
||||
class Meta:
|
||||
@ -106,9 +113,9 @@ class UserFoodImage(models.Model):
|
||||
suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
|
||||
temp_handle.read(),
|
||||
content_type='image/jpg')
|
||||
# TODO: Fix it
|
||||
str_food = smart_text(self.food.name, encoding='utf-8')
|
||||
self.thumb.save('%s_thumbnail.%s' % (self.food.id, 'jpg'), suf, save=False)
|
||||
|
||||
str_food = smart_str(self.food.name, encoding='utf-8')
|
||||
self.thumb.save('%s_%s_thumbnail.%s' % (str_food, self.user.username, 'jpg'), suf, save=False)
|
||||
# save the image object
|
||||
self.image.name = "%s_%s_original.%s" % (self.food.id, 'jpg')
|
||||
super(UserFoodImage, self).save(force_update, force_insert)
|
||||
|
||||
@ -12,12 +12,23 @@ LINK_ERBA_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken
|
||||
LINK_MARKUS_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/sonderspeiseplaene/cafeteria-markusplatz.html"
|
||||
LINK_FEKIDE_GUIDE = "https://www.feki.de/happyhour"
|
||||
|
||||
LOCATION_NAMES = ('erba', 'markusplatz', 'feldkirchenstraße', 'austraße')
|
||||
|
||||
|
||||
def getJsonFromFile(path):
|
||||
with open(path, "r") as file:
|
||||
return json.load(file)
|
||||
|
||||
|
||||
def getLocation(raw_loc):
|
||||
for choice, name in zip(Menu.LOCATION_CHOICES, LOCATION_NAMES):
|
||||
print(name.upper() in str(raw_loc).upper())
|
||||
if (name.upper() in str(raw_loc).upper()):
|
||||
return choice
|
||||
|
||||
print("LOCATION NOT FOUND")
|
||||
|
||||
|
||||
def writeStudentenwerkDataInDB(data):
|
||||
data = json.loads(data)
|
||||
pprint(data)
|
||||
@ -69,8 +80,9 @@ def writeStudentenwerkDataInDB(data):
|
||||
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=getLocation(data['name']), date=date)
|
||||
menu.menu.set(foodlist)
|
||||
menu.save()
|
||||
except IntegrityError as error:
|
||||
|
||||
@ -19,17 +19,17 @@ def daily_food(request):
|
||||
start_week = today - datetime.timedelta(today.weekday())
|
||||
end_week = start_week + datetime.timedelta(7)
|
||||
|
||||
feki_menu = Menu.objects.filter(date__exact=today).filter(location__contains="Feldkirchenstraße").last()
|
||||
austr_menu = Menu.objects.filter(date__exact=today).filter(location__contains="Austraße").last()
|
||||
erba_cafete = Menu.objects.filter(date__exact=today).filter(location__contains="Erba").last()
|
||||
markus_cafete = Menu.objects.filter(date__exact=today).filter(location__contains="markus").last()
|
||||
feki_menu = Menu.objects.filter(date__exact=today).filter(location__contains=Menu.FEKI).last()
|
||||
austr_menu = Menu.objects.filter(date__exact=today).filter(location__contains=Menu.AUSTRASSE).last()
|
||||
erba_cafete = Menu.objects.filter(date__exact=today).filter(location__contains=Menu.ERBA).last()
|
||||
markus_cafete = Menu.objects.filter(date__exact=today).filter(location__contains=Menu.MARKUSPLATZ).last()
|
||||
happy_hours = HappyHour.objects.filter(date__exact=today)
|
||||
|
||||
weekly_menus = Menu.objects.filter(date__gte=start_week, date__lte=end_week)
|
||||
weekly_feki_menu = weekly_menus.filter(location__contains="Feldkirchenstraße")
|
||||
weekly_austr_menu = weekly_menus.filter(location__contains="Austraße")
|
||||
weekly_erba_cafete = weekly_menus.filter(location__contains="Erba")
|
||||
weekly_markus_cafete = weekly_menus.filter(location__contains="markus")
|
||||
weekly_feki_menu = weekly_menus.filter(location__contains=Menu.FEKI)
|
||||
weekly_austr_menu = weekly_menus.filter(location__contains=Menu.AUSTRASSE)
|
||||
weekly_erba_cafete = weekly_menus.filter(location__contains=Menu.ERBA)
|
||||
weekly_markus_cafete = weekly_menus.filter(location__contains=Menu.MARKUSPLATZ)
|
||||
|
||||
return render(request, "food/daily_food.jinja", {
|
||||
'day': today,
|
||||
|
||||
Reference in New Issue
Block a user