From: Emilie Date: Wed, 2 Nov 2016 18:09:24 +0000 (+0100) Subject: Media : get related FK dynamically, need to set dynamically context object name X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=169bd3f02cf4e482f7b5e02c3bda086e5c28c169;p=mezzo.git Media : get related FK dynamically, need to set dynamically context object name --- diff --git a/app/organization/core/templatetags/organization_tags.py b/app/organization/core/templatetags/organization_tags.py index 683e37e9..0fe1784f 100644 --- a/app/organization/core/templatetags/organization_tags.py +++ b/app/organization/core/templatetags/organization_tags.py @@ -119,3 +119,19 @@ def sub_topics(topic): @register.filter def classname(obj): return obj.__class__.__name__ + + +@register.filter +def classname(obj): + return obj.__class__.__name__ + +@register.filter +def app_label_short(obj): + app_label = obj._meta.app_config.label + if app_label.find("_") > 0: + app_label_short = app_label.split("_")[1] + elif app_label.find("-") > 0: + app_label_short = app_label.split("-")[1] + else : + app_label_short = app_label + return app_label_short diff --git a/app/organization/media/views.py b/app/organization/media/views.py index 95358fba..88626c7f 100644 --- a/app/organization/media/views.py +++ b/app/organization/media/views.py @@ -12,18 +12,28 @@ class PlaylistDetailView(SlugMixin, DetailView): model = Playlist template_name='media/playlist_detail.html' context_object_name = 'playlist' - def get_context_data(self, **kwargs): - self.related_objects = [] 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)) - context['related_objects'] = self.related_objects + # 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) + + 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 new file mode 100644 index 00000000..3aff6459 --- /dev/null +++ b/app/templates/agenda/event/includes/event_card.html @@ -0,0 +1,76 @@ +{% extends "core/inc/generic_card.html" %} +{% load i18n pages_tags mezzanine_tags media_tags organization_tags %} + +{% block metatitle %} + {{ event.title }} +{% endblock %} + +{% block title %} + {{ event.title }} +{% endblock %} + +{% block url %} + {{ event.get_absolute_url }} +{% endblock %} + +{% block image %} + {% with event.images.all|get_type:'card' as images %} + {% if images %} +
+ +
+ {% else %} +
+ {% if event.departments.first %} + {% with event.departments.first as department %} +
+ {% endwith %} + {% else %} +
+ {% endif %} +
+ {% endif %} + {% endwith %} +{% endblock %} + +{% block tags %} +
+ {% if event.departments.first %} + {% with event.departments.first as department %} +
+ {{ department.department.name }} +
+ {% endwith %} + {% endif %} + {% if event.category %} +
+ {{ event.category|truncatechars:15 }} +
+ {% endif %} +
+{% endblock %} + +{% block content %} + {{ event.description|richtext_filters|safe|truncatechars_html:200 }} +{% endblock %} + +{% block subtitle %} + + {% include 'agenda/includes/event_date_line.html' %} + + {% if event.location %} +
{{ event.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 forloop.first %} +
+ {% trans "Reserve" %} +
+ {% endif %} + {% endfor %} + {% endif %} +{% endblock %} diff --git a/app/templates/agenda/includes/event_card.html b/app/templates/agenda/includes/event_card.html deleted file mode 100644 index 3aff6459..00000000 --- a/app/templates/agenda/includes/event_card.html +++ /dev/null @@ -1,76 +0,0 @@ -{% extends "core/inc/generic_card.html" %} -{% load i18n pages_tags mezzanine_tags media_tags organization_tags %} - -{% block metatitle %} - {{ event.title }} -{% endblock %} - -{% block title %} - {{ event.title }} -{% endblock %} - -{% block url %} - {{ event.get_absolute_url }} -{% endblock %} - -{% block image %} - {% with event.images.all|get_type:'card' as images %} - {% if images %} -
- -
- {% else %} -
- {% if event.departments.first %} - {% with event.departments.first as department %} -
- {% endwith %} - {% else %} -
- {% endif %} -
- {% endif %} - {% endwith %} -{% endblock %} - -{% block tags %} -
- {% if event.departments.first %} - {% with event.departments.first as department %} -
- {{ department.department.name }} -
- {% endwith %} - {% endif %} - {% if event.category %} -
- {{ event.category|truncatechars:15 }} -
- {% endif %} -
-{% endblock %} - -{% block content %} - {{ event.description|richtext_filters|safe|truncatechars_html:200 }} -{% endblock %} - -{% block subtitle %} - - {% include 'agenda/includes/event_date_line.html' %} - - {% if event.location %} -
{{ event.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 forloop.first %} -
- {% trans "Reserve" %} -
- {% endif %} - {% endfor %} - {% endif %} -{% endblock %} diff --git a/app/templates/core/inc/related_content.html b/app/templates/core/inc/related_content.html index 795c6e76..2b87edc7 100644 --- a/app/templates/core/inc/related_content.html +++ b/app/templates/core/inc/related_content.html @@ -17,11 +17,11 @@ {% endwith %} {% elif content.content_type.model == "event" %} {% with content.content_object as event %} - {% include "agenda/includes/event_card.html" %} + {% include "agenda/event/includes/event_card.html" %} {% endwith %} {% elif content.content_type.model == "custompage" %} {% with content.content_object as page %} - {% include "pages/includes/page_card.html" %} + {% include "pages/page/sincludes/page_card.html" %} {% endwith %} {% endif %} diff --git a/app/templates/core/inc/related_content_media.html b/app/templates/core/inc/related_content_media.html new file mode 100644 index 00000000..ffe1c69c --- /dev/null +++ b/app/templates/core/inc/related_content_media.html @@ -0,0 +1,25 @@ +{% load i18n mezzanine_tags keyword_tags organization_tags pages_tags %} +{% if concrete_objects %} +
+
+
+
+
+

{% if object.related_title.title %}{{ object.related_title.title }}{% else %}{% trans "Also discover" %}{% endif %}

+
+
+
+ {% 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|add:"/"|add:classname|add:"/includes/"|add:classname|add:"_card.html" as template %} + {% include template with classname=concrete_object %} + {% endwith %} + {% endwith %} +
+ {% endfor %} +
+
+
+{% endif %} diff --git a/app/templates/festival/artist_detail.html b/app/templates/festival/artist_detail.html index f94297b8..439ce01b 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/includes/event_card.html' %} + {% include 'agenda/event/includes/event_card.html' %} {% 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 b954cc14..341105ec 100644 --- a/app/templates/festival/video_detail.html +++ b/app/templates/festival/video_detail.html @@ -29,7 +29,7 @@
{% with video.event as event %} - {% include 'agenda/includes/event_card.html' %} + {% include 'agenda/event/includes/event_card.html' %} {% for artist in video.artists.all %} {% include "festival/inc/artist_card.html" %} {% endfor %} diff --git a/app/templates/home/inc/body.html b/app/templates/home/inc/body.html index bf5be256..f5b462f7 100644 --- a/app/templates/home/inc/body.html +++ b/app/templates/home/inc/body.html @@ -13,11 +13,11 @@ {% endwith %} {% elif slider.content_type.model == "event" %} {% with slider.content_object as event %} - {% include "agenda/includes/event_card.html" %} + {% include "agenda/event/includes/event_card.html" %} {% endwith %} {% elif slider.content_type.model == "custompage" %} {% with slider.content_object as page %} - {% include "pages/includes/page_card.html" %} + {% include "pages/page/includes/page_card.html" %} {% endwith %} {% endif %}
@@ -34,11 +34,11 @@ {% endwith %} {% elif content.content_type.model == "event" %} {% with content.content_object as event %} - {% include "agenda/includes/event_card.html" %} + {% include "agenda/event/includes/event_card.html" %} {% endwith %} {% elif content.content_type.model == "custompage" %} {% with content.content_object as page %} - {% include "pages/includes/page_card.html" %} + {% include "pages/page/includes/page_card.html" %} {% endwith %} {% endif %}
diff --git a/app/templates/media/playlist_detail.html b/app/templates/media/playlist_detail.html index 7bf636bf..af929c0f 100644 --- a/app/templates/media/playlist_detail.html +++ b/app/templates/media/playlist_detail.html @@ -64,10 +64,5 @@
{{ playlist.content|safe }}
- - {% for related_object in related_objects %} - {{ related_object }} -
- {% endfor %} - + {% include "core/inc/related_content_media.html" %} {% endblock %} diff --git a/app/templates/pages/custompage.html b/app/templates/pages/custompage.html index 2ffb0b39..ae57217b 100644 --- a/app/templates/pages/custompage.html +++ b/app/templates/pages/custompage.html @@ -43,7 +43,7 @@ {% for child in childrens %} {% if child.in_menus.0 %} {% with child as object %} - {% include "pages/includes/page_box.html" %} + {% include "pages/page/includes/page_box.html" %} {% endwith %} {% endif %} {% endfor %} diff --git a/app/templates/pages/includes/page_box.html b/app/templates/pages/includes/page_box.html deleted file mode 100644 index 39f4cdf6..00000000 --- a/app/templates/pages/includes/page_box.html +++ /dev/null @@ -1,18 +0,0 @@ -{% load mezzanine_tags organization_tags %} - -
- {% with object.get_content_model.images.all|get_type:'card' as images %} - {% if images %} - - {% endif %} - {% endwith %} -
-
-
-

{{ object.title }}

-
- {{ object.get_content_model.sub_title }} -
-
-
-
diff --git a/app/templates/pages/includes/page_card.html b/app/templates/pages/includes/page_card.html deleted file mode 100644 index 22a5c391..00000000 --- a/app/templates/pages/includes/page_card.html +++ /dev/null @@ -1,32 +0,0 @@ -{% extends "core/inc/generic_card.html" %} -{% load i18n pages_tags mezzanine_tags media_tags organization_tags %} - -{% block metatitle %} - {{ page.title }} -{% endblock %} - -{% block title %} - {{ page.title }} -{% endblock %} - -{% block url %} - {{ page.get_absolute_url }} -{% endblock %} - -{% block image %} - {% with page.images.all|get_type:'card' as images %} - {% if images %} -
- -
- {% endif %} - {% endwith %} -{% endblock %} - -{% block content %} - {{ page.description|richtext_filters|safe|truncatechars_html:200 }} -{% endblock %} - -{% block subtitle %} - {{ page.sub_title }} -{% endblock %} diff --git a/app/templates/pages/includes/page_search.html b/app/templates/pages/includes/page_search.html deleted file mode 100644 index 160ee9a0..00000000 --- a/app/templates/pages/includes/page_search.html +++ /dev/null @@ -1,48 +0,0 @@ -{% extends "core/inc/search_card.html" %} -{% load i18n mezzanine_tags organization_tags %} - -{% block title %} - {{ result.title }} -{% endblock %} - -{% block icon %}files-o{% endblock %} - -{% block tags %} - {% with page.get_ascendants|last as top_level_parent %} - {% if top_level_parent.get_content_model.title %} -
-
- {{ top_level_parent.get_content_model.title }} -
-
- {% elif page.departmentpage %} -
-
- {{ page.departmentpage.title }} -
-
- {% elif page|classname == "Project" %} -
-
- {{ page|classname }} -
-
- {% else %} -
-
- {% trans 'Page' %} -
-
- {% endif %} - {% endwith %} -{% endblock %} - -{% block url %} - {{ page.get_absolute_url }} -{% endblock %} - -{% block content %} - {% if result.description != result|stringformat:"s" %} - {{ result.description|truncatewords_html:200|safe }} - {% endif %} -{% endblock %} diff --git a/app/templates/pages/page/includes/page_box.html b/app/templates/pages/page/includes/page_box.html new file mode 100644 index 00000000..39f4cdf6 --- /dev/null +++ b/app/templates/pages/page/includes/page_box.html @@ -0,0 +1,18 @@ +{% load mezzanine_tags organization_tags %} + +
+ {% with object.get_content_model.images.all|get_type:'card' as images %} + {% if images %} + + {% endif %} + {% endwith %} +
+
+
+

{{ object.title }}

+
+ {{ object.get_content_model.sub_title }} +
+
+
+
diff --git a/app/templates/pages/page/includes/page_card.html b/app/templates/pages/page/includes/page_card.html new file mode 100644 index 00000000..94e426f4 --- /dev/null +++ b/app/templates/pages/page/includes/page_card.html @@ -0,0 +1,31 @@ +{% extends "core/inc/generic_card.html" %} +{% load i18n pages_tags mezzanine_tags media_tags organization_tags %} + +{% block metatitle %} + {{ page.title }} +{% endblock %} + +{% block title %} + {{ page.title }} +{% endblock %} + +{% block url %} + {{ page.get_absolute_url }} +{% endblock %} +{% block image %} + {% with page.images.all|get_type:'card' as images %} + {% if images %} +
+ +
+ {% endif %} + {% endwith %} +{% endblock %} + +{% block content %} + {{ page.description|richtext_filters|safe|truncatechars_html:200 }} +{% endblock %} + +{% block subtitle %} + {{ page.sub_title }} +{% endblock %} diff --git a/app/templates/pages/page/includes/page_search.html b/app/templates/pages/page/includes/page_search.html new file mode 100644 index 00000000..160ee9a0 --- /dev/null +++ b/app/templates/pages/page/includes/page_search.html @@ -0,0 +1,48 @@ +{% extends "core/inc/search_card.html" %} +{% load i18n mezzanine_tags organization_tags %} + +{% block title %} + {{ result.title }} +{% endblock %} + +{% block icon %}files-o{% endblock %} + +{% block tags %} + {% with page.get_ascendants|last as top_level_parent %} + {% if top_level_parent.get_content_model.title %} +
+
+ {{ top_level_parent.get_content_model.title }} +
+
+ {% elif page.departmentpage %} +
+
+ {{ page.departmentpage.title }} +
+
+ {% elif page|classname == "Project" %} +
+
+ {{ page|classname }} +
+
+ {% else %} +
+
+ {% trans 'Page' %} +
+
+ {% endif %} + {% endwith %} +{% endblock %} + +{% block url %} + {{ page.get_absolute_url }} +{% endblock %} + +{% block content %} + {% if result.description != result|stringformat:"s" %} + {{ result.description|truncatewords_html:200|safe }} + {% endif %} +{% endblock %} diff --git a/app/templates/pages/richtextpage.html b/app/templates/pages/richtextpage.html index 51ed3dc5..5f7953b1 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/includes/event_card.html' %} + {% include 'agenda/event/includes/event_card.html' %} {% endfor %}
{% endif %} diff --git a/app/templates/pages/teampage.html b/app/templates/pages/teampage.html index f262eadf..3dfd6d33 100644 --- a/app/templates/pages/teampage.html +++ b/app/templates/pages/teampage.html @@ -41,7 +41,7 @@
{% for children in childrens %} {% with children as object %} - {% include "pages/includes/page_box.html" %} + {% include "pages/page/includes/page_box.html" %} {% endwith %} {% endfor %}