From 4821d5e49ddad6ac57959970250c036a34825680 Mon Sep 17 00:00:00 2001 From: Emilie Date: Thu, 3 Nov 2016 11:57:51 +0100 Subject: [PATCH] Media: dynamic object card --- app/organization/media/views.py | 18 +++++++---- .../agenda/event/includes/event_card.html | 32 +++++++++---------- .../agenda/includes/event_date_line.html | 10 +++--- .../agenda/includes/event_metainfo_line.html | 2 +- .../agenda/includes/event_search.html | 2 +- app/templates/core/inc/related_content.html | 12 ++----- .../core/inc/related_content_media.html | 5 ++- app/templates/festival/artist_detail.html | 2 +- app/templates/festival/video_detail.html | 28 ++++++++-------- app/templates/home/inc/body.html | 24 ++++---------- .../article/includes/article_card.html | 30 ++++++++--------- .../magazine/topic/topic_detail.html | 2 +- .../pages/page/includes/page_card.html | 12 +++---- app/templates/pages/richtextpage.html | 2 +- .../project/includes/project_card.html | 31 ++++++++++++++++++ 15 files changed, 114 insertions(+), 98 deletions(-) create mode 100644 app/templates/projects/project/includes/project_card.html diff --git a/app/organization/media/views.py b/app/organization/media/views.py index 88626c7f..dfdb218e 100644 --- a/app/organization/media/views.py +++ b/app/organization/media/views.py @@ -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 diff --git a/app/templates/agenda/event/includes/event_card.html b/app/templates/agenda/event/includes/event_card.html index 3aff6459..9a791ecb 100644 --- a/app/templates/agenda/event/includes/event_card.html +++ b/app/templates/agenda/event/includes/event_card.html @@ -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 %}
{% else %}
- {% if event.departments.first %} - {% with event.departments.first as department %} + {% if object.departments.first %} + {% with object.departments.first as department %}
{% endwith %} {% else %} @@ -35,37 +35,37 @@ {% block tags %}
- {% if event.departments.first %} - {% with event.departments.first as department %} + {% if object.departments.first %} + {% with object.departments.first as department %}
{{ department.department.name }}
{% endwith %} {% endif %} - {% if event.category %} + {% if object.category %}
- {{ event.category|truncatechars:15 }} + {{ object.category|truncatechars:15 }}
{% endif %}
{% endblock %} {% block content %} - {{ event.description|richtext_filters|safe|truncatechars_html:200 }} + {{ object.description|richtext_filters|safe|truncatechars_html:200 }} {% endblock %} {% block subtitle %} - {% include 'agenda/includes/event_date_line.html' %} + {% include 'agenda/includes/event_date_line.html' with object=event %} - {% if event.location %} -
{{ event.location }} + {% if object.location %} +
{{ 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 %}
{% trans "Reserve" %} diff --git a/app/templates/agenda/includes/event_date_line.html b/app/templates/agenda/includes/event_date_line.html index 43a49cb9..82f5fe6e 100644 --- a/app/templates/agenda/includes/event_date_line.html +++ b/app/templates/agenda/includes/event_date_line.html @@ -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 %} diff --git a/app/templates/agenda/includes/event_metainfo_line.html b/app/templates/agenda/includes/event_metainfo_line.html index e73ecb68..38a9ab31 100644 --- a/app/templates/agenda/includes/event_metainfo_line.html +++ b/app/templates/agenda/includes/event_metainfo_line.html @@ -2,7 +2,7 @@ diff --git a/app/templates/agenda/includes/event_search.html b/app/templates/agenda/includes/event_search.html index a933ff7c..1ecdf8ce 100644 --- a/app/templates/agenda/includes/event_search.html +++ b/app/templates/agenda/includes/event_search.html @@ -9,7 +9,7 @@ {% block 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 %} {% trans "Reserve" %} diff --git a/app/templates/core/inc/related_content.html b/app/templates/core/inc/related_content.html index 2b87edc7..ff4b14e2 100644 --- a/app/templates/core/inc/related_content.html +++ b/app/templates/core/inc/related_content.html @@ -12,17 +12,11 @@ {% for content in dynamic_content %}
{% 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 %}
{% endfor %} diff --git a/app/templates/core/inc/related_content_media.html b/app/templates/core/inc/related_content_media.html index ffe1c69c..a1236f58 100644 --- a/app/templates/core/inc/related_content_media.html +++ b/app/templates/core/inc/related_content_media.html @@ -11,10 +11,9 @@
{% for concrete_object in concrete_objects %}
- {{ 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 %}
diff --git a/app/templates/festival/artist_detail.html b/app/templates/festival/artist_detail.html index 439ce01b..38d7cca9 100644 --- a/app/templates/festival/artist_detail.html +++ b/app/templates/festival/artist_detail.html @@ -28,7 +28,7 @@
{% 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' %} diff --git a/app/templates/festival/video_detail.html b/app/templates/festival/video_detail.html index 341105ec..f2c46b01 100644 --- a/app/templates/festival/video_detail.html +++ b/app/templates/festival/video_detail.html @@ -29,20 +29,20 @@
{% 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 %}
diff --git a/app/templates/home/inc/body.html b/app/templates/home/inc/body.html index f5b462f7..5942ea92 100644 --- a/app/templates/home/inc/body.html +++ b/app/templates/home/inc/body.html @@ -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 %}
{% endif %} @@ -29,17 +23,11 @@ {% 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 %}
{% endfor %} diff --git a/app/templates/magazine/article/includes/article_card.html b/app/templates/magazine/article/includes/article_card.html index 89db81d2..3e3e111f 100644 --- a/app/templates/magazine/article/includes/article_card.html +++ b/app/templates/magazine/article/includes/article_card.html @@ -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 %}
- +
{% else %}
- {% if article.department %} -
+ {% if object.department %} +
{% else %}
{% endif %} @@ -44,21 +44,21 @@
{% trans 'News' %}
- {% if article.department %} + {% if object.department %}
- {{ article.department.name }} + {{ object.department.name }}
{% endif %}
{% 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 %} {{ category }} diff --git a/app/templates/magazine/topic/topic_detail.html b/app/templates/magazine/topic/topic_detail.html index b9f48504..5bcaaf97 100644 --- a/app/templates/magazine/topic/topic_detail.html +++ b/app/templates/magazine/topic/topic_detail.html @@ -63,7 +63,7 @@
{% for article in articles %}
- {% include 'magazine/article/includes/article_card.html' %} + {% include 'magazine/article/includes/article_card.html' with object=article %}
{% endfor %}
diff --git a/app/templates/pages/page/includes/page_card.html b/app/templates/pages/page/includes/page_card.html index 94e426f4..ef64bbd6 100644 --- a/app/templates/pages/page/includes/page_card.html +++ b/app/templates/pages/page/includes/page_card.html @@ -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 %}
@@ -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 %} diff --git a/app/templates/pages/richtextpage.html b/app/templates/pages/richtextpage.html index 5f7953b1..31a96068 100644 --- a/app/templates/pages/richtextpage.html +++ b/app/templates/pages/richtextpage.html @@ -18,7 +18,7 @@
{% 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 %}
{% 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 index 00000000..ef64bbd6 --- /dev/null +++ b/app/templates/projects/project/includes/project_card.html @@ -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 %} +
+ +
+ {% endif %} + {% endwith %} +{% endblock %} + +{% block content %} + {{ object.description|richtext_filters|safe|truncatechars_html:200 }} +{% endblock %} + +{% block subtitle %} + {{ object.sub_title }} +{% endblock %} -- 2.39.5