diff --git a/cookbook/tables.py b/cookbook/tables.py index 160e3e95..967c9d2c 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -45,7 +45,7 @@ class MonitoredPathTable(tables.Table): delete = tables.TemplateColumn("" + _('Delete') + "") class Meta: - model = Keyword + model = Monitor template_name = 'generic/table_template.html' fields = ('path', 'last_checked') @@ -54,6 +54,6 @@ class NewRecipeTable(tables.Table): delete = tables.TemplateColumn("" + _('Delete') + "") class Meta: - model = Keyword + model = NewRecipe template_name = 'generic/table_template.html' fields = ('name','path') diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index f92b3228..dc5b6bd6 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -67,9 +67,9 @@ {% trans 'List' %} diff --git a/cookbook/templates/generic/list_template.html b/cookbook/templates/generic/list_template.html new file mode 100644 index 00000000..8c8b7071 --- /dev/null +++ b/cookbook/templates/generic/list_template.html @@ -0,0 +1,17 @@ +{% extends "base.html" %} +{% load crispy_forms_tags %} +{% load i18n %} +{% load django_tables2 %} + +{% block title %}{% trans 'List' %} - {{ title }}{% endblock %} + +{% block content %} + +

{{ title }} {% trans 'List' %}

+
+ + {% if table %} + {% render_table table %} + {% endif %} + +{% endblock %} \ No newline at end of file diff --git a/cookbook/templates/generic/table_template.html b/cookbook/templates/generic/table_template.html index eec006ef..c40a9b96 100644 --- a/cookbook/templates/generic/table_template.html +++ b/cookbook/templates/generic/table_template.html @@ -4,8 +4,8 @@
{% block table %} - +
+ {{ table.attrs.as_html }}{% else %}class="table table-bordered"{% endif %}> {% block table.thead %} {% if table.show_header %} diff --git a/cookbook/urls.py b/cookbook/urls.py index 9f867c16..905300ba 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -12,8 +12,10 @@ urlpatterns = [ path('new/category', new.category, name='new_category'), path('new/keyword', new.keyword, name='new_keyword'), - path('edit/recipe//', edit.RecipeUpdate.as_view(), name='edit_recipe'), + path('list/keyword', lists.keyword_list, name='list_keyword'), + path('list/category', lists.category_list, name='list_category'), + path('edit/recipe//', edit.RecipeUpdate.as_view(), name='edit_recipe'), path('edit/keyword//', edit.KeywordUpdate.as_view(), name='edit_keyword'), path('edit/category//', edit.CategoryUpdate.as_view(), name='edit_category'), path('edit/monitor//', edit.MonitorUpdate.as_view(), name='edit_monitor'), diff --git a/cookbook/views/__init__.py b/cookbook/views/__init__.py index 9b99fbd0..d6ec7ae9 100644 --- a/cookbook/views/__init__.py +++ b/cookbook/views/__init__.py @@ -3,3 +3,4 @@ from cookbook.views.api import * from cookbook.views.batch import * from cookbook.views.edit import * from cookbook.views.new import * +from cookbook.views.lists import * \ No newline at end of file diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 54d9fdeb..42b87d64 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -74,28 +74,6 @@ class RecipeUpdate(LoginRequiredMixin, UpdateView): return context -@login_required -def recipe(request, recipe_id): - recipe_obj = Recipe.objects.get(id=recipe_id) - if request.method == "POST": - form = EditRecipeForm(request.POST) - if form.is_valid(): - recipe_obj.name = form.cleaned_data['name'] - recipe_obj.path = form.cleaned_data['path'] - recipe_obj.category = Category.objects.get(name=form.cleaned_data['category']) - recipe_obj.keywords.clear() - recipe_obj.keywords.add(*list(form.cleaned_data['keywords'])) - recipe_obj.save() - messages.add_message(request, messages.SUCCESS, _('Recipe updated')) - return redirect(reverse_lazy('edit_recipe', args=[recipe_id])) - else: - messages.add_message(request, messages.ERROR, _('Recipe update failed')) - else: - form = EditRecipeForm(instance=recipe_obj) - - return render(request, 'edit/recipe.html', {'form': form}) - - # Generic Delete views class RecipeDelete(LoginRequiredMixin, DeleteView): template_name = "generic\delete_template.html" diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py new file mode 100644 index 00000000..4e337d02 --- /dev/null +++ b/cookbook/views/lists.py @@ -0,0 +1,23 @@ +from django.contrib.auth.decorators import login_required +from django.shortcuts import render +from django_tables2 import RequestConfig +from django.utils.translation import gettext as _ + +from cookbook.models import Category, Keyword +from cookbook.tables import CategoryTable, KeywordTable + + +@login_required +def category_list(request): + table = CategoryTable(Category.objects.all()) + RequestConfig(request, paginate={'per_page': 25}).configure(table) + + return render(request, 'generic/list_template.html', {'title': _("Category"), 'table': table}) + + +@login_required +def keyword_list(request): + table = KeywordTable(Keyword.objects.all()) + RequestConfig(request, paginate={'per_page': 25}).configure(table) + + return render(request, 'generic/list_template.html', {'title': _("Keyword"), 'table': table})