Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add modal dialog to add entries to the nutrition diary

Roland Geider34cce30d4548
diff --git a/wger/core/templates/index.html b/wger/core/templates/index.html
index c81541dda..f59c8569a 100644
--- a/wger/core/templates/index.html
+++ b/wger/core/templates/index.html
@@ -44,6 +44,46 @@ day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</str
</div>
</div>
{% endif %}
+{% if plan %}
+<div class="modal fade" id="nutrition-diary-popup">
+ <div class="modal-dialog">
+ <div class="modal-content">
+ <div class="modal-header">
+ <h4 class="modal-title">{% trans 'Add new diary entry' %}</h4>
+ <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
+ </div>
+ <div class="modal-body">
+ <p>
+ {% blocktrans trimmed %}Click to add an entry to your nutrition diary for
+ today. You can either log a meal as you defined it, or entry any number of
+ custom entries.{% endblocktrans %}
+ </p>
+
+ {% for meal in plan.meal_set.all %}
+ <a href="{% url 'nutrition:log:log_meal' meal.pk %}" class="btn btn-block btn-light">
+ {{meal.time}}
+ - {{meal.get_nutritional_values.energy|floatformat:0}}{% trans "kcal" %}
+ <br>
+ <small>
+ {% for item in meal.mealitem_set.select_related %}
+ {{ item.ingredient }}
+ {% if not forloop.last %} / {% endif %}
+ {% endfor %}
+ </small>
+ </a>
+ {% endfor %}
+
+ <a href="{% url 'nutrition:log:add' plan.pk %}" class="btn btn-block btn-light">
+ {% trans "Add custom diary entry" %}
+ </a>
+ </div>
+ <div class="modal-footer">
+ <button type="button" class="btn btn-light" data-dismiss="modal">{% trans "Close" %}</button>
+ </div>
+ </div>
+ </div>
+</div>
+{% endif %}
<div class="card-deck">
@@ -151,15 +191,17 @@ day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</str
</div>
<div id="nutrition_diary_chart"></div>
</div>
- {% if not plan %}
<div class="card-footer">
- <p>
+ {% if not plan %}
<a href="{% url 'nutrition:plan:add' %}" class="btn btn-sm btn-block btn-success">
{% trans "No nutrition plans." %} {% trans "Add one now." %}
</a>
- </p>
+ {% else %}
+ <a href="#" id="nutrition-diary-link" data-toggle="modal" data-target="#nutrition-diary-popup" class="btn btn-success btn-sm btn-block">
+ {% trans "Add new diary entry" %}
+ </a>
+ {% endif %}
</div>
- {% endif %}
</div>
diff --git a/wger/nutrition/models.py b/wger/nutrition/models.py
index 8bd20c0ac..1c9e37933 100644
--- a/wger/nutrition/models.py
+++ b/wger/nutrition/models.py
@@ -232,9 +232,9 @@ class NutritionPlan(models.Model):
return self.logitem_set.filter(datetime__date=date).select_related()
def get_log_summary(self, date=None):
- '''
+ """
Sums the nutritional info of the items logged for the given date
- '''
+ """
use_metric = self.user.userprofile.use_metric
result = {'energy': 0,
'protein': 0,
@@ -756,46 +756,46 @@ class LogItem(BaseMealItem, models.Model):
verbose_name=_('Nutrition plan'),
editable=False,
on_delete=models.CASCADE)
- '''
+ """
The plan this log belongs to
- '''
+ """
datetime = models.DateTimeField(auto_now=True)
- '''
+ """
Time and date when the log was added
- '''
+ """
comment = models.TextField(verbose_name=_('Comment'),
blank=True,
null=True)
- '''
+ """
Comment field, for additional information
- '''
+ """
ingredient = models.ForeignKey(Ingredient,
verbose_name=_('Ingredient'),
on_delete=models.CASCADE)
- '''
+ """
Ingredient
- '''
+ """
weight_unit = models.ForeignKey(IngredientWeightUnit,
verbose_name=_('Weight unit'),
null=True,
blank=True,
on_delete=models.CASCADE)
- '''
+ """
Weight unit used (grams, slices, etc.)
- '''
+ """
amount = models.DecimalField(decimal_places=2,
max_digits=6,
verbose_name=_('Amount'),
validators=[MinValueValidator(1),
MaxValueValidator(1000)])
- '''
+ """
The amount of units
- '''
+ """
def __str__(self):
"""
diff --git a/wger/nutrition/views/plan.py b/wger/nutrition/views/plan.py
index 0737ebaea..fb676b6d6 100644
--- a/wger/nutrition/views/plan.py
+++ b/wger/nutrition/views/plan.py
@@ -160,9 +160,7 @@ def view(request, id):
# Process and show the last 5 diary entries
log_data = []
planned_calories = plan.get_nutritional_values()['total']['energy']
- for item in plan.get_log_overview():
- if len(log_data) == 5:
- break
+ for item in plan.get_log_overview()[:5]:
log_data.append({'date': item['date'],
'planned_calories': planned_calories,
'logged_calories': item['energy'],