From d3a169a20dfe26d3259481d8407d90e54565eaa2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 9 Feb 2018 12:59:28 +0100 Subject: [PATCH] messages + misc --- .gitignore | 4 +- .idea/Recipies.iml | 2 +- .idea/misc.xml | 2 +- .idea/workspace.xml | 780 ------------------ .../migrations/0005_auto_20180209_1241.py | 23 + .../migrations/0006_auto_20180209_1246.py | 29 + .../migrations/0007_auto_20180209_1250.py | 29 + .../migrations/0008_auto_20180209_1251.py | 19 + cookbook/models.py | 7 +- cookbook/tables.py | 6 +- cookbook/templates/base.html | 10 + .../{tables => generic}/table_template.html | 0 cookbook/views/edit.py | 5 + cookbook/views/new.py | 5 + recipes/secret_settings.py | 25 - recipes/settings.py | 5 + 16 files changed, 136 insertions(+), 815 deletions(-) delete mode 100644 .idea/workspace.xml create mode 100644 cookbook/migrations/0005_auto_20180209_1241.py create mode 100644 cookbook/migrations/0006_auto_20180209_1246.py create mode 100644 cookbook/migrations/0007_auto_20180209_1250.py create mode 100644 cookbook/migrations/0008_auto_20180209_1251.py rename cookbook/templates/{tables => generic}/table_template.html (100%) delete mode 100644 recipes/secret_settings.py diff --git a/.gitignore b/.gitignore index d81d8e640..cd00b1df3 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,8 @@ target/ venv/ -Recipies/secret_settings\.py +secret_settings\.py *.sqlite3 + +\.idea/workspace\.xml diff --git a/.idea/Recipies.iml b/.idea/Recipies.iml index 7a827bde2..9a80dc366 100644 --- a/.idea/Recipies.iml +++ b/.idea/Recipies.iml @@ -15,7 +15,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index b3e4b45be..ce57ca017 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml deleted file mode 100644 index 587002da6..000000000 --- a/.idea/workspace.xml +++ /dev/null @@ -1,780 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1517427579474 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - keyword.__sizeof__() - Python - EXPRESSION - - - (Category.objects.filter(name=category).get('id')) - Python - EXPRESSION - - - os.path.splitext(recipe['name'])[0] - Python - EXPRESSION - - - splitext(recipe['name'])[0] - Python - EXPRESSION - - - recipe['name'] - Python - EXPRESSION - - - recipes[1]['name'] - Python - EXPRESSION - - - recipes[0]['name'] - Python - EXPRESSION - - - r.json() - Python - EXPRESSION - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/cookbook/migrations/0005_auto_20180209_1241.py b/cookbook/migrations/0005_auto_20180209_1241.py new file mode 100644 index 000000000..c9121152d --- /dev/null +++ b/cookbook/migrations/0005_auto_20180209_1241.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.1 on 2018-02-09 11:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0004_auto_20180205_2316'), + ] + + operations = [ + migrations.AlterField( + model_name='category', + name='name', + field=models.CharField(max_length=64, unique=True), + ), + migrations.AlterField( + model_name='keyword', + name='name', + field=models.CharField(max_length=64, unique=True), + ), + ] diff --git a/cookbook/migrations/0006_auto_20180209_1246.py b/cookbook/migrations/0006_auto_20180209_1246.py new file mode 100644 index 000000000..d90e9f8d2 --- /dev/null +++ b/cookbook/migrations/0006_auto_20180209_1246.py @@ -0,0 +1,29 @@ +# Generated by Django 2.0.1 on 2018-02-09 11:46 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0005_auto_20180209_1241'), + ] + + operations = [ + migrations.AlterField( + model_name='recipe', + name='category', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='cookbook.Category'), + ), + migrations.AlterField( + model_name='recipe', + name='link', + field=models.CharField(blank=True, default='', max_length=512), + ), + migrations.AlterField( + model_name='recipe', + name='path', + field=models.CharField(blank=True, default='', max_length=512), + ), + ] diff --git a/cookbook/migrations/0007_auto_20180209_1250.py b/cookbook/migrations/0007_auto_20180209_1250.py new file mode 100644 index 000000000..398e8d7a2 --- /dev/null +++ b/cookbook/migrations/0007_auto_20180209_1250.py @@ -0,0 +1,29 @@ +# Generated by Django 2.0.1 on 2018-02-09 11:50 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0006_auto_20180209_1246'), + ] + + operations = [ + migrations.AlterField( + model_name='recipe', + name='category', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.SET_DEFAULT, to='cookbook.Category'), + ), + migrations.AlterField( + model_name='recipe', + name='link', + field=models.CharField(default='', max_length=512), + ), + migrations.AlterField( + model_name='recipe', + name='path', + field=models.CharField(default='', max_length=512), + ), + ] diff --git a/cookbook/migrations/0008_auto_20180209_1251.py b/cookbook/migrations/0008_auto_20180209_1251.py new file mode 100644 index 000000000..aec4e8175 --- /dev/null +++ b/cookbook/migrations/0008_auto_20180209_1251.py @@ -0,0 +1,19 @@ +# Generated by Django 2.0.1 on 2018-02-09 11:51 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0007_auto_20180209_1250'), + ] + + operations = [ + migrations.AlterField( + model_name='recipe', + name='category', + field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.SET_DEFAULT, to='cookbook.Category'), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index 89cb12205..6edfd11f6 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -2,7 +2,7 @@ from django.db import models class Keyword(models.Model): - name = models.CharField(max_length=64) + name = models.CharField(max_length=64, unique=True) description = models.TextField(default="", blank=True) created_by = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) @@ -13,8 +13,7 @@ class Keyword(models.Model): class Category(models.Model): - # TODO unique name or model with id - name = models.CharField(max_length=64) + name = models.CharField(max_length=64, unique=True) description = models.TextField(default="", blank=True) created_by = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) @@ -28,7 +27,7 @@ class Recipe(models.Model): name = models.CharField(max_length=64) path = models.CharField(max_length=512, default="") link = models.CharField(max_length=512, default="") - category = models.ForeignKey(Category, on_delete=models.CASCADE) + category = models.ForeignKey(Category, on_delete=models.SET_DEFAULT, default=0) 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 e12ab4178..fc5ecaf25 100644 --- a/cookbook/tables.py +++ b/cookbook/tables.py @@ -10,7 +10,7 @@ class RecipeTable(tables.Table): class Meta: model = Recipe - template_name = 'tables/table_template.html' + template_name = 'generic/table_template.html' fields = ('id', 'name', 'category', 'all_tags') @@ -19,7 +19,7 @@ class CategoryTable(tables.Table): class Meta: model = Category - template_name = 'tables/table_template.html' + template_name = 'generic/table_template.html' fields = ('id', 'name') @@ -28,5 +28,5 @@ class KeywordTable(tables.Table): class Meta: model = Keyword - template_name = 'tables/table_template.html' + template_name = 'generic/table_template.html' fields = ('id', 'name') diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 4197bdba7..d7b17b28c 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -73,6 +73,16 @@
+ + {% for message in messages %} + + {% endfor %} + {% block content %} {% endblock %}
diff --git a/cookbook/templates/tables/table_template.html b/cookbook/templates/generic/table_template.html similarity index 100% rename from cookbook/templates/tables/table_template.html rename to cookbook/templates/generic/table_template.html diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index eaac9f306..1367b387e 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -1,6 +1,8 @@ from django.contrib.auth.decorators import login_required +from django.contrib import messages from django.shortcuts import redirect, render from django.urls import reverse_lazy +from django.utils.translation import gettext as _ from cookbook.forms import EditRecipeForm from cookbook.models import Recipe, Category @@ -18,7 +20,10 @@ def recipe(request, recipe_id): 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) diff --git a/cookbook/views/new.py b/cookbook/views/new.py index 1ee92c99b..7784a8427 100644 --- a/cookbook/views/new.py +++ b/cookbook/views/new.py @@ -1,6 +1,8 @@ +from django.contrib import messages from django.contrib.auth.decorators import login_required from django.shortcuts import redirect, render from django_tables2 import RequestConfig +from django.utils.translation import gettext as _ from cookbook.forms import CategoryForm, KeywordForm, RecipeForm from cookbook.models import Category, Keyword @@ -16,6 +18,7 @@ def recipe(request): recipe_obj.created_by = request.user.id recipe_obj.save() form.save_m2m() + messages.add_message(request, messages.SUCCESS, _('Recipe saved!')) return redirect('index') else: form = RecipeForm() @@ -31,6 +34,7 @@ def category(request): category_obj = form.save(commit=False) category_obj.created_by = request.user.id category_obj.save() + messages.add_message(request, messages.SUCCESS, _('Category saved!')) return redirect('new_category') else: form = CategoryForm() @@ -49,6 +53,7 @@ def keyword(request): keyword_obj = form.save(commit=False) keyword_obj.created_by = request.user.id keyword_obj.save() + messages.add_message(request, messages.SUCCESS, _('Keyword saved!')) return redirect('new_keyword') else: form = KeywordForm() diff --git a/recipes/secret_settings.py b/recipes/secret_settings.py deleted file mode 100644 index 4366fef44..000000000 --- a/recipes/secret_settings.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -Setting file for secret settings -imported by settings.py -""" - -import os - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -# defined in secret settings to be able to use local sqlite db's -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = '3*2&bz92brcnq^3c9b=_g%sc3b(i1j#rs*%1k67c8=cy2397j3' - -# Database -# https://docs.djangoproject.com/en/2.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - -DROPBOX_API_KEY = "DhDcF7_Ik7EAAAAAAAA9Ez24v8-Tmf37UZcFqrLxZ8wTthIwc6Ko_oWU5WvxnSLM" diff --git a/recipes/settings.py b/recipes/settings.py index 9be10c501..9b96e84d2 100644 --- a/recipes/settings.py +++ b/recipes/settings.py @@ -9,6 +9,7 @@ https://docs.djangoproject.com/en/2.0/topics/settings/ For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ """ +from django.contrib import messages from recipes.secret_settings import * @@ -25,6 +26,10 @@ LOGOUT_REDIRECT_URL = "index" CRISPY_TEMPLATE_PACK = 'bootstrap4' +MESSAGE_TAGS = { + messages.ERROR: 'danger' +} + # Application definition INSTALLED_APPS = [