]> gitweb.fperrin.net Git - djsite.git/commitdiff
Use django-tagging for tags
authorFrédéric Perrin <frederic.perrin@resel.fr>
Mon, 31 Oct 2016 01:21:54 +0000 (01:21 +0000)
committerFrédéric Perrin <frederic.perrin@resel.fr>
Mon, 31 Oct 2016 01:22:58 +0000 (01:22 +0000)
14 files changed:
djsite/settings.py
quotes/admin.py
quotes/localmodels.py
quotes/migrations/0001_initial.py
quotes/migrations/0002_auto_20161031_0033.py [moved from quotes/migrations/0002_context_author.py with 55% similarity]
quotes/migrations/0003_auto_20161009_2254.py [deleted file]
quotes/migrations/0003_auto_20161031_0034.py [new file with mode: 0644]
quotes/migrations/0004_auto_20161009_2255.py [deleted file]
quotes/migrations/0004_auto_20161031_0036.py [new file with mode: 0644]
quotes/migrations/0005_auto_20161031_0052.py [new file with mode: 0644]
quotes/migrations/0006_auto_20161031_0055.py [new file with mode: 0644]
quotes/migrations/0007_auto_20161031_0056.py [new file with mode: 0644]
quotes/models.py
quotes/views.py

index f8a06058a40bfdae467122d72b49b110c328ddc6..4c0385e62b73941ecf430c1f0af922cef387e3b8 100644 (file)
@@ -25,8 +25,7 @@ SECRET_KEY = 's665xl1i*aa@k@-!3xnga&qf47^hl*g9z7z7r51e_3*5vqi7=m'
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = True
 
-ALLOWED_HOSTS = []
-
+ALLOWED_HOSTS = ['quotes.fperrin.net']
 
 # Application definition
 
@@ -37,6 +36,7 @@ INSTALLED_APPS = (
     'django.contrib.sessions',
     'django.contrib.messages',
     'django.contrib.staticfiles',
+    'tagging',
     'tinymce',
     'quotes',
 )
@@ -97,6 +97,7 @@ USE_L10N = True
 
 USE_TZ = True
 
+USE_X_FORWARDED_HOST = True
 
 # Static files (CSS, JavaScript, Images)
 # https://docs.djangoproject.com/en/1.8/howto/static-files/
index 7e8f1adfb3a778ba4174032b6b06b8215e300ecd..9617bc779497b484eb9f30ec3e4d6ce10d3705d6 100644 (file)
@@ -1,8 +1,16 @@
+from django import forms
 from django.contrib import admin
 
 # Register your models here.
-from .models import Tag, Author, Work, Quote
-admin.site.register(Tag)
-admin.site.register(Author)
+from .models import Author, Work, Quote
+#admin.site.register(Tag)
 admin.site.register(Work)
 admin.site.register(Quote)
+
+class AuthorForm(forms.ModelForm):
+#    taggit = TagField(required=False, widget=LabelWidget)
+    pass
+
+class AuthorAdmin(admin.ModelAdmin):
+    form = AuthorForm
+admin.site.register(Author, AuthorAdmin)
index afe874a6c8c8938f2412aa3873e5fc3250240613..0cbb37603afd06805272de4b282a8a83092f9214 100644 (file)
@@ -10,3 +10,10 @@ class HTMLField(tinymce.models.HTMLField):
         safe_value = valid_html(value)
         setattr(model_instance, self.attname, safe_value)
         return safe_value
+
+import tagging.fields
+
+class TagField(tagging.fields.TagField):
+    def __init__(self, *args, **kwargs):
+        kwargs.setdefault('help_text', 'Space-separated list of tags')
+        return tagging.fields.TagField.__init__(self, *args, **kwargs)
index c7f97c4a58b7a20b0ae950315b5a987e161ac993..927cce952bf1bbc33259c6d499cb9e36288cfeff 100644 (file)
@@ -1,11 +1,16 @@
 # -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:22
 from __future__ import unicode_literals
 
 from django.db import migrations, models
+import django.db.models.deletion
+import quotes.localmodels
 
 
 class Migration(migrations.Migration):
 
