]> git.parisson.com Git - mezzo.git/commitdiff
CustomPage : add dynamic content
authorEmilie <zawadzki@ircam.fr>
Fri, 7 Oct 2016 11:04:37 +0000 (13:04 +0200)
committerEmilie <zawadzki@ircam.fr>
Fri, 7 Oct 2016 11:04:37 +0000 (13:04 +0200)
app/organization/pages/admin.py
app/organization/pages/forms.py
app/organization/pages/migrations/0005_dynamiccontentpage.py [new file with mode: 0644]
app/organization/pages/models.py
app/organization/pages/translation.py
app/organization/pages/urls.py
app/organization/pages/views.py
app/templates/core/inc/related_content.html [new file with mode: 0644]
app/templates/pages/custompage.html
app/templates/pages/page.html

index fde7064f14d63d516bd17e2ac5694e4b255add74..ff35c3b7911d1d50414ad2be9019db3bfe9aa3c1 100644 (file)
@@ -64,6 +64,17 @@ class PageProductListInline(TabularDynamicInlineAdmin):
     model = PageProductList
 
 
+class DynamicContentPageInline(TabularDynamicInlineAdmin):
+
+    model = DynamicContentPage
+    form = DynamicContentPageForm
+
+    class Media:
+        js = (
+            static("mezzanine/js/admin/dynamic_inline.js"),
+        )
+
+
 class CustomPageAdmin(PageAdmin):
 
     inlines = [PageBlockInline,
@@ -72,7 +83,8 @@ class CustomPageAdmin(PageAdmin):
             PageVideoInline,
             PageLinkInline,
             PersonListBlockAutocompleteInlineAdmin,
-            PageProductListInline
+            PageProductListInline,
+            DynamicContentPageInline
             ]
 
 
index 69247ffbeb380b10034b19a7fc8435fa26c32da2..ec1b91aa619af2cdca18665ddef7fff9330f6420 100644 (file)
@@ -9,7 +9,7 @@ from django.forms import ModelForm
 from mezzanine.core.models import Orderable
 from organization.magazine.models import Article, Topic, Brief
 from organization.pages.models import CustomPage
-from organization.pages.models import DynamicContentHomeSlider, DynamicContentHomeBody
+from organization.pages.models import *
 from organization.agenda.models import Event
 
 class DynamicContentHomeSliderForm(autocomplete.FutureModelForm):
@@ -45,3 +45,20 @@ class DynamicContentHomeBodyForm(autocomplete.FutureModelForm):
     class Meta:
         model = DynamicContentHomeBody
         fields = ('content_object',)
+
+
+class DynamicContentPageForm(autocomplete.FutureModelForm):
+
+    content_object = dal_queryset_sequence.fields.QuerySetSequenceModelField(
+        queryset=autocomplete.QuerySetSequence(
+            Article.objects.all(),
+            CustomPage.objects.all(),
+            Event.objects.all()
+        ),
+        required=False,
+        widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-page'),
+    )
+
+    class Meta:
+        model = DynamicContentPage
+        fields = ('content_object',)
diff --git a/app/organization/pages/migrations/0005_dynamiccontentpage.py b/app/organization/pages/migrations/0005_dynamiccontentpage.py
new file mode 100644 (file)
index 0000000..bfafc94
--- /dev/null
@@ -0,0 +1,33 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.10 on 2016-10-07 10:44
+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', '0005_auto_20160923_1219'),
+        ('organization-pages', '0004_auto_20160928_1858'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='DynamicContentPage',
+            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='dynamic_content_pages', to='pages.Page', verbose_name='page')),
+            ],
+            options={
+                'ordering': ('_order',),
+                'verbose_name': 'Dynamic Content Page',
+            },
+        ),
+    ]
index f1afc8dda378a7e66c2e90d57f23f58a28f82bcc..b33e78b24a0dd20c77f2d1c16347b01b1260f85d 100644 (file)
@@ -63,6 +63,14 @@ class PageLink(Link):
         order_with_respect_to = "page"
 
 
