internal recipe stuff
This commit is contained in:
parent
b54da49858
commit
50cd44d13b
24
cookbook/templates/forms/edit_internal_recipe.html
Normal file
24
cookbook/templates/forms/edit_internal_recipe.html
Normal file
@ -0,0 +1,24 @@
|
||||
{% extends "base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% trans 'Edit Recipe' %}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h3>{% trans 'Edit Recipe' %}</h3>
|
||||
|
||||
<form action="." method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
//converts multiselct in recipe edit to searchable multiselect
|
||||
//shitty solution that needs to be redone at some point
|
||||
$(document).ready(function () {
|
||||
$('#id_keywords').select2();
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
@ -9,7 +9,7 @@ urlpatterns = [
|
||||
path('test', views.test, name='test'),
|
||||
|
||||
path('new/recipe/', new.RecipeCreate.as_view(), name='new_recipe'),
|
||||
path('new/recipe_import/<int:import_id>/', new.create_new_recipe, name='new_recipe_import'),
|
||||
path('new/recipe_import/<int:import_id>/', new.create_new_external_recipe, name='new_recipe_import'),
|
||||
path('new/keyword/', new.KeywordCreate.as_view(), name='new_keyword'),
|
||||
path('new/storage/', new.StorageCreate.as_view(), name='new_storage'),
|
||||
|
||||
|
@ -1,14 +1,40 @@
|
||||
from django.contrib import messages
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.shortcuts import redirect
|
||||
from django.shortcuts import redirect, get_object_or_404, render
|
||||
from django.urls import reverse_lazy, reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views.generic import UpdateView, DeleteView
|
||||
|
||||
from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm
|
||||
from cookbook.forms import ExternalRecipeForm, KeywordForm, StorageForm, SyncForm, InternalRecipeForm
|
||||
from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage
|
||||
|
||||
|
||||
@login_required
|
||||
def edit_internal_recipe(request, pk):
|
||||
recipe_instance = get_object_or_404(Recipe, pk=pk)
|
||||
|
||||
if request.method == "POST":
|
||||
form = InternalRecipeForm(request.POST)
|
||||
if form.is_valid():
|
||||
recipe = Recipe()
|
||||
recipe.name = form.cleaned_data['name']
|
||||
recipe.instructions = form.cleaned_data['instructions']
|
||||
|
||||
recipe.save()
|
||||
|
||||
recipe.keywords.set(form.cleaned_data['keywords'])
|
||||
|
||||
messages.add_message(request, messages.SUCCESS, _('Recipe saved!'))
|
||||
return redirect('index')
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, _('There was an error importing this recipe!'))
|
||||
else:
|
||||
form = InternalRecipeForm(recipe_instance)
|
||||
|
||||
return render(request, 'forms/edit_internal_recipe.html', {'form': form})
|
||||
|
||||
|
||||
class SyncUpdate(LoginRequiredMixin, UpdateView):
|
||||
template_name = "generic/edit_template.html"
|
||||
model = Sync
|
||||
|
@ -47,7 +47,7 @@ class StorageCreate(LoginRequiredMixin, CreateView):
|
||||
|
||||
|
||||
@login_required
|
||||
def create_new_recipe(request, import_id):
|
||||
def create_new_external_recipe(request, import_id):
|
||||
if request.method == "POST":
|
||||
form = ImportRecipeForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
Loading…
Reference in New Issue
Block a user