+    initial = True
+
     dependencies = [
     ]
 
@@ -13,54 +18,55 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name='Author',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                 ('name', models.CharField(help_text=b'Name of the author', max_length=100)),
-                ('notes', models.TextField(help_text=b'Notes about the author; may be left blank. Will                               not be HTML-escaped.', blank=True)),
-                ('pvt_notes', models.TextField(help_text=b'Notes about the author; not displayed on                                   the public interface', blank=True)),
-                ('birth_date', models.DateField(help_text=b'Date of birth', null=True, blank=True)),
-                ('death_date', models.DateField(help_text=b'Date of death (leave blank                                   if still alive!)', null=True, blank=True)),
+                ('notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the author; may be left blank. Will                       not be HTML-escaped.')),
+                ('pvt_notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the author; not displayed on                           the public interface')),
+                ('birth_date', models.DateField(blank=True, help_text=b'Date of birth', null=True)),
+                ('death_date', models.DateField(blank=True, help_text=b'Date of death (leave blank                                   if still alive!)', null=True)),
             ],
         ),
         migrations.CreateModel(
-            name='Context',
+            name='Quote',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('name', models.CharField(help_text=b'Name of the context for the quote                             (title of the work or speech it appears in)', max_length=100)),
-                ('date', models.DateField(help_text=b'Date of the quote', null=True, blank=True)),
-                ('notes', models.TextField(help_text=b'Notes about the work; may be left blank. Will                               not be HTML-escaped. XXX: offer a WYSIWYG editor', blank=True)),
-                ('pvt_notes', models.TextField(help_text=b'Notes about the work; not displayed on                                   the public interface', blank=True)),
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('text', quotes.localmodels.HTMLField()),
+                ('notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the quote; may be left blank. Will                       not be HTML-escaped. XXX: offer a WYSIWYG editor')),
+                ('pvt_notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the quote; not displayed on                           the public interface')),
             ],
         ),
         migrations.CreateModel(
-            name='Quote',
+            name='Tag',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('text', models.TextField()),
-                ('notes', models.TextField(help_text=b'Notes about the quote; may be left blank. Will                               not be HTML-escaped. XXX: offer a WYSIWYG editor', blank=True)),
-                ('pvt_notes', models.TextField(help_text=b'Notes about the quote; not displayed on                                   the public interface', blank=True)),
-                ('context', models.ForeignKey(to='quotes.Context')),
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('tag', models.CharField(max_length=100)),
             ],
         ),
         migrations.CreateModel(
-            name='Tag',
+            name='Work',
             fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('tag', models.CharField(max_length=100)),
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(help_text=b'Name of the context for the quote                             (title of the work or speech it appears in)', max_length=100)),
+                ('date', models.DateField(blank=True, help_text=b'Date of the quote', null=True)),
+                ('notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the work; may be left blank. Will                       not be HTML-escaped. XXX: offer a WYSIWYG editor')),
+                ('pvt_notes', quotes.localmodels.HTMLField(blank=True, help_text=b'Notes about the work; not displayed on                           the public interface')),
+                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='quotes.Author')),
+                ('tags', models.ManyToManyField(blank=True, to='quotes.Tag')),
             ],
         ),
         migrations.AddField(
             model_name='quote',
             name='tags',
-            field=models.ManyToManyField(to='quotes.Tag', blank=True),
+            field=models.ManyToManyField(blank=True, to='quotes.Tag'),
         ),
         migrations.AddField(
-            model_name='context',
-            name='tags',
-            field=models.ManyToManyField(to='quotes.Tag', blank=True),
+            model_name='quote',
+            name='work',
+            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='quotes.Work'),
         ),
         migrations.AddField(
             model_name='author',
             name='tags',
-            field=models.ManyToManyField(to='quotes.Tag', blank=True),
+            field=models.ManyToManyField(blank=True, to='quotes.Tag'),
         ),
     ]
