Update location handling

This commit is contained in:
Michael Götz 2018-01-11 11:52:15 +01:00
parent 80250d9e6d
commit f35364d02c
5 changed files with 41 additions and 5 deletions

View File

@ -48,7 +48,7 @@ class Lecture(models.Model):
class Lecture_Terms(models.Model):
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)
def __str__(self):

View 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),
),
]

View File

@ -11,15 +11,19 @@ from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import models
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'))
# Create your models here.
class Menu(models.Model):
id = models.AutoField(primary_key=True)
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")
class Meta:

View File

@ -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
from apps.food.models import SingleFood, Menu, HappyHour, Allergene, LOCATION_CHOICES
from apps.food.utils.parser import mensa_page_parser, fekide_happyhour_page_parser, cafete_page_parser
# CONFIG SERVICE LINKS
@ -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_FEKIDE_GUIDE = "https://www.feki.de/happyhour"
LOCATION_NAMES = ('erba', 'markusplatz', 'feldkirchenstraße', 'austraße')
def getJsonFromFile(path):
with open(path, "r") as file:
return json.load(file)
def getLocation(raw_loc):
for choice, name in zip(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):
data = json.loads(data)
pprint(data)
@ -69,8 +80,9 @@ def writeStudentenwerkDataInDB(data):
db_single_food.allergens = allergens
foodlist.append(db_single_food)
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.objects.create(location=getLocation(data['name']), date=date)
menu.menu.set(foodlist)
menu.save()
except IntegrityError as error:

View File

@ -17,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(20)
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()