Update food i don't care
This commit is contained in:
parent
e57399b7f1
commit
51f850e40c
@ -2,7 +2,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from apps.food.models import SingleFood, Menu, HappyHour, UserRating, UserFoodImage, FoodImage
|
from apps.food.models import SingleFood, Menu, HappyHour, UserFoodRating, UserFoodImage, FoodImage
|
||||||
|
|
||||||
|
|
||||||
class SingleFoodInline(admin.TabularInline):
|
class SingleFoodInline(admin.TabularInline):
|
||||||
@ -22,7 +22,7 @@ class MenuAdmin(admin.ModelAdmin):
|
|||||||
# Register your models here.
|
# Register your models here.
|
||||||
admin.site.register(SingleFood)
|
admin.site.register(SingleFood)
|
||||||
admin.site.register(HappyHour)
|
admin.site.register(HappyHour)
|
||||||
admin.site.register(UserRating)
|
admin.site.register(UserFoodRating)
|
||||||
admin.site.register(UserFoodImage)
|
admin.site.register(UserFoodImage)
|
||||||
admin.site.register(Menu, MenuAdmin)
|
admin.site.register(Menu, MenuAdmin)
|
||||||
admin.site.register(FoodImage)
|
admin.site.register(FoodImage)
|
||||||
|
|||||||
49
ofu_app/apps/food/migrations/0009_auto_20180324_0039.py
Normal file
49
ofu_app/apps/food/migrations/0009_auto_20180324_0039.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# Generated by Django 2.0.1 on 2018-03-24 00:39
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('food', '0008_auto_20180201_1018'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserFoodComment',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('comment', models.CharField(max_length=2048)),
|
||||||
|
('food', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.SingleFood')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='UserFoodRating',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('rating', models.FloatField(default=0)),
|
||||||
|
('food', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.SingleFood')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='userrating',
|
||||||
|
name='food',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='userrating',
|
||||||
|
name='user',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='UserRating',
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='userfoodcomment',
|
||||||
|
unique_together={('user', 'food')},
|
||||||
|
),
|
||||||
|
]
|
||||||
26
ofu_app/apps/food/migrations/0010_auto_20180325_1630.py
Normal file
26
ofu_app/apps/food/migrations/0010_auto_20180325_1630.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Generated by Django 2.0.1 on 2018-03-25 16:30
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('food', '0009_auto_20180324_0039'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='HappyHourLocation',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||||
|
('name', models.CharField(max_length=256, unique=True)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='happyhour',
|
||||||
|
name='location',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='food.HappyHourLocation'),
|
||||||
|
),
|
||||||
|
]
|
||||||
23
ofu_app/apps/food/migrations/0011_auto_20180326_2255.py
Normal file
23
ofu_app/apps/food/migrations/0011_auto_20180326_2255.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
# Generated by Django 2.0.1 on 2018-03-26 22:55
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
|
('food', '0010_auto_20180325_1630'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='happyhour',
|
||||||
|
unique_together={('location', 'starttime', 'endtime')},
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='userfoodrating',
|
||||||
|
unique_together={('user', 'food')},
|
||||||
|
),
|
||||||
|
]
|
||||||
19
ofu_app/apps/food/migrations/0012_auto_20180326_2343.py
Normal file
19
ofu_app/apps/food/migrations/0012_auto_20180326_2343.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 2.0.1 on 2018-03-26 23:43
|
||||||
|
|
||||||
|
import django.core.validators
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('food', '0011_auto_20180326_2255'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='userfoodrating',
|
||||||
|
name='rating',
|
||||||
|
field=models.FloatField(default=0, validators=[django.core.validators.MaxValueValidator(5), django.core.validators.MinValueValidator(0)]),
|
||||||
|
),
|
||||||
|
]
|
||||||
0
ofu_app/apps/food/templates/__init__.py
Normal file
0
ofu_app/apps/food/templates/__init__.py
Normal file
126
ofu_app/apps/food/templates/root_api.jinja
Normal file
126
ofu_app/apps/food/templates/root_api.jinja
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
{% import '/macros/nav.jinja' as nav %}
|
||||||
|
{# ===== HTML ===== #}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en" dir="ltr">
|
||||||
|
{# ===== Head ===== #}
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
|
<title>BaStA</title>
|
||||||
|
<meta name="author" content="Michael Götz"/>
|
||||||
|
<script src="{{ static('libs/jquery/jquery-3.2.1.min.js') }}"></script>
|
||||||
|
<script src="{{ static('libs/bootstrap-4.0.0-beta-dist/js/bootstrap.js') }}"></script>
|
||||||
|
{% block js_extra %}{% endblock %}
|
||||||
|
<!-- Bootstrap CSS -->
|
||||||
|
<link rel="stylesheet" href="{{ static('libs/font-awesome-4.7.0/css/font-awesome.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ static('libs/bootstrap-4.0.0-beta-dist/css/bootstrap.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ static('css/nav.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{ static('css/main.css') }}">
|
||||||
|
{% block css_extra %}{% endblock %}
|
||||||
|
<!-- Piwik -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
var _paq = _paq || [];
|
||||||
|
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
|
||||||
|
_paq.push(['trackPageView']);
|
||||||
|
_paq.push(['enableLinkTracking']);
|
||||||
|
(function () {
|
||||||
|
var u = "//mg-server.ddns.net/piwik/";
|
||||||
|
_paq.push(['setTrackerUrl', u + 'piwik.php']);
|
||||||
|
_paq.push(['setSiteId', '1']);
|
||||||
|
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
|
||||||
|
g.type = 'text/javascript';
|
||||||
|
g.async = true;
|
||||||
|
g.defer = true;
|
||||||
|
g.src = u + 'piwik.js';
|
||||||
|
s.parentNode.insertBefore(g, s);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<!-- End Piwik Code -->
|
||||||
|
</head>
|
||||||
|
|
||||||
|
{# ===== Body ===== #}
|
||||||
|
<body>
|
||||||
|
{% block body %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-2 text-center m-auto">
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
<div class="dropdown">
|
||||||
|
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenuButton"
|
||||||
|
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||||
|
<i class="fa fa-user" aria-hidden="true"></i>
|
||||||
|
</button>
|
||||||
|
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
||||||
|
<a class="dropdown-item" href="{{ url('account') }}"><i class="fa fa-user"
|
||||||
|
aria-hidden="true"></i> Profile</a>
|
||||||
|
<a class="dropdown-item" href="{{ url('logout') }}"><i class="fa fa-sign-out"
|
||||||
|
aria-hidden="true"></i> Logout</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<a href="{{ url('login') }}"><i class="fa fa-sign-in" aria-hidden="true"></i></a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
<div class="col-8 pt-2">
|
||||||
|
{% block headline %}{% endblock %}</div>
|
||||||
|
<div class="col-2 text-center m-auto">
|
||||||
|
<div id="menu-button"><i class="fa fa-bars" aria-hidden="true"></i>
|
||||||
|
{{ nav.main_nav() }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">{% block bottom_nav %}{% endblock %}</div>
|
||||||
|
<div class="test row bg-dark text-white">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
<div class="col">
|
||||||
|
<table class="table">
|
||||||
|
<tr><th>Method</th><th>Request URL</th><th>Description</th></tr>
|
||||||
|
<tr><td></td></tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% block test %}
|
||||||
|
<div class="row text-center bg-warning pb-2 pl-3 pr-3" style="font-size: 12px !important;">
|
||||||
|
<div class="col-12 text-center">
|
||||||
|
Hinweis: Diese Seite dient <strong>nur</strong> zu Testzwecken.
|
||||||
|
Wir garantieren weder die Vollständigkeit, noch
|
||||||
|
die Korrektheit der dargestellten Daten.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
{% block footer %}
|
||||||
|
<footer>
|
||||||
|
<div class="row bg-dark text-white">
|
||||||
|
<div class="col-6">
|
||||||
|
<p class="text-right mb-0"><a href="{{ url('impressum') }}#bug-report">Bug Report</a></p>
|
||||||
|
</div>
|
||||||
|
<div class="col-6">
|
||||||
|
<p class="text-left mb-0"><a href="{{ url('impressum') }}">Impressum</a></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row text-center bg-dark text-white pb-2">
|
||||||
|
<div class="col">
|
||||||
|
© Copyright 2018, Michael Götz
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</footer>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
<!-- Optional JavaScript -->
|
||||||
|
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
|
||||||
|
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"
|
||||||
|
integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"
|
||||||
|
integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"
|
||||||
|
integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
{% block js_tail %}{% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@ -4,9 +4,8 @@ from __future__ import unicode_literals
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from apps.food.models import SingleFood, Menu
|
from apps.food.models import SingleFood, Menu
|
||||||
from apps.food.api.serializers import MenuSerializer
|
from apps.food.api.v1_1.serializers import MenuSerializer
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
from rest_framework.test import APIRequestFactory
|
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|||||||
@ -13,12 +13,11 @@ 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 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
|
||||||
from apps.food.api import views as api_views
|
from apps.food.api.v1_1 import views as api_views
|
||||||
|
|
||||||
# API Version 1.0
|
# API Version 1.0
|
||||||
apiRouter_v1 = routers.DefaultRouter()
|
apiRouter_v1 = routers.DefaultRouter()
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import json
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
from django.db.utils import IntegrityError
|
from django.db.utils import IntegrityError
|
||||||
from apps.food.models import SingleFood, Menu, HappyHour, Allergene
|
from apps.food.models import SingleFood, Menu, HappyHour, Allergene, HappyHourLocation
|
||||||
from apps.food.utils.parser import mensa_page_parser, fekide_happyhour_page_parser, cafete_page_parser
|
from apps.food.utils.parser import mensa_page_parser, fekide_happyhour_page_parser, cafete_page_parser
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@ -75,21 +75,22 @@ def writeStudentenwerkDataInDB(data):
|
|||||||
def writeFekideDataInDB(data):
|
def writeFekideDataInDB(data):
|
||||||
for happyhour_data in data['happyhours']:
|
for happyhour_data in data['happyhours']:
|
||||||
time = str(happyhour_data['time']).replace(" ", "").split("-")
|
time = str(happyhour_data['time']).replace(" ", "").split("-")
|
||||||
happyhour, new = HappyHour.objects.get_or_create(date=datetime.strptime(data['day'], "%A, %d.%m.%Y"),
|
try:
|
||||||
location=happyhour_data['location'],
|
location, _ = HappyHourLocation.objects.get_or_create(name=happyhour_data['location'])
|
||||||
description=happyhour_data['description'],
|
happyhour, _ = HappyHour.objects.get_or_create(location=location,
|
||||||
starttime=datetime.strptime(time[0], "%H:%M").time(),
|
starttime=datetime.strptime(time[0], "%H:%M").time(),
|
||||||
endtime=datetime.strptime(time[1], "%H:%M").time())
|
endtime=datetime.strptime(time[1], "%H:%M").time())
|
||||||
if not new:
|
|
||||||
happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y")
|
happyhour.date = datetime.strptime(data['day'], "%A, %d.%m.%Y")
|
||||||
happyhour.location = happyhour_data['location']
|
|
||||||
happyhour.description = happyhour_data['description']
|
happyhour.description = happyhour_data['description']
|
||||||
happyhour.starttime = datetime.strptime(time[0], "%H:%M").time()
|
|
||||||
happyhour.endtime = datetime.strptime(time[1], "%H:%M").time()
|
|
||||||
happyhour.save()
|
happyhour.save()
|
||||||
|
|
||||||
logger.info("%s: Happy Hour: Location: %s, Description: %s",
|
logger.info("{date}: Happy Hour: Location: {location}, Description: {description}".format(
|
||||||
str(happyhour.date.date()), str(happyhour.location), str(happyhour.description))
|
date=happyhour.date,
|
||||||
|
location=happyhour.location,
|
||||||
|
description=happyhour.description)
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
logger.exception(e)
|
||||||
|
|
||||||
|
|
||||||
def writeoutDBObjects():
|
def writeoutDBObjects():
|
||||||
@ -102,10 +103,13 @@ def writeoutDBObjects():
|
|||||||
|
|
||||||
def delete():
|
def delete():
|
||||||
happy_hours = HappyHour.objects.all()
|
happy_hours = HappyHour.objects.all()
|
||||||
print("Deleted following Happy Hours:")
|
logger.info("Deleted following Happy Hours:")
|
||||||
for happy_hour in happy_hours:
|
for happy_hour in happy_hours:
|
||||||
print("%s: Happy Hour: Location: %s, Description: %s" % (
|
logger.info("{date}: Happy Hour: Location: {location}, Description: {description}".format(
|
||||||
str(happy_hour.date), str(happy_hour.location), str(happy_hour.description)))
|
date=happy_hour.date,
|
||||||
|
location=happy_hour.location,
|
||||||
|
description=happy_hour.description)
|
||||||
|
)
|
||||||
happy_hour.delete()
|
happy_hour.delete()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ from django.http import HttpResponse
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
|
||||||
from apps.food.forms import UploadImageForm
|
from apps.food.forms import UploadImageForm
|
||||||
from apps.food.models import Menu, HappyHour, SingleFood, UserRating, UserFoodImage, FoodImage
|
from apps.food.models import Menu, HappyHour, SingleFood, UserFoodRating, UserFoodImage, FoodImage
|
||||||
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@ -100,12 +100,12 @@ def food_rating(request):
|
|||||||
rating = request.GET.get('rating', None)
|
rating = request.GET.get('rating', None)
|
||||||
if food_id and rating:
|
if food_id and rating:
|
||||||
food = SingleFood.objects.get(id=food_id)
|
food = SingleFood.objects.get(id=food_id)
|
||||||
user_rating, created = UserRating.objects.get_or_create(user=request.user,
|
user_rating, created = UserFoodRating.objects.get_or_create(user=request.user,
|
||||||
food=food)
|
food=food)
|
||||||
user_rating.rating = rating
|
user_rating.rating = rating
|
||||||
user_rating.save()
|
user_rating.save()
|
||||||
|
|
||||||
food_user_ratings = UserRating.objects.all().filter(food=food)
|
food_user_ratings = UserFoodRating.objects.all().filter(food=food)
|
||||||
sum = 0
|
sum = 0
|
||||||
for food_user_rating in food_user_ratings:
|
for food_user_rating in food_user_ratings:
|
||||||
sum += food_user_rating.rating
|
sum += food_user_rating.rating
|
||||||
|
|||||||
Reference in New Issue
Block a user