list views

This commit is contained in:
vabene1111 2018-05-03 20:43:47 +02:00
parent 284beb47af
commit e722863093
8 changed files with 50 additions and 29 deletions

View File

@ -45,7 +45,7 @@ class MonitoredPathTable(tables.Table):
delete = tables.TemplateColumn("<a href='{% url 'delete_monitor' record.id %}' >" + _('Delete') + "</a>")
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("<a href='{% url 'delete_new_recipe' record.id %}' >" + _('Delete') + "</a>")
class Meta:
model = Keyword
model = NewRecipe
template_name = 'generic/table_template.html'
fields = ('name','path')

View File

@ -67,9 +67,9 @@
{% trans 'List' %}
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="{% url 'new_category' %}"><i
<a class="dropdown-item" href="{% url 'list_category' %}"><i
class="fas fa-archive"></i> {% trans 'Category' %}</a>
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i
<a class="dropdown-item" href="{% url 'list_keyword' %}"><i
class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
</div>
</li>

View File

@ -0,0 +1,17 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% load i18n %}
{% load django_tables2 %}
{% block title %}{% trans 'List' %} - {{ title }}{% endblock %}
{% block content %}
<h3>{{ title }} {% trans 'List' %}</h3>
<br/>
{% if table %}
{% render_table table %}
{% endif %}
{% endblock %}

View File

@ -4,8 +4,8 @@
<div class="row">
<div class="table-responsive">
{% block table %}
<table style='font-size: 24px' {% if table.attrs %}
{{ table.attrs.as_html }}{% else %}class="table table-bordered table-xl"{% endif %}>
<table {% if table.attrs %} <!-- style='font-size: 24px' removed because smaller looked better -->
{{ table.attrs.as_html }}{% else %}class="table table-bordered"{% endif %}>
{% block table.thead %}
{% if table.show_header %}
<thead>

View File

@ -12,8 +12,10 @@ urlpatterns = [
path('new/category', new.category, name='new_category'),
path('new/keyword', new.keyword, name='new_keyword'),
path('edit/recipe/<int:pk>/', 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/<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'),
path('edit/monitor/<int:pk>/', edit.MonitorUpdate.as_view(), name='edit_monitor'),

View File

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

View File

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

23
cookbook/views/lists.py Normal file
View File

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