]> git.parisson.com Git - mezzo.git/commitdiff
Media: dynamic object card
authorEmilie <zawadzki@ircam.fr>
Thu, 3 Nov 2016 10:57:51 +0000 (11:57 +0100)
committerEmilie <zawadzki@ircam.fr>
Thu, 3 Nov 2016 10:57:51 +0000 (11:57 +0100)
15 files changed:
app/organization/media/views.py
app/templates/agenda/event/includes/event_card.html
app/templates/agenda/includes/event_date_line.html
app/templates/agenda/includes/event_metainfo_line.html
app/templates/agenda/includes/event_search.html
app/templates/core/inc/related_content.html
app/templates/core/inc/related_content_media.html
app/templates/festival/artist_detail.html
app/templates/festival/video_detail.html
app/templates/home/inc/body.html
app/templates/magazine/article/includes/article_card.html
app/templates/magazine/topic/topic_detail.html
app/templates/pages/page/includes/page_card.html
app/templates/pages/richtextpage.html
app/templates/projects/project/includes/project_card.html [new file with mode: 0644]

index 88626c7f798556b877f2e074ed0ae2c13f19b4e7..dfdb218ed3fb3eb6952da14e64586879676e76f9 100644 (file)
@@ -6,6 +6,8 @@ from dal import autocomplete
 from dal_select2_queryset_sequence.views import Select2QuerySetSequenceView
 from django.core.exceptions import FieldDoesNotExist
 
+# temporarily excluse not ready models
+EXCLUDED_MODELS = ("organizationplaylist", "personplaylist")
 
 class PlaylistDetailView(SlugMixin, DetailView):
 
@@ -16,22 +18,24 @@ class PlaylistDetailView(SlugMixin, DetailView):
         context = super(PlaylistDetailView, self).get_context_data(**kwargs)
         self.related_objects = []
         self.concrete_objects = []
-
         related_model = PlaylistRelated._meta.get_fields()
         related_playlist = self.object.playlist_related.all()
+
         # get dynamically related objects like articleplaylist, projectplaylist, eventplaylist etc....
         for rm in related_model:
-            for rp in related_playlist:
-                if hasattr(rp, rm.name):
-                    self.related_objects.append(getattr(rp, rm.name))
+            if rm.name not in EXCLUDED_MODELS :
+                for rp in related_playlist:
+                    if hasattr(rp, rm.name):
+                        self.related_objects.append(getattr(rp, rm.name))
 
         # get dynamically related instance of related objects. Example: articleplaylist => article
         for ro in self.related_objects:
             if not isinstance(ro, int) and ro != self.object:
                 for c_field in ro._meta.get_fields():
-                    attr = getattr(ro, c_field.name)
-                    if not isinstance(attr, int) and attr != self.object and not isinstance(attr, PlaylistRelated):
-                        self.concrete_objects.append(attr)
+                    if hasattr(ro, c_field.nam):
+                        attr = getattr(ro, c_field.name)
+                        if not isinstance(attr, int) and attr != self.object and not isinstance(attr, PlaylistRelated):
+                            self.concrete_objects.append(attr)
 
         context['concrete_objects'] = self.concrete_objects
         return context
