generic forms ...
@ -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, 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>
|
||||
</project>
|
@ -26,6 +26,7 @@
|
||||
<orderEntry type="library" name="bootstrap" 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="select2" level="application" />
|
||||
</component>
|
||||
<component name="TemplatesService">
|
||||
<option name="TEMPLATE_CONFIGURATION" value="Django" />
|
||||
|
@ -4,6 +4,7 @@ from django.utils.translation import gettext as _
|
||||
from django import forms
|
||||
from .models import *
|
||||
|
||||
# noinspection PyPackageRequirements
|
||||
from dal import autocomplete
|
||||
|
||||
|
||||
@ -66,7 +67,7 @@ class KeywordForm(forms.ModelForm):
|
||||
class EditRecipeForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Recipe
|
||||
fields = ('name', 'category', 'keywords','path')
|
||||
fields = ('name', 'category', 'keywords', 'path')
|
||||
|
||||
labels = {
|
||||
'name': _('Name'),
|
||||
@ -75,10 +76,6 @@ class EditRecipeForm(forms.ModelForm):
|
||||
'path': _('Path'),
|
||||
}
|
||||
|
||||
widgets = {
|
||||
'keywords': autocomplete.ModelSelect2Multiple(url='dal_keyword')
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(EditRecipeForm, self).__init__(*args, **kwargs)
|
||||
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"
|
||||
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>
|
||||
@media (max-width: 1025px) {
|
||||
@ -50,9 +53,12 @@
|
||||
{% trans 'New' %}
|
||||
</a>
|
||||
<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_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>
|
||||
<a class="dropdown-item" href="{% url 'new_recipe' %}"><i
|
||||
class="fas fa-book"></i> {% trans 'Recipe' %}</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>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
@ -61,8 +67,10 @@
|
||||
{% trans 'List' %}
|
||||
</a>
|
||||
<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_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>
|
||||
</li>
|
||||
<li class="nav-item dropdown">
|
||||
@ -71,9 +79,12 @@
|
||||
{% trans 'Manage Data' %}
|
||||
</a>
|
||||
<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_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>
|
||||
<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_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>
|
||||
</li>
|
||||
</ul>
|
||||
@ -84,9 +95,10 @@
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -14,4 +14,12 @@
|
||||
<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 %}
|
@ -12,7 +12,7 @@ urlpatterns = [
|
||||
path('new/category', new.category, name='new_category'),
|
||||
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/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.auth.mixins import LoginRequiredMixin
|
||||
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.views.generic import UpdateView, DeleteView
|
||||
|
||||
@ -15,6 +15,9 @@ class MonitorUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = Monitor
|
||||
fields = ['path']
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(MonitorUpdate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Monitor")
|
||||
@ -26,6 +29,9 @@ class CategoryUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = Category
|
||||
fields = ['name', 'description']
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CategoryUpdate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Category")
|
||||
@ -37,12 +43,37 @@ class KeywordUpdate(LoginRequiredMixin, UpdateView):
|
||||
model = Keyword
|
||||
fields = ['name', 'description']
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('edit_recipe', kwargs={'pk': self.object.pk})
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(KeywordUpdate, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Keyword")
|
||||
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
|
||||
def recipe(request, recipe_id):
|
||||
recipe_obj = Recipe.objects.get(id=recipe_id)
|
||||
|