From 4d3e8e6b53114ab8a6a6110ce103d9e22faa3437 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 1 Feb 2018 15:05:53 +0100 Subject: [PATCH] forms --- .idea/Recipies.iml | 3 + .idea/jsLibraryMappings.xml | 2 +- .idea/workspace.xml | 248 ++++++++++++------ cookbook/forms.py | 39 ++- .../migrations/0002_auto_20180201_1457.py | 23 ++ cookbook/models.py | 4 +- cookbook/templates/base.html | 11 +- cookbook/templates/index.html | 5 +- cookbook/templates/new_category.html | 11 +- cookbook/templates/new_keyword.html | 15 +- db.sqlite3 | Bin 172032 -> 172032 bytes 11 files changed, 244 insertions(+), 117 deletions(-) create mode 100644 cookbook/migrations/0002_auto_20180201_1457.py diff --git a/.idea/Recipies.iml b/.idea/Recipies.iml index 3ce50c0a..9a80dc36 100644 --- a/.idea/Recipies.iml +++ b/.idea/Recipies.iml @@ -22,6 +22,9 @@ + + + + + + + + + + + + Django + + + + + DjangoUnresolvedFilterInspection + + + + + @@ -184,6 +234,12 @@ + + + + + + @@ -201,7 +257,7 @@ - + @@ -268,9 +324,10 @@ + - + @@ -278,12 +335,11 @@ - + - @@ -296,12 +352,12 @@ - + + - - @@ -422,6 +478,7 @@ + @@ -445,13 +502,6 @@ - - - - - - - @@ -496,30 +546,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - @@ -539,6 +565,7 @@ + @@ -546,6 +573,7 @@ + @@ -564,34 +592,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -602,13 +602,89 @@ - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/cookbook/forms.py b/cookbook/forms.py index 642dd4f4..679484b1 100644 --- a/cookbook/forms.py +++ b/cookbook/forms.py @@ -1,3 +1,6 @@ +from crispy_forms.helper import FormHelper +from crispy_forms.layout import Submit +from django.utils.translation import gettext as _ from django import forms from .models import * @@ -8,13 +11,14 @@ class RecipeForm(forms.ModelForm): fields = ('name', 'category', 'keywords') labels = { - 'name': 'Name', - 'category': 'Kategorie', - 'keywords': 'Tags', + 'name': _('Name'), + 'category': _('Category'), + 'keywords': _('Keywords'), + } help_texts = { - 'keywords': 'Strg+Click für Mehrfachauswahl', + 'keywords': _('Ctrl+Click to select multiple keywords'), } def __init__(self, *args, **kwargs): @@ -30,14 +34,15 @@ class CategoryForm(forms.ModelForm): fields = ('name', 'description') labels = { - 'name': 'Name', - 'description': 'Beschreibung', + 'name': _('Name'), + 'description': _('Description'), } def __init__(self, *args, **kwargs): super(CategoryForm, self).__init__(*args, **kwargs) - self.fields['name'].widget.attrs.update({'class': 'form-control'}) - self.fields['description'].widget.attrs.update({'class': 'form-control'}) + self.helper = FormHelper() + self.helper.form_method = 'post' + self.helper.add_input(Submit('save', _('Save'), css_class='btn-primary')) class KeywordForm(forms.ModelForm): @@ -46,13 +51,23 @@ class KeywordForm(forms.ModelForm): fields = ('name', 'description') labels = { - 'name': 'Name', - 'description': 'Beschreibung', + 'name': _('Name'), + 'description': _('Description'), } def __init__(self, *args, **kwargs): super(KeywordForm, self).__init__(*args, **kwargs) - self.fields['name'].widget.attrs.update({'class': 'form-control'}) - self.fields['description'].widget.attrs.update({'class': 'form-control'}) + self.helper = FormHelper() + self.helper.form_method = 'post' + self.helper.add_input(Submit('save', _('Save'), css_class='btn-primary')) +class EditCategoryForm(forms.ModelForm): + class Meta: + model = Keyword + fields = ('name', 'description') + + labels = { + 'name': _('Name'), + 'description': _('Description'), + } diff --git a/cookbook/migrations/0002_auto_20180201_1457.py b/cookbook/migrations/0002_auto_20180201_1457.py new file mode 100644 index 00000000..3c2ce6b8 --- /dev/null +++ b/cookbook/migrations/0002_auto_20180201_1457.py @@ -0,0 +1,23 @@ +# Generated by Django 2.0.1 on 2018-02-01 13:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cookbook', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='category', + name='description', + field=models.TextField(blank=True, default=''), + ), + migrations.AlterField( + model_name='keyword', + name='description', + field=models.TextField(blank=True, default=''), + ), + ] diff --git a/cookbook/models.py b/cookbook/models.py index a8643468..e8c4814e 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -3,7 +3,7 @@ from django.db import models class Keyword(models.Model): name = models.CharField(max_length=64) - description = models.TextField(default="") + description = models.TextField(default="", blank=True) created_by = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) @@ -14,7 +14,7 @@ class Keyword(models.Model): class Category(models.Model): name = models.CharField(max_length=64) - description = models.TextField(default="") + description = models.TextField(default="", blank=True) created_by = models.IntegerField(default=0) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) diff --git a/cookbook/templates/base.html b/cookbook/templates/base.html index 11c458aa..dbd19219 100644 --- a/cookbook/templates/base.html +++ b/cookbook/templates/base.html @@ -1,4 +1,5 @@ {% load staticfiles %} +{% load i18n %} @@ -19,7 +20,7 @@