index 3aff6459b0c49dfee768842c9423dd47d874ede4..9a791ecbf03139955c9c1e513503fa2ea64d141c 100644 (file)
@@ -2,27 +2,27 @@
 {% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
 
 {% block metatitle %}
-    {{ event.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block title %}
-    {{ event.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block url %}
-    {{ event.get_absolute_url }}
+    {{ object.get_absolute_url }}
 {% endblock %}
 
 {% block image %}
-    {% with event.images.all|get_type:'card' as images %}
+    {% with object.images.all|get_type:'card' as images %}
         {% if images %}
             <figure class="article-box__image">
                 <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-original="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 top=0.5 left=article.photo_alignment|get_photo_alignment %}" class="lazyload" />
             </figure>
         {% else %}
             <figure class="article-box__image">
-                {% if event.departments.first %}
-                    {% with event.departments.first as department %}
+                {% if object.departments.first %}
+                    {% with object.departments.first as department %}
                         <div class="article-box__placeholder {{department.department.name|slugify}}"></div>
                     {% endwith %}
                 {% else %}
 
 {% block tags %}
     <div class="article-box__tags">
-        {% if event.departments.first %}
-            {% with event.departments.first as department %}
+        {% if object.departments.first %}
+            {% with object.departments.first as department %}
                 <div class="tag tag--small dashed dashed--small">
                   {{ department.department.name }}
                 </div>
             {% endwith %}
         {% endif %}
-        {% if event.category %}
+        {% if object.category %}
             <div class="tag tag--small tag--category">
-                {{ event.category|truncatechars:15 }}
+                {{ object.category|truncatechars:15 }}
             </div>
         {% endif %}
     </div>
 {% endblock %}
 
 {% block content %}
-    {{ event.description|richtext_filters|safe|truncatechars_html:200 }}
+    {{ object.description|richtext_filters|safe|truncatechars_html:200 }}
 {% endblock %}
 
 {% block subtitle %}
     <strong>
-        {% include 'agenda/includes/event_date_line.html' %}
+        {% include 'agenda/includes/event_date_line.html' with object=event %}
     </strong>
-    {% if event.location %}
-         <br />{{ event.location }}
+    {% if object.location %}
+         <br />{{ object.location }}
     {% endif %}
 {% endblock %}
 
 {% block btn %}
-    {% if event.prices.all.0|floatformat != '0' and event.prices.all|length > 0 %}
-        {% for price in event.prices.all %}
+    {% if object.prices.all.0|floatformat != '0' and object.prices.all|length > 0 %}
+        {% for price in object.prices.all %}
             {% if forloop.first %}
                 <div class="article-box__btn">
                     <object><a href="{% url 'event_booking' content.content_object.slug %}" class="button button--small mr0">{% trans "Reserve" %}</a></object>
index 43a49cb9067d1bfd56b133d8bfc2e61e4374bcd6..82f5fe6eb3b257c359437ebb5ff6eee36f065386 100644 (file)
@@ -1,12 +1,12 @@
 {% load i18n %}
 {% load event_tags %}
 
-{% if event.start and not event.end %}
-    {{ event.start|date:"l j F" }}
+{% if object.start and not object.end %}
+    {{ object.start|date:"l j F" }}
 {% else %}
-    {% if event.start|date:"d.m.y" == event.end|date:"d.m.y" %}
-        {{ event.start|date:"l j F" }}
+    {% if object.start|date:"d.m.y" == object.end|date:"d.m.y" %}
+        {{ object.start|date:"l j F" }}
     {% else %}
-        {{ event.start|date:"j F" }} {% trans "to" %} {{ event.end|date:"j F" }}
+        {{ object.start|date:"j F" }} {% trans "to" %} {{ object.end|date:"j F" }}
     {% endif %}
 {% endif %}
index e73ecb6820db3a248fd06be6e96ab315a477c795..38a9ab3175452bf7e65a8e580d14282658cb8897 100644 (file)
@@ -2,7 +2,7 @@
 
 <div class="page__meta-date">
     <a href="{{ event.get_absolute_url }}">
-        {% include 'agenda/includes/event_date_line.html' %}
+        {% include 'agenda/includes/event_date_line.html' with object=event %}
     </a>
 </div>
 
index a933ff7c2006a1000896659f1dabd3ce13c22de9..1ecdf8cee2cb4886b8d01aa1fcee02b27a82d4ac 100644 (file)
@@ -9,7 +9,7 @@
 
 {% block subtitle %}
     <div class="search-box__subtitle">
-        {% include 'agenda/includes/event_date_line.html' %}
+        {% include 'agenda/includes/event_date_line.html' with object=event %}
         {% if event.prices.all.0|floatformat != '0' and event.prices.all|length > 0 and not is_archive %}
             <a class="button button--small ml1" href="{% url 'event_booking' event.slug %}" class="event__meta__btn">
                 {% trans "Reserve" %}
index 2b87edc765549d9c73c24cda076a38434baccdf6..ff4b14e28bc691205addbb711a013be77db1b28c 100644 (file)
                 {% for content in dynamic_content %}
                     <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
                         {% if content.content_type.model == "article" %}
-                            {% with content.content_object as article %}
-                                {% include "magazine/article/includes/article_card.html" %}
-                            {% endwith %}
+                            {% include "magazine/article/includes/article_card.html" with object=content.content_object  %}
                         {% elif content.content_type.model == "event" %}
-                            {% with content.content_object as event %}
-                                {% include "agenda/event/includes/event_card.html" %}
-                            {% endwith %}
+                            {% include "agenda/event/includes/event_card.html" with object=content.content_object %}
                         {% elif content.content_type.model == "custompage" %}
-                            {% with content.content_object as page %}
-                                {% include "pages/page/sincludes/page_card.html" %}
-                            {% endwith %}
+                            {% include "pages/page/includes/page_card.html" with object=content.content_object %}
                         {% endif %}
                     </div>
                 {% endfor %}
index ffe1c69c513daea57e944f4367e55f1f75638e94..a1236f584c297e779a75ea93ca8dd16d08187e38 100644 (file)
             <div class="row tac">
                 {% for concrete_object in concrete_objects %}
                     <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
-                        {{ concrete_object|app_label_short }}
-                        {% with app_label=concrete_object|app_label_short classname=concrete_object|classname|lower %}
+                        {% with app_label=concrete_object|app_label_short classname=concrete_object|classname|lower object=concrete_object  %}
                             {% with app_label|add:"/"|add:classname|add:"/includes/"|add:classname|add:"_card.html" as template %}
-                                {% include template with classname=concrete_object %}
+                                {% include template %}
                             {% endwith %}
                         {% endwith %}
                     </div>
index 439ce01ba0c70fb1e6e7c360ff65f0eb326459ef..38d7cca9e1535ad0d00b1582f07681344fb6cfa7 100644 (file)
@@ -28,7 +28,7 @@
 <div class="msry__container">
  <div class="msry__sizer"></div>
  {% for event in artist.events.all|no_parents %}
-    {% include 'agenda/event/includes/event_card.html' %}
+    {% include 'agenda/event/includes/event_card.html' with object=event %}
  {% endfor %}
  {% for video in artist.videos.all %}
     {% include 'festival/inc/video_card.html' %}
index 341105ec5f67506292d5f440d9cafc28f5564df8..f2c46b01ccc6f952eed7167a1da733887b4febdc 100644 (file)
   <div class="msry__container">
    <div class="msry__sizer"></div>
     {% with video.event as event %}
-        {% include 'agenda/event/includes/event_card.html' %}
-    {% for artist in video.artists.all %}
-        {% include "festival/inc/artist_card.html" %}
-    {% endfor %}
-    {% for v in event.videos.all %}
-      {% if v != video %}
-       {% with v as video %}
-        {% include 'festival/inc/video_card.html' %}
-       {% endwith %}
-      {% endif %}
-    {% endfor %}
-    {% for post in event.blog_posts.all %}
-        {% include 'blog/includes/post_card.html' %}
-    {% endfor %}
+        {% include 'agenda/event/includes/event_card.html' with object=event %}
+        {% for artist in video.artists.all %}
+            {% include "festival/inc/artist_card.html" %}
+        {% endfor %}
+        {% for v in event.videos.all %}
+          {% if v != video %}
+           {% with v as video %}
+            {% include 'festival/inc/video_card.html' %}
+           {% endwith %}
+          {% endif %}
+        {% endfor %}
+        {% for post in event.blog_posts.all %}
+            {% include 'blog/includes/post_card.html' %}
+        {% endfor %}
     {% endwith %}
 
 </div>
index f5b462f71132dbce7b3d0448f58a973f0163d0fb..5942ea92825165925d24aecc5a347b38d6e2fc56 100644 (file)
@@ -8,17 +8,11 @@
                         {% if slider.content_type.model == "brief" %}
                             {% include "magazine/brief/inc/brief_card.html" %}
                         {% elif slider.content_type.model == "article" %}
-                            {% with slider.content_object as article %}
-                                {% include "magazine/article/includes/article_card.html" %}
-                            {% endwith %}
+                            {% include "magazine/article/includes/article_card.html" with object=slider.content_object %}
                         {% elif slider.content_type.model == "event" %}
-                            {% with slider.content_object as event %}
-                                {% include "agenda/event/includes/event_card.html" %}
-                            {% endwith %}
+                            {% include "agenda/event/includes/event_card.html" with object=slider.content_object %}
                         {% elif slider.content_type.model == "custompage" %}
-                            {% with slider.content_object as page %}
-                                {% include "pages/page/includes/page_card.html" %}
-                            {% endwith %}
+                            {% include "pages/page/includes/page_card.html" with object=slider.content_object %}
                         {% endif %}
                     </div>
                 {% endif %}
                 {% if content.content_type.model == "brief" %}
                     {% include "magazine/brief/inc/brief_card.html" %}
                 {% elif content.content_type.model == "article" %}
-                    {% with content.content_object as article %}
-                        {% include "magazine/article/includes/article_card.html" %}
-                    {% endwith %}
+                    {% include "magazine/article/includes/article_card.html" with object=content.content_object %}
                 {% elif content.content_type.model == "event" %}
-                    {% with content.content_object as event %}
-                        {% include "agenda/event/includes/event_card.html" %}
-                    {% endwith %}
+                    {% include "agenda/event/includes/event_card.html" with object=content.content_object %}
                 {% elif content.content_type.model == "custompage" %}
-                    {% with content.content_object as page %}
-                        {% include "pages/page/includes/page_card.html" %}
-                    {% endwith %}
+                    {% include "pages/page/includes/page_card.html" with  object=content.content_object %}
                 {% endif %}
             </div>
         {% endfor %}
index 89db81d27951eadb6f781e854f919722a033a308..3e3e111fcf457f693ee21e3078bd9c5da75e3bad 100644 (file)
@@ -2,35 +2,35 @@
 {% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
 
 {% block metatitle %}
-    {{ article.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block title %}
-    {{ article.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block url %}
-  {% if article.content|removetags:"p"|slice:':4' == 'http' %}
-    {{ article.content|removetags:"p" }}
+  {% if object.content|removetags:"p"|slice:':4' == 'http' %}
+    {{ object.content|removetags:"p" }}
   {% else %}
-    {% url 'magazine-article-detail' article.slug %}
+    {% url 'magazine-article-detail' object.slug %}
   {% endif %}
 {% endblock %}
 
 {% block target %}
-  {% if article.content|removetags:"p"|slice:':4' == 'http' %}target="_blank"{% endif %}
+  {% if object.content|removetags:"p"|slice:':4' == 'http' %}target="_blank"{% endif %}
 {% endblock %}
 
 {% block image %}
-    {% with article.images.all|get_type:'card' as images %}
+    {% with object.images.all|get_type:'card' as images %}
         {% if images %}
             <figure class="article-box__image">
-                <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-original="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 top=0.5 left=article.photo_alignment|get_photo_alignment %}" class="lazyload" />
+                <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-original="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 top=0.5 left=object.photo_alignment|get_photo_alignment %}" class="lazyload" />
             </figure>
         {% else %}
             <figure class="article-box__image">
-                {% if article.department %}
-                    <div class="article-box__placeholder {{article.department.name|slugify}}"></div>
+                {% if object.department %}
+                    <div class="article-box__placeholder {{object.department.name|slugify}}"></div>
                 {% else %}
                     <div class="article-box__placeholder"></div>
                 {% endif %}
         <div class="tag tag--small tag--category">
             {% trans 'News' %}
         </div>
-        {% if article.department %}
+        {% if object.department %}
             <div class="tag tag--small dashed dashed--gray dashed--small">
-              {{ article.department.name }}
+              {{ object.department.name }}
             </div>
         {% endif %}
     </div>
 {% endblock %}
 
 {% block content %}
-    {{ article.description|richtext_filters|safe|truncatechars_html:200 }}
+    {{ object.description|richtext_filters|safe|truncatechars_html:200 }}
 {% endblock %}
 
 {% block subtitle %}
-    {{ article.publish_date|date:"DATE_FORMAT" }}
-    {% for category in article.categories.all %}
+    {{ object.publish_date|date:"DATE_FORMAT" }}
+    {% for category in object.categories.all %}
         {% if forloop.first %} | {% endif %}
         {% if not forloop.first %}, {% endif %}
         <strong>{{ category }}</strong>
index b9f485048e701efb63915de8615b8a6eaba47230..5bcaaf97702f261fba5a5dff2c08e201947b93f9 100644 (file)
@@ -63,7 +63,7 @@
         <div class="row">
             {% for article in articles %}
                 <div class="col-lg-3 col-md-4 col-sm-4 col-xs-6">
-                    {% include 'magazine/article/includes/article_card.html' %}
+                    {% include 'magazine/article/includes/article_card.html' with object=article %}
                 </div>
             {% endfor %}
         </div>
index 94e426f47dbfcbdeb867da285b94fe5d3dfab2dd..ef64bbd6cf4135941d26e1852095e440f5a15a78 100644 (file)
@@ -2,18 +2,18 @@
 {% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
 
 {% block metatitle %}
-    {{ page.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block title %}
-    {{ page.title }}
+    {{ object.title }}
 {% endblock %}
 
 {% block url %}
-    {{ page.get_absolute_url }}
+    {{ object.get_absolute_url }}
 {% endblock %}
 {% block image %}
-    {% with page.images.all|get_type:'card' as images %}
+    {% with object.images.all|get_type:'card' as images %}
         {% if images %}
             <figure class="article-box__image">
                 <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-original="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 top=0.5 left=article.photo_alignment|get_photo_alignment %}" class="lazyload" />
@@ -23,9 +23,9 @@
 {% endblock %}
 
 {% block content %}
-    {{ page.description|richtext_filters|safe|truncatechars_html:200 }}
+    {{ object.description|richtext_filters|safe|truncatechars_html:200 }}
 {% endblock %}
 
 {% block subtitle %}
-    {{ page.sub_title }}
+    {{ object.sub_title }}
 {% endblock %}
index 5f7953b1c0f9901af6abaa628324e4bf9b5db2a0..31a96068df69f4cd743449bbdafdda2346974e19 100644 (file)
@@ -18,7 +18,7 @@
 <div class="msry__container">
  <div class="msry__sizer"></div>
   {% for event in page.featured.all.0.events.all %}
-   {% include 'agenda/event/includes/event_card.html' %}
+   {% include 'agenda/event/includes/event_card.html' with object=event %}
   {% endfor %}
 </div>
 {% endif %}
diff --git a/app/templates/projects/project/includes/project_card.html b/app/templates/projects/project/includes/project_card.html
new file mode 100644 (file)
index 0000000..ef64bbd
--- /dev/null
@@ -0,0 +1,31 @@
+{% extends "core/inc/generic_card.html" %}
+{% load i18n pages_tags mezzanine_tags media_tags organization_tags %}
+
+{% block metatitle %}
+    {{ object.title }}
+{% endblock %}
+
+{% block title %}
+    {{ object.title }}
+{% endblock %}
+
+{% block url %}
+    {{ object.get_absolute_url }}
+{% endblock %}
+{% block image %}
+    {% with object.images.all|get_type:'card' as images %}
+        {% if images %}
+            <figure class="article-box__image">
+                <img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-original="{{ MEDIA_URL }}{% thumbnail images.0.file 427 286 top=0.5 left=article.photo_alignment|get_photo_alignment %}" class="lazyload" />
+            </figure>
+        {% endif %}
+    {% endwith %}
+{% endblock %}
+
+{% block content %}
+    {{ object.description|richtext_filters|safe|truncatechars_html:200 }}
+{% endblock %}
+
+{% block subtitle %}
+    {{ object.sub_title }}
+{% endblock %}