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):
|
class Lecture_Terms(models.Model):
|
||||||
id = models.AutoField(primary_key=True)
|
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)
|
room = models.ManyToManyField('Room', blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
@ -27,6 +27,7 @@ class SingleFoodSerializer(serializers.HyperlinkedModelSerializer):
|
|||||||
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
date = serializers.DateField(format='iso-8601')
|
date = serializers.DateField(format='iso-8601')
|
||||||
menu = SingleFoodSerializer(many=True, read_only=True)
|
menu = SingleFoodSerializer(many=True, read_only=True)
|
||||||
|
location = serializers.ChoiceField(choices=Menu.LOCATION_CHOICES)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Menu
|
model = Menu
|
||||||
|
|||||||
@ -15,16 +15,17 @@ Including another URLconf
|
|||||||
"""
|
"""
|
||||||
from django.conf.urls import url
|
from django.conf.urls import url
|
||||||
from apps.food.api import views as api_views
|
from apps.food.api import views as api_views
|
||||||
|
from apps.food.models import Menu
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# API Version 1.1
|
# API Version 1.1
|
||||||
url(r'^food/$', api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
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'})),
|
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})/$',
|
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'})),
|
api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||||
url(
|
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'})),
|
api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||||
url(r'food/today/$', 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'})),
|
url(r'food/week/$', api_views.FoodViewSetV1_1.as_view({'get': 'list'})),
|
||||||
|
|||||||
@ -25,18 +25,17 @@ class FoodViewSet(viewsets.ModelViewSet, ):
|
|||||||
queryset = Menu.objects.all()
|
queryset = Menu.objects.all()
|
||||||
location = self.request.query_params.get('location')
|
location = self.request.query_params.get('location')
|
||||||
date = self.request.query_params.get('date')
|
date = self.request.query_params.get('date')
|
||||||
|
print(str(location).upper() == Menu.ERBA.upper())
|
||||||
if location:
|
if location:
|
||||||
locations = ["erba", "feldkirchenstrasse", "austrasse", "markusplatz"]
|
print(str(location).upper() == Menu.ERBA.upper())
|
||||||
if locations.__contains__(location):
|
if str(location).upper() is Menu.ERBA.upper():
|
||||||
if location == locations[0]:
|
queryset = queryset.filter(location_contains='Erba')
|
||||||
queryset = queryset.filter(location__contains="Erba")
|
elif str(location).upper() is Menu.FEKI.upper():
|
||||||
elif location == locations[1]:
|
queryset = queryset.filter(location=Menu.FEKI)
|
||||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
elif str(location).upper() is Menu.AUSTRASSE.upper():
|
||||||
elif location == locations[2]:
|
queryset = queryset.filter(location=Menu.AUSTRASSE)
|
||||||
queryset = queryset.filter(location__contains="austraße")
|
elif str(location).upper() is Menu.MARKUSPLATZ.upper():
|
||||||
elif location == locations[3]:
|
queryset = queryset.filter(location=Menu.MARKUSPLATZ)
|
||||||
queryset = queryset.filter(location__contains="markusplatz")
|
|
||||||
if date:
|
if date:
|
||||||
if date == "week":
|
if date == "week":
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
@ -82,19 +81,16 @@ class FoodViewSetV1_1(viewsets.ModelViewSet, ):
|
|||||||
day = self.kwargs['day']
|
day = self.kwargs['day']
|
||||||
|
|
||||||
if location:
|
if location:
|
||||||
# TODO better way to get location list
|
if str(location).upper() == Menu.ERBA.upper():
|
||||||
locations = ["erba", "feldkirchenstrasse", "austrasse", "markusstrasse"]
|
queryset = queryset.filter(location__contains=Menu.ERBA)
|
||||||
if locations.__contains__(location):
|
elif str(location).upper() == Menu.FEKI.upper():
|
||||||
print("Location: " + str(location))
|
queryset = queryset.filter(location__contains=Menu.FEKI)
|
||||||
if location == locations[0]:
|
elif str(location).upper() == Menu.AUSTRASSE.upper():
|
||||||
queryset = queryset.filter(location__contains="Erba")
|
print("Before: " + str(queryset))
|
||||||
elif location == locations[1]:
|
queryset = queryset.filter(location__contains=Menu.AUSTRASSE)
|
||||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
elif str(location).upper() == Menu.MARKUSPLATZ.upper():
|
||||||
elif location == locations[2]:
|
queryset = queryset.filter(location__contains=Menu.MARKUSPLATZ)
|
||||||
queryset = queryset.filter(location__contains="Austraße")
|
print(queryset)
|
||||||
elif location == locations[3]:
|
|
||||||
queryset = queryset.filter(location__contains="Markusplatz")
|
|
||||||
|
|
||||||
if year and month and day:
|
if year and month and day:
|
||||||
date = '%s-%s-%s' % (year, month, day)
|
date = '%s-%s-%s' % (year, month, day)
|
||||||
queryset = queryset.filter(date=datetime.strptime(date, '%Y-%m-%d'))
|
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.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
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.
|
# Create your models here.
|
||||||
class Menu(models.Model):
|
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)
|
id = models.AutoField(primary_key=True)
|
||||||
date = models.DateField(default=timezone.now)
|
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")
|
menu = models.ManyToManyField("SingleFood", related_name="foods")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
@ -106,9 +113,9 @@ class UserFoodImage(models.Model):
|
|||||||
suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
|
suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
|
||||||
temp_handle.read(),
|
temp_handle.read(),
|
||||||
content_type='image/jpg')
|
content_type='image/jpg')
|
||||||
# TODO: Fix it
|
|
||||||
str_food = smart_text(self.food.name, encoding='utf-8')
|
str_food = smart_str(self.food.name, encoding='utf-8')
|
||||||
self.thumb.save('%s_thumbnail.%s' % (self.food.id, 'jpg'), suf, save=False)
|
self.thumb.save('%s_%s_thumbnail.%s' % (str_food, self.user.username, 'jpg'), suf, save=False)
|
||||||
# save the image object
|
# save the image object
|
||||||
self.image.name = "%s_%s_original.%s" % (self.food.id, 'jpg')
|
self.image.name = "%s_%s_original.%s" % (self.food.id, 'jpg')
|
||||||
super(UserFoodImage, self).save(force_update, force_insert)
|
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_MARKUS_CAFETE = "https://www.studentenwerk-wuerzburg.de/bamberg/essen-trinken/sonderspeiseplaene/cafeteria-markusplatz.html"
|
||||||
LINK_FEKIDE_GUIDE = "https://www.feki.de/happyhour"
|
LINK_FEKIDE_GUIDE = "https://www.feki.de/happyhour"
|
||||||
|
|
||||||
|
LOCATION_NAMES = ('erba', 'markusplatz', 'feldkirchenstraße', 'austraße')
|
||||||
|
|
||||||
|
|
||||||
def getJsonFromFile(path):
|
def getJsonFromFile(path):
|
||||||
with open(path, "r") as file:
|
with open(path, "r") as file:
|
||||||
return json.load(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):
|
def writeStudentenwerkDataInDB(data):
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
pprint(data)
|
pprint(data)
|
||||||
@ -69,8 +80,9 @@ def writeStudentenwerkDataInDB(data):
|
|||||||
db_single_food.allergens = allergens
|
db_single_food.allergens = allergens
|
||||||
foodlist.append(db_single_food)
|
foodlist.append(db_single_food)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
date = datetime.strptime(str(menu['date']), "%d.%m.").replace(year=datetime.today().year)
|
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.menu.set(foodlist)
|
||||||
menu.save()
|
menu.save()
|
||||||
except IntegrityError as error:
|
except IntegrityError as error:
|
||||||
|
|||||||
@ -19,17 +19,17 @@ def daily_food(request):
|
|||||||
start_week = today - datetime.timedelta(today.weekday())
|
start_week = today - datetime.timedelta(today.weekday())
|
||||||
end_week = start_week + datetime.timedelta(7)
|
end_week = start_week + datetime.timedelta(7)
|
||||||
|
|
||||||
feki_menu = Menu.objects.filter(date__exact=today).filter(location__contains="Feldkirchenstraße").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="Austraße").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="Erba").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="markus").last()
|
markus_cafete = Menu.objects.filter(date__exact=today).filter(location__contains=Menu.MARKUSPLATZ).last()
|
||||||
happy_hours = HappyHour.objects.filter(date__exact=today)
|
happy_hours = HappyHour.objects.filter(date__exact=today)
|
||||||
|
|
||||||
weekly_menus = Menu.objects.filter(date__gte=start_week, date__lte=end_week)
|
weekly_menus = Menu.objects.filter(date__gte=start_week, date__lte=end_week)
|
||||||
weekly_feki_menu = weekly_menus.filter(location__contains="Feldkirchenstraße")
|
weekly_feki_menu = weekly_menus.filter(location__contains=Menu.FEKI)
|
||||||
weekly_austr_menu = weekly_menus.filter(location__contains="Austraße")
|
weekly_austr_menu = weekly_menus.filter(location__contains=Menu.AUSTRASSE)
|
||||||
weekly_erba_cafete = weekly_menus.filter(location__contains="Erba")
|
weekly_erba_cafete = weekly_menus.filter(location__contains=Menu.ERBA)
|
||||||
weekly_markus_cafete = weekly_menus.filter(location__contains="markus")
|
weekly_markus_cafete = weekly_menus.filter(location__contains=Menu.MARKUSPLATZ)
|
||||||
|
|
||||||
return render(request, "food/daily_food.jinja", {
|
return render(request, "food/daily_food.jinja", {
|
||||||
'day': today,
|
'day': today,
|
||||||
|
|||||||
Reference in New Issue
Block a user