]> git.parisson.com Git - mezzo.git/commitdiff
Article [WIP]: add related Article and Event | generalizing card template
authorEmilie <zawadzki@ircam.fr>
Fri, 23 Sep 2016 16:53:02 +0000 (18:53 +0200)
committerEmilie <zawadzki@ircam.fr>
Fri, 23 Sep 2016 16:53:02 +0000 (18:53 +0200)
15 files changed:
app/organization/magazine/admin.py
app/organization/magazine/forms.py
app/organization/magazine/migrations/0004_dynamiccontentarticle.py [new file with mode: 0644]
app/organization/magazine/migrations/0005_auto_20160923_1821.py [new file with mode: 0644]
app/organization/magazine/models.py
app/organization/magazine/translation.py
app/organization/magazine/urls.py
app/organization/magazine/views.py
app/templates/core/inc/generic_card.html [new file with mode: 0644]
app/templates/home/inc/body.html
app/templates/home/inc/brief_card.html [deleted file]
app/templates/home/inc/generic_card.html [deleted file]
app/templates/magazine/article/article_detail.html
app/templates/magazine/brief/inc/brief_card.html [new file with mode: 0644]
app/templates/magazine/topic/topic_detail.html

index 2499e922dfca9559823eaf2d8cbb229a6eba8fa9..1891bc318e473eda8b516ca7e7254b5837302200 100644 (file)
@@ -3,9 +3,8 @@ from django import forms
 from copy import deepcopy
 from mezzanine.core.admin import *
 from mezzanine.pages.admin import PageAdmin
-#from orderable.admin import OrderableTabularInline #OrderableAdmin,
-from organization.magazine.models import Article, Brief, Topic, ArticleImage, ArticlePersonListBlockInline
-from organization.magazine.forms import BriefForm, ArticlePersonListForm
+from organization.magazine.models import *
+from organization.magazine.forms import *
 
 
 class ArticleImageInline(TabularDynamicInlineAdmin):
@@ -24,12 +23,25 @@ class ArticlePersonAutocompleteInlineAdmin(TabularDynamicInlineAdmin):
     form = ArticlePersonListForm
 
 
+class DynamicContentArticleInline(TabularDynamicInlineAdmin):
+
+    model = DynamicContentArticle
+    form = DynamicContentArticleForm
+
+    class Media:
+        js = (
+            static("mezzanine/js/admin/dynamic_inline.js"),
+        )
+
+
 class ArticleAdminDisplayable(DisplayableAdmin):
 
     fieldsets = deepcopy(ArticleAdmin.fieldsets)
     exclude = ('related_posts',)
     filter_horizontal = ['categories', 'related_articles', ]
-    inlines = [ArticleImageInline, ArticlePersonAutocompleteInlineAdmin]
+    inlines = [ArticleImageInline,
+              ArticlePersonAutocompleteInlineAdmin,
+              DynamicContentArticleInline]
 
 
 class BriefAdmin(admin.ModelAdmin): #OrderableTabularInline
index 1a316d2bada12278606df66b7bf043fd6b1ac124..5f5e6392762d368ea08e0708851e6815a925017e 100644 (file)
@@ -2,7 +2,7 @@ from dal import autocomplete
 import dal_queryset_sequence
 import dal_select2_queryset_sequence
 from django import forms
-from organization.magazine.models import Article, Topic, Brief, ArticlePersonListBlockInline
+from organization.magazine.models import *
 from organization.pages.models import CustomPage
 from organization.network.models import PersonListBlock
 from mezzanine_agenda.models import Event
@@ -34,3 +34,19 @@ class ArticlePersonListForm(forms.ModelForm):
     class Meta:
         model = ArticlePersonListBlockInline
         fields = ('person_list_block',)
+
+
+class DynamicContentArticleForm(autocomplete.FutureModelForm):
+
+    content_object = dal_queryset_sequence.fields.QuerySetSequenceModelField(
+        queryset=autocomplete.QuerySetSequence(
+            Article.objects.all(),
+            Event.objects.all()
+        ),
+        required=False,
+        widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-article'),
+    )
+
+    class Meta:
+        model = DynamicContentArticle
+        fields = ('content_object',)
diff --git a/app/organization/magazine/migrations/0004_dynamiccontentarticle.py b/app/organization/magazine/migrations/0004_dynamiccontentarticle.py
new file mode 100644 (file)
index 0000000..c4a4215
--- /dev/null
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-23 16:03
+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'),
+        ('organization-magazine', '0003_articlepersonlistblockinline'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='DynamicContentArticle',
+            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')),
+                ('article', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='organization-magazine.Article', verbose_name='article')),
+                ('content_type', models.ForeignKey(blank=True, editable=False, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType', verbose_name='content type')),
+            ],
+            options={
+                'verbose_name': 'Dynamic Content Article',
+                'ordering': ('_order',),
+            },
+        ),
+    ]
diff --git a/app/organization/magazine/migrations/0005_auto_20160923_1821.py b/app/organization/magazine/migrations/0005_auto_20160923_1821.py
new file mode 100644 (file)
index 0000000..55f1811
--- /dev/null
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.7 on 2016-09-23 16:21
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('organization-magazine', '0004_dynamiccontentarticle'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='dynamiccontentarticle',
+            name='article',
+            field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='dynamic_content_articles', to='organization-magazine.Article', verbose_name='article'),
+        ),
+    ]
index 12cf3762f9041704d2a313ba2d7452e79ef50aff..d9276b2626e3ce16df20a1a323b5fb9f9f14f91e 100644 (file)
@@ -85,3 +85,11 @@ class ArticlePersonListBlockInline(Titled):
 
     def __str__(self):
         return self.title
