]> git.parisson.com Git - mezzo.git/commitdiff
[Home] : add media on home | [Media] : add image block
authorEmilie <zawadzki@ircam.fr>
Wed, 15 Feb 2017 11:39:35 +0000 (12:39 +0100)
committerEmilie <zawadzki@ircam.fr>
Wed, 15 Feb 2017 11:39:35 +0000 (12:39 +0100)
app/organization/media/admin.py
app/organization/media/migrations/0013_mediaimage.py [new file with mode: 0644]
app/organization/media/models.py
app/organization/media/translation.py
app/organization/pages/forms.py
app/organization/pages/views.py
app/templates/home/inc/body.html
app/templates/media/media/includes/media_card.html

index 44b2813ea71d3a2621c029588bdefe6e353f6cc6..7eb1695a5919014c00e972df87ce0eaa9c0be90b 100644 (file)
@@ -31,10 +31,15 @@ class MediaTranscodedAdmin(TabularDynamicInlineAdmin):
     model = MediaTranscoded
 
 
+class MediaImageInline(TabularDynamicInlineAdmin):
+
+    model = MediaImage
+
+    
 class MediaAdmin(BaseTranslationModelAdmin):
 
     model = Media
-    inlines = (MediaTranscodedAdmin,)
+    inlines = (MediaTranscodedAdmin, MediaImageInline)
     list_display = ['title',]
 
 
diff --git a/app/organization/media/migrations/0013_mediaimage.py b/app/organization/media/migrations/0013_mediaimage.py
new file mode 100644 (file)
index 0000000..da739c0
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.11 on 2017-02-15 10:55
+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 = [
+        ('organization-media', '0012_auto_20161028_1812'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='MediaImage',
+            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')),
+                ('title', models.CharField(max_length=1024, verbose_name='title')),
+                ('description', models.TextField(blank=True, verbose_name='description')),
+                ('file', mezzanine.core.fields.FileField(max_length=1024, verbose_name='Image')),
+                ('credits', models.CharField(blank=True, max_length=256, null=True, verbose_name='credits')),
+                ('type', models.CharField(choices=[('logo', 'logo'), ('logo_white', 'logo white'), ('logo_black', 'logo black'), ('logo_header', 'logo header'), ('logo_footer', 'logo footer'), ('slider', 'slider'), ('card', 'card'), ('page_slider', 'page - slider'), ('page_featured', 'page - featured')], max_length=64, verbose_name='type')),
+                ('media', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='images', to='organization-media.Media', verbose_name='media')),
+            ],
+            options={
+                'verbose_name_plural': 'images',
+                'verbose_name': 'image',
+                'ordering': ('_order',),
+            },
+        ),
+    ]
index 182fea99f3d7c0a21208edf12a0eb2eacf500fba..404e9e968e54714e2bdc061677d57563e12086c5 100644 (file)
@@ -122,6 +122,16 @@ class MediaTranscoded(models.Model):
         return self.url
 
 
+class MediaImage(Image):
+
+    media = models.ForeignKey(Media, verbose_name=_('media'), related_name='images', blank=True, null=True, on_delete=models.SET_NULL)
+
+    class Meta:
+        verbose_name = _("image")
+        verbose_name_plural = _("images")
+        order_with_respect_to = "media"
+
+
 class MediaCategory(Slugged, Description):
     """Media Category"""
 
index e28ab80cbebab50b366bddfa993e4da5a6788043..3dc1ed9b93ef97244a37bc2f34b9dfd7bb5259cd 100644 (file)
@@ -52,3 +52,9 @@ class PlaylistMediaTranslationOptions(TranslationOptions):
 class MediaCategoryTranslationOptions(TranslationOptions):
 
     fields = ('title', 'description',)
+
+
+@register(MediaImage)
+class MediaImageTranslationOptions(TranslationOptions):
+
+    fields = ()
index 2b1332744880ed4f6581e70f4093cb1a548ade6e..6a776380109e511c72f3596694b45676e806b055 100644 (file)
@@ -32,7 +32,7 @@ from organization.magazine.models import Article, Topic, Brief
 from organization.pages.models import CustomPage
 from organization.pages.models import *
 from organization.agenda.models import Event
-from organization.media.models import Playlist
+from organization.media.models import Playlist, Media
 from organization.network.models import Person
 
 
@@ -43,7 +43,8 @@ class DynamicContentHomeSliderForm(autocomplete.FutureModelForm):
             Article.objects.all(),
             CustomPage.objects.all(),
             Event.objects.all(),
-            Person.objects.published()
+            Person.objects.published(),
+            Media.objects.all()
         ),
         required=False,
         widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-home-slider'),
@@ -61,7 +62,8 @@ class DynamicContentHomeBodyForm(autocomplete.FutureModelForm):
             Article.objects.all(),
             CustomPage.objects.all(),
             Brief.objects.all(),
