Merge branch 'master' of /media/data_1/www/gogs/gogs-repositories/basta/basta-server
This commit is contained in:
commit
6dc7778ff4
0
ofu_app/ofu_app/__init__.py → ofu_app/api/__init__.py
Executable file → Normal file
0
ofu_app/ofu_app/__init__.py → ofu_app/api/__init__.py
Executable file → Normal file
3
ofu_app/api/admin.py
Normal file
3
ofu_app/api/admin.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
5
ofu_app/api/apps.py
Normal file
5
ofu_app/api/apps.py
Normal file
@ -0,0 +1,5 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ApiConfig(AppConfig):
|
||||
name = 'api'
|
||||
3
ofu_app/api/models.py
Normal file
3
ofu_app/api/models.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
@ -1,4 +1,4 @@
|
||||
from apps.food.models import Menu, SingleFood
|
||||
from apps.food.models import Menu, SingleFood, HappyHour
|
||||
from rest_framework import serializers
|
||||
|
||||
|
||||
@ -15,3 +15,13 @@ class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||
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')
|
||||
3
ofu_app/api/tests.py
Normal file
3
ofu_app/api/tests.py
Normal file
@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
29
ofu_app/api/urls.py
Normal file
29
ofu_app/api/urls.py
Normal file
@ -0,0 +1,29 @@
|
||||
"""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'))
|
||||
]
|
||||
0
ofu_app/api/views/__init__.py
Normal file
0
ofu_app/api/views/__init__.py
Normal file
10
ofu_app/api/views/base_views.py
Normal file
10
ofu_app/api/views/base_views.py
Normal file
@ -0,0 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from rest_framework import generics
|
||||
|
||||
|
||||
class APIRoot(generics.GenericAPIView):
|
||||
"""
|
||||
My API documentation
|
||||
"""
|
||||
76
ofu_app/api/views/food_views.py
Normal file
76
ofu_app/api/views/food_views.py
Normal file
@ -0,0 +1,76 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
|
||||
from api.serializers.food_serializers import MenuSerializer, HappyHourSerializer
|
||||
from apps.food.models import Menu, HappyHour
|
||||
from rest_framework import viewsets
|
||||
|
||||
from rest_framework.decorators import api_view, permission_classes
|
||||
from rest_framework.permissions import AllowAny
|
||||
|
||||
|
||||
# @api_view(['GET'])
|
||||
@permission_classes((AllowAny,))
|
||||
class FoodViewSet(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 = self.request.query_params.get('location')
|
||||
date = self.request.query_params.get('date')
|
||||
|
||||
if location:
|
||||
locations = ["erba", "feldkirchenstrasse", "austrasse", "markusplatz"]
|
||||
if locations.__contains__(location):
|
||||
if location == locations[0]:
|
||||
queryset = queryset.filter(location__contains="Erba")
|
||||
elif location == locations[1]:
|
||||
queryset = queryset.filter(location__contains="Feldkirchen")
|
||||
elif location == locations[2]:
|
||||
queryset = queryset.filter(location__contains="Austraße")
|
||||
elif location == locations[3]:
|
||||
queryset = queryset.filter(location__contains="Markusplatz")
|
||||
if date:
|
||||
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("DATE: " + str(date))
|
||||
print(str(queryset))
|
||||
|
||||
return queryset
|
||||
|
||||
|
||||
# @api_view(['GET'])
|
||||
@permission_classes((AllowAny,))
|
||||
class HappyHourViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
queryset = HappyHour.objects.all()
|
||||
serializer_class = HappyHourSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = HappyHour.objects.all()
|
||||
type = self.request.query_params.get('type')
|
||||
|
||||
# if type == "food":
|
||||
# queryset = HappyHour.filter(location__contains="Austraße")
|
||||
# elif type == "drinks":
|
||||
# queryset = HappyHour.filter(location__contains="Austraße")
|
||||
|
||||
return queryset
|
||||
22
ofu_app/apps/donar/migrations/0003_auto_20171111_1013.py
Normal file
22
ofu_app/apps/donar/migrations/0003_auto_20171111_1013.py
Normal file
@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.7 on 2017-11-11 09:13
|
||||
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_20171030_0029'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='lecture_terms',
|
||||
name='starttime',
|
||||
field=models.TimeField(default=datetime.datetime(2017, 11, 11, 9, 13, 24, 139058, tzinfo=utc)),
|
||||
),
|
||||
]
|
||||
@ -13,32 +13,23 @@ 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 django.conf.urls import url
|
||||
|
||||
from apps.food import views
|
||||
|
||||
router = routers.DefaultRouter()
|
||||
router.register(r'all', views.FoodViewSet)
|
||||
router.register(r'loc/(?P<location>.+)/$', views.FoodList.as_view(), base_name="food-on-loaction")
|
||||
router.register(r'date/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.FoodList.as_view(),
|
||||
base_name="food-on-day")
|
||||
# router.register(r'(?P<location>.+)/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.FoodList.as_view(), base_name="food-list")
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.food, name='food'),
|
||||
|
||||
# Daily Menus
|
||||
url(r'^daily/$', views.daily_food, name='daily-food'),
|
||||
|
||||
# Weekly Menus
|
||||
url(r'^weekly/$', views.weekly_food, name='weekly-food'),
|
||||
url(r'^all/$', views.food, name='all-food'),
|
||||
|
||||
# All known Menus
|
||||
# url(r'^all/$', views.food, name='all-food'),
|
||||
|
||||
# Food Rating
|
||||
url(r'^daily/rating/$', views.food_rating, name='rating-food'),
|
||||
url(r'^weekly/rating/$', views.food_rating, name='rating-food'),
|
||||
url(r'^api/', include(router.urls)),
|
||||
url(r'^api/(?P<location>[a-zA-Z]+)/$', views.FoodList.as_view(), name='rating-food'),
|
||||
url(r'^api/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$', views.FoodList.as_view(),
|
||||
name='rating-food'),
|
||||
url(r'^api/(?P<location>[a-zA-Z]+)/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/(?P<day>[0-9]{2})/$',
|
||||
views.FoodList.as_view(),
|
||||
name='rating-food'),
|
||||
url(r'^detail/(?P<id>[0-9]+)/$', views.food_detail, name='food-detail')
|
||||
]
|
||||
|
||||
@ -3,15 +3,10 @@ from __future__ import unicode_literals
|
||||
|
||||
import datetime
|
||||
|
||||
from django.http import HttpResponse
|
||||
from django.shortcuts import render
|
||||
|
||||
from apps.food.models import Menu, HappyHour, SingleFood, UserRating
|
||||
from django.http import HttpResponse
|
||||
from rest_framework import viewsets, generics
|
||||
from rest_framework import status
|
||||
from rest_framework.decorators import api_view
|
||||
from rest_framework.response import Response
|
||||
from apps.food.serializers import MenuSerializer, SingleFoodSerializer
|
||||
|
||||
|
||||
# Create your views here.
|
||||
@ -113,42 +108,3 @@ def food_image(request):
|
||||
return HttpResponse(status=200)
|
||||
|
||||
return HttpResponse(status=404)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
def serialize_daily_food(request, location="", year="", month="", day=""):
|
||||
request_date = datetime.datetime.strptime((year + "-" + month + "-" + day), "%Y-%m-%d")
|
||||
queryset = Menu.objects.filter(location__contains=location).filter(date__exact=request_date)
|
||||
serializer = MenuSerializer(queryset)
|
||||
return Response(serializer)
|
||||
|
||||
|
||||
class FoodViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
queryset = Menu.objects.all()
|
||||
serializer_class = MenuSerializer
|
||||
|
||||
|
||||
class FoodList(generics.ListAPIView):
|
||||
serializer_class = MenuSerializer
|
||||
|
||||
def get_queryset(self):
|
||||
"""
|
||||
This view should return a list of all the purchases for
|
||||
the user as determined by the username portion of the URL.
|
||||
"""
|
||||
if 'location' in self.kwargs:
|
||||
location = self.kwargs['location']
|
||||
else:
|
||||
location = ""
|
||||
|
||||
if 'year' in self.kwargs and 'month' in self.kwargs and 'day' in self.kwargs:
|
||||
request_date = datetime.datetime.strptime(
|
||||
(self.kwargs['year'] + "-" + self.kwargs['month'] + "-" + self.kwargs['day']), "%Y-%m-%d")
|
||||
else:
|
||||
request_date = datetime.datetime.now()
|
||||
print("LOCATION: " + location)
|
||||
print("DATE: " + str(request_date))
|
||||
return Menu.objects.filter(location__contains=location).filter(date__exact=request_date)
|
||||
|
||||
0
ofu_app/core/__init__.py
Normal file
0
ofu_app/core/__init__.py
Normal file
0
ofu_app/core/models.py
Normal file
0
ofu_app/core/models.py
Normal file
@ -40,6 +40,7 @@ INSTALLED_APPS = [
|
||||
'apps.events',
|
||||
'apps.donar',
|
||||
'apps.registration',
|
||||
'api',
|
||||
'rest_framework',
|
||||
'analytical',
|
||||
]
|
||||
@ -48,7 +49,7 @@ SITE_ID = 1
|
||||
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_PERMISSION_CLASSES': [
|
||||
'rest_framework.permissions.IsAdminUser',
|
||||
'rest_framework.permissions.IsAuthenticated',
|
||||
],
|
||||
'PAGE_SIZE': 10
|
||||
}
|
||||
@ -62,7 +63,7 @@ REST_FRAMEWORK = {
|
||||
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
# ]
|
||||
|
||||
ROOT_URLCONF = 'ofu_app.urls'
|
||||
ROOT_URLCONF = 'core.urls'
|
||||
TEMPLATES = [
|
||||
{
|
||||
'BACKEND': 'django_jinja.backend.Jinja2',
|
||||
@ -71,7 +72,7 @@ TEMPLATES = [
|
||||
],
|
||||
'APP_DIRS': True,
|
||||
'OPTIONS': {
|
||||
'environment': 'ofu_app.jinja2.environment'
|
||||
'environment': 'core.jinja2.environment'
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -89,7 +90,7 @@ TEMPLATES = [
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = 'ofu_app.wsgi.application'
|
||||
WSGI_APPLICATION = 'core.wsgi.application'
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
|
||||
@ -13,23 +13,26 @@ 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 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 ofu_app import views
|
||||
|
||||
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'),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
# url(r'^signup/$', core_views.signup, name='signup'),
|
||||
url(r"^account/", include("apps.registration.urls")),
|
||||
url(r'^account/', include("apps.registration.urls")),
|
||||
|
||||
url(r'^$', views.home, name="home"),
|
||||
|
||||
# -- Apps --
|
||||
url(r'^food/', include('apps.food.urls')),
|
||||
url(r'^events/', include('apps.events.urls')),
|
||||
url(r'^donar/', include('apps.donar.urls')),
|
||||
url(r'^links/$', views.links, name='links-home'),
|
||||
url(r'^impressum/$', views.impressum, name='impressum'),
|
||||
|
||||
url(r'', include('api.urls'))
|
||||
]
|
||||
@ -11,6 +11,6 @@ import os
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ofu_app.settings")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
@ -3,7 +3,7 @@ import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "ofu_app.settings")
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "core.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user