From a3da7c2ffd21de8ea16d4346399445c29ff2d551 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Thu, 14 Nov 2019 18:28:50 +0100 Subject: [PATCH] lots of cleanup and refactoring --- .../migrations/0009_auto_20191114_1800.py | 20 +++++ cookbook/models.py | 2 +- cookbook/tables.py | 2 +- .../templates/forms/edit_internal_recipe.html | 3 + cookbook/templates/generic/edit_template.html | 17 ++--- cookbook/templates/generic/list_template.html | 1 - cookbook/templates/generic/new_template.html | 11 +-- .../templates/generic/table_template.html | 4 +- .../templates/include/recipe_open_modal.html | 74 +++++++++++++++++++ .../include/storage_backend_warning.html | 12 +++ cookbook/templates/index.html | 71 +----------------- cookbook/templates/recipe_view.html | 41 ++++++---- cookbook/views/edit.py | 3 +- cookbook/views/views.py | 2 +- 14 files changed, 154 insertions(+), 109 deletions(-) create mode 100644 cookbook/migrations/0009_auto_20191114_1800.py create mode 100644 cookbook/templates/include/recipe_open_modal.html create mode 100644 cookbook/templates/include/storage_backend_warning.html diff --git a/cookbook/migrations/0009_auto_20191114_1800.py b/cookbook/migrations/0009_auto_20191114_1800.py new file mode 100644 index 00000000..54f9d826 --- /dev/null +++ b/cookbook/migrations/0009_auto_20191114_1800.py @@ -0,0 +1,20 @@ +# Generated by Django 2.2.7 on 2019-11-14 17:00 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0008_auto_20191114_1046'), + ] + + operations = [ + migrations.AlterField( + model_name='recipe', + name='created_by', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index eb33f73a..e6b2a830 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -61,7 +61,7 @@ class Recipe(models.Model): file_path = models.CharField(max_length=512, default="") link = models.CharField(max_length=512, default="") keywords = models.ManyToManyField(Keyword, blank=True) - created_by = models.IntegerField(default=0) + created_by = models.ForeignKey(User, on_delete=models.PROTECT) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/cookbook/tables.py b/cookbook/tables.py index aba98fec..35d0f2d8 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -7,7 +7,7 @@ from .models import * class RecipeTable(tables.Table): - id = tables.LinkColumn('edit_recipe', args=[A('id')]) + id = tables.LinkColumn('view_recipe', args=[A('id')]) name = tables.TemplateColumn( "{{record.name}}") all_tags = tables.Column( diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index f846511a..4ae14369 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -19,6 +19,9 @@
+ {% if view_url %} + {% trans 'View' %} + {% endif %} \ No newline at end of file diff --git a/cookbook/templates/include/storage_backend_warning.html b/cookbook/templates/include/storage_backend_warning.html new file mode 100644 index 00000000..817a5840 --- /dev/null +++ b/cookbook/templates/include/storage_backend_warning.html @@ -0,0 +1,12 @@ +{% load i18n %} + + \ No newline at end of file diff --git a/cookbook/templates/index.html b/cookbook/templates/index.html index bc08dc64..28241681 100644 --- a/cookbook/templates/index.html +++ b/cookbook/templates/index.html @@ -42,75 +42,6 @@ {% endif %} - - - - - + {% include 'include/recipe_open_modal.html' %} {% endblock %} \ No newline at end of file diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index ea1c9d21..a41c9af3 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -8,26 +8,40 @@ {% block content %}

{{ recipe.name }}

+ {% if ingredients %} + {% trans 'by' %} {{ recipe.created_by.username }}

+ {% else %} + {% trans 'in' %} {{ recipe.storage.name }}

+ {% endif %} + {% if recipe.all_tags %} {{ recipe.all_tags }}
{% endif %}
-
-
-
{% trans 'Ingredients' %}
+ + {% if ingredients %} +
+
+
{% trans 'Ingredients' %}
- {% for i in ingredients %} - {{ i.amount }} {{ i.unit }} {{ i.ingredient.name }}
- {% endfor %} + {% for i in ingredients %} + {{ i.amount }} {{ i.unit }} {{ i.ingredient.name }}
+ {% endfor %} +
-
-
-
+
+
+ {{ recipe.instructions | markdown | safe }} - {{ recipe.instructions | markdown | safe }} + {% else %} + {% trans 'This is an external recipe.' %} + {% trans 'Open recipe' %} + {% endif %}

@@ -37,11 +51,9 @@
{% csrf_token %} {{ form|crispy }} - +
- - {% for c in comments %}
@@ -52,4 +64,7 @@
{% endfor %} + {% if not ingredients %} + {% include 'include/recipe_open_modal.html' %} + {% endif %} {% endblock %} \ No newline at end of file diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 73912def..d49b4dd6 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -42,7 +42,7 @@ def internal_recipe_update(request, pk): else: form = InternalRecipeForm(instance=recipe_instance) - return render(request, 'forms/edit_internal_recipe.html', {'form': form}) + return render(request, 'forms/edit_internal_recipe.html', {'form': form, 'view_url': reverse('view_recipe', args=[pk])}) class SyncUpdate(LoginRequiredMixin, UpdateView): @@ -128,6 +128,7 @@ class RecipeUpdate(LoginRequiredMixin, UpdateView): def get_context_data(self, **kwargs): context = super(RecipeUpdate, self).get_context_data(**kwargs) context['title'] = _("Recipe") + context['view_url'] = reverse('view_recipe', args=[self.object.pk]) return context diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 2060025c..77617fd6 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -13,7 +13,7 @@ from cookbook.tables import RecipeTable def index(request): if request.user.is_authenticated: - f = RecipeFilter(request.GET, queryset=Recipe.objects.all()) + f = RecipeFilter(request.GET, queryset=Recipe.objects.all().order_by('name')) table = RecipeTable(f.qs) RequestConfig(request, paginate={'per_page': 25}).configure(table)