Merge branch 'develop_restapi'
This commit is contained in:
commit
0dd3f51668
@ -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 -*-
|
# -*- 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 __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -31,7 +31,7 @@ class Migration(migrations.Migration):
|
|||||||
name='Lecture_Terms',
|
name='Lecture_Terms',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
('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(
|
migrations.CreateModel(
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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 02:00
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -17,6 +17,6 @@ class Migration(migrations.Migration):
|
|||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='lecture_terms',
|
model_name='lecture_terms',
|
||||||
name='starttime',
|
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, 2, 0, 11, 705365, 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,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Generated by Django 1.11.7 on 2017-12-04 14:43
|
# Generated by Django 1.11.7 on 2018-01-05 02:04
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
@ -10,13 +10,13 @@ from django.utils.timezone import utc
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('donar', '0005_auto_20171204_0454'),
|
('donar', '0002_auto_20180105_0300'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.AlterField(
|
migrations.AlterField(
|
||||||
model_name='lecture_terms',
|
model_name='lecture_terms',
|
||||||
name='starttime',
|
name='starttime',
|
||||||
field=models.TimeField(default=datetime.datetime(2017, 12, 4, 14, 42, 5, 347, tzinfo=utc)),
|
field=models.TimeField(default=datetime.datetime(2018, 1, 5, 2, 4, 12, 19246, 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 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)),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
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')
|
||||||
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from datetime import timedelta
|
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 apps.food.models import Menu, HappyHour
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ from rest_framework.permissions import AllowAny
|
|||||||
|
|
||||||
# @api_view(['GET'])
|
# @api_view(['GET'])
|
||||||
@permission_classes((AllowAny,))
|
@permission_classes((AllowAny,))
|
||||||
class FoodViewSet(viewsets.ModelViewSet):
|
class FoodViewSet(viewsets.ModelViewSet, ):
|
||||||
"""
|
"""
|
||||||
API endpoint that allows users to be viewed or edited.
|
API endpoint that allows users to be viewed or edited.
|
||||||
"""
|
"""
|
||||||
@ -1,5 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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 __future__ import unicode_literals
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
@ -59,7 +59,8 @@ class Migration(migrations.Migration):
|
|||||||
name='UserFoodImage',
|
name='UserFoodImage',
|
||||||
fields=[
|
fields=[
|
||||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
('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')),
|
('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)),
|
('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(
|
migrations.AddField(
|
||||||
model_name='singlefood',
|
model_name='singlefood',
|
||||||
name='image',
|
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(
|
migrations.AddField(
|
||||||
model_name='menu',
|
model_name='menu',
|
||||||
name='menu',
|
name='menu',
|
||||||
field=models.ManyToManyField(to='food.SingleFood'),
|
field=models.ManyToManyField(related_name='foods', to='food.SingleFood'),
|
||||||
),
|
),
|
||||||
migrations.AlterUniqueTogether(
|
migrations.AlterUniqueTogether(
|
||||||
name='happyhour',
|
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'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
20
ofu_app/apps/food/migrations/0002_auto_20180105_0304.py
Normal file
20
ofu_app/apps/food/migrations/0002_auto_20180105_0304.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.11.7 on 2018-01-05 02:04
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('food', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RenameField(
|
||||||
|
model_name='userfoodimage',
|
||||||
|
old_name='thumbnail',
|
||||||
|
new_name='thumb',
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -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,15 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
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.contrib.auth.models import User
|
||||||
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
MAX_LENGTH = 60
|
MAX_LENGTH = 60
|
||||||
|
|
||||||
@ -72,10 +79,37 @@ 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/%Y/%m/%W', blank=True)
|
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:
|
class Meta:
|
||||||
unique_together = ('user', 'food')
|
unique_together = ('user', 'food')
|
||||||
|
|
||||||
def __str__(self):
|
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')
|
||||||
|
self.thumb.save('%s_%s_thumbnail.%s' % (self.food.name, self.user.username, 'jpg'), suf, save=False)
|
||||||
|
# save the image object
|
||||||
|
self.image.name = "%s_%s_original.%s" % (self.food.name, 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,31 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.conf.urls import url, include
|
1. Import the include() function: from django.conf.urls import url, include
|
||||||
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
|
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 apps.food import views, admin_views
|
from apps.food import views, admin_views
|
||||||
from django.conf.urls import url, include
|
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')
|
||||||
|
|
||||||
|
# API Version 1.1
|
||||||
|
apiRouter_v1_1 = routers.DefaultRouter()
|
||||||
|
apiRouter_v1_1.register(r'food', api_views.FoodViewSet, base_name='Food')
|
||||||
|
apiRouter_v1_1.register(r'food/(?P<location>[feldkirchenstrasse, markusstrasse, erba, austrasse])/$',
|
||||||
|
api_views.FoodViewSet, base_name='Food')
|
||||||
|
apiRouter_v1_1.register(r'food/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', api_views.FoodViewSet,
|
||||||
|
base_name='Food')
|
||||||
|
apiRouter_v1_1.register(
|
||||||
|
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.FoodViewSet, base_name='Food')
|
||||||
|
apiRouter_v1_1.register(r'food/today/$', api_views.FoodViewSet, base_name='Food')
|
||||||
|
apiRouter_v1_1.register(r'food/week/$', api_views.FoodViewSet, base_name='Food')
|
||||||
|
apiRouter_v1_1.register(r'happy-hour', api_views.HappyHourViewSet, base_name='HappyHours')
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.food, name='food'),
|
url(r'^$', views.food, name='food'),
|
||||||
|
|||||||
@ -4,7 +4,6 @@ from __future__ import unicode_literals
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
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
|
||||||
@ -138,7 +137,7 @@ def pic_upload(request, id):
|
|||||||
try:
|
try:
|
||||||
old_user_pic = UserFoodImage.objects.get(user=request.user, food=id)
|
old_user_pic = UserFoodImage.objects.get(user=request.user, food=id)
|
||||||
old_user_pic.delete()
|
old_user_pic.delete()
|
||||||
os.remove(os.path.join(settings.MEDIA_ROOT, old_user_pic.image.name))
|
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
pass
|
pass
|
||||||
userPic = form.save(commit=False)
|
userPic = form.save(commit=False)
|
||||||
|
|||||||
@ -40,7 +40,6 @@ INSTALLED_APPS = [
|
|||||||
'apps.events',
|
'apps.events',
|
||||||
'apps.donar',
|
'apps.donar',
|
||||||
'apps.registration',
|
'apps.registration',
|
||||||
'api',
|
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'analytical',
|
'analytical',
|
||||||
]
|
]
|
||||||
|
|||||||
@ -17,9 +17,18 @@ from core import views
|
|||||||
from django.conf.urls import url, include
|
from django.conf.urls import url, include
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth import views as auth_views
|
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 import settings
|
||||||
from django.conf.urls.static import static
|
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 = [
|
urlpatterns = [
|
||||||
url(r'^login/$', auth_views.login, {'template_name': 'registration/login.jinja'}, name='login'),
|
url(r'^login/$', auth_views.login, {'template_name': 'registration/login.jinja'}, name='login'),
|
||||||
url(r'^logout/$', auth_views.logout, {'next_page': 'home'}, name='logout'),
|
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'^links/$', views.links, name='links-home'),
|
||||||
url(r'^impressum/$', views.impressum, name='impressum'),
|
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(api_router_v1_1.urls)),
|
||||||
|
url(r'^api/auth/', include('rest_framework.urls', namespace='rest_framework'))
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + 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
|
||||||
@ -40,7 +40,6 @@
|
|||||||
|
|
||||||
{# ===== Body ===== #}
|
{# ===== Body ===== #}
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
{% block body %}
|
{% block body %}
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row pt-5">
|
<div class="row pt-5">
|
||||||
<form type="get" action="{{ url('search-rooms') }}" style="margin: 0">
|
<form type="get" action="{{ url('search-rooms') }}" style="margin: 0">
|
||||||
|
{% csrf_token %}
|
||||||
<input id="search_room" type="text" name="search_room" placeholder="Search...">
|
<input id="search_room" type="text" name="search_room" placeholder="Search...">
|
||||||
<button id="search_submit" type="submit">Search</button>
|
<button id="search_submit" type="submit">Search</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -68,9 +68,9 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% else %}
|
{% 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 }}">
|
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>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user