diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml index 6422d0b38..6150fb772 100644 --- a/.idea/jsLibraryMappings.xml +++ b/.idea/jsLibraryMappings.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/cookbook/templates/forms/edit_internal_recipe.html b/cookbook/templates/forms/edit_internal_recipe.html index 4ae14369d..8bb031048 100644 --- a/cookbook/templates/forms/edit_internal_recipe.html +++ b/cookbook/templates/forms/edit_internal_recipe.html @@ -1,12 +1,16 @@ {% extends "base.html" %} {% load crispy_forms_tags %} {% load i18n %} +{% load custom_tags %} {% block title %}{% trans 'Edit Recipe' %}{% endblock %} {% block extra_head %} - - + + {% endblock %} {% block content %} @@ -19,6 +23,8 @@
+ {% trans 'Delete' %} {% if view_url %} {% trans 'View' %} {% endif %} @@ -38,17 +44,29 @@ reactiveData: true, data: data, columns: [ - {title: "{% trans 'ingredient' %}", field: "ingredient", validator: "required", editor:"select", editorParams:{values:{"test1":"Test1", "test2":"Test2"}}}, + { + title: "{% trans 'ingredient' %}", + field: "ingredient", + validator: "required", + editor: "select", + editorParams: {values: {"test1": "Test1", "test2": "Test2"}} + }, {title: "{% trans 'amount' %}", field: "amount", validator: "required", editor: "input"}, {title: "{% trans 'unit' %}", field: "unit", validator: "required", editor: "input"}, - {title: "{% trans 'delete' %}", field:"delete", align:"center", editor:true, formatter:"tickCross"}, + { + title: "{% trans 'delete' %}", + field: "delete", + align: "center", + editor: true, + formatter: "tickCross" + }, {title: "id", field: "id", visible: false} ], dataEdited: function (data) { $('#ingredients_data_input').val(JSON.stringify(data)) data.forEach(function (cur, i) { - if(cur.delete) { + if (cur.delete) { table.deleteRow(cur.id); } }) diff --git a/cookbook/templates/index.html b/cookbook/templates/index.html index 282416815..0c7d63ce2 100644 --- a/cookbook/templates/index.html +++ b/cookbook/templates/index.html @@ -24,6 +24,7 @@ {% trans 'Reset' %} + {% trans 'New' %} diff --git a/cookbook/templates/recipe_view.html b/cookbook/templates/recipe_view.html index a41c9af37..20af3846d 100644 --- a/cookbook/templates/recipe_view.html +++ b/cookbook/templates/recipe_view.html @@ -8,18 +8,18 @@ {% block content %}

{{ recipe.name }}

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

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

+ href="{% url 'edit_storage' recipe.storage.pk %}">{{ recipe.storage.name }}

+ {% else %} + {% trans 'by' %} {{ recipe.created_by.username }}

{% endif %} {% if recipe.all_tags %} {{ recipe.all_tags }}
+
{% endif %} -
{% if ingredients %}
@@ -35,10 +35,13 @@


- {{ recipe.instructions | markdown | safe }} + {% endif %} - {% else %} - {% trans 'This is an external recipe.' %} + {% if recipe.instructions %} + {{ recipe.instructions | markdown | safe }} + {% endif %} + + {% if recipe.storage %} {% trans 'Open recipe' %} {% endif %} diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index d49b4dd63..e8178af5a 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -14,10 +14,10 @@ from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage @login_required def switch_recipe(request, pk): recipe = get_object_or_404(Recipe, pk=pk) - if recipe.instructions: - return HttpResponseRedirect(reverse('edit_internal_recipe', args=[pk])) - else: + if recipe.storage and not recipe.instructions: return HttpResponseRedirect(reverse('edit_external_recipe', args=[pk])) + else: + return HttpResponseRedirect(reverse('edit_internal_recipe', args=[pk])) @login_required diff --git a/cookbook/views/new.py b/cookbook/views/new.py index ae5ba9275..3437c11b7 100644 --- a/cookbook/views/new.py +++ b/cookbook/views/new.py @@ -1,8 +1,9 @@ from django.contrib import messages from django.contrib.auth.decorators import login_required from django.contrib.auth.mixins import LoginRequiredMixin +from django.http import HttpResponseRedirect from django.shortcuts import render, redirect -from django.urls import reverse_lazy +from django.urls import reverse_lazy, reverse from django.utils.translation import gettext as _ from django.views.generic import CreateView @@ -13,8 +14,16 @@ from cookbook.models import Keyword, Recipe class RecipeCreate(LoginRequiredMixin, CreateView): template_name = "generic/new_template.html" model = Recipe - form_class = InternalRecipeForm - success_url = reverse_lazy('index') + fields = ('name', ) + + def form_valid(self, form): + obj = form.save(commit=False) + obj.created_by = self.request.user + obj.save() + return HttpResponseRedirect(reverse('edit_recipe', kwargs={'pk': obj.pk})) + + def get_success_url(self): + return reverse('edit_recipe', kwargs={'pk': self.object.pk}) def get_context_data(self, **kwargs): context = super(RecipeCreate, self).get_context_data(**kwargs)