+class DynamicContentPage(DynamicContent, Orderable):
+
+    page = models.ForeignKey(Page, verbose_name=_('page'), related_name='dynamic_content_pages', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = 'Dynamic Content Page'
+
+
 class LinkImage(models.Model):
 
     link = models.ForeignKey(MezzanineLink, verbose_name=_('link'), related_name='link_images', blank=True, null=True, on_delete=models.SET_NULL)
index 5cae7e874e32188fb52b54a60b693f06d3a2cccb..2b00ae34ebd8d81c237af8a2fed8d348a7bc423f 100644 (file)
@@ -58,6 +58,12 @@ class PageLinkTranslationOptions(TranslationOptions):
     pass
 
 
+@register(DynamicContentPage)
+class DynamicContentPageTranslationOptions(TranslationOptions):
+
+    pass
+
+
 @register(LinkImage)
 class LinkImageTranslationOptions(TranslationOptions):
 
index b061a701af116e2855c0b15b22ae6a2f86d17a1c..559de3687edf8b14d15fbfedc56b408643259b78 100644 (file)
@@ -14,6 +14,7 @@ urlpatterns = [
     url("^$", HomeView.as_view(), name="home"),
     url("^dynamic-content-home-slider/$", permission_required('home.can_edit')(DynamicContentHomeSliderView.as_view()), name='dynamic-content-home-slider'),
     url("^dynamic-content-home-body/$",  permission_required('home.can_edit')(DynamicContentHomeBodyView.as_view()), name='dynamic-content-home-body'),
+    url("^dynamic-content-page/$",  permission_required('page.can_edit')(DynamicContentPageView.as_view()), name='dynamic-content-page'),
     url("^home/$", HomeView.as_view(), name='organization-home'),
     url("^newsletter/$", NewsletterView.as_view(), name='organization-newsletter'),
 ]
index b7ca516d02261511514ac74406a9fa5d98db5e65..e2bb796dc5f2bed76421e60da42ceda988957cac 100644 (file)
@@ -87,3 +87,26 @@ class DynamicContentHomeBodyView(Select2QuerySetSequenceView):
 class NewsletterView(TemplateView):
 
     template_name = "pages/newsletter.html"
+
+
+class DynamicContentPageView(Select2QuerySetSequenceView):
+
+    def get_queryset(self):
+
+        articles = Article.objects.all()
+        custompage = CustomPage.objects.all()
+        events = Event.objects.all()
+
+        if self.q:
+            articles = articles.filter(title__icontains=self.q)
+            custompage = custompage.filter(title__icontains=self.q)
+            events = events.filter(title__icontains=self.q)
+
+        qs = autocomplete.QuerySetSequence(articles, custompage, events)
+
+        if self.q:
+            qs = qs.filter(title__icontains=self.q)
+
+        qs = self.mixup_querysets(qs)
+
+        return qs
diff --git a/app/templates/core/inc/related_content.html b/app/templates/core/inc/related_content.html
new file mode 100644 (file)
index 0000000..ce869ed
--- /dev/null
@@ -0,0 +1,26 @@
+{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %}
+{% if dynamic_content.all %}
+    <hr class="mt0 mb0" />
+    <div class="white-bg pb2">
+        <div class="container">
+            <div class="row tac">
+                <div class="col-xs-12">
+                    <h2 class="dashed dashed--center mt2">{% trans "Also discover" %}</h2>
+                </div>
+            </div>
+            <div class="row tac">
+                {% for content in dynamic_content %}
+                    {% if content.content_model == "article" %}
+                        <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
+                            {% include 'magazine/article/includes/article_card.html' %}
+                        </div>
+                    {% else %}
+                    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
+                        {% include "core/inc/generic_card.html" %}
+                    </div>
+                    {%endif%}
+                {% endfor %}
+            </div>
+        </div>
+    </div>
+{% endif %}
index 56a5b6d50ecbda31c4ab8ee8b4b9ea7a5c102985..ef0235d85ea8413d9f79fade876183bb5c12e8ee 100644 (file)
   {% endwith %}
 {% endblock %}
 
+{% block page_related_content %}
+    {{ block.super }}
+{% endblock %}
+
 {% block products %}
     {% for page_product_list in page.custompage.product_lists.all %}
       {% with page_product_list.list as list %}
index cc2a3a4a5e916bbcf183c0ec2ce32fbe95f092aa..1b927040ce2798b193563d19405dbb3110fdefb7 100644 (file)
             {% endwith %}
         {% endblock %}
         {% block page_related_content %}
+            {% with page.dynamic_content_pages.all as dynamic_content %}
+                {% include "core/inc/related_content.html" %}
+            {% endwith %}
         {% endblock %}
         {% block related_project %}
         {% endblock %}