From 59641e1af6d7b9d9d62c142fb83419e90c71e6b3 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Mon, 5 Feb 2018 23:59:31 +0100 Subject: [PATCH] more nice things --- .idea/workspace.xml | 286 +++++++++--------- cookbook/forms.py | 11 + cookbook/models.py | 1 + cookbook/templates/base.html | 26 +- cookbook/templates/batch/category.html | 19 ++ .../templates/{storage => batch}/import.html | 0 cookbook/templates/tables/table_template.html | 4 +- cookbook/urls.py | 16 +- cookbook/views/api.py | 2 +- cookbook/views/views.py | 19 +- 10 files changed, 220 insertions(+), 164 deletions(-) create mode 100644 cookbook/templates/batch/category.html rename cookbook/templates/{storage => batch}/import.html (100%) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index a7623e06..f0f3626a 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,14 +2,16 @@ + + - - - + + + + - - + - - - - - - - - - - - - + + - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + @@ -121,8 +108,8 @@ - - + + @@ -159,13 +146,11 @@ @@ -272,7 +260,7 @@ - + @@ -305,7 +293,7 @@ - + @@ -381,7 +369,7 @@ - + @@ -411,16 +399,21 @@ - + + (Category.objects.filter(name=category).get('id')) + Python + EXPRESSION + os.path.splitext(recipe['name'])[0] Python @@ -454,13 +447,6 @@ - - - - - - - @@ -479,7 +465,9 @@ - + + + @@ -602,14 +590,6 @@ - - - - - - - - @@ -628,22 +608,6 @@ - - - - - - - - - - - - - - - - @@ -660,16 +624,6 @@ - - - - - - - - - - @@ -699,14 +653,6 @@ - - - - - - - - @@ -715,10 +661,39 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -730,49 +705,70 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - + + - + - - + + - + diff --git a/cookbook/forms.py b/cookbook/forms.py index 76637658..d4c8d23f 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -85,3 +85,14 @@ class ImportForm(forms.Form): self.helper.form_method = 'post' self.helper.add_input(Submit('import', _('Import'), css_class='btn-primary')) + +class BatchCategoryForm(forms.Form): + search = forms.CharField(label=_('Search String')) + category = forms.ModelChoiceField(queryset=Category.objects.all().order_by('id')) + + def __init__(self, *args, **kwargs): + super(BatchCategoryForm, self).__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_method = 'post' + self.helper.add_input(Submit('import', _('Import'), css_class='btn-primary')) + diff --git a/cookbook/models.py b/cookbook/models.py index 7e03414f..89cb1220 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -13,6 +13,7 @@ class Keyword(models.Model): class Category(models.Model): + # TODO unique name or model with id name = models.CharField(max_length=64) description = models.TextField(default="", blank=True) created_by = models.IntegerField(default=0) diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 748dbb07..05945ec1 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -31,14 +31,26 @@ {% trans 'Cookbook' %}(current) - - - diff --git a/cookbook/templates/batch/category.html b/cookbook/templates/batch/category.html new file mode 100644 index 00000000..10c6f3ef --- /dev/null +++ b/cookbook/templates/batch/category.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} +{% load crispy_forms_tags %} +{% load i18n %} +{% load django_tables2 %} + +{% block title %}{% trans 'Batch edit Category' %}{% endblock %} + +{% block content %} + +

+ {% trans 'Batch edit Category' %} + {% trans 'Add the specified category to all recipes containing a word' %} +

+ +
{% csrf_token %} + {% crispy form %} +
+ +{% endblock %} \ No newline at end of file diff --git a/cookbook/templates/storage/import.html b/cookbook/templates/batch/import.html similarity index 100% rename from cookbook/templates/storage/import.html rename to cookbook/templates/batch/import.html diff --git a/cookbook/templates/tables/table_template.html b/cookbook/templates/tables/table_template.html index 3ba9992d..773e8b28 100644 --- a/cookbook/templates/tables/table_template.html +++ b/cookbook/templates/tables/table_template.html @@ -2,10 +2,10 @@ {% load i18n %} {% block table-wrapper %}
-
+
{% block table %} + {{ table.attrs.as_html }}{% else %}class="table table-bordered table-lg"{% endif %}> {% block table.thead %} {% if table.show_header %} diff --git a/cookbook/urls.py b/cookbook/urls.py index 682fb662..7bb68a79 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -5,14 +5,16 @@ from cookbook.views import api urlpatterns = [ path('', views.index, name='index'), - path('new_recipe', views.new_recipe, name='new_recipe'), - path('new_category', views.new_category, name='new_category'), - path('new_keyword', views.new_keyword, name='new_keyword'), - path('edit_recipe//', views.edit_recipe, name='edit_recipe'), - path('edit_category//', views.edit_category, name='edit_category'), - path('edit_keyword//', views.new_keyword, name='edit_keyword'), + path('new/recipe', views.new_recipe, name='new_recipe'), + path('new/category', views.new_category, name='new_category'), + path('new/keyword', views.new_keyword, name='new_keyword'), - path('storage/import_recipes', views.import_recipes, name='import_recipes'), + path('edit/recipe//', views.edit_recipe, name='edit_recipe'), + path('edit/category//', views.edit_category, name='edit_category'), + path('edit/keyword//', views.new_keyword, name='edit_keyword'), + + path('batch/import', views.batch_import, name='batch_import'), + path('batch/category', views.batch_category, name='batch_category'), path('api/get_file_link//', api.get_file_link, name='get_file_link'), ] diff --git a/cookbook/views/api.py b/cookbook/views/api.py index 30116c45..e5fb598a 100644 --- a/cookbook/views/api.py +++ b/cookbook/views/api.py @@ -7,7 +7,7 @@ from cookbook.helper import dropbox def get_file_link(request, recipe_id): recipe = Recipe.objects.get(id=recipe_id) if recipe.link == "": - response = dropbox.get_share_link(recipe.path) + response = dropbox.get_share_link(recipe.path) # TODO response validation recipe.link = response['url'] recipe.save() diff --git a/cookbook/views/views.py b/cookbook/views/views.py index 83ea7c58..25b0faeb 100644 --- a/cookbook/views/views.py +++ b/cookbook/views/views.py @@ -21,7 +21,7 @@ def index(request): @login_required -def import_recipes(request): +def batch_import(request): if request.method == "POST": form = ImportForm(request.POST) if form.is_valid(): @@ -30,7 +30,22 @@ def import_recipes(request): else: form = ImportForm() - return render(request, 'storage/import.html', {'form': form}) + return render(request, 'batch/import.html', {'form': form}) + + +@login_required +def batch_category(request): + if request.method == "POST": + form = BatchCategoryForm(request.POST) + if form.is_valid(): + word = form.cleaned_data['search'] + category = form.cleaned_data['category'] + Recipe.objects.filter(name__contains=word).update(category=(Category.objects.get(name=category)).id) + return redirect('index') + else: + form = BatchCategoryForm() + + return render(request, 'batch/category.html', {'form': form}) @login_required