From 2bcaa0996696acac0196621cbe17819aed5450f5 Mon Sep 17 00:00:00 2001 From: Merlin Buczek Date: Thu, 13 Jun 2019 13:35:17 +0200 Subject: [PATCH] Add groups table --- .../migrations/0013_auto_20190613_1333.py | 28 +++++++ .../migrations/0014_auto_20190613_1333.py | 26 +++++++ mpicms/base/models.py | 14 ++-- .../migrations/0003_auto_20190613_1333.py | 56 ++++++++++++++ .../migrations/0007_auto_20190613_1333.py | 27 +++++++ .../migrations/0003_auto_20190613_1333.py | 64 ++++++++++++++++ mpicms/personal/models.py | 73 +++++++++++++++---- 7 files changed, 266 insertions(+), 22 deletions(-) create mode 100644 mpicms/base/migrations/0013_auto_20190613_1333.py create mode 100644 mpicms/base/migrations/0014_auto_20190613_1333.py create mode 100644 mpicms/events/migrations/0003_auto_20190613_1333.py create mode 100644 mpicms/news/migrations/0007_auto_20190613_1333.py create mode 100644 mpicms/personal/migrations/0003_auto_20190613_1333.py diff --git a/mpicms/base/migrations/0013_auto_20190613_1333.py b/mpicms/base/migrations/0013_auto_20190613_1333.py new file mode 100644 index 0000000..7498e21 --- /dev/null +++ b/mpicms/base/migrations/0013_auto_20190613_1333.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.1 on 2019-06-13 11:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0012_auto_20190607_1139'), + ] + + operations = [ + migrations.CreateModel( + name='ContactRelation', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), + ('position', models.CharField(blank=True, max_length=50)), + ], + options={ + 'verbose_name': 'contact information', + 'verbose_name_plural': 'contact information', + }, + ), + migrations.DeleteModel( + name='Contacts', + ), + ] diff --git a/mpicms/base/migrations/0014_auto_20190613_1333.py b/mpicms/base/migrations/0014_auto_20190613_1333.py new file mode 100644 index 0000000..33ff2a2 --- /dev/null +++ b/mpicms/base/migrations/0014_auto_20190613_1333.py @@ -0,0 +1,26 @@ +# Generated by Django 2.2.1 on 2019-06-13 11:33 + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('personal', '0003_auto_20190613_1333'), + ('base', '0013_auto_20190613_1333'), + ] + + operations = [ + migrations.AddField( + model_name='contactrelation', + name='contact', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contact_references', to='personal.Contact', verbose_name='contact'), + ), + migrations.AddField( + model_name='contactrelation', + name='page', + field=modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='contacts', to='base.CategoryPage'), + ), + ] diff --git a/mpicms/base/models.py b/mpicms/base/models.py index 47e9e6c..dbf144a 100644 --- a/mpicms/base/models.py +++ b/mpicms/base/models.py @@ -39,7 +39,7 @@ class Meta: # noqa verbose_name_plural = _('banners') -class Contacts(Orderable, models.Model): +class ContactRelation(Orderable, models.Model): """ This defines the relationship between the `People` within the `personal` app and the CategoryPage below. This allows People to be added to the contact field. @@ -47,22 +47,22 @@ class Contacts(Orderable, models.Model): page = ParentalKey( 'CategoryPage', related_name=_('contacts'), on_delete=models.CASCADE ) - person = models.ForeignKey( - 'personal.Person', + contact = models.ForeignKey( + 'personal.Contact', related_name='contact_references', on_delete=models.CASCADE, - verbose_name=_('person') + verbose_name=_('contact') ) position = models.CharField(max_length=50, blank=True) panels = [ - SnippetChooserPanel('person'), + SnippetChooserPanel('contact'), FieldPanel('position') ] class Meta: # noqa - verbose_name = _('contact') - verbose_name_plural = _('contacts') + verbose_name = _('contact information') + verbose_name_plural = _('contact information') class CategoryMixin(models.Model): diff --git a/mpicms/events/migrations/0003_auto_20190613_1333.py b/mpicms/events/migrations/0003_auto_20190613_1333.py new file mode 100644 index 0000000..d3991a6 --- /dev/null +++ b/mpicms/events/migrations/0003_auto_20190613_1333.py @@ -0,0 +1,56 @@ +# Generated by Django 2.2.1 on 2019-06-13 11:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('events', '0002_auto_20190601_1604'), + ] + + operations = [ + migrations.AlterModelOptions( + name='event', + options={'ordering': ['start_date'], 'verbose_name': 'event', 'verbose_name_plural': 'events'}, + ), + migrations.AlterModelOptions( + name='eventindex', + options={'verbose_name': 'event index', 'verbose_name_plural': 'event indexes'}, + ), + migrations.AlterField( + model_name='event', + name='description', + field=models.TextField(blank=True, max_length=400, verbose_name='description'), + ), + migrations.AlterField( + model_name='event', + name='description_de', + field=models.TextField(blank=True, max_length=400, null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='event', + name='description_en', + field=models.TextField(blank=True, max_length=400, null=True, verbose_name='description'), + ), + migrations.AlterField( + model_name='event', + name='end_date', + field=models.DateField(blank=True, null=True, verbose_name='end date'), + ), + migrations.AlterField( + model_name='event', + name='end_time', + field=models.TimeField(blank=True, null=True, verbose_name='end time'), + ), + migrations.AlterField( + model_name='event', + name='start_date', + field=models.DateField(verbose_name='start date'), + ), + migrations.AlterField( + model_name='event', + name='start_time', + field=models.TimeField(blank=True, null=True, verbose_name='start time'), + ), + ] diff --git a/mpicms/news/migrations/0007_auto_20190613_1333.py b/mpicms/news/migrations/0007_auto_20190613_1333.py new file mode 100644 index 0000000..e8351e5 --- /dev/null +++ b/mpicms/news/migrations/0007_auto_20190613_1333.py @@ -0,0 +1,27 @@ +# Generated by Django 2.2.1 on 2019-06-13 11:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0006_auto_20190605_1200'), + ] + + operations = [ + migrations.AlterModelOptions( + name='newspage', + options={'verbose_name': 'news blog', 'verbose_name_plural': 'news blogs'}, + ), + migrations.AlterField( + model_name='newsentry', + name='date', + field=models.DateField(auto_now_add=True, verbose_name='post date'), + ), + migrations.AlterField( + model_name='newspage', + name='show_all', + field=models.BooleanField(default=False, help_text='Include all news from subpages', verbose_name='show all news'), + ), + ] diff --git a/mpicms/personal/migrations/0003_auto_20190613_1333.py b/mpicms/personal/migrations/0003_auto_20190613_1333.py new file mode 100644 index 0000000..c7039a8 --- /dev/null +++ b/mpicms/personal/migrations/0003_auto_20190613_1333.py @@ -0,0 +1,64 @@ +# Generated by Django 2.2.1 on 2019-06-13 11:33 + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields +import wagtail.search.index + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0013_auto_20190613_1333'), + ('personal', '0002_auto_20190527_1655'), + ] + + operations = [ + migrations.CreateModel( + name='Contact', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=254, verbose_name='name')), + ('email', models.EmailField(blank=True, max_length=254, verbose_name='email')), + ('phone', models.IntegerField(blank=True, null=True, verbose_name='phone number')), + ('room', models.CharField(blank=True, max_length=25, verbose_name='room')), + ], + options={ + 'verbose_name': 'Contact', + 'verbose_name_plural': 'Contacts', + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + migrations.CreateModel( + name='ContactGroups', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), + ('contact', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='groups', to='personal.Contact')), + ], + options={ + 'ordering': ['sort_order'], + 'abstract': False, + }, + ), + migrations.CreateModel( + name='Group', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=254, verbose_name='name')), + ], + options={ + 'verbose_name': 'Group', + 'verbose_name_plural': 'Groups', + }, + bases=(wagtail.search.index.Indexed, models.Model), + ), + migrations.DeleteModel( + name='Person', + ), + migrations.AddField( + model_name='contactgroups', + name='group', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='contacts', to='personal.Group', verbose_name='groups'), + ), + ] diff --git a/mpicms/personal/models.py b/mpicms/personal/models.py index b7d3387..1d6e52a 100644 --- a/mpicms/personal/models.py +++ b/mpicms/personal/models.py @@ -1,14 +1,37 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, FieldRowPanel +from wagtail.core.models import Orderable +from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel, FieldRowPanel, InlinePanel from wagtail.snippets.models import register_snippet from wagtail.search import index +from wagtail.snippets.edit_handlers import SnippetChooserPanel + from modelcluster.models import ClusterableModel +from modelcluster.fields import ParentalKey + + +class ContactGroups(Orderable, models.Model): + """ + This defines the relationship between the `Group` within the `Contact` model below. + """ + contact = ParentalKey( + 'Contact', related_name=_('groups'), on_delete=models.CASCADE + ) + group = models.ForeignKey( + 'personal.Group', + related_name='contacts', + on_delete=models.CASCADE, + verbose_name=_('groups') + ) + + panels = [ + SnippetChooserPanel('group'), + ] @register_snippet -class Person(index.Indexed, ClusterableModel): +class Contact(index.Indexed, ClusterableModel): """ A Django model to store People objects. It uses the `@register_snippet` decorator to allow it to be accessible @@ -20,32 +43,52 @@ class Person(index.Indexed, ClusterableModel): to the database. https://github.com/wagtail/django-modelcluster """ - first_name = models.CharField(_("first name"), max_length=254) - last_name = models.CharField(_("last name"), max_length=254) + name = models.CharField(_("name"), max_length=254) email = models.EmailField(_("email"), blank=True) phone = models.IntegerField(_("phone number"), blank=True, null=True) room = models.CharField(_("room"), max_length=25, blank=True) panels = [ - MultiFieldPanel([ - FieldRowPanel([ - FieldPanel('first_name', classname="col6"), - FieldPanel('last_name', classname="col6"), - ]) - ], "Name"), + FieldPanel('name'), FieldPanel('email'), FieldPanel('phone'), FieldPanel('room'), + InlinePanel( + 'groups', label="Groups", + panels=None), + ] + + search_fields = [ + index.SearchField('name'), + index.SearchField('email'), + index.SearchField('phone'), + index.SearchField('room'), + # index.SearchField('groups'), + ] + + def __str__(self): + return self.name + + class Meta: # noqa + verbose_name = 'Contact' + verbose_name_plural = 'Contacts' + + +@register_snippet +class Group(index.Indexed, ClusterableModel): + name = models.CharField(_("name"), max_length=254) + + panels = [ + FieldPanel('name'), ] search_fields = [ - index.SearchField('first_name'), - index.SearchField('last_name'), + index.SearchField('name'), ] def __str__(self): - return '{} {}'.format(self.first_name, self.last_name) + return self.name class Meta: # noqa - verbose_name = 'Person' - verbose_name_plural = 'People' + verbose_name = 'Group' + verbose_name_plural = 'Groups'