similarity index 55%
rename from quotes/migrations/0002_context_author.py
rename to quotes/migrations/0002_auto_20161031_0033.py
index 79ca5e31a0316e0d4186af9eac4bd3280c53dce8..f83d287e79f7cb1050f30f4ab91e0241dd11d9dd 100644 (file)
@@ -1,4 +1,5 @@
 # -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:33
 from __future__ import unicode_literals
 
 from django.db import migrations, models
@@ -11,10 +12,9 @@ class Migration(migrations.Migration):
     ]
 
     operations = [
-        migrations.AddField(
-            model_name='context',
-            name='author',
-            field=models.ForeignKey(default=1, to='quotes.Author'),
-            preserve_default=False,
+        migrations.AlterField(
+            model_name='author',
+            name='tags',
+            field=models.ManyToManyField(to='quotes.Tag'),
         ),
     ]
diff --git a/quotes/migrations/0003_auto_20161009_2254.py b/quotes/migrations/0003_auto_20161009_2254.py
deleted file mode 100644 (file)
index b3b0366..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('quotes', '0002_context_author'),
-    ]
-
-    operations = [
-        migrations.CreateModel(
-            name='Work',
-            fields=[
-                ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
-                ('name', models.CharField(help_text=b'Name of the context for the quote                             (title of the work or speech it appears in)', max_length=100)),
-                ('date', models.DateField(help_text=b'Date of the quote', null=True, blank=True)),
-                ('notes', models.TextField(help_text=b'Notes about the work; may be left blank. Will                               not be HTML-escaped. XXX: offer a WYSIWYG editor', blank=True)),
-                ('pvt_notes', models.TextField(help_text=b'Notes about the work; not displayed on                                   the public interface', blank=True)),
-                ('author', models.ForeignKey(to='quotes.Author')),
-                ('tags', models.ManyToManyField(to='quotes.Tag', blank=True)),
-            ],
-        ),
-        migrations.RemoveField(
-            model_name='context',
-            name='author',
-        ),
-        migrations.RemoveField(
-            model_name='context',
-            name='tags',
-        ),
-        migrations.AlterField(
-            model_name='quote',
-            name='context',
-            field=models.ForeignKey(to='quotes.Work'),
-        ),
-        migrations.DeleteModel(
-            name='Context',
-        ),
-    ]
diff --git a/quotes/migrations/0003_auto_20161031_0034.py b/quotes/migrations/0003_auto_20161031_0034.py
new file mode 100644 (file)
index 0000000..baab095
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:34
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('quotes', '0002_auto_20161031_0033'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='author',
+            name='tags',
+            field=models.ManyToManyField(blank=True, to='quotes.Tag'),
+        ),
+    ]
diff --git a/quotes/migrations/0004_auto_20161009_2255.py b/quotes/migrations/0004_auto_20161009_2255.py
deleted file mode 100644 (file)
index cf435ab..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# -*- coding: utf-8 -*-
-from __future__ import unicode_literals
-
-from django.db import migrations, models
-
-
-class Migration(migrations.Migration):
-
-    dependencies = [
-        ('quotes', '0003_auto_20161009_2254'),
-    ]
-
-    operations = [
-        migrations.RenameField(
-            model_name='quote',
-            old_name='context',
-            new_name='work',
-        ),
-    ]
diff --git a/quotes/migrations/0004_auto_20161031_0036.py b/quotes/migrations/0004_auto_20161031_0036.py
new file mode 100644 (file)
index 0000000..2e67927
--- /dev/null
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:36
+from __future__ import unicode_literals
+
+from django.db import migrations
+import tagging.fields
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('quotes', '0003_auto_20161031_0034'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='author',
+            name='tagbis',
+            field=tagging.fields.TagField(blank=True, max_length=255),
+        ),
+        migrations.AddField(
+            model_name='work',
+            name='tagter',
+            field=tagging.fields.TagField(blank=True, max_length=255),
+        ),
+    ]
diff --git a/quotes/migrations/0005_auto_20161031_0052.py b/quotes/migrations/0005_auto_20161031_0052.py
new file mode 100644 (file)
index 0000000..ad509a7
--- /dev/null
@@ -0,0 +1,54 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:52
+from __future__ import unicode_literals
+
+from django.db import migrations
+import quotes.localmodels
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('quotes', '0004_auto_20161031_0036'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='author',
+            name='tagbis',
+        ),
+        migrations.RemoveField(
+            model_name='work',
+            name='tagter',
+        ),
+        migrations.RemoveField(
+            model_name='author',
+            name='tags',
+        ),
+        migrations.AddField(
+            model_name='author',
+            name='tags',
+            field=quotes.localmodels.TagField(blank=True, max_length=255),
+        ),
+        migrations.RemoveField(
+            model_name='quote',
+            name='tags',
+        ),
+        migrations.AddField(
+            model_name='quote',
+            name='tags',
+            field=quotes.localmodels.TagField(blank=True, max_length=255),
+        ),
+        migrations.RemoveField(
+            model_name='work',
+            name='tags',
+        ),
+        migrations.AddField(
+            model_name='work',
+            name='tags',
+            field=quotes.localmodels.TagField(blank=True, max_length=255),
+        ),
+        migrations.DeleteModel(
+            name='Tag',
+        ),
+    ]
diff --git a/quotes/migrations/0006_auto_20161031_0055.py b/quotes/migrations/0006_auto_20161031_0055.py
new file mode 100644 (file)
index 0000000..047eed7
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:55
+from __future__ import unicode_literals
+
+from django.db import migrations
+import quotes.localmodels
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('quotes', '0005_auto_20161031_0052'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='author',
+            name='tags',
+        ),
+        migrations.AddField(
+            model_name='author',
+            name='tag',
+            field=quotes.localmodels.TagField(blank=True, max_length=255),
+        ),
+    ]
diff --git a/quotes/migrations/0007_auto_20161031_0056.py b/quotes/migrations/0007_auto_20161031_0056.py
new file mode 100644 (file)
index 0000000..c01a8a4
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.2 on 2016-10-31 00:56
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('quotes', '0006_auto_20161031_0055'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='author',
+            old_name='tag',
+            new_name='tags',
+        ),
+    ]
index 0fa66afd0ed91e8e076bd7d674c068246ef09b46..7539152451509845f8e984c31bbd16c2dd4ddb69 100644 (file)
@@ -1,12 +1,7 @@
 from django.db import models
