custom recipes

This commit is contained in:
vabene1111
2019-11-14 18:59:50 +01:00
parent a3da7c2ffd
commit 49a60eddc6
6 changed files with 51 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<file url="file://$PROJECT_DIR$" libraries="{bootstrap, jquery-3.2.1.slim, jquery-3.3.1, popper, select2}" />
<file url="file://$PROJECT_DIR$" libraries="{bootstrap, jquery-3.2.1.slim, jquery-3.3.1, popper, select2, tabulator}" />
</component>
</project>

View File

@@ -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 %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/js/tabulator.min.js" integrity="sha256-u2YCVBkzzkIuLh6bMHUmqv6uuuHLxGgc6XF+rCJUV5k=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/css/bootstrap/tabulator_bootstrap4.min.css" integrity="sha256-+AmauyGZPl0HNTBQ5AMZBxfzP+rzXJjraezMKpWwWSE=" crossorigin="anonymous" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/js/tabulator.min.js"
integrity="sha256-u2YCVBkzzkIuLh6bMHUmqv6uuuHLxGgc6XF+rCJUV5k=" crossorigin="anonymous"></script>
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/css/bootstrap/tabulator_bootstrap4.min.css"
integrity="sha256-+AmauyGZPl0HNTBQ5AMZBxfzP+rzXJjraezMKpWwWSE=" crossorigin="anonymous"/>
{% endblock %}
{% block content %}
@@ -19,6 +23,8 @@
<div id="ingredients-table"></div>
<input type="hidden" id="ingredients_data_input" name="ingredients">
<input type="submit" value="Submit" class="btn btn-success">
<a href="{% url 'redirect_delete' form.instance|get_class|lower form.instance.pk %}"
class="btn btn-danger">{% trans 'Delete' %}</a>
{% if view_url %}
<a href="{{ view_url }}" class="btn btn-info">{% trans 'View' %} <i class="far fa-eye"></i></a>
{% 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);
}
})

View File

@@ -24,6 +24,7 @@
<input class="btn btn-primary" type="submit"/>
<a href="#" onclick="window.location = window.location.pathname;"
class="btn btn-warning">{% trans 'Reset' %}</a>
<a href="{% url 'new_recipe' %}" class="btn btn-success">{% trans 'New' %}</a>
</form>
</div>

View File

@@ -8,18 +8,18 @@
{% block content %}
<h3>{{ recipe.name }} <a href="{% url 'edit_recipe' recipe.pk %}"><i class="fas fa-pencil-alt"></i></a></h3>
{% if ingredients %}
<small>{% trans 'by' %} {{ recipe.created_by.username }}</small><br/><br/>
{% else %}
{% if recipe.storage %}
<small>{% trans 'in' %} <a
href="{% url 'edit_storage' recipe.storage.pk %}">{{ recipe.storage.name }}</a></small><br/><br/>
href="{% url 'edit_storage' recipe.storage.pk %}">{{ recipe.storage.name }}</a></small><br/><br/>
{% else %}
<small>{% trans 'by' %} {{ recipe.created_by.username }}</small><br/><br/>
{% endif %}
{% if recipe.all_tags %}
{{ recipe.all_tags }}
<br/>
<br/>
{% endif %}
<br/>
{% if ingredients %}
<div class="card" style="width: 18rem;">
@@ -35,10 +35,13 @@
</div>
<br/>
<br/>
{{ recipe.instructions | markdown | safe }}
{% endif %}
{% else %}
{% trans 'This is an external recipe.' %}
{% if recipe.instructions %}
{{ recipe.instructions | markdown | safe }}
{% endif %}
{% if recipe.storage %}
<a href='#' onClick='openRecipe({{ recipe.id }})'>{% trans 'Open recipe' %} <i
class="fas fa-external-link-alt"></i></a>
{% endif %}

View File

@@ -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

View File

@@ -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)