generic forms ...
@ -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, jquery-3.2.1.slim, jquery-3.3.1, popper}" />
|
<file url="file://$PROJECT_DIR$" libraries="{bootstrap, jquery-3.2.1, jquery-3.2.1.slim, jquery-3.3.1, popper, select2}" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -26,6 +26,7 @@
|
|||||||
<orderEntry type="library" name="bootstrap" level="application" />
|
<orderEntry type="library" name="bootstrap" level="application" />
|
||||||
<orderEntry type="library" name="jquery-3.2.1" level="application" />
|
<orderEntry type="library" name="jquery-3.2.1" level="application" />
|
||||||
<orderEntry type="library" name="jquery-3.3.1" level="application" />
|
<orderEntry type="library" name="jquery-3.3.1" level="application" />
|
||||||
|
<orderEntry type="library" name="select2" level="application" />
|
||||||
</component>
|
</component>
|
||||||
<component name="TemplatesService">
|
<component name="TemplatesService">
|
||||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||||
|
@ -4,6 +4,7 @@ from django.utils.translation import gettext as _
|
|||||||
from django import forms
|
from django import forms
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
# noinspection PyPackageRequirements
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
|
|
||||||
|
|
||||||
@ -66,7 +67,7 @@ class KeywordForm(forms.ModelForm):
|
|||||||
class EditRecipeForm(forms.ModelForm):
|
class EditRecipeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Recipe
|
model = Recipe
|
||||||
fields = ('name', 'category', 'keywords','path')
|
fields = ('name', 'category', 'keywords', 'path')
|
||||||
|
|
||||||
labels = {
|
labels = {
|
||||||
'name': _('Name'),
|
'name': _('Name'),
|
||||||
@ -75,10 +76,6 @@ class EditRecipeForm(forms.ModelForm):
|
|||||||
'path': _('Path'),
|
'path': _('Path'),
|
||||||
}
|
}
|
||||||
|
|
||||||
widgets = {
|
|
||||||
'keywords': autocomplete.ModelSelect2Multiple(url='dal_keyword')
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(EditRecipeForm, self).__init__(*args, **kwargs)
|
super(EditRecipeForm, self).__init__(*args, **kwargs)
|
||||||
self.helper = FormHelper()
|
self.helper = FormHelper()
|
||||||
|
Before Width: | Height: | Size: 500 KiB After Width: | Height: | Size: 500 KiB |
Before Width: | Height: | Size: 759 KiB After Width: | Height: | Size: 759 KiB |
Before Width: | Height: | Size: 699 KiB After Width: | Height: | Size: 699 KiB |
Before Width: | Height: | Size: 593 KiB After Width: | Height: | Size: 593 KiB |
@ -18,7 +18,10 @@
|
|||||||
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
|
||||||
crossorigin="anonymous"></script>
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
<link rel="stylesheet" href="{% static "fontawesome/fontawesome-all.css" %}" >
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/css/select2.min.css" rel="stylesheet"/>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.6-rc.0/js/select2.min.js"></script>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="{% static "fontawesome/fontawesome-all.css" %}">
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@media (max-width: 1025px) {
|
@media (max-width: 1025px) {
|
||||||
@ -50,9 +53,12 @@
|
|||||||
{% trans 'New' %}
|
{% trans 'New' %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
<a class="dropdown-item" href="{% url 'new_recipe' %}"><i class="fas fa-book"></i> {% trans 'Recipe' %}</a>
|
<a class="dropdown-item" href="{% url 'new_recipe' %}"><i
|
||||||
<a class="dropdown-item" href="{% url 'new_category' %}"><i class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
class="fas fa-book"></i> {% trans 'Recipe' %}</a>
|
||||||
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
<a class="dropdown-item" href="{% url 'new_category' %}"><i
|
||||||
|
class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
||||||
|
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i
|
||||||
|
class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
@ -61,8 +67,10 @@
|
|||||||
{% trans 'List' %}
|
{% trans 'List' %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
<a class="dropdown-item" href="{% url 'new_category' %}"><i class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
<a class="dropdown-item" href="{% url 'new_category' %}"><i
|
||||||
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
class="fas fa-archive"></i> {% trans 'Category' %}</a>
|
||||||
|
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i
|
||||||
|
class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item dropdown">
|
<li class="nav-item dropdown">
|
||||||
@ -71,9 +79,12 @@
|
|||||||
{% trans 'Manage Data' %}
|
{% trans 'Manage Data' %}
|
||||||
</a>
|
</a>
|
||||||
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
|
||||||
<a class="dropdown-item" href="{% url 'batch_monitor' %}"><i class="fas fa-sync-alt"></i> {% trans 'Configure Sync' %}</a>
|
<a class="dropdown-item" href="{% url 'batch_monitor' %}"><i
|
||||||
<a class="dropdown-item" href="{% url 'batch_import' %}"><i class="fas fa-wrench"></i> {% trans 'Manage imported Recipes' %}</a>
|
class="fas fa-sync-alt"></i> {% trans 'Configure Sync' %}</a>
|
||||||
<a class="dropdown-item" href="{% url 'batch_edit' %}"><i class="fas fa-edit"></i> {% trans 'Batch Edit' %}</a>
|
<a class="dropdown-item" href="{% url 'batch_import' %}"><i
|
||||||
|
class="fas fa-wrench"></i> {% trans 'Manage imported Recipes' %}</a>
|
||||||
|
<a class="dropdown-item" href="{% url 'batch_edit' %}"><i
|
||||||
|
class="fas fa-edit"></i> {% trans 'Batch Edit' %}</a>
|
||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
@ -84,9 +95,10 @@
|
|||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
{% if user.is_authenticated %}
|
{% if user.is_authenticated %}
|
||||||
<a class="nav-link" href="{% url 'logout' %}">{% trans 'Logout' %} {{ user.get_username }}</a>
|
<a class="nav-link" href="{% url 'logout' %}">{% trans 'Logout' %} {{ user.get_username }} <i
|
||||||
|
class="fas fa-sign-out-alt"></i></a>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="nav-link" href="{% url 'login' %}">{% trans 'Login' %}</a>
|
<a class="nav-link" href="{% url 'login' %}">{% trans 'Login' %} <i class="fas fa-sign-in-alt"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -14,4 +14,12 @@
|
|||||||
<input type="submit" value="Submit" class="btn btn-success">
|
<input type="submit" value="Submit" class="btn btn-success">
|
||||||
</form>
|
</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 %}
|
{% endblock %}
|
@ -12,7 +12,7 @@ urlpatterns = [
|
|||||||
path('new/category', new.category, name='new_category'),
|
path('new/category', new.category, name='new_category'),
|
||||||
path('new/keyword', new.keyword, name='new_keyword'),
|
path('new/keyword', new.keyword, name='new_keyword'),
|
||||||
|
|
||||||
path('edit/recipe/<int:recipe_id>/', edit.recipe, name='edit_recipe'),
|
path('edit/recipe/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_recipe'),
|
||||||
|
|
||||||
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
||||||
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
|
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
|
||||||
|
@ -2,7 +2,7 @@ from django.contrib.auth.decorators import login_required
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.shortcuts import redirect, render
|
from django.shortcuts import redirect, render
|
||||||
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 UpdateView, DeleteView
|
from django.views.generic import UpdateView, DeleteView
|
||||||
|
|
||||||
@ -15,6 +15,9 @@ class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Monitor
|
model = Monitor
|
||||||
fields = ['path']
|
fields = ['path']
|
||||||
|
|
||||||
|
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(MonitorUpdate, self).get_context_data(**kwargs)
|
context = super(MonitorUpdate, self).get_context_data(**kwargs)
|
||||||
context['title'] = _("Monitor")
|
context['title'] = _("Monitor")
|
||||||
@ -26,6 +29,9 @@ class CategoryUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Category
|
model = Category
|
||||||
fields = ['name', 'description']
|
fields = ['name', 'description']
|
||||||
|
|
||||||
|
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(CategoryUpdate, self).get_context_data(**kwargs)
|
context = super(CategoryUpdate, self).get_context_data(**kwargs)
|
||||||
context['title'] = _("Category")
|
context['title'] = _("Category")
|
||||||
@ -37,12 +43,37 @@ class KeywordUpdate(LoginRequiredMixin, UpdateView):
|
|||||||
model = Keyword
|
model = Keyword
|
||||||
fields = ['name', 'description']
|
fields = ['name', 'description']
|
||||||
|
|
||||||
|
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(KeywordUpdate, self).get_context_data(**kwargs)
|
context = super(KeywordUpdate, self).get_context_data(**kwargs)
|
||||||
context['title'] = _("Keyword")
|
context['title'] = _("Keyword")
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class RecipeUpdate(LoginRequiredMixin, UpdateView):
|
||||||
|
model = Recipe
|
||||||
|
form_class = EditRecipeForm
|
||||||
|
template_name = "generic\edit_template.html"
|
||||||
|
|
||||||
|
def form_valid(self, form):
|
||||||
|
messages.add_message(self.request, messages.SUCCESS, _('Changes saved!'))
|
||||||
|
return super(RecipeUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
def form_invalid(self, form):
|
||||||
|
messages.add_message(self.request, messages.ERROR, _('Error saving changes!'))
|
||||||
|
return super(RecipeUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
def get_success_url(self):
|
||||||
|
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
||||||
|
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(RecipeUpdate, self).get_context_data(**kwargs)
|
||||||
|
context['title'] = _("Recipe")
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def recipe(request, recipe_id):
|
def recipe(request, recipe_id):
|
||||||
recipe_obj = Recipe.objects.get(id=recipe_id)
|
recipe_obj = Recipe.objects.get(id=recipe_id)
|
||||||
|