]> git.parisson.com Git - mezzo.git/commitdiff
[Actualité] : create view mixing Articles and Medias
authorEmilie <zawadzki@ircam.fr>
Wed, 8 Feb 2017 14:54:38 +0000 (15:54 +0100)
committerEmilie <zawadzki@ircam.fr>
Wed, 8 Feb 2017 14:54:38 +0000 (15:54 +0100)
app/organization/core/templatetags/organization_tags.py
app/organization/magazine/urls.py
app/organization/magazine/views.py
app/templates/magazine/article/article_list.html [new file with mode: 0644]
app/templates/media/media/includes/media_card.html [new file with mode: 0644]

index 155f743f5671e30758dd27ac344150f9a248806c..329e008e12e9eaa6b920a7874e56e0083146b4ef 100644 (file)
@@ -22,6 +22,7 @@
 # -*- coding: utf-8 -*-
 import datetime
 import calendar
+from re import match
 from django.http import QueryDict
 from mezzanine.pages.models import Page
 from mezzanine.blog.models import BlogPost
@@ -29,7 +30,6 @@ from mezzanine.template import Library
 from mezzanine_agenda.models import Event
 from mezzanine.conf import settings
 from random import shuffle
-
 from organization.magazine.models import *
 from organization.projects.models import *
 
@@ -216,3 +216,13 @@ def format_wp(work_packages):
 @register.filter
 def format_percent(percent):
     return str(percent * 100) + ' %'
+
+@register.filter
+def get_media_type(media):
+    mime_type = media.transcoded.first().mime_type
+    media_type = ""
+    if match('video', mime_type):
+        media_type = "Video"
+    elif match('audio', mime_type):
+        media_type = "Audio"
+    return media_type
index 76ace67c40bb4ca68f7dae8b15ce16709fb8273e..78074935f638aab6ac954f1ff4f9624f85da72e4 100644 (file)
@@ -34,6 +34,7 @@ _slash = "/" if settings.APPEND_SLASH else ""
 
 urlpatterns = [
     url("^article/detail/(?P<slug>.*)%s$" % _slash, ArticleDetailView.as_view(), name="magazine-article-detail"),
+    url("^article/list%s$" % _slash, ArticleListView.as_view(), name="magazine-article-list"),
     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 75c710c986f9b19c90111de59e309da9df629680..4c680d0adf48badb73a048734a4cbc8df2291058 100644 (file)
@@ -38,6 +38,7 @@ from organization.network.models import DepartmentPage
 from organization.pages.models import CustomPage, DynamicContentPage
 from organization.core.views import SlugMixin, autocomplete_result_formatting
 from django.template.defaultfilters import slugify
+from itertools import chain
 
 
 class ArticleDetailView(SlugMixin, DetailView):
@@ -177,3 +178,26 @@ class DynamicContentArticleView(Select2QuerySetSequenceView):
     def get_results(self, context):
         results = autocomplete_result_formatting(self, context)
         return results
+
+
+class ArticleListView(SlugMixin, ListView):
+
+    model = Article
+    template_name='magazine/article/article_list.html'
+    context_object_name = 'objects'
+
+    def get_queryset(self):
+        qs = super(ArticleListView, self).get_queryset()
+        qs = qs.filter(status=2)
+        medias = Media.objects.published()
+
+        qs = sorted(
+            chain(qs, medias),
+            key=lambda instance: instance.created,
+            reverse=True)
+
+        return qs
+
+    def get_context_data(self, **kwargs):
+        context = super(ArticleListView, self).get_context_data(**kwargs)
+        return context
diff --git a/app/templates/magazine/article/article_list.html b/app/templates/magazine/article/article_list.html
new file mode 100644 (file)
index 0000000..18e2d3a
--- /dev/null
@@ -0,0 +1,17 @@
+{% extends "base.html" %}
+{% load mezzanine_tags organization_tags %}
+
+{% block main %}
+
+{% for object in objects %}
+    <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
+        {% with app_label=object|app_label_short classname=object|classname|lower  %}
+            {% with app_label|add:"/"|add:classname|add:"/includes/"|add:classname|add:"_card.html" as template %}
+                {% include template %}
+            {% endwith %}
+        {% endwith %}
+    </div>
+{% endfor %}
+{% pagination_for objects %}
+
+{% endblock %}
diff --git a/app/templates/media/media/includes/media_card.html b/app/templates/media/media/includes/media_card.html
new file mode 100644 (file)
index 0000000..e620514
--- /dev/null
@@ -0,0 +1,19 @@
+{% load mezzanine_tags keyword_tags i18n organization_tags staticfiles %}
+
+<div class="">
+    <a class="media-box" href="{% url 'organization-media-detail' object.slug %}">
+        <figure class="media-box__image media-box__image--video">
+            {% if object.poster_url %}
+                <img src="{{ object.poster_url }}">
+            {% else %}
+                <img src="{% static "img/placeholder-media.png" %}">
+            {% endif %}
+        </figure>
+
+        {{ object|get_media_type }}
+        <h2 class="media-box__title">{{ object.title }}</h2>
+        <div class="media-box__desc">
+            {{ object.description|richtext_filters|safe|truncatechars_html:200 }}
+        </div>
+    </a>
+</div>