Merge branch 'master' into app.wiai.de
This commit is contained in:
commit
365ed3c04a
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):
|
||||||
|
|||||||
@ -2,15 +2,11 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
from django.http import HttpResponseForbidden
|
from django.http import HttpResponseForbidden
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from apps.food.models import Menu, SingleFood, UserFoodImage
|
from apps.food.models import SingleFood, UserFoodImage
|
||||||
|
|
||||||
|
|
||||||
def food_picture_management(request):
|
def food_picture_management(request):
|
||||||
@ -31,7 +27,7 @@ def food_picture_save(request, id):
|
|||||||
if (request.user.is_superuser):
|
if (request.user.is_superuser):
|
||||||
chosen_pic = UserFoodImage.objects.get(id=id)
|
chosen_pic = UserFoodImage.objects.get(id=id)
|
||||||
food = SingleFood.objects.get(id=chosen_pic.food.id)
|
food = SingleFood.objects.get(id=chosen_pic.food.id)
|
||||||
food.image.set([chosen_pic, ])
|
food.image = chosen_pic.image
|
||||||
food.save()
|
food.save()
|
||||||
|
|
||||||
return food_picture_management(request)
|
return food_picture_management(request)
|
||||||
|
|||||||
@ -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'))
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
from apps.food.models import UserFoodImage
|
from apps.food.models import FoodImage
|
||||||
|
|
||||||
|
|
||||||
class UploadImageForm(forms.ModelForm):
|
class UploadImageForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = UserFoodImage
|
model = FoodImage
|
||||||
fields = ['image']
|
fields = ['image']
|
||||||
|
|||||||
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),
|
||||||
|
),
|
||||||
|
]
|
||||||
42
ofu_app/apps/food/migrations/0005_auto_20180113_0023.py
Normal file
42
ofu_app/apps/food/migrations/0005_auto_20180113_0023.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.7 on 2018-01-12 23:23
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('food', '0004_auto_20180111_1246'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='FoodImage',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('image', models.ImageField(blank=True, upload_to='food/originals/%Y/%m/%W')),
|
||||||
|
('thumb', models.ImageField(blank=True, upload_to='food/thumbs/%Y/%m/%W')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='userfoodimage',
|
||||||
|
name='thumb',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='singlefood',
|
||||||
|
name='image',
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='userfoodimage',
|
||||||
|
name='image',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.FoodImage'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='singlefood',
|
||||||
|
name='image',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to='food.FoodImage'),
|
||||||
|
),
|
||||||
|
]
|
||||||
25
ofu_app/apps/food/migrations/0006_auto_20180113_0121.py
Normal file
25
ofu_app/apps/food/migrations/0006_auto_20180113_0121.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.7 on 2018-01-13 00:21
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('food', '0005_auto_20180113_0023'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='foodimage',
|
||||||
|
name='image',
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to='food/originals/%Y/%m/%W'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='foodimage',
|
||||||
|
name='thumb',
|
||||||
|
field=models.ImageField(blank=True, null=True, upload_to='food/thumbs/%Y/%m/%W'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -10,16 +10,22 @@ 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
|
|
||||||
|
|
||||||
MAX_LENGTH = 256
|
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:
|
||||||
@ -35,7 +41,7 @@ class SingleFood(models.Model):
|
|||||||
price_student = models.CharField(max_length=10, blank=True, null=True)
|
price_student = models.CharField(max_length=10, blank=True, null=True)
|
||||||
price_employee = 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)
|
price_guest = models.CharField(max_length=10, blank=True, null=True)
|
||||||
image = models.ManyToManyField("UserFoodImage", blank=True, null=True)
|
image = models.ForeignKey('FoodImage', on_delete=models.PROTECT, blank=True, null=True)
|
||||||
rating = models.FloatField(default=0)
|
rating = models.FloatField(default=0)
|
||||||
allergens = models.ManyToManyField("Allergene", blank=True)
|
allergens = models.ManyToManyField("Allergene", blank=True)
|
||||||
|
|
||||||
@ -81,8 +87,7 @@ class UserFoodImage(models.Model):
|
|||||||
id = models.AutoField(primary_key=True)
|
id = models.AutoField(primary_key=True)
|
||||||
user = models.ForeignKey(User, on_delete=models.PROTECT, unique=False)
|
user = models.ForeignKey(User, on_delete=models.PROTECT, unique=False)
|
||||||
food = models.ForeignKey(SingleFood, on_delete=models.PROTECT)
|
food = models.ForeignKey(SingleFood, on_delete=models.PROTECT)
|
||||||
image = models.ImageField(upload_to='food/originals/%Y/%m/%W', blank=True)
|
image = models.ForeignKey('FoodImage', on_delete=models.PROTECT)
|
||||||
thumb = models.ImageField(upload_to='food/thumbs/%Y/%m/%W', blank=True)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = ('user', 'food')
|
unique_together = ('user', 'food')
|
||||||
@ -90,6 +95,12 @@ class UserFoodImage(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "User: %s - Image: %s" % (self.user.username, str(self.image))
|
return "User: %s - Image: %s" % (self.user.username, str(self.image))
|
||||||
|
|
||||||
|
|
||||||
|
class FoodImage(models.Model):
|
||||||
|
id = models.AutoField(primary_key=True)
|
||||||
|
image = models.ImageField(upload_to='food/originals/%Y/%m/%W', blank=True, null=True)
|
||||||
|
thumb = models.ImageField(upload_to='food/thumbs/%Y/%m/%W', blank=True, null=True)
|
||||||
|
|
||||||
def save(self, force_update=False, force_insert=False, thumb_size=(640, 480)):
|
def save(self, force_update=False, force_insert=False, thumb_size=(640, 480)):
|
||||||
image = Image.open(self.image)
|
image = Image.open(self.image)
|
||||||
|
|
||||||
@ -106,13 +117,13 @@ 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')
|
||||||
str_food = smart_text(self.food.name, encoding='utf-8')
|
|
||||||
self.thumb.save('%s_%s_thumbnail.%s' % (str_food, self.user.username, 'jpg'), suf, save=False)
|
self.thumb.save('%s_thumbnail.%s' % (self.id, 'jpg'), suf, save=False)
|
||||||
# save the image object
|
# save the image object
|
||||||
self.image.name = "%s_%s_original.%s" % (str_food, self.user.username, 'jpg')
|
self.image.name = "%s_original.%s" % (self.id, 'jpg')
|
||||||
super(UserFoodImage, self).save(force_update, force_insert)
|
super(FoodImage, self).save(force_update, force_insert)
|
||||||
|
|
||||||
def delete(self, using=None, keep_parents=False):
|
def delete(self, using=None, keep_parents=False):
|
||||||
os.remove(os.path.join(settings.MEDIA_ROOT, self.image.name))
|
os.remove(os.path.join(settings.MEDIA_ROOT, self.image.name))
|
||||||
os.remove(os.path.join(settings.MEDIA_ROOT, self.thumb.name))
|
os.remove(os.path.join(settings.MEDIA_ROOT, self.thumb.name))
|
||||||
super(UserFoodImage, self).delete()
|
super(FoodImage, self).delete()
|
||||||
|
|||||||
@ -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:
|
||||||
|
|||||||
@ -2,34 +2,31 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
import os
|
|
||||||
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
from pprint import pprint
|
|
||||||
|
|
||||||
from apps.food.forms import UploadImageForm
|
from apps.food.forms import UploadImageForm
|
||||||
from apps.food.models import Menu, HappyHour, SingleFood, UserRating, UserFoodImage
|
from apps.food.models import Menu, HappyHour, SingleFood, UserRating, UserFoodImage, FoodImage
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def daily_food(request):
|
def daily_food(request):
|
||||||
today = datetime.datetime.now()
|
today = datetime.datetime.now()
|
||||||
start_week = today - datetime.timedelta(today.weekday())
|
start_week = today - datetime.timedelta(today.weekday())
|
||||||
end_week = start_week + datetime.timedelta(20)
|
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,
|
||||||
@ -134,15 +131,10 @@ def food_image(request):
|
|||||||
def pic_upload(request, id):
|
def pic_upload(request, id):
|
||||||
form = UploadImageForm(request.POST, request.FILES)
|
form = UploadImageForm(request.POST, request.FILES)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
try:
|
pic = form.save(commit=True)
|
||||||
old_user_pic = UserFoodImage.objects.get(user=request.user, food=id)
|
userPic, success = UserFoodImage.objects.get_or_create(user_id=request.user)
|
||||||
old_user_pic.delete()
|
userPic.image = pic
|
||||||
|
|
||||||
except ObjectDoesNotExist:
|
|
||||||
pass
|
|
||||||
userPic = form.save(commit=False)
|
|
||||||
userPic.food = SingleFood.objects.get(id=id)
|
userPic.food = SingleFood.objects.get(id=id)
|
||||||
userPic.user = request.user
|
|
||||||
userPic.save()
|
userPic.save()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<a href="{{ url('foodpicture-save', kwargs={'id':picture.id}) }}">
|
<a href="{{ url('foodpicture-save', kwargs={'id':picture.id}) }}">
|
||||||
<h3>{{ picture.food.name }}</h3>
|
<h3>{{ picture.food.name }}</h3>
|
||||||
<img src="{{ picture.image.url }}" style="width: 50%">
|
<img src="{{ picture.image.image.url }}" style="width: 50%">
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
{% for image in images %}
|
{% for image in images %}
|
||||||
<div class="col-12 mt-2">
|
<div class="col-12 mt-2">
|
||||||
<p>{{ image.food.name }}</p>
|
<p>{{ image.food.name }}</p>
|
||||||
<img src="{{ image.image.url }}" style="width:50%">
|
<img src="{{ image.image.image.url }}" style="width:50%">
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -60,13 +60,11 @@
|
|||||||
<li data-food="{{ single_food.id }}" data-rating="{{ single_food.rating }}" class="food-item media mb-2">
|
<li data-food="{{ single_food.id }}" data-rating="{{ single_food.rating }}" class="food-item media mb-2">
|
||||||
<div class="mr-2 media-left media-middle">
|
<div class="mr-2 media-left media-middle">
|
||||||
{# TODO: without many to many #}
|
{# TODO: without many to many #}
|
||||||
{% if single_food.image.all() %}
|
{% if single_food.image %}
|
||||||
{% for image in single_food.image.all() %}
|
<a href="{{ single_food.image.image.url }}" data-lightbox="{{ title }}"
|
||||||
<a href="{{ image.image.url }}" data-lightbox="{{ title }}"
|
data-title="{{ single_food.name }}">
|
||||||
data-title="{{ single_food.name }}">
|
<img src="{{ single_food.image.image.url }}" class="media-object" alt="Bild" width="80px">
|
||||||
<img src="{{ image.image.url }}" class="media-object" alt="Bild" width="80px">
|
</a>
|
||||||
</a>
|
|
||||||
{% endfor %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<a href="/media/food/default/default.jpg" data-lightbox="{{ title }}"
|
<a href="/media/food/default/default.jpg" data-lightbox="{{ title }}"
|
||||||
data-title="{{ single_food.name }}">
|
data-title="{{ single_food.name }}">
|
||||||
|
|||||||
Reference in New Issue
Block a user