-            Event.objects.all()
+            Event.objects.all(),
+            Media.objects.all()
         ),
         required=False,
         widget=dal_select2_queryset_sequence.widgets.QuerySetSequenceSelect2('dynamic-content-home-body'),
index e7618946e1bae6e67821eb5fd41a5409d9c2f651..88c4764571108796c8bcb94c72cb5cf2deb3cb19 100644 (file)
@@ -33,7 +33,7 @@ from organization.core.views import SlugMixin, autocomplete_result_formatting
 from organization.magazine.models import Article, Topic, Brief
 from organization.pages.models import Home
 from organization.agenda.models import Event
-from organization.media.models import Playlist
+from organization.media.models import Playlist, Media
 from organization.network.models import Person
 
 
@@ -64,15 +64,16 @@ class DynamicContentHomeSliderView(Select2QuerySetSequenceView):
         custompage = CustomPage.objects.all()
         events = Event.objects.all()
         persons = Person.objects.published()
-
+        medias = Media.objects.all()
 
         if self.q:
             articles = articles.filter(title__icontains=self.q)
             custompage = custompage.filter(title__icontains=self.q)
             events = events.filter(title__icontains=self.q)
             persons = persons.filter(title__icontains=self.q)
+            medias = medias.filter(title__icontains=self.q)
 
-        qs = autocomplete.QuerySetSequence(articles, custompage, events, persons)
+        qs = autocomplete.QuerySetSequence(articles, custompage, events, persons, medias)
 
         if self.q:
             # This would apply the filter on all the querysets
@@ -99,14 +100,16 @@ class DynamicContentHomeBodyView(Select2QuerySetSequenceView):
         custompage = CustomPage.objects.all()
         events = Event.objects.all()
         briefs = Brief.objects.all()
+        medias = Media.objects.all()
 
         if self.q:
             articles = articles.filter(title__icontains=self.q)
             custompage = custompage.filter(title__icontains=self.q)
             events = events.filter(title__icontains=self.q)
             briefs = briefs.filter(title__icontains=self.q)
+            medias = medias.filter(title__icontains=self.q)
 
-        qs = autocomplete.QuerySetSequence(articles, custompage, briefs, events)
+        qs = autocomplete.QuerySetSequence(articles, custompage, briefs, events, medias)
 
         if self.q:
             # This would apply the filter on all the querysets
index e073d8c066129aa2a942f1268c493be99e2073ea..6170bc7c42ffba798dc77956c496a62df186b108 100644 (file)
@@ -18,6 +18,8 @@
                                     {% include "agenda/event/includes/event_card.html" with object=slider.content_object %}
                                 {% elif slider.content_type.model == "custompage" %}
                                     {% include "pages/page/includes/page_card.html" with object=slider.content_object %}
+                                {% elif slider.content_type.model == "media" %}
+                                    {% include "media/media/includes/media_card.html" with object=slider.content_object %}
                                 {% endif %}
                             </div>
                         {% endif %}
@@ -33,6 +35,8 @@
                             {% include "agenda/event/includes/event_card.html" with object=content.content_object %}
                         {% elif content.content_type.model == "custompage" %}
                             {% include "pages/page/includes/page_card.html" with  object=content.content_object %}
+                        {% elif content.content_type.model == "media" %}
+                            {% include "media/media/includes/media_card.html" with  object=content.content_object %}
                         {% endif %}
                     </div>
                 {% endfor %}
index db774cb95850ed273000f065d67a0a9f9983e37b..a7671a1a156e5e765d3ec709961340cb2d53a72e 100644 (file)
@@ -1,14 +1,17 @@
-{% load mezzanine_tags keyword_tags i18n organization_tags staticfiles %}
-
+{% load i18n future mezzanine_tags event_tags keyword_tags disqus_tags organization_tags %}
 <div class="">
     <div class="media-box media-box--{{object|get_media_type|lower}}">
         <a class="media-box__image-container" href="{% url 'organization-media-overlay' object.type object.slug %}" data-video-overlay>
             <figure class="media-box__image media-box__image--video">
-                {% if object.poster_url %}
-                    <img src="{{ object.poster_url }}">
-                {% else %}
-                    <div class="media-box__placeholder"></div>
-                {% endif %}
+                {% with object.images.all|get_type:'card' as images %}
+                    {% if object.poster_url %}
+                        <img src="{{ object.poster_url }}">
+                    {% elif images %}
+                        <img class="lazyload" src="{{ MEDIA_URL }}{% thumbnail images.0.file 720 435 %}" data-original="">
+                    {% else %}
+                        <div class="media-box__placeholder"></div>
+                    {% endif %}
+                {% endwith %}
             </figure>
         </a>
         <a class="media-box__content" href="{% url 'organization-media-detail' object|get_media_type|lower object.slug %}">