diff --git a/cookbook/fixtures/default_category.json b/cookbook/fixtures/default_category.json deleted file mode 100644 index 69cf367b..00000000 --- a/cookbook/fixtures/default_category.json +++ /dev/null @@ -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" - } - } -] \ No newline at end of file diff --git a/cookbook/models.py b/cookbook/models.py index 7f369fcf..f02a2494 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -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) diff --git a/cookbook/tables.py b/cookbook/tables.py index 03cf454f..82608c2a 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -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("" + _('Delete') + "") diff --git a/cookbook/templates/batch/edit.html b/cookbook/templates/batch/edit.html index 61c61608..348a4e06 100644 --- a/cookbook/templates/batch/edit.html +++ b/cookbook/templates/batch/edit.html @@ -13,7 +13,7 @@
{% csrf_token %} - {% crispy form %} + {{ form|crispy }}
diff --git a/cookbook/templates/batch/monitor.html b/cookbook/templates/batch/monitor.html index c17b2803..06cfc8f0 100644 --- a/cookbook/templates/batch/monitor.html +++ b/cookbook/templates/batch/monitor.html @@ -15,10 +15,9 @@ {% trans 'Sync Now!' %}
{% csrf_token %} - {% crispy form %} + {{ form|crispy }}
-

{% render_table monitored_paths %} diff --git a/cookbook/templates/generic/list_template.html b/cookbook/templates/generic/list_template.html index 8c8b7071..d65ab1e2 100644 --- a/cookbook/templates/generic/list_template.html +++ b/cookbook/templates/generic/list_template.html @@ -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 @@

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


+ {% if table.Meta.model|get_class == 'RecipeImport' %} + {% trans 'Import all' %} +
+
+ {% endif %} + {% if table %} {% render_table table %} {% endif %} diff --git a/cookbook/templatetags/class_tag.py b/cookbook/templatetags/class_tag.py new file mode 100644 index 00000000..1cc6e30f --- /dev/null +++ b/cookbook/templatetags/class_tag.py @@ -0,0 +1,8 @@ +from django import template + +register = template.Library() + + +@register.filter(name='get_class') +def get_class(value): + return value.__class__.__name__ diff --git a/cookbook/urls.py b/cookbook/urls.py index bf114465..4b0bbbe9 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -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//', edit.RecipeUpdate.as_view(), name='edit_recipe'), path('edit/keyword//', edit.KeywordUpdate.as_view(), name='edit_keyword'), diff --git a/cookbook/views/api.py b/cookbook/views/api.py index d6a7a971..e0ef0616 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -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') diff --git a/cookbook/views/batch.py b/cookbook/views/batch.py index 67fe984e..48df527c 100644 --- a/cookbook/views/batch.py +++ b/cookbook/views/batch.py @@ -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 diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 6daa0a8b..6616488c 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -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 \ No newline at end of file + return context diff --git a/cookbook/views/lists.py b/cookbook/views/lists.py index 90995d5a..3a435e25 100644 --- a/cookbook/views/lists.py +++ b/cookbook/views/lists.py @@ -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})