From: Emilie Date: Mon, 19 Sep 2016 21:14:24 +0000 (+0200) Subject: Person List: saving code... some issue with reverse request > can't access Person X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=1298b64f6702047cf62dc0e2b909a7e03d19c15a;p=mezzo.git Person List: saving code... some issue with reverse request > can't access Person --- diff --git a/app/organization/network/admin.py b/app/organization/network/admin.py index 4057edef..ae3607b5 100644 --- a/app/organization/network/admin.py +++ b/app/organization/network/admin.py @@ -118,15 +118,15 @@ class PersonAdmin(BaseTranslationModelAdmin): return res -class PersonAutocompleteInline(TabularDynamicInlineAdmin): +class PersonListBlockInlineAdmin(TabularDynamicInlineAdmin): - model = PersonAutocomplete - form = PersonAutocompleteForm + model = PersonListBlockInline + form = PersonListBlockInlineForm class PersonListBlockAdmin(admin.ModelAdmin): - inlines = [PersonAutocompleteInline,] + inlines = [PersonListBlockInlineAdmin,] admin.site.register(Organization, OrganizationAdmin) diff --git a/app/organization/network/forms.py b/app/organization/network/forms.py index 2872e579..736a4dc4 100644 --- a/app/organization/network/forms.py +++ b/app/organization/network/forms.py @@ -5,11 +5,11 @@ from django import forms from django.forms.widgets import HiddenInput from django.forms import ModelForm from mezzanine.core.models import Orderable -from organization.network.models import Person, PersonListBlock, DynamicPersonList, PersonAutocomplete #DynamicContentPersonList, -from organization.pages.models import DynamicPersonListBlockPage, Page +from organization.network.models import Person, PersonListBlock, PersonListBlockInline, PageCustomPersonListBlockInline +from organization.pages.models import Page, CustomPage -class PagePersonListForm(forms.ModelForm): +class PageCustomPersonListForm(forms.ModelForm): person_list_block = forms.ModelChoiceField( queryset=PersonListBlock.objects.all(), @@ -17,11 +17,11 @@ class PagePersonListForm(forms.ModelForm): ) class Meta: - model = Page - fields = ('person_list_block',) + model = PageCustomPersonListBlockInline #CustomPage + fields = ('person_list_block',) #person_list_block -class PersonAutocompleteForm(forms.ModelForm): +class PersonListBlockInlineForm(forms.ModelForm): person = forms.ModelChoiceField( queryset=Person.objects.all(), @@ -29,5 +29,5 @@ class PersonAutocompleteForm(forms.ModelForm): ) class Meta: - model = PersonAutocomplete + model = PersonListBlockInline fields = ('__all__') diff --git a/app/organization/network/migrations/0013_auto_20160919_1829.py b/app/organization/network/migrations/0013_auto_20160919_1829.py new file mode 100644 index 00000000..98476aed --- /dev/null +++ b/app/organization/network/migrations/0013_auto_20160919_1829.py @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-19 16:29 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization-pages', '0002_auto_20160914_1838'), + ('organization-network', '0012_auto_20160916_1423'), + ] + + operations = [ + migrations.CreateModel( + name='PageCustomPersonListBlockInline', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=1024, verbose_name='title')), + ('description', models.TextField(blank=True, verbose_name='description')), + ('page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_block', to='organization-pages.CustomPage', verbose_name='Page')), + ], + options={ + 'verbose_name': 'Person List', + }, + ), + migrations.CreateModel( + name='PersonListBlock', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=1024, verbose_name='title')), + ('description', models.TextField(blank=True, verbose_name='description')), + ('style', models.CharField(choices=[('square', 'square'), ('circle', 'circle')], max_length=16, verbose_name='style')), + ], + options={ + 'verbose_name': 'Person List', + }, + ), + migrations.CreateModel( + name='PersonListBlockInline', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('person', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_block', to='organization-network.Person', verbose_name='Person')), + ('person_list_block', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_autocomplete', to='organization-network.PersonListBlock', verbose_name='Person List Block')), + ], + options={ + 'verbose_name': 'Person autocomplete', + }, + ), + migrations.AddField( + model_name='pagecustompersonlistblockinline', + name='person_list_block', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='page_custom', to='organization-network.PersonListBlock', verbose_name='Person List Block'), + ), + ] diff --git a/app/organization/network/migrations/0014_auto_20160919_1912.py b/app/organization/network/migrations/0014_auto_20160919_1912.py new file mode 100644 index 00000000..af030946 --- /dev/null +++ b/app/organization/network/migrations/0014_auto_20160919_1912.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-19 17:12 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization-network', '0013_auto_20160919_1829'), + ] + + operations = [ + migrations.AlterField( + model_name='personlistblockinline', + name='person', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_block_inline', to='organization-network.Person', verbose_name='Person'), + ), + migrations.AlterField( + model_name='personlistblockinline', + name='person_list_block', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_block_inline', to='organization-network.PersonListBlock', verbose_name='Person List Block'), + ), + ] diff --git a/app/organization/network/migrations/0015_auto_20160919_1914.py b/app/organization/network/migrations/0015_auto_20160919_1914.py new file mode 100644 index 00000000..930ef7cf --- /dev/null +++ b/app/organization/network/migrations/0015_auto_20160919_1914.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-19 17:14 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization-network', '0014_auto_20160919_1912'), + ] + + operations = [ + migrations.AlterField( + model_name='personlistblockinline', + name='person', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list', to='organization-network.Person', verbose_name='Person'), + ), + ] diff --git a/app/organization/network/migrations/0016_auto_20160919_1923.py b/app/organization/network/migrations/0016_auto_20160919_1923.py new file mode 100644 index 00000000..7a2675c1 --- /dev/null +++ b/app/organization/network/migrations/0016_auto_20160919_1923.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-19 17:23 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization-network', '0015_auto_20160919_1914'), + ] + + operations = [ + migrations.AlterField( + model_name='personlistblockinline', + name='person', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='coucou', to='organization-network.Person', verbose_name='Person'), + ), + ] diff --git a/app/organization/network/migrations/0017_auto_20160919_1927.py b/app/organization/network/migrations/0017_auto_20160919_1927.py new file mode 100644 index 00000000..2efbd5f4 --- /dev/null +++ b/app/organization/network/migrations/0017_auto_20160919_1927.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-09-19 17:27 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('organization-network', '0016_auto_20160919_1923'), + ] + + operations = [ + migrations.AlterField( + model_name='pagecustompersonlistblockinline', + name='page', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='page_custom_person_list_block_inline', to='organization-pages.CustomPage', verbose_name='Page'), + ), + migrations.AlterField( + model_name='pagecustompersonlistblockinline', + name='person_list_block', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='page_custom_person_list_block_inline', to='organization-network.PersonListBlock', verbose_name='Person List Block'), + ), + migrations.AlterField( + model_name='personlistblockinline', + name='person', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_block_inline', to='organization-network.Person', verbose_name='Person'), + ), + ] diff --git a/app/organization/network/models.py b/app/organization/network/models.py index 15d8a2dd..7f3eaeab 100644 --- a/app/organization/network/models.py +++ b/app/organization/network/models.py @@ -22,6 +22,7 @@ from mezzanine.utils.models import AdminThumbMixin, upload_to from organization.core.models import * from organization.media.models import * +from organization.pages.models import CustomPage from django_countries.fields import CountryField # from .nationalities.fields import NationalityField @@ -35,6 +36,11 @@ GENDER_CHOICES = [ ('female', _('female')), ] +PERSON_LIST_STYLE_CHOICES = [ + ('square', _('square')), + ('circle', _('circle')), +] + TITLE_CHOICES = [ ('Dr', _('Dr')), ('Prof', _('Prof')), @@ -229,9 +235,10 @@ class PersonBlock(Block): person = models.ForeignKey(Person, verbose_name=_('person'), related_name='blocks', blank=True, null=True, on_delete=models.SET_NULL) -class PersonListBlock(Titled): +class PageCustomPersonListBlockInline(Titled): - page = models.ForeignKey(Page, verbose_name=_('Page'), related_name='person_list_block', blank=True, null=True, on_delete=models.SET_NULL) + page = models.ForeignKey(CustomPage, verbose_name=_('Page'), related_name='page_custom_person_list_block_inline', blank=True, null=True, on_delete=models.SET_NULL) + person_list_block = models.ForeignKey("PersonListBlock", verbose_name=_('Person List Block'), related_name='page_custom_person_list_block_inline', blank=True, null=True) class Meta: verbose_name = _('Person List') @@ -240,21 +247,25 @@ class PersonListBlock(Titled): return self.title -class PersonAutocomplete(models.Model): +class PersonListBlock(Titled): - person_list_block = models.ForeignKey(PersonListBlock, verbose_name=_('Person List Block'), related_name='person_autocomplete', blank=True, null=True, on_delete=models.SET_NULL) - person = models.ForeignKey(Person, verbose_name=_('Person'), related_name='person_list_block', blank=True, null=True, on_delete=models.SET_NULL) + style = models.CharField(_('style'), max_length=16, choices=PERSON_LIST_STYLE_CHOICES) class Meta: - verbose_name = _('Person autocomplete') + verbose_name = _('Person List') + + def __str__(self): + return self.title -class DynamicPersonList(DynamicContent, Orderable): +class PersonListBlockInline(models.Model): - person_list_block = models.ForeignKey("PersonListBlock", verbose_name=_('Person List Block'), related_name='dynamic_person_list', blank=True, null=True, on_delete=models.SET_NULL) + person_list_block = models.ForeignKey(PersonListBlock, verbose_name=_('Person List Block'), related_name='person_list_block_inline', blank=True, null=True, on_delete=models.SET_NULL) + person = models.ForeignKey(Person, verbose_name=_('Person'), related_name='person_list_block_inline', blank=True, null=True, on_delete=models.SET_NULL) class Meta: - verbose_name = 'Dynamic Content Person List' + verbose_name = _('Person autocomplete') + class ActivityStatus(Named): diff --git a/app/organization/network/translation.py b/app/organization/network/translation.py index 286d6c2f..9319ba8d 100644 --- a/app/organization/network/translation.py +++ b/app/organization/network/translation.py @@ -105,19 +105,19 @@ class OrganizationBlockTranslationOptions(TranslationOptions): pass -@register(DynamicPersonList) -class DynamicPersonListTranslationOptions(TranslationOptions): +@register(PersonListBlock) +class PersonListBlockTranslationOptions(TranslationOptions): pass -@register(PersonListBlock) -class PersonListBlockTranslationOptions(TranslationOptions): +@register(PersonListBlockInline) +class PersonListBlockInlineTranslationOptions(TranslationOptions): pass -@register(PersonAutocomplete) -class PersonListBlockTranslationOptions(TranslationOptions): +@register(PageCustomPersonListBlockInline) +class PageCustomPersonListBlockInlineTranslationOptions(TranslationOptions): pass diff --git a/app/organization/pages/admin.py b/app/organization/pages/admin.py index 26650827..1cbf8b3c 100644 --- a/app/organization/pages/admin.py +++ b/app/organization/pages/admin.py @@ -11,6 +11,7 @@ from organization.pages.models import ( ) from organization.pages.forms import * from organization.network.forms import * +from organization.network.models import PageCustomPersonListBlockInline class PageBlockInline(StackedDynamicInlineAdmin): @@ -39,19 +40,20 @@ class PageLinkInline(StackedDynamicInlineAdmin): model = PageLink -class PersonListBlockAutocompleteInline(TabularDynamicInlineAdmin): +class PersonListBlockAutocompleteInlineAdmin(TabularDynamicInlineAdmin): - model = PersonListBlock - form = PagePersonListForm + model = PageCustomPersonListBlockInline + form = PageCustomPersonListForm class CustomPageAdmin(PageAdmin): - inlines = [PageBlockInline, PageImageInline, + inlines = [PageBlockInline, + PageImageInline, PageAudioInline, PageVideoInline, PageLinkInline, - PersonListBlockAutocompleteInline, + PersonListBlockAutocompleteInlineAdmin, ] diff --git a/app/organization/pages/migrations/0003_dynamicpersonlistblockpage.py b/app/organization/pages/migrations/0003_dynamicpersonlistblockpage.py deleted file mode 100644 index 77015c8f..00000000 --- a/app/organization/pages/migrations/0003_dynamicpersonlistblockpage.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.7 on 2016-09-16 09:29 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion -import mezzanine.core.fields - - -class Migration(migrations.Migration): - - dependencies = [ - ('contenttypes', '0002_remove_content_type_name'), - ('pages', '0004_auto_20160804_1547'), - ('organization-pages', '0002_auto_20160914_1838'), - ] - - operations = [ - migrations.CreateModel( - name='DynamicPersonListBlockPage', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('_order', mezzanine.core.fields.OrderField(null=True, verbose_name='Order')), - ('object_id', models.PositiveIntegerField(editable=False, null=True, verbose_name='related object')), - ('content_type', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType', verbose_name='content type')), - ('page', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='person_list_blocks', to='pages.Page', verbose_name='Page')), - ], - options={ - 'ordering': ('_order',), - 'verbose_name': 'Person List', - }, - ), - ] diff --git a/app/organization/pages/models.py b/app/organization/pages/models.py index bfdb4868..c183a899 100644 --- a/app/organization/pages/models.py +++ b/app/organization/pages/models.py @@ -88,11 +88,3 @@ class Home(Displayable): return reverse("organization-home") verbose_name = _('Person List') - - -class DynamicPersonListBlockPage(DynamicContent, Orderable): - - page = models.ForeignKey(Page, verbose_name=_('Page'), related_name='person_list_blocks', blank=True, null=True, on_delete=models.SET_NULL) - - class Meta: - verbose_name = _('Person List') diff --git a/app/organization/pages/translation.py b/app/organization/pages/translation.py index 4ad2d9f7..d84002dc 100644 --- a/app/organization/pages/translation.py +++ b/app/organization/pages/translation.py @@ -56,8 +56,3 @@ class PageAudioTranslationOptions(TranslationOptions): class PageLinkTranslationOptions(TranslationOptions): pass - -@register(DynamicPersonListBlockPage) -class DynamicPersonListBlockPageTranslationOptions(TranslationOptions): - - pass diff --git a/app/templates/network/inc/person/list_circle_style.html b/app/templates/network/inc/person/list_circle_style.html new file mode 100644 index 00000000..c6ef8d80 --- /dev/null +++ b/app/templates/network/inc/person/list_circle_style.html @@ -0,0 +1,7 @@ +

