Added page to view meal plan(s)

This commit is contained in:
Jim Martens 2020-02-23 15:39:41 +01:00
parent 6ee50c683c
commit 854c1a5081
4 changed files with 102 additions and 0 deletions

View File

@ -6,4 +6,18 @@
{% block content %}
<h1>{% trans "Home" %}</h1>
<table class="table">
<thead>
<tr>
<th scope="col">{% trans "Name" %}</th>
</tr>
</thead>
<tbody>
{% for mealplan in mealplans %}
<tr>
<td><a href="{% url 'food_planner:mealplan' mealplan.author.id mealplan.name %}">{{ mealplan.name }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

View File

@ -0,0 +1,75 @@
{% extends "food_planner/base.html" %}
{% load i18n %}
{% block title %}{{ site.title }} - {% trans "Mealplan" %}{% endblock %}
{% block content %}
<h1>{% trans "Meal plan: " %}{{ mealplan.name }}</h1>
<table class="table">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">{% trans "Monday" %}</th>
<th scope="col">{% trans "Tuesday" %}</th>
<th scope="col">{% trans "Wednesday" %}</th>
<th scope="col">{% trans "Thursday" %}</th>
<th scope="col">{% trans "Friday" %}</th>
<th scope="col">{% trans "Saturday" %}</th>
<th scope="col">{% trans "Sunday" %}</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">{% trans "Breakfast" %}</th>
<td>{{ mealplan.monday_breakfast.name }}</td>
<td>{{ mealplan.tuesday_breakfast.name }}</td>
<td>{{ mealplan.wednesday_breakfast.name }}</td>
<td>{{ mealplan.thursday_breakfast.name }}</td>
<td>{{ mealplan.friday_breakfast.name }}</td>
<td>{{ mealplan.saturday_breakfast.name }}</td>
<td>{{ mealplan.sunday_breakfast.name }}</td>
</tr>
<tr>
<th scope="row">{% trans "Morning snack" %}</th>
<td>{{ mealplan.monday_morning_snack.name }}</td>
<td>{{ mealplan.tuesday_morning_snack.name }}</td>
<td>{{ mealplan.wednesday_morning_snack.name }}</td>
<td>{{ mealplan.thursday_morning_snack.name }}</td>
<td>{{ mealplan.friday_morning_snack.name }}</td>
<td>{{ mealplan.saturday_morning_snack.name }}</td>
<td>{{ mealplan.sunday_morning_snack.name }}</td>
</tr>
<tr>
<th scope="row">{% trans "Lunch" %}</th>
<td>{{ mealplan.monday_lunch.name }}</td>
<td>{{ mealplan.tuesday_lunch.name }}</td>
<td>{{ mealplan.wednesday_lunch.name }}</td>
<td>{{ mealplan.thursday_lunch.name }}</td>
<td>{{ mealplan.friday_lunch.name }}</td>
<td>{{ mealplan.saturday_lunch.name }}</td>
<td>{{ mealplan.sunday_lunch.name }}</td>
</tr>
<tr>
<th scope="row">{% trans "Afternoon snack" %}</th>
<td>{{ mealplan.monday_afternoon_snack.name }}</td>
<td>{{ mealplan.tuesday_afternoon_snack.name }}</td>
<td>{{ mealplan.wednesday_afternoon_snack.name }}</td>
<td>{{ mealplan.thursday_afternoon_snack.name }}</td>
<td>{{ mealplan.friday_afternoon_snack.name }}</td>
<td>{{ mealplan.saturday_afternoon_snack.name }}</td>
<td>{{ mealplan.sunday_afternoon_snack.name }}</td>
</tr>
<tr>
<th scope="row">{% trans "Dinner" %}</th>
<td>{{ mealplan.monday_dinner.name }}</td>
<td>{{ mealplan.tuesday_dinner.name }}</td>
<td>{{ mealplan.wednesday_dinner.name }}</td>
<td>{{ mealplan.thursday_dinner.name }}</td>
<td>{{ mealplan.friday_dinner.name }}</td>
<td>{{ mealplan.saturday_dinner.name }}</td>
<td>{{ mealplan.sunday_dinner.name }}</td>
</tr>
</tbody>
</table>
{% endblock %}

View File

@ -8,4 +8,5 @@ urlpatterns = [
path('', views.index, name='index'),
path('legal-notice/', views.legal, name='legal'),
path('privacy/', views.privacy, name='privacy'),
path('mealplans/<int:user_id>/<str:mealplan>/', views.mealplan, name='mealplan'),
]

View File

@ -14,6 +14,7 @@ from django.urls import reverse
from food_planner.forms import ProfileForm
from food_planner.forms import UserForm
from food_planner.models import MealPlan
def index(request) -> HttpResponse:
@ -23,11 +24,22 @@ def index(request) -> HttpResponse:
}
}
if request.user.is_authenticated:
context['mealplans'] = MealPlan.objects.filter(author=request.user)
return render(request, template_name='food_planner/home.html', context=context)
else:
return render(request, template_name='food_planner/landing.html', context=context)
def mealplan(request, user_id: int, mealplan: str) -> HttpResponse:
context = {
'site': {
'title': 'Food planner'
},
'mealplan': MealPlan.objects.get(author_id=user_id, name=mealplan)
}
return render(request, template_name='food_planner/mealplan.html', context=context)
@transaction.atomic
def register(request) -> HttpResponse:
if request.user.is_authenticated: