Fix location choices bug
This commit is contained in:
parent
f35364d02c
commit
bdc6d36ce4
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(),
|
||||
),
|
||||
]
|
||||
@ -27,6 +27,7 @@ class SingleFoodSerializer(serializers.HyperlinkedModelSerializer):
|
||||
class MenuSerializer(serializers.HyperlinkedModelSerializer):
|
||||
date = serializers.DateField(format='iso-8601')
|
||||
menu = SingleFoodSerializer(many=True, read_only=True)
|
||||
location = serializers.ChoiceField(choices=Menu.LOCATION_CHOICES)
|
||||
|
||||
class Meta:
|
||||
model = Menu
|
||||
|
||||
@ -15,16 +15,17 @@ Including another URLconf
|
||||
"""
|
||||
from django.conf.urls import url
|
||||
from apps.food.api import views as api_views
|
||||
from apps.food.models import Menu
|
||||
|
||||
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)/$',
|
||||
url(r'^food/(?P<location>' + Menu.FEKI + '|' + Menu.MARKUSPLATZ + '|' + Menu.ERBA + '|' + Menu.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})/$',
|
||||
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'})),
|
||||
url(r'food/today/$', 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()
|
||||
location = self.request.query_params.get('location')
|
||||
date = self.request.query_params.get('date')
|
||||
|
||||
print(str(location).upper() == Menu.ERBA.upper())
|
||||
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")
|
||||
print(str(location).upper() == Menu.ERBA.upper())
|
||||
if str(location).upper() is Menu.ERBA.upper():
|
||||
queryset = queryset.filter(location_contains='Erba')
|
||||
elif str(location).upper() is Menu.FEKI.upper():
|
||||
queryset = queryset.filter(location=Menu.FEKI)
|
||||
elif str(location).upper() is Menu.AUSTRASSE.upper():
|
||||
queryset = queryset.filter(location=Menu.AUSTRASSE)
|
||||
elif str(location).upper() is Menu.MARKUSPLATZ.upper():
|
||||
queryset = queryset.filter(location=Menu.MARKUSPLATZ)
|
||||
if date:
|
||||
if date == "week":
|
||||
today = datetime.now()
|
||||
@ -82,19 +81,16 @@ class FoodViewSetV1_1(viewsets.ModelViewSet, ):
|
||||
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 str(location).upper() == Menu.ERBA.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.ERBA)
|
||||
elif str(location).upper() == Menu.FEKI.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.FEKI)
|
||||
elif str(location).upper() == Menu.AUSTRASSE.upper():
|
||||
print("Before: " + str(queryset))
|
||||
queryset = queryset.filter(location__contains=Menu.AUSTRASSE)
|
||||
elif str(location).upper() == Menu.MARKUSPLATZ.upper():
|
||||
queryset = queryset.filter(location__contains=Menu.MARKUSPLATZ)
|
||||
print(queryset)
|
||||
if year and month and day:
|
||||
date = '%s-%s-%s' % (year, month, day)
|
||||
queryset = queryset.filter(date=datetime.strptime(date, '%Y-%m-%d'))
|
||||
|
||||
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),
|
||||
),
|
||||
]
|
||||
@ -13,14 +13,18 @@ from django.utils import timezone
|
||||
from django.utils.encoding import smart_text
|
||||
from enum import Enum
|
||||
|
||||
MAX_LENGTH = 60
|
||||
|
||||
LOCATION_CHOICES = (
|
||||
('ERBA', 'Erba'), ('MARKUSPLATZ', 'Markusplatz'), ('FEKI', 'Feldkirchenstrasse'), ('AUSTRASSE', 'Austrasse'))
|
||||
MAX_LENGTH = 256
|
||||
|
||||
|
||||
# Create your models here.
|
||||
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)
|
||||
date = models.DateField(default=timezone.now)
|
||||
location = models.CharField(max_length=MAX_LENGTH, choices=LOCATION_CHOICES)
|
||||
|
||||
@ -2,7 +2,7 @@ import json
|
||||
from datetime import datetime
|
||||
from pprint import pprint
|
||||
from django.db.utils import IntegrityError
|
||||
from apps.food.models import SingleFood, Menu, HappyHour, Allergene, LOCATION_CHOICES
|
||||
from apps.food.models import SingleFood, Menu, HappyHour, Allergene
|
||||
from apps.food.utils.parser import mensa_page_parser, fekide_happyhour_page_parser, cafete_page_parser
|
||||
|
||||
# CONFIG SERVICE LINKS
|
||||
@ -21,7 +21,7 @@ def getJsonFromFile(path):
|
||||
|
||||
|
||||
def getLocation(raw_loc):
|
||||
for choice, name in zip(LOCATION_CHOICES, LOCATION_NAMES):
|
||||
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
|
||||
|
||||
@ -19,17 +19,17 @@ def daily_food(request):
|
||||
start_week = today - datetime.timedelta(today.weekday())
|
||||
end_week = start_week + datetime.timedelta(7)
|
||||
|
||||
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()
|
||||
erba_cafete = Menu.objects.filter(date__exact=today).filter(location__contains="Erba").last()
|
||||
markus_cafete = Menu.objects.filter(date__exact=today).filter(location__contains="markus").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=Menu.AUSTRASSE).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=Menu.MARKUSPLATZ).last()
|
||||
happy_hours = HappyHour.objects.filter(date__exact=today)
|
||||
|
||||
weekly_menus = Menu.objects.filter(date__gte=start_week, date__lte=end_week)
|
||||
weekly_feki_menu = weekly_menus.filter(location__contains="Feldkirchenstraße")
|
||||
weekly_austr_menu = weekly_menus.filter(location__contains="Austraße")
|
||||
weekly_erba_cafete = weekly_menus.filter(location__contains="Erba")
|
||||
weekly_markus_cafete = weekly_menus.filter(location__contains="markus")
|
||||
weekly_feki_menu = weekly_menus.filter(location__contains=Menu.FEKI)
|
||||
weekly_austr_menu = weekly_menus.filter(location__contains=Menu.AUSTRASSE)
|
||||
weekly_erba_cafete = weekly_menus.filter(location__contains=Menu.ERBA)
|
||||
weekly_markus_cafete = weekly_menus.filter(location__contains=Menu.MARKUSPLATZ)
|
||||
|
||||
return render(request, "food/daily_food.jinja", {
|
||||
'day': today,
|
||||
|
||||
Reference in New Issue
Block a user