Skip to content

Commit

Permalink
Merge pull request #45 from tourn/improved-meal-plan
Browse files Browse the repository at this point in the history
Add buttons to add a meal plan to a specific point in time
  • Loading branch information
vabene1111 committed Apr 5, 2020
2 parents 84a8308 + de145b6 commit 4cf6a3b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
22 changes: 21 additions & 1 deletion cookbook/templates/meal_plan.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@
{% endblock %}

{% block content %}
<style>
.mealplan-cell .mealplan-add-button{
text-align: center;
display: block;
}

@media (hover: hover) {
.mealplan-cell .mealplan-add-button{
visibility: hidden;
float: right;
display: inline;
}

.mealplan-cell:hover .mealplan-add-button{
visibility: initial;
}
}

</style>

<h3>
{% trans 'Meal-Plan' %} <a href="{% url 'new_meal_plan' %}"><i class="fas fa-plus-circle"></i></a>
Expand Down Expand Up @@ -53,7 +72,8 @@ <h3>
</tr>
<tr>
{% for day_key, days_value in plan_value.days.items %}
<td>
<td class="mealplan-cell">
<a class="mealplan-add-button" href="{% url 'new_meal_plan' %}?date={{ day_key|date:'Y-m-d' }}&meal={{ plan_key }}"><i class="fas fa-plus"></i></a>
{% for mp in days_value %}
<a href="{% url 'edit_meal_plan' mp.pk %}"><i class="fas fa-edit"></i></a>
<a href="{% url 'view_recipe' mp.recipe.id %}">{{ mp.recipe.name }}</a><br/>
Expand Down
7 changes: 7 additions & 0 deletions cookbook/views/new.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from datetime import datetime

from django.contrib import messages
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -120,6 +121,12 @@ class MealPlanCreate(LoginRequiredMixin, CreateView):
form_class = MealPlanForm
success_url = reverse_lazy('view_plan')

def get_initial(self):
return dict(
meal=self.request.GET['meal'] if 'meal' in self.request.GET else None,
date=datetime.strptime(self.request.GET['date'], '%Y-%m-%d') if 'date' in self.request.GET else None
)

def form_valid(self, form):
obj = form.save(commit=False)
obj.user = self.request.user
Expand Down

0 comments on commit 4cf6a3b

Please sign in to comment.