more generic views

This commit is contained in:
vabene1111 2018-05-02 22:28:02 +02:00
parent b3a45d8069
commit 399f581d86
7 changed files with 70 additions and 13 deletions

View File

@ -13,6 +13,7 @@ class RecipeTable(tables.Table):
attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}})
all_tags = tables.Column(
attrs={'td': {'class': 'd-none d-lg-table-cell'}, 'th': {'class': 'd-none d-lg-table-cell'}})
delete = tables.TemplateColumn("<a href='{% url 'delete_recipe' record.id %}' >" + _('Delete') + "</a>") # TODO remove and put into edit page
class Meta:
model = Recipe
@ -22,6 +23,7 @@ class RecipeTable(tables.Table):
class CategoryTable(tables.Table):
id = tables.LinkColumn('edit_category', args=[A('id')])
delete = tables.TemplateColumn("<a href='{% url 'delete_category' record.id %}' >" + _('Delete') + "</a>")
class Meta:
model = Category
@ -31,6 +33,7 @@ class CategoryTable(tables.Table):
class KeywordTable(tables.Table):
id = tables.LinkColumn('edit_keyword', args=[A('id')])
delete = tables.TemplateColumn("<a href='{% url 'delete_keyword' record.id %}' >" + _('Delete') + "</a>")
class Meta:
model = Keyword

View File

@ -41,7 +41,7 @@
<div class="collapse navbar-collapse" id="navbarText">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="{% url 'index' %}">{% trans 'Cookbook' %}<span
<a class="nav-link" href="{% url 'index' %}"><i class="fas fa-book"></i> {% trans 'Cookbook' %}<span
class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown">
@ -55,6 +55,16 @@
<a class="dropdown-item" href="{% url 'new_keyword' %}"><i class="fas fa-tags"></i> {% trans 'Keyword' %}</a>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{% 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>
</div>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">

View File

@ -2,17 +2,17 @@
{% load crispy_forms_tags %}
{% load i18n %}
{% block title %}{% trans 'Delete' %}{% endblock %}
{% block title %}{% trans 'Delete' %} - {{ title }}{% endblock %}
{% block content %}
<h3>
{% trans 'Delete' %}
<small class="text-muted">{% trans 'Delete this Object' %}</small>
</h3>
<h3>{% trans 'Delete' %} {{ title }}</h3>
<form action="." method="post">
{% csrf_token %}
<div class="alert alert-danger" role="alert">
{% blocktrans %}Are you sure you want to delete the {{ title }}: <b>{{ object }}</b> {% endblocktrans %}
</div>
{{ form|crispy }}
<input type="submit" value="Submit" class="btn btn-success">
</form>

View File

@ -2,14 +2,11 @@
{% load crispy_forms_tags %}
{% load i18n %}
{% block title %}{% trans 'Edit' %}{% endblock %}
{% block title %}{% trans 'Edit' %} - {{ title }}{% endblock %}
{% block content %}
<h3>
{% trans 'Edit' %}
<small class="text-muted">{% trans 'Edit this Object' %}</small>
</h3>
<h3>{% trans 'Edit' %} {{ title }}</h3>
<form action="." method="post">
{% csrf_token %}

View File

@ -12,7 +12,7 @@
{% if filter %}
<div class="card">
<div class="card-header">
{% trans "Search" %}
<i class="fas fa-search"></i> {% trans "Search" %}
</div>
<div class="card-body">
<form action="" method="get">
@ -81,7 +81,7 @@
var link = $('#a_recipe_open');
link.hide();
url = "{% url 'api_get_file_link' recipe_id=12345 %}".replace(/12345/, id);
var url = "{% url 'api_get_file_link' recipe_id=12345 %}".replace(/12345/, id);
link.text("{% trans 'Open Recipe' %}");
$('#modal_recipe').modal('show');

View File

@ -18,6 +18,7 @@ urlpatterns = [
path('edit/category/<int:pk>/', edit.CategoryUpdate.as_view(), name='edit_category'),
path('edit/monitor/<int:pk>/', edit.MonitorUpdate.as_view(), name='edit_monitor'),
path('delete/recipe/<int:pk>/', edit.RecipeDelete.as_view(), name='delete_recipe'),
path('delete/keyword/<int:pk>/', edit.KeywordDelete.as_view(), name='delete_keyword'),
path('delete/category/<int:pk>/', edit.CategoryDelete.as_view(), name='delete_category'),
path('delete/monitor/<int:pk>/', edit.MonitorDelete.as_view(), name='delete_monitor'),

View File

@ -15,18 +15,33 @@ class MonitorUpdate(LoginRequiredMixin, UpdateView):
model = Monitor
fields = ['path']
def get_context_data(self, **kwargs):
context = super(MonitorUpdate, self).get_context_data(**kwargs)
context['title'] = _("Monitor")
return context
class CategoryUpdate(LoginRequiredMixin, UpdateView):
template_name = "generic\edit_template.html"
model = Category
fields = ['name', 'description']
def get_context_data(self, **kwargs):
context = super(CategoryUpdate, self).get_context_data(**kwargs)
context['title'] = _("Category")
return context
class KeywordUpdate(LoginRequiredMixin, UpdateView):
template_name = "generic\edit_template.html"
model = Keyword
fields = ['name', 'description']
def get_context_data(self, **kwargs):
context = super(KeywordUpdate, self).get_context_data(**kwargs)
context['title'] = _("Keyword")
return context
@login_required
def recipe(request, recipe_id):
@ -51,25 +66,56 @@ def recipe(request, recipe_id):
# Generic Delete views
class RecipeDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Recipe
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super(RecipeDelete, self).get_context_data(**kwargs)
context['title'] = _("Recipe")
return context
class MonitorDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Monitor
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super(MonitorDelete, self).get_context_data(**kwargs)
context['title'] = _("Monitor")
return context
class CategoryDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Category
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super(CategoryDelete, self).get_context_data(**kwargs)
context['title'] = _("Category")
return context
class KeywordDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = Keyword
success_url = reverse_lazy('index')
def get_context_data(self, **kwargs):
context = super(KeywordDelete, self).get_context_data(**kwargs)
context['title'] = _("Keyword")
return context
class NewRecipeDelete(LoginRequiredMixin, DeleteView):
template_name = "generic\delete_template.html"
model = NewRecipe
success_url = reverse_lazy('batch_import')
def get_context_data(self, **kwargs):
context = super(NewRecipeDelete, self).get_context_data(**kwargs)
context['title'] = _("Import Recipe")
return context