Merge branch 'master' into app.wiai.de
This commit is contained in:
commit
1ca02a9a61
@ -1,3 +0,0 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
@ -1,5 +0,0 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
name = 'api'
|
||||
@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -1,27 +0,0 @@
|
||||
from apps.food.models import Menu, SingleFood, HappyHour
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
class SingleFoodSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = SingleFood
|
||||
fields = ('name', 'rating')
|
||||
|
||||
|
||||
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
menu = SingleFoodSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Menu
|
||||
fields = ('date', 'location', 'menu')
|
||||
|
||||
|
||||
class HappyHourSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
starttime = serializers.TimeField()
|
||||
endtime = serializers.TimeField()
|
||||
|
||||
class Meta:
|
||||
model = HappyHour
|
||||
fields = ('date', 'starttime', 'endtime', 'location', 'description')
|
||||
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -1,29 +0,0 @@
|
||||
"""ofu_app URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.11/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls import url, include
|
||||
from rest_framework import routers
|
||||
|
||||
from api.views import food_views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'food', food_views.FoodViewSet, base_name='Food')
|
||||
router.register(r'happy-hour', food_views.HappyHourViewSet, base_name='HappyHours')
|
||||
|
||||
urlpatterns = [
|
||||
# url(r'^api/v1/', ),
|
||||
url(r'^api/v1/', include(router.urls)),
|
||||
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
]
|
||||
@ -1,10 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import generics
|
||||
|
||||
|
||||
class APIRoot(generics.GenericAPIView):
|
||||
"""
|
||||
My API documentation
|
||||
"""
|
||||
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 01:44
|
||||
# Generated by Django 1.11.7 on 2017-12-21 11:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
@ -31,7 +31,7 @@ class Migration(migrations.Migration):
|
||||
name='Lecture_Terms',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('starttime', models.TimeField(default=datetime.datetime(2017, 12, 4, 1, 44, 13, 10710, tzinfo=utc))),
|
||||
('starttime', models.TimeField(default=datetime.datetime(2017, 12, 21, 11, 43, 16, 16543, tzinfo=utc))),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 01:44
|
||||
# Generated by Django 1.11.7 on 2018-01-05 13:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
@ -17,6 +17,6 @@ class Migration(migrations.Migration):
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 1, 44, 28, 301106, tzinfo=utc)),
|
||||
field=models.TimeField(default=datetime.datetime(2018, 1, 5, 13, 49, 38, 439221, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 02:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0002_auto_20171204_0244'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 2, 3, 45, 618615, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 03:47
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0003_auto_20171204_0303'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 3, 47, 55, 513852, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 03:54
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0004_auto_20171204_0447'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 3, 54, 33, 503002, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 14:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0005_auto_20171204_0454'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 14, 42, 5, 347, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 15:34
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0006_auto_20171204_1543'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 15, 34, 41, 765204, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 15:45
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0007_auto_20171204_1634'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 15, 45, 46, 720753, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -1,22 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 15:48
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
from django.db import migrations, models
|
||||
from django.utils.timezone import utc
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('donar', '0008_auto_20171204_1645'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 15, 48, 28, 229201, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
39
ofu_app/apps/food/admin_views.py
Normal file
39
ofu_app/apps/food/admin_views.py
Normal file
@ -0,0 +1,39 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpResponseForbidden
|
||||
from django.shortcuts import render
|
||||
from pprint import pprint
|
||||
|
||||
from apps.food.models import Menu, SingleFood, UserFoodImage
|
||||
|
||||
|
||||
def food_picture_management(request):
|
||||
if (request.user.is_superuser):
|
||||
today = datetime.datetime.now()
|
||||
today_images = UserFoodImage.objects.filter(food__foods__date__exact=today)
|
||||
|
||||
return render(request, "admin/picture_management.jinja", {
|
||||
'day': today,
|
||||
'pictures': today_images,
|
||||
})
|
||||
|
||||
else:
|
||||
return HttpResponseForbidden
|
||||
|
||||
|
||||
def food_picture_save(request, id):
|
||||
if (request.user.is_superuser):
|
||||
chosen_pic = UserFoodImage.objects.get(id=id)
|
||||
food = SingleFood.objects.get(id=chosen_pic.food.id)
|
||||
food.image.set([chosen_pic, ])
|
||||
food.save()
|
||||
|
||||
return food_picture_management(request)
|
||||
else:
|
||||
return HttpResponseForbidden
|
||||
43
ofu_app/apps/food/api/serializers.py
Normal file
43
ofu_app/apps/food/api/serializers.py
Normal file
@ -0,0 +1,43 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from apps.food.models import Menu, SingleFood, HappyHour, Allergene, UserFoodImage
|
||||
|
||||
|
||||
class UserFoodImageSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = UserFoodImage
|
||||
fields = ('id', 'image', 'thumb')
|
||||
|
||||
|
||||
class AllergensSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class Meta:
|
||||
model = Allergene
|
||||
fields = ('id', 'name')
|
||||
|
||||
|
||||
class SingleFoodSerializer(serializers.HyperlinkedModelSerializer):
|
||||
allergens = AllergensSerializer(many=True, read_only=True)
|
||||
image = UserFoodImageSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = SingleFood
|
||||
fields = ('name', 'rating', 'price_student', 'price_employee', 'price_guest', 'allergens', 'image')
|
||||
|
||||
|
||||
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
menu = SingleFoodSerializer(many=True, read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Menu
|
||||
fields = ('id', 'date', 'location', 'menu')
|
||||
|
||||
|
||||
class HappyHourSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
starttime = serializers.TimeField()
|
||||
endtime = serializers.TimeField()
|
||||
|
||||
class Meta:
|
||||
model = HappyHour
|
||||
fields = ('id', 'date', 'starttime', 'endtime', 'location', 'description')
|
||||
32
ofu_app/apps/food/api/urls.py
Normal file
32
ofu_app/apps/food/api/urls.py
Normal file
@ -0,0 +1,32 @@
|
||||
"""ofu_app URL Configuration
|
||||
|
||||
The `urlpatterns` list routes URLs to views. For more information please see:
|
||||
https://docs.djangoproject.com/en/1.11/topics/http/urls/
|
||||
Examples:
|
||||
Function views
|
||||
1. Add an import: from my_app import views
|
||||
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
|
||||
Class-based views
|
||||
1. Add an import: from other_app.views import Home
|
||||
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
|
||||
Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from apps.food.api import views as api_views
|
||||
|
||||
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)/$',
|
||||
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})/$',
|
||||
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'happy-hour', api_views.HappyHourViewSet.as_view({'get': 'list'})),
|
||||
]
|
||||
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from api.serializers.food_serializers import MenuSerializer, HappyHourSerializer
|
||||
from apps.food.api.serializers import MenuSerializer, HappyHourSerializer
|
||||
from apps.food.models import Menu, HappyHour
|
||||
from rest_framework import viewsets
|
||||
|
||||
@ -14,7 +14,7 @@ from rest_framework.permissions import AllowAny
|
||||
|
||||
# @api_view(['GET'])
|
||||
@permission_classes((AllowAny,))
|
||||
class FoodViewSet(viewsets.ModelViewSet):
|
||||
class FoodViewSet(viewsets.ModelViewSet, ):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
@ -34,9 +34,9 @@ class FoodViewSet(viewsets.ModelViewSet):
|
||||
elif location == locations[1]:
|
||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
||||
elif location == locations[2]:
|
||||
queryset = queryset.filter(location__contains="Austraße")
|
||||
queryset = queryset.filter(location__contains="austraße")
|
||||
elif location == locations[3]:
|
||||
queryset = queryset.filter(location__contains="Markusplatz")
|
||||
queryset = queryset.filter(location__contains="markusplatz")
|
||||
if date:
|
||||
if date == "week":
|
||||
today = datetime.now()
|
||||
@ -49,12 +49,73 @@ class FoodViewSet(viewsets.ModelViewSet):
|
||||
else:
|
||||
queryset = queryset.filter(date=datetime.strptime(date, "%Y-%m-%d"))
|
||||
|
||||
print("LOCATION: %s" % str(location))
|
||||
print("DATE: " + str(date))
|
||||
print(str(queryset))
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
# @api_view(['GET'])
|
||||
@permission_classes((AllowAny,))
|
||||
class FoodViewSetV1_1(viewsets.ModelViewSet, ):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
# queryset = Menu.objects.all()
|
||||
serializer_class = MenuSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Menu.objects.all()
|
||||
location = None
|
||||
if 'location' in self.kwargs:
|
||||
location = self.kwargs['location']
|
||||
|
||||
year = None
|
||||
if 'year' in self.kwargs:
|
||||
year = self.kwargs['year']
|
||||
month = None
|
||||
if 'month' in self.kwargs:
|
||||
month = self.kwargs['month']
|
||||
day = None
|
||||
if 'day' in self.kwargs:
|
||||
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 year and month and day:
|
||||
date = '%s-%s-%s' % (year, month, day)
|
||||
queryset = queryset.filter(date=datetime.strptime(date, '%Y-%m-%d'))
|
||||
|
||||
# if date == "week":
|
||||
# today = datetime.now()
|
||||
# weekday = today.weekday()
|
||||
# monday = today - timedelta(weekday)
|
||||
# sunday = today + (timedelta(6 - weekday))
|
||||
# print("Monday: " + str(monday))
|
||||
# print("Sunday: " + str(sunday))
|
||||
# queryset = queryset.filter(date__gte=monday, date__lte=sunday)
|
||||
# else:
|
||||
# queryset = queryset.filter(date=datetime.strptime(date, "%Y-%m-%d"))
|
||||
|
||||
print("LOCATION: %s" % str(location))
|
||||
print(str(queryset))
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
# @api_view(['GET'])
|
||||
@permission_classes((AllowAny,))
|
||||
class HappyHourViewSet(viewsets.ModelViewSet):
|
||||
@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 01:44
|
||||
# Generated by Django 1.11.7 on 2017-12-21 11:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
@ -59,7 +59,8 @@ class Migration(migrations.Migration):
|
||||
name='UserFoodImage',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('image', models.ImageField(blank=True, upload_to='food/%Y/%m/%W')),
|
||||
('image', models.ImageField(blank=True, upload_to='food/originals/%Y/%m/%W')),
|
||||
('thumbnail', models.ImageField(blank=True, upload_to='food/thumbs/%Y/%m/%W')),
|
||||
('food', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='food.SingleFood')),
|
||||
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
@ -76,12 +77,12 @@ class Migration(migrations.Migration):
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='image',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_images', to='food.UserFoodImage'),
|
||||
field=models.ManyToManyField(blank=True, null=True, to='food.UserFoodImage'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='menu',
|
||||
name='menu',
|
||||
field=models.ManyToManyField(to='food.SingleFood'),
|
||||
field=models.ManyToManyField(related_name='foods', to='food.SingleFood'),
|
||||
),
|
||||
migrations.AlterUniqueTogether(
|
||||
name='happyhour',
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 02:03
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='singlefood',
|
||||
name='image',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='singlefood',
|
||||
name='image',
|
||||
field=models.ManyToManyField(related_name='user_images', to='food.UserFoodImage'),
|
||||
),
|
||||
]
|
||||
42
ofu_app/apps/food/migrations/0002_auto_20180105_1449.py
Normal file
42
ofu_app/apps/food/migrations/0002_auto_20180105_1449.py
Normal file
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2018-01-05 13:49
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='userfoodimage',
|
||||
old_name='thumbnail',
|
||||
new_name='thumb',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='userfoodimage',
|
||||
name='food',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.SingleFood'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='userfoodimage',
|
||||
name='user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='userrating',
|
||||
name='food',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.SingleFood'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='userrating',
|
||||
name='user',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
||||
@ -1,20 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 03:54
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0002_auto_20171204_0303'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='singlefood',
|
||||
name='image',
|
||||
field=models.ManyToManyField(blank=True, null=True, to='food.UserFoodImage'),
|
||||
),
|
||||
]
|
||||
@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 14:43
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0003_auto_20171204_0454'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='menu',
|
||||
name='menu',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='menu',
|
||||
name='menu',
|
||||
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='food.SingleFood'),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
||||
@ -1,24 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-12-04 15:34
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('food', '0004_auto_20171204_1543'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='menu',
|
||||
name='menu',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='menu',
|
||||
name='menu',
|
||||
field=models.ManyToManyField(to='food.SingleFood'),
|
||||
),
|
||||
]
|
||||
@ -1,8 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from django.utils import timezone
|
||||
from django.db import models
|
||||
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
from PIL import Image
|
||||
from django.conf import settings
|
||||
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
|
||||
|
||||
MAX_LENGTH = 60
|
||||
|
||||
@ -52,6 +60,7 @@ class HappyHour(models.Model):
|
||||
description = models.CharField(max_length=MAX_LENGTH)
|
||||
|
||||
class Meta:
|
||||
# TODO: unique description instead of date
|
||||
unique_together = ('date', 'location', 'starttime', 'endtime')
|
||||
|
||||
def __str__(self):
|
||||
@ -60,8 +69,8 @@ class HappyHour(models.Model):
|
||||
|
||||
class UserRating(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, unique=False)
|
||||
food = models.ForeignKey(SingleFood)
|
||||
user = models.ForeignKey(User, on_delete=models.PROTECT, unique=False)
|
||||
food = models.ForeignKey(SingleFood, on_delete=models.PROTECT)
|
||||
rating = models.FloatField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
@ -70,12 +79,40 @@ class UserRating(models.Model):
|
||||
|
||||
class UserFoodImage(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE, unique=False)
|
||||
food = models.ForeignKey(SingleFood)
|
||||
image = models.ImageField(upload_to='food/%Y/%m/%W', blank=True)
|
||||
user = models.ForeignKey(User, on_delete=models.PROTECT, unique=False)
|
||||
food = models.ForeignKey(SingleFood, on_delete=models.PROTECT)
|
||||
image = models.ImageField(upload_to='food/originals/%Y/%m/%W', blank=True)
|
||||
thumb = models.ImageField(upload_to='food/thumbs/%Y/%m/%W', blank=True)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('user', 'food')
|
||||
|
||||
def __str__(self):
|
||||
return "User: %s - Rating: %s" % (self.user.username, str(self.image))
|
||||
return "User: %s - Image: %s" % (self.user.username, str(self.image))
|
||||
|
||||
def save(self, force_update=False, force_insert=False, thumb_size=(640, 480)):
|
||||
image = Image.open(self.image)
|
||||
|
||||
if image.mode not in ('L', 'RGB'):
|
||||
image = image.convert('RGB')
|
||||
image.thumbnail(thumb_size, Image.ANTIALIAS)
|
||||
|
||||
# save the thumbnail to memory
|
||||
temp_handle = BytesIO()
|
||||
image.save(temp_handle, 'jpeg')
|
||||
temp_handle.seek(0) # rewind the file
|
||||
|
||||
# save to the thumbnail field
|
||||
suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
|
||||
temp_handle.read(),
|
||||
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)
|
||||
# save the image object
|
||||
self.image.name = "%s_%s_original.%s" % (str_food, self.user.username, 'jpg')
|
||||
super(UserFoodImage, self).save(force_update, force_insert)
|
||||
|
||||
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.thumb.name))
|
||||
super(UserFoodImage, self).delete()
|
||||
|
||||
@ -13,9 +13,17 @@ Including another URLconf
|
||||
1. Import the include() function: from django.conf.urls import url, include
|
||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
||||
"""
|
||||
|
||||
from apps.food import views
|
||||
from django.conf.urls import url, include
|
||||
from rest_framework import routers
|
||||
|
||||
from apps.food import views, admin_views
|
||||
from django.conf.urls import url, include
|
||||
from apps.food.api import views as api_views
|
||||
|
||||
# API Version 1.0
|
||||
apiRouter_v1 = routers.DefaultRouter()
|
||||
apiRouter_v1.register(r'food', api_views.FoodViewSet, base_name='Food')
|
||||
apiRouter_v1.register(r'happy-hour', api_views.HappyHourViewSet, base_name='HappyHours')
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.food, name='food'),
|
||||
@ -35,4 +43,8 @@ urlpatterns = [
|
||||
# Food Rating
|
||||
url(r'^daily/rating/$', views.food_rating, name='rating-food'),
|
||||
url(r'^weekly/rating/$', views.food_rating, name='rating-food'),
|
||||
|
||||
# Admin Pages
|
||||
url(r'^admin/$', admin_views.food_picture_management, name='foodpicture-management'),
|
||||
url(r'^admin/(?P<id>[0-9]+)/$', admin_views.food_picture_save, name='foodpicture-save'),
|
||||
]
|
||||
|
||||
@ -71,7 +71,7 @@ def writeStudentenwerkDataInDB(data):
|
||||
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 = foodlist
|
||||
menu.menu.set(foodlist)
|
||||
menu.save()
|
||||
except IntegrityError as error:
|
||||
# ignored
|
||||
|
||||
@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
||||
import datetime
|
||||
import os
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
@ -18,7 +17,7 @@ from apps.food.models import Menu, HappyHour, SingleFood, UserRating, UserFoodIm
|
||||
def daily_food(request):
|
||||
today = datetime.datetime.now()
|
||||
start_week = today - datetime.timedelta(today.weekday())
|
||||
end_week = start_week + datetime.timedelta(7)
|
||||
end_week = start_week + datetime.timedelta(20)
|
||||
|
||||
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()
|
||||
@ -138,7 +137,7 @@ def pic_upload(request, id):
|
||||
try:
|
||||
old_user_pic = UserFoodImage.objects.get(user=request.user, food=id)
|
||||
old_user_pic.delete()
|
||||
os.remove(os.path.join(settings.MEDIA_ROOT, old_user_pic.image.name))
|
||||
|
||||
except ObjectDoesNotExist:
|
||||
pass
|
||||
userPic = form.save(commit=False)
|
||||
|
||||
@ -40,7 +40,6 @@ INSTALLED_APPS = [
|
||||
'apps.events',
|
||||
'apps.donar',
|
||||
'apps.registration',
|
||||
'api',
|
||||
'rest_framework',
|
||||
'analytical',
|
||||
]
|
||||
|
||||
@ -17,9 +17,18 @@ from core import views
|
||||
from django.conf.urls import url, include
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth import views as auth_views
|
||||
from rest_framework import routers
|
||||
from apps.food import urls as food_urls
|
||||
from django.conf import settings
|
||||
from django.conf.urls.static import static
|
||||
|
||||
# API router
|
||||
api_router_v1 = routers.DefaultRouter()
|
||||
api_router_v1.registry.extend(food_urls.apiRouter_v1.registry)
|
||||
|
||||
# api_router_v1_1 = routers.DefaultRouter()
|
||||
# api_router_v1_1.registry.extend(food_urls.apiRouter_v1_1.registry)
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^login/$', auth_views.login, {'template_name': 'registration/login.jinja'}, name='login'),
|
||||
url(r'^logout/$', auth_views.logout, {'next_page': 'home'}, name='logout'),
|
||||
@ -36,5 +45,8 @@ urlpatterns = [
|
||||
url(r'^links/$', views.links, name='links-home'),
|
||||
url(r'^impressum/$', views.impressum, name='impressum'),
|
||||
|
||||
url(r'', include('api.urls'))
|
||||
# -- API --
|
||||
url(r'^api/v1/', include(api_router_v1.urls)),
|
||||
url(r'^api/v1.1/', include('apps.food.api.urls')),
|
||||
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
||||
BIN
ofu_app/media/food/default/default.jpg
Normal file
BIN
ofu_app/media/food/default/default.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 154 KiB |
2
ofu_app/requirements.txt
Normal file
2
ofu_app/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
django
|
||||
djangorestframework
|
||||
20
ofu_app/templates/admin/picture_management.jinja
Normal file
20
ofu_app/templates/admin/picture_management.jinja
Normal file
@ -0,0 +1,20 @@
|
||||
{% extends 'food/food_wrapper.jinja' %}
|
||||
{% import '/macros/food_macros.jinja' as macros %}
|
||||
{% block headline %}
|
||||
<h1 class="text-center">Food Picture Management View</h1>
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
<div class="container-fluid">
|
||||
<h2>Bilder</h2>
|
||||
<div class="row">
|
||||
{% for picture in pictures %}
|
||||
<div class="col-6">
|
||||
<a href="{{ url('foodpicture-save', kwargs={'id':picture.id}) }}">
|
||||
<h3>{{ picture.food.name }}</h3>
|
||||
<img src="{{ picture.image.url }}" style="width: 50%">
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -40,7 +40,6 @@
|
||||
|
||||
{# ===== Body ===== #}
|
||||
<body>
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
<div class="container">
|
||||
<div class="row pt-5">
|
||||
<form type="get" action="{{ url('search-rooms') }}" style="margin: 0">
|
||||
{% csrf_token %}
|
||||
<input id="search_room" type="text" name="search_room" placeholder="Search...">
|
||||
<button id="search_submit" type="submit">Search</button>
|
||||
</form>
|
||||
|
||||
@ -15,4 +15,4 @@
|
||||
{{ macros.home_item_with_icon(icon='fa-th-large', url_id='links-home', title='Links') }}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}fa-cutlery
|
||||
{% endblock %}
|
||||
@ -68,9 +68,9 @@
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<a href="/media/food/default/gorilla.jpg" data-lightbox="{{ title }}"
|
||||
<a href="/media/food/default/default.jpg" data-lightbox="{{ title }}"
|
||||
data-title="{{ single_food.name }}">
|
||||
<img src="/media/food/default/gorilla.jpg" class="media-object" alt="Bild" width="80px">
|
||||
<img src="/media/food/default/default.jpg" class="media-object" alt="Bild" width="80px">
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user