class filter tag
This commit is contained in:
parent
9b2d2bea4d
commit
8107e46b60
@ -1,13 +0,0 @@
|
||||
[
|
||||
{
|
||||
"model": "cookbook.category",
|
||||
"pk": 1,
|
||||
"fields": {
|
||||
"name": "-",
|
||||
"description": "Default Category",
|
||||
"created_by": 0,
|
||||
"created_at": "2018-05-06T21:21:08.860Z",
|
||||
"updated_at": "2018-05-06T21:21:08.860Z"
|
||||
}
|
||||
}
|
||||
]
|
@ -27,7 +27,7 @@ class Recipe(models.Model):
|
||||
name = models.CharField(max_length=128)
|
||||
path = models.CharField(max_length=512, default="")
|
||||
link = models.CharField(max_length=512, default="")
|
||||
category = models.ForeignKey(Category, on_delete=models.SET_DEFAULT, default=0)
|
||||
category = models.ForeignKey(Category, blank=True, on_delete=models.PROTECT, null=True)
|
||||
keywords = models.ManyToManyField(Keyword, blank=True)
|
||||
created_by = models.IntegerField(default=0)
|
||||
created_at = models.DateTimeField(auto_now_add=True)
|
||||
|
@ -60,7 +60,7 @@ class MonitoredPathTable(tables.Table):
|
||||
fields = ('id', 'path', 'last_checked')
|
||||
|
||||
|
||||
class ImportTable(tables.Table):
|
||||
class RecipeImportTable(tables.Table):
|
||||
id = tables.LinkColumn('new_recipe_import', args=[A('id')])
|
||||
delete = tables.TemplateColumn("<a href='{% url 'delete_import' record.id %}' >" + _('Delete') + "</a>")
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
</h3>
|
||||
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
|
||||
|
@ -15,10 +15,9 @@
|
||||
<a href="{% url 'api_dropbox_sync' %}" class="btn btn-success">{% trans 'Sync Now!' %}</a>
|
||||
<br/>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{% crispy form %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Submit" class="btn btn-success">
|
||||
</form>
|
||||
<br/><br/>
|
||||
|
||||
{% render_table monitored_paths %}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
{% load crispy_forms_tags %}
|
||||
{% load i18n %}
|
||||
{% load django_tables2 %}
|
||||
{% load class_tag %}
|
||||
|
||||
{% block title %}{% trans 'List' %} - {{ title }}{% endblock %}
|
||||
|
||||
@ -10,6 +11,12 @@
|
||||
<h3>{{ title }} {% trans 'List' %}</h3>
|
||||
<br/>
|
||||
|
||||
{% if table.Meta.model|get_class == 'RecipeImport' %}
|
||||
<a href="{% url 'batch_import_all' %}" class="btn btn-warning">{% trans 'Import all' %}</a>
|
||||
<br/>
|
||||
<br/>
|
||||
{% endif %}
|
||||
|
||||
{% if table %}
|
||||
{% render_table table %}
|
||||
{% endif %}
|
||||
|
8
cookbook/templatetags/class_tag.py
Normal file
8
cookbook/templatetags/class_tag.py
Normal file
@ -0,0 +1,8 @@
|
||||
from django import template
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter(name='get_class')
|
||||
def get_class(value):
|
||||
return value.__class__.__name__
|
@ -15,8 +15,8 @@ urlpatterns = [
|
||||
|
||||
path('list/keyword', lists.keyword, name='list_keyword'),
|
||||
path('list/category', lists.category, name='list_category'),
|
||||
path('list/import_log', lists.import_log, name='list_import_log'),
|
||||
path('list/import', lists.new_recipe, name='list_import'),
|
||||
path('list/import_log', lists.sync_log, name='list_import_log'),
|
||||
path('list/import', lists.recipe_import, name='list_import'),
|
||||
|
||||
path('edit/recipe/<int:pk>/', edit.RecipeUpdate.as_view(), name='edit_recipe'),
|
||||
path('edit/keyword/<int:pk>/', edit.KeywordUpdate.as_view(), name='edit_keyword'),
|
||||
|
@ -24,7 +24,7 @@ def dropbox_sync(request):
|
||||
ret = dropbox.sync_all()
|
||||
if ret:
|
||||
messages.add_message(request, messages.SUCCESS, _('Sync successful!'))
|
||||
return redirect('batch_import')
|
||||
return redirect('list_import')
|
||||
else:
|
||||
messages.add_message(request, messages.ERROR, _('Error synchronizing with Storage'))
|
||||
return redirect('batch_monitor')
|
||||
return redirect('list_import')
|
||||
|
@ -18,7 +18,7 @@ def batch_monitor(request):
|
||||
new_path.path = form.cleaned_data['path']
|
||||
new_path.last_checked = datetime.now()
|
||||
new_path.save()
|
||||
return redirect('batch_import')
|
||||
return redirect('batch_monitor')
|
||||
else:
|
||||
form = MonitorForm()
|
||||
|
||||
@ -33,11 +33,11 @@ def batch_import_all(request):
|
||||
if request.method == "POST":
|
||||
imports = RecipeImport.objects.all()
|
||||
for new_recipe in imports:
|
||||
recipe = Recipe(name=new_recipe.name, path=new_recipe.path, category=(Category.objects.get(id=0)))
|
||||
recipe = Recipe(name=new_recipe.name, path=new_recipe.path)
|
||||
recipe.save()
|
||||
new_recipe.delete()
|
||||
|
||||
return redirect('batch_import')
|
||||
return redirect('list_import')
|
||||
|
||||
|
||||
@login_required
|
||||
|
@ -112,7 +112,7 @@ class ImportDelete(LoginRequiredMixin, DeleteView):
|
||||
class MonitorDelete(LoginRequiredMixin, DeleteView):
|
||||
template_name = "generic\delete_template.html"
|
||||
model = Sync
|
||||
success_url = reverse_lazy('index')
|
||||
success_url = reverse_lazy('batch_monitor')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(MonitorDelete, self).get_context_data(**kwargs)
|
||||
@ -139,4 +139,4 @@ class KeywordDelete(LoginRequiredMixin, DeleteView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(KeywordDelete, self).get_context_data(**kwargs)
|
||||
context['title'] = _("Keyword")
|
||||
return context
|
||||
return context
|
||||
|
@ -5,7 +5,7 @@ from django_tables2 import RequestConfig
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from cookbook.models import Category, Keyword, SyncLog, RecipeImport
|
||||
from cookbook.tables import CategoryTable, KeywordTable, ImportLogTable, ImportTable
|
||||
from cookbook.tables import CategoryTable, KeywordTable, ImportLogTable, RecipeImportTable
|
||||
|
||||
|
||||
@login_required
|
||||
@ -25,7 +25,7 @@ def keyword(request):
|
||||
|
||||
|
||||
@login_required
|
||||
def import_log(request):
|
||||
def sync_log(request):
|
||||
table = ImportLogTable(SyncLog.objects.all().order_by(Lower('created_at').desc()))
|
||||
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
||||
|
||||
@ -33,8 +33,8 @@ def import_log(request):
|
||||
|
||||
|
||||
@login_required
|
||||
def new_recipe(request):
|
||||
table = ImportTable(RecipeImport.objects.all())
|
||||
def recipe_import(request):
|
||||
table = RecipeImportTable(RecipeImport.objects.all())
|
||||
RequestConfig(request, paginate={'per_page': 25}).configure(table)
|
||||
|
||||
return render(request, 'generic/list_template.html', {'title': _("Import"), 'table': table})
|
||||
|
Loading…
Reference in New Issue
Block a user