+
+
+class DynamicContentArticle(DynamicContent, Orderable):
+
+    article = models.ForeignKey(Article, verbose_name=_('article'), related_name='dynamic_content_articles', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = 'Dynamic Content Article'
index c030a31d334b54a735690489006ba523706f85b9..4e57c4e0cfc1b837ca38f07be7803e9947cec26e 100644 (file)
@@ -4,11 +4,8 @@ from modeltranslation.translator import TranslationOptions
 from mezzanine.core.translation import (TranslatedSlugged,
                                         TranslatedDisplayable,
                                         TranslatedRichText)
-from organization.magazine.models import (Article,
-                                          Topic,
-                                          Brief,
-                                          ArticleImage,
-                                          ArticlePersonListBlockInline)
+from organization.magazine.models import *
+
 
 @register(Article)
 class ArticleTranslationOptions(TranslationOptions):
@@ -38,3 +35,9 @@ class ArticleImageTranslationOptions(TranslationOptions):
 class ArticlePersonListBlockInlineTranslationOptions(TranslationOptions):
 
     pass
+
+
+@register(DynamicContentArticle)
+class DynamicContentArticleTranslationOptions(TranslationOptions):
+
+    pass
index 4f188b6781b5bb64cde0a4ec856596e853bb8fa5..13cb07292d9ff7fdc5f5346fc12d554f1e7b262e 100644 (file)
@@ -16,4 +16,5 @@ urlpatterns = [
     url("^article/detail/(?P<slug>.*)%s$" % _slash, ArticleDetailView.as_view(), name="magazine-article-detail"),
     url("^topic/detail/(?P<slug>.*)%s$" % _slash, TopicDetailView.as_view(), name='topic-detail'),
     url("^object-autocomplete/$", ObjectAutocomplete.as_view(), name='object-autocomplete'),
+    url("^dynamic-content-article/$",  DynamicContentArticleView.as_view(), name='dynamic-content-article'),
 ]
index 29c2f01070a6b5b3c0070d86198c08d2a1a9bbc9..cded9354e443faee9d0dae724f4532c5000a3bd8 100644 (file)
@@ -106,3 +106,26 @@ class ObjectAutocomplete(Select2QuerySetSequenceView):
         qs = self.mixup_querysets(qs)
 
         return qs
+
+
+class DynamicContentArticleView(Select2QuerySetSequenceView):
+    def get_queryset(self):
+
+        articles = Article.objects.all()
+        events = Event.objects.all()
+
+        if self.q:
+            articles = articles.filter(title__icontains=self.q)
+            events = events.filter(title__icontains=self.q)
+
+        qs = autocomplete.QuerySetSequence(articles, events )
+
+        if self.q:
+            # This would apply the filter on all the querysets
+            qs = qs.filter(title__icontains=self.q)
+
+        # This will limit each queryset so that they show an equal number
+        # of results.
+        qs = self.mixup_querysets(qs)
+
+        return qs
diff --git a/app/templates/core/inc/generic_card.html b/app/templates/core/inc/generic_card.html
new file mode 100644 (file)
index 0000000..3cd9915
--- /dev/null
@@ -0,0 +1,70 @@
+{% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
+
+<a class="article-box" href="{{ content.content_object.get_absolute_url }}" title="{{ content.content_object.title }}">
+    <div class="article-box__header">
+        <figure class="article-box__image">
+            {% with content.content_object.images.all|get_type:'card' as image %}
+                {% if image %}
+                    <img src="{{ MEDIA_URL }}{% thumbnail image.first.file 427 286 %}" data-src="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 %}" class="lazyload" alt="" />
+                {% endif %}
+            {% endwith %}
+        </figure>
+        {% if content.content_type.model == 'article' %}
+            <div class="article-box__tags">
+                <div class="tag tag--small tag--category">
+                    {% trans 'News' %}
+                </div>
+                {% if content.content_object.department %}
+                    <div class="tag tag--small dashed dashed--gray">
+                      {{ content.content_object.department.name }}
+                    </div>
+                {% endif %}
+            </div>
+        {% elif content.content_type.model == 'event' %}
+        <div class="article-box__tags">
+            {% if content.content_object.departments.first %}
+                {% with content.content_object.departments.first as department %}
+                    <div class="tag tag--small dashed">
+                      {{ department.department.name }}
+                    </div>
+                {% endwith %}
+            {% endif %}
+            {% if content.content_object.category %}
+                <div class="tag tag--small tag--category">
+                    {{ content.content_object.category }}
+                </div>
+            {% endif %}
+        </div>
+        {% endif %}
+    </div>
+
+    <div class="article-box__content tal">
+        <h3 class="article-box__title">{{ content.content_object.title }}</h3>
+        <div class="article-box__subtitle">
+            {% if content.content_type.model == 'article' %}
+                {{ content.content_object.publish_date|date:"DATE_FORMAT" }}
+                {% for category in content.content_object.categories.all %}
+                    {% if forloop.first %} | {% endif %}
+                    {% if not forloop.first %}, {% endif %}
+                    <strong>{{ category }}</strong>
+                {% endfor %}
+            {% elif content.content_type.model == 'event' %}
+                {% if content.content_object.start %}
+                    {% if content.content_object.end %}
+                        {% trans "From" %}
+                    {% endif %}
+                    {{ content.content_object.start|date:"DATE_FORMAT" }}
+                    {% if content.content_object.end %}
+                        {% trans "to" %} {{ content.content_object.end|date:"DATE_FORMAT" }}
+                    {% endif %}
+                {% endif %}
+                {% if content.content_object.location %}
+                     <br /><strong>{{ content.content_object.location }}</strong>
+                {% endif %}
+            {% endif %}
+        </div>
+        <div class="article-box__desc">
+             {{ content.content_object.description|richtext_filters|safe|truncatechars_html:200 }}
+        </div>
+    </div>
+</a>
index 5bcfdfa4419ea24740b537f6cc56a8bb529b689b..dc977b146cd0aca73da310bc7f4d93d2749d8fa9 100644 (file)
@@ -1,11 +1,11 @@
 <div class="container">
     <div class="row">
-        {% for body in home.dynamiccontenthomebody_set.all %}
+        {% for content in home.dynamiccontenthomebody_set.all %}
             <div class="col-xs-4">
-                {% if body.content_type.model == "brief" %}
-                    {% include "home/inc/brief_card.html" %}
+                {% if content.content_type.model == "brief" %}
+                    {% include "magazine/brief/inc/brief_card.html" %}
                 {% else %}
-                    {% include "home/inc/generic_card.html" %}
+                    {% include "core/inc/generic_card.html" %}
                 {% endif %}
             </div>
         {% endfor %}
diff --git a/app/templates/home/inc/brief_card.html b/app/templates/home/inc/brief_card.html
deleted file mode 100644 (file)
index e9b6626..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-{% load i18n %}
-
-<div class="brief-box">
-
-    <div class="brief-box__head">
-        {% trans 'Brief !' %}
-    </div>
-
-    <h3 class="brief-box__title">{{ body.content_object.title }}</h3>
-    <div class="brief-box__desc">
-        {{ body.content_object.description|slice:":500" }}
-    </div>
-    {% if body.content_object.external_content %}
-        <a class="brief-box__button" href="{{ body.content_object.external_content }}" title="{{ body.content_object.text_button }}">{{ body.content_object.text_button }}</a>
-    {% elif body.content_object.content_object %}
-        <a class="brief-box__button" href="{{ body.content_object.content_object.get_absolute_url }}" title="{{ body.content_object.text_button }}">{{ body.content_object.text_button }}</a>
-    {% else %}
-        <a class="brief-box__button" href="{{ body.content_object.get_absolute_url }}" title="{{ body.content_object.title }}">{{ body.content_object.title }}</a>
-    {% endif %}
-
-</div>
diff --git a/app/templates/home/inc/generic_card.html b/app/templates/home/inc/generic_card.html
deleted file mode 100644 (file)
index 9a4f6cb..0000000
+++ /dev/null
@@ -1,70 +0,0 @@
-{% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
-
-<a class="article-box" href="{{ body.content_object.get_absolute_url }}" title="{{ body.content_object.title }}">
-    <div class="article-box__header">
-        <figure class="article-box__image">
-            {% with body.content_object.images.all|get_type:'card' as image %}
-                {% if image %}
-                    <img src="{{ MEDIA_URL }}{% thumbnail image.first.file 427 286 %}" data-src="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 %}" class="lazyload" alt="" />
-                {% endif %}
-            {% endwith %}
-        </figure>
-        {% if body.content_type.model == 'article' %}
-            <div class="article-box__tags">
-                <div class="tag tag--small tag--category">
-                    {% trans 'News' %}
-                </div>
-                {% if body.content_object.department %}
-                    <div class="tag tag--small dashed dashed--gray">
-                      {{ body.content_object.department.name }}
-                    </div>
-                {% endif %}
-            </div>
-        {% elif body.content_type.model == 'event' %}
-        <div class="article-box__tags">
-            {% if body.content_object.departments.first %}
-                {% with body.content_object.departments.first as department %}
-                    <div class="tag tag--small dashed">
-                      {{ department.department.name }}
-                    </div>
-                {% endwith %}
-            {% endif %}
-            {% if body.content_object.category %}
-                <div class="tag tag--small tag--category">
-                    {{ body.content_object.category }}
-                </div>
-            {% endif %}
-        </div>
-        {% endif %}
-    </div>
-
-    <div class="article-box__content tal">
-        <h3 class="article-box__title">{{ body.content_object.title }}</h3>
-        <div class="article-box__subtitle">
-            {% if body.content_type.model == 'article' %}
-                {{ body.content_object.publish_date|date:"DATE_FORMAT" }}
-                {% for category in body.content_object.categories.all %}
-                    {% if forloop.first %} | {% endif %}
-                    {% if not forloop.first %}, {% endif %}
-                    <strong>{{ category }}</strong>
-                {% endfor %}
-            {% elif body.content_type.model == 'event' %}
-                {% if body.content_object.start %}
-                    {% if body.content_object.end %}
-                        {% trans "From" %}
-                    {% endif %}
-                    {{ body.content_object.start|date:"DATE_FORMAT" }}
-                    {% if body.content_object.end %}
-                        {% trans "to" %} {{ body.content_object.end|date:"DATE_FORMAT" }}
-                    {% endif %}
-                {% endif %}
-                {% if body.content_object.location %}
-                     <br /><strong>{{ body.content_object.location }}</strong>
-                {% endif %}
-            {% endif %}
-        </div>
-        <div class="article-box__desc">
-             {{ body.content_object.description|richtext_filters|safe|truncatechars_html:200 }}
-        </div>
-    </div>
-</a>
index 4b7f16e42af016d4a1c1789178b80d321f546080..8d0941ed2def132d2520176a6bdb448715d961cb 100644 (file)
     {% endfor %}
 {% endblock %}
 
-
 {% block page_related_content %}
-
-    {% if article.related_articles.all %}
-
+    {% if article.dynamic_content_articles.all %}
         <hr class="mt0 mb0" />
         <div class="white-bg pb2">
             <div class="container">
                     </div>
                 </div>
                 <div class="row tac">
-                    {% for article in article.related_articles.all %}
+                    {% for content in article.dynamic_content_articles.all %}
+                        {% 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 'magazine/article/includes/article_card.html' %}
+                            {% include "core/inc/generic_card.html" %}
                         </div>
+                        {%endif%}
                     {% endfor %}
                 </div>
             </div>
         </div>
-
     {% endif %}
-
 {% endblock %}
 
 {% block page_sidebar %}
diff --git a/app/templates/magazine/brief/inc/brief_card.html b/app/templates/magazine/brief/inc/brief_card.html
new file mode 100644 (file)
index 0000000..ce0b038
--- /dev/null
@@ -0,0 +1,21 @@
+{% load i18n %}
+
+<div class="brief-box">
+
+    <div class="brief-box__head">
+        {% trans 'Brief !' %}
+    </div>
+
+    <h3 class="brief-box__title">{{content.content_object.title }}</h3>
+    <div class="brief-box__desc">
+        {{content.content_object.description|slice:":500" }}
+    </div>
+    {% if content.content_object.external_content %}
+        <a class="brief-box__button" href="{{ content.content_object.external_content }}" title="{{ content.content_object.text_button }}">{{ content.content_object.text_button }}</a>
+    {% elif content.content_object.content_object %}
+        <a class="brief-box__button" href="{{ content.content_object.content_object.get_absolute_url }}" title="{{ content.content_object.text_button }}">{{ content.content_object.text_button }}</a>
+    {% else %}
+        <a class="brief-box__button" href="{{ content.content_object.get_absolute_url }}" title="{{ content.content_object.title }}">{{ content.content_object.title }}</a>
+    {% endif %}
+
+</div>
index dcd45d06ffde8dacbd9dfbc68760e604cd63537f..b9f485048e701efb63915de8615b8a6eaba47230 100644 (file)
@@ -70,5 +70,5 @@
     </div>
 
     {% pagination_for articles %}
-    
+
 {% endblock %}