{{ person_list_block.title }}

+

{{ person_list_block.description }}

+{{ person_list_block.persons.all }} +{% for person in person_list_block.person %} +-----------{{person}}--------- +

{{ person.person_title }}

+{% endfor %} diff --git a/app/templates/network/inc/person/list_square_style.html b/app/templates/network/inc/person/list_square_style.html new file mode 100644 index 00000000..85d112ca --- /dev/null +++ b/app/templates/network/inc/person/list_square_style.html @@ -0,0 +1,6 @@ +

{{ person_list_block.title }}

+

{{ person_list_block.description }}

+{% for person in person_list_block.person %} +-----------{{person}}--------- +

{{ person.person_title }}

+{% endfor %} diff --git a/app/templates/pages/custompage.html b/app/templates/pages/custompage.html index 6341e50f..106fd495 100644 --- a/app/templates/pages/custompage.html +++ b/app/templates/pages/custompage.html @@ -90,6 +90,20 @@ {% endwith %} {% endblock %} +{% block page_person_list %} +{% with page.custompage.person_list_block.all as person_list_blocks %} + {% for person_list_block in person_list_blocks %} + {% with person_list_block.person_list_block as person_list_block %} + {% with "network/inc/person/list_"|add:person_list_block.style|add:"_style.html" as template %} + {% include template %} + {% endwith %} + + {% endwith %} + {% endfor %} +{% endwith %} + +{% endblock %} + {% block page_sub_content %} {% with page.custompage.blocks.all as blocks %} {% include "core/inc/block.html" %} diff --git a/app/templates/pages/page.html b/app/templates/pages/page.html index 06a6ccf2..c73d3f2a 100644 --- a/app/templates/pages/page.html +++ b/app/templates/pages/page.html @@ -67,6 +67,8 @@ {% endblock %} {% block page_link %} {% endblock %} + {% block page_person_list %} + {% endblock %} {% block page_sub_content %} {% endblock %} {% block page_related_content %}