]> git.parisson.com Git - mezzo.git/commitdiff
Task #59: adding custom page with a field sub_title
authorEmilie <zawadzki@ircam.fr>
Tue, 5 Jul 2016 14:33:05 +0000 (16:33 +0200)
committerEmilie <zawadzki@ircam.fr>
Tue, 5 Jul 2016 14:33:05 +0000 (16:33 +0200)
app/custom/__init__.py [new file with mode: 0644]
app/custom/admin.py [new file with mode: 0644]
app/custom/apps.py [new file with mode: 0644]
app/custom/migrations/0001_initial.py [new file with mode: 0644]
app/custom/migrations/0002_auto_20160705_1559.py [new file with mode: 0644]
app/custom/migrations/__init__.py [new file with mode: 0644]
app/custom/models.py [new file with mode: 0644]
app/custom/tests.py [new file with mode: 0644]
app/custom/translations.py [new file with mode: 0644]
app/custom/views.py [new file with mode: 0644]
app/settings.py

diff --git a/app/custom/__init__.py b/app/custom/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/app/custom/admin.py b/app/custom/admin.py
new file mode 100644 (file)
index 0000000..7ca39c3
--- /dev/null
@@ -0,0 +1,18 @@
+from django.contrib import admin
+from copy import deepcopy
+from mezzanine.pages.models import Page
+from mezzanine.pages.admin import PageAdmin
+from mezzanine.pages.models import RichTextPage
+from custom.models import BasicPage
+
+
+# page_fieldsets = deepcopy(PageAdmin.fieldsets)
+# page_fieldsets[0][1]["fields"] += ("sub_title",)
+# print(page_fieldsets[0][1]["fields"])
+# PageAdmin.fieldsets = page_fieldsets
+#
+# admin.site.unregister(RichTextPage)
+# admin.site.register(RichTextPage, PageAdmin)
+
+
+admin.site.register(BasicPage, PageAdmin)
diff --git a/app/custom/apps.py b/app/custom/apps.py
new file mode 100644 (file)
index 0000000..245de53
--- /dev/null
@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class CustomConfig(AppConfig):
+    name = 'custom'
diff --git a/app/custom/migrations/0001_initial.py b/app/custom/migrations/0001_initial.py
new file mode 100644 (file)
index 0000000..66ad115
--- /dev/null
@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-05 13:58
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+import mezzanine.core.fields
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+        ('pages', '0004_auto_20151223_1313'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='BasicPage',
+            fields=[
+                ('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='pages.Page')),
+                ('content', mezzanine.core.fields.RichTextField(verbose_name='Content')),
+                ('sub_title', models.TextField(blank=True, verbose_name='sub title')),
+            ],
+            options={
+                'ordering': ('_order',),
+            },
+            bases=('pages.page', models.Model),
+        ),
+    ]
diff --git a/app/custom/migrations/0002_auto_20160705_1559.py b/app/custom/migrations/0002_auto_20160705_1559.py
new file mode 100644 (file)
index 0000000..2f140ab
--- /dev/null
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-07-05 13:59
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('custom', '0001_initial'),
+    ]
+
+    operations = [
+        migrations.AddField(
+            model_name='basicpage',
+            name='sub_title_en',
+            field=models.TextField(blank=True, null=True, verbose_name='sub title'),
+        ),
+        migrations.AddField(
+            model_name='basicpage',
+            name='sub_title_fr',
+            field=models.TextField(blank=True, null=True, verbose_name='sub title'),
+        ),
+    ]
diff --git a/app/custom/migrations/__init__.py b/app/custom/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/app/custom/models.py b/app/custom/models.py
new file mode 100644 (file)
index 0000000..5be18ac
--- /dev/null
@@ -0,0 +1,22 @@
+from django.db import models
+from django.utils.translation import ugettext_lazy as _
+from django.core.urlresolvers import reverse, reverse_lazy
+#from mezzanine.core.models import Displayable
+from mezzanine.pages.models import Page, RichText
+# Create your models here.
+# class DisplayableCustom(Displayable):
+#
+#     sub_title = models.TextField(_('sub_title'), blank=True)
+
+
+class SubTitle(models.Model):
+
+    sub_title = models.TextField(_('sub title'), blank=True)
+
+    class Meta:
+        abstract = True
+
+
+class BasicPage(Page, RichText):
+
+    sub_title = models.TextField(_('sub title'), blank=True)
diff --git a/app/custom/tests.py b/app/custom/tests.py
new file mode 100644 (file)
index 0000000..7ce503c
--- /dev/null
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/app/custom/translations.py b/app/custom/translations.py
new file mode 100644 (file)
index 0000000..bd3f3db
--- /dev/null
@@ -0,0 +1,31 @@
+# from modeltranslation.translator import translator, register, TranslationOptions
+# from mezzanine.pages.models import Page, RichTextPage, Link
+# from mezzanine.pages.translation import TranslatedRichText
+# from mezzanine.forms.models import Form
+# from mezzanine.galleries.models import Gallery
+#
+# # @register(RichText)
+# # class RichTextTranslationOptions(TranslatedRichText):
+# #
+# #     fields = ('sub_title')
+#
+# # print(RichTextPage._meta.get_fields())
+# # print('///////////////////////////')
+# class TranslatedInjectedRichText(TranslatedRichText):
+#     fields = ('sub_title',)
+#
+# translator.unregister(RichTextPage)
+#
+# translator.register(RichTextPage, TranslatedInjectedRichText)
+
+
+from modeltranslation.translator import translator, register, TranslationOptions
+from mezzanine.pages.models import Page, RichText
+from mezzanine.pages.translation import TranslatedRichText
+from .models import BasicPage
+
+
+@register(BasicPage)
+class EventTranslationOptions(TranslationOptions):
+
+    fields = ('sub_title',)
diff --git a/app/custom/views.py b/app/custom/views.py
new file mode 100644 (file)
index 0000000..91ea44a
--- /dev/null
@@ -0,0 +1,3 @@
+from django.shortcuts import render
+
+# Create your views here.
index 778bc3d5cb1cb3717ae3acd72744194f2d7d520f..18b8e05f7326e4f7c003ff101406c748a0cc8ad9 100644 (file)
@@ -213,6 +213,7 @@ INSTALLED_APPS = [
     "mezzanine.core",
     "mezzanine.generic",
     "mezzanine.pages",
+    "custom",
     "mezzanine.blog",
     "mezzanine.forms",
     "mezzanine.galleries",
@@ -246,6 +247,7 @@ MIGRATION_MODULES = {
 }
 
 MODELTRANSLATION_TRANSLATION_FILES = (
+    'custom.translations',
     'translations',
 )