mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-01 04:10:06 -05:00
custom recipes
This commit is contained in:
2
.idea/jsLibraryMappings.xml
generated
2
.idea/jsLibraryMappings.xml
generated
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="JavaScriptLibraryMappings">
|
<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>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,12 +1,16 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% load crispy_forms_tags %}
|
{% load crispy_forms_tags %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
|
||||||
{% block title %}{% trans 'Edit Recipe' %}{% endblock %}
|
{% block title %}{% trans 'Edit Recipe' %}{% endblock %}
|
||||||
|
|
||||||
{% block extra_head %}
|
{% 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>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabulator/4.4.3/js/tabulator.min.js"
|
||||||
<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" />
|
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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
@@ -19,6 +23,8 @@
|
|||||||
<div id="ingredients-table"></div>
|
<div id="ingredients-table"></div>
|
||||||
<input type="hidden" id="ingredients_data_input" name="ingredients">
|
<input type="hidden" id="ingredients_data_input" name="ingredients">
|
||||||
<input type="submit" value="Submit" class="btn btn-success">
|
<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 %}
|
{% if view_url %}
|
||||||
<a href="{{ view_url }}" class="btn btn-info">{% trans 'View' %} <i class="far fa-eye"></i></a>
|
<a href="{{ view_url }}" class="btn btn-info">{% trans 'View' %} <i class="far fa-eye"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@@ -38,17 +44,29 @@
|
|||||||
reactiveData: true,
|
reactiveData: true,
|
||||||
data: data,
|
data: data,
|
||||||
columns: [
|
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 'amount' %}", field: "amount", validator: "required", editor: "input"},
|
||||||
{title: "{% trans 'unit' %}", field: "unit", 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}
|
{title: "id", field: "id", visible: false}
|
||||||
],
|
],
|
||||||
dataEdited: function (data) {
|
dataEdited: function (data) {
|
||||||
$('#ingredients_data_input').val(JSON.stringify(data))
|
$('#ingredients_data_input').val(JSON.stringify(data))
|
||||||
|
|
||||||
data.forEach(function (cur, i) {
|
data.forEach(function (cur, i) {
|
||||||
if(cur.delete) {
|
if (cur.delete) {
|
||||||
table.deleteRow(cur.id);
|
table.deleteRow(cur.id);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
<input class="btn btn-primary" type="submit"/>
|
<input class="btn btn-primary" type="submit"/>
|
||||||
<a href="#" onclick="window.location = window.location.pathname;"
|
<a href="#" onclick="window.location = window.location.pathname;"
|
||||||
class="btn btn-warning">{% trans 'Reset' %}</a>
|
class="btn btn-warning">{% trans 'Reset' %}</a>
|
||||||
|
<a href="{% url 'new_recipe' %}" class="btn btn-success">{% trans 'New' %}</a>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,18 +8,18 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h3>{{ recipe.name }} <a href="{% url 'edit_recipe' recipe.pk %}"><i class="fas fa-pencil-alt"></i></a></h3>
|
<h3>{{ recipe.name }} <a href="{% url 'edit_recipe' recipe.pk %}"><i class="fas fa-pencil-alt"></i></a></h3>
|
||||||
{% if ingredients %}
|
{% if recipe.storage %}
|
||||||
<small>{% trans 'by' %} {{ recipe.created_by.username }}</small><br/><br/>
|
|
||||||
{% else %}
|
|
||||||
<small>{% trans 'in' %} <a
|
<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 %}
|
{% endif %}
|
||||||
|
|
||||||
{% if recipe.all_tags %}
|
{% if recipe.all_tags %}
|
||||||
{{ recipe.all_tags }}
|
{{ recipe.all_tags }}
|
||||||
<br/>
|
<br/>
|
||||||
|
<br/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br/>
|
|
||||||
|
|
||||||
{% if ingredients %}
|
{% if ingredients %}
|
||||||
<div class="card" style="width: 18rem;">
|
<div class="card" style="width: 18rem;">
|
||||||
@@ -35,10 +35,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
{{ recipe.instructions | markdown | safe }}
|
{% endif %}
|
||||||
|
|
||||||
{% else %}
|
{% if recipe.instructions %}
|
||||||
{% trans 'This is an external recipe.' %}
|
{{ recipe.instructions | markdown | safe }}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if recipe.storage %}
|
||||||
<a href='#' onClick='openRecipe({{ recipe.id }})'>{% trans 'Open recipe' %} <i
|
<a href='#' onClick='openRecipe({{ recipe.id }})'>{% trans 'Open recipe' %} <i
|
||||||
class="fas fa-external-link-alt"></i></a>
|
class="fas fa-external-link-alt"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ from cookbook.models import Recipe, Sync, Keyword, RecipeImport, Storage
|
|||||||
@login_required
|
@login_required
|
||||||
def switch_recipe(request, pk):
|
def switch_recipe(request, pk):
|
||||||
recipe = get_object_or_404(Recipe, pk=pk)
|
recipe = get_object_or_404(Recipe, pk=pk)
|
||||||
if recipe.instructions:
|
if recipe.storage and not recipe.instructions:
|
||||||
return HttpResponseRedirect(reverse('edit_internal_recipe', args=[pk]))
|
|
||||||
else:
|
|
||||||
return HttpResponseRedirect(reverse('edit_external_recipe', args=[pk]))
|
return HttpResponseRedirect(reverse('edit_external_recipe', args=[pk]))
|
||||||
|
else:
|
||||||
|
return HttpResponseRedirect(reverse('edit_internal_recipe', args=[pk]))
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
from django.shortcuts import render, redirect
|
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.utils.translation import gettext as _
|
||||||
from django.views.generic import CreateView
|
from django.views.generic import CreateView
|
||||||
|
|
||||||
@@ -13,8 +14,16 @@ from cookbook.models import Keyword, Recipe
|
|||||||
class RecipeCreate(LoginRequiredMixin, CreateView):
|
class RecipeCreate(LoginRequiredMixin, CreateView):
|
||||||
template_name = "generic/new_template.html"
|
template_name = "generic/new_template.html"
|
||||||
model = Recipe
|
model = Recipe
|
||||||
form_class = InternalRecipeForm
|
fields = ('name', )
|
||||||
success_url = reverse_lazy('index')
|
|
||||||
|
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):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(RecipeCreate, self).get_context_data(**kwargs)
|
context = super(RecipeCreate, self).get_context_data(**kwargs)
|
||||||
|
|||||||
Reference in New Issue
Block a user