-from localmodels import HTMLField
+from localmodels import HTMLField, TagField
 
 # Create your models here.
-class Tag(models.Model):
-    tag = models.CharField(max_length=100)
-    def __unicode__(self):
-        return self.tag
-
 class Author(models.Model):
     name = models.CharField(max_length=100,
                             help_text="Name of the author")
@@ -16,7 +11,7 @@ class Author(models.Model):
     pvt_notes = HTMLField(blank=True, help_text= \
                           "Notes about the author; not displayed on \
                           the public interface",)
-    tags = models.ManyToManyField(Tag, blank=True)
+    tags = TagField()
 
     birth_date = models.DateField(blank=True, null=True,
                                   help_text="Date of birth")
@@ -53,7 +48,7 @@ class Work(models.Model):
     author = models.ForeignKey(Author)
     date = models.DateField(blank=True, null=True,
                             help_text="Date of the quote")
-    tags = models.ManyToManyField(Tag, blank=True)
+    tags = TagField()
 
     notes = HTMLField(blank=True, help_text= \
                       "Notes about the work; may be left blank. Will \
@@ -67,7 +62,7 @@ class Work(models.Model):
 
 class Quote(models.Model):
     text = HTMLField()
-    tags = models.ManyToManyField(Tag, blank=True)
+    tags = TagField()
     work = models.ForeignKey(Work)
 
     notes = HTMLField(blank=True, help_text= \
index df4081d5b79b251ff5523b98d283dd470b2367d2..002c4e34a6b8ada081f5ffcd0ffab4663c204d7a 100644 (file)
@@ -2,7 +2,7 @@ from django.shortcuts import render
 
 from random import randint
 
-from .models import Author, Work, Quote, Tag
+from .models import Author, Work, Quote
 
 # Create your views here.
 def onequote(request, quote_id):