]> git.parisson.com Git - mezzo.git/commitdiff
add global featured model instead of unit
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 7 Apr 2016 21:26:28 +0000 (23:26 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Thu, 7 Apr 2016 21:26:28 +0000 (23:26 +0200)
app/festival/admin.py
app/festival/migrations/0015_auto_20160407_2249.py [new file with mode: 0644]
app/festival/migrations/0016_auto_20160407_2255.py [new file with mode: 0644]
app/festival/migrations/0017_auto_20160407_2256.py [new file with mode: 0644]
app/festival/migrations/0018_auto_20160407_2301.py [new file with mode: 0644]
app/festival/models.py
app/festival/templatetags/festival_tags.py
app/migrations/forms/0006_auto_20160407_2249.py [new file with mode: 0644]
app/migrations/mezzanine_agenda/0006_remove_event_featured.py [new file with mode: 0644]
app/sandbox/settings.py
app/templates/index.html

index fa18242d8d51eca77572f4bd8f83241d443b7450..45593b33907834ccd8a0448b3744f1467da60e92 100644 (file)
@@ -56,8 +56,17 @@ class PageCategoryAdmin(admin.ModelAdmin):
     list_display = ('__unicode__',)
 
 
+
+class FeaturedAdmin(admin.ModelAdmin):
+
+    model = Featured
+    list_display = ('__unicode__',)
+    filter_horizontal = ['artists', 'events', 'videos', 'pages', 'blogposts', 'pages', 'playlists']
+
+
 admin.site.register(PageCategory, PageCategoryAdmin)
 admin.site.register(Artist, ArtistAdminDisplayable)
 admin.site.register(Video, VideoAdminDisplayable)
 admin.site.register(Audio, AudioAdminDisplayable)
 admin.site.register(Playlist, PlaylistAdmin)
+admin.site.register(Featured, FeaturedAdmin)
diff --git a/app/festival/migrations/0015_auto_20160407_2249.py b/app/festival/migrations/0015_auto_20160407_2249.py
new file mode 100644 (file)
index 0000000..7f6bd1d
--- /dev/null
@@ -0,0 +1,71 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 20:49
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('blog', '0003_auto_20151223_1313'),
+        ('pages', '0004_auto_20151223_1313'),
+        ('mezzanine_agenda', '0006_remove_event_featured'),
+        ('festival', '0014_auto_20160407_1433'),
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='Featured',
+            fields=[
+                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+                ('name', models.CharField(max_length=512, verbose_name='name')),
+                ('description', models.TextField(blank=True, verbose_name='description')),
+            ],
+            options={
+                'abstract': False,
+            },
+        ),
+        migrations.RemoveField(
+            model_name='artist',
+            name='featured',
+        ),
+        migrations.RemoveField(
+            model_name='audio',
+            name='featured',
+        ),
+        migrations.RemoveField(
+            model_name='video',
+            name='featured',
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='artists',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='festival.Artist', verbose_name='artists'),
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='blogpost',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='blog.BlogPost', verbose_name='blog post'),
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='events',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='mezzanine_agenda.Event', verbose_name='events'),
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='page',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='pages.Page', verbose_name='page'),
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='playlists',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='festival.Playlist', verbose_name='playlists'),
+        ),
+        migrations.AddField(
+            model_name='featured',
+            name='videos',
+            field=models.ManyToManyField(blank=True, related_name='featured', to='festival.Video', verbose_name='videos'),
+        ),
+    ]
diff --git a/app/festival/migrations/0016_auto_20160407_2255.py b/app/festival/migrations/0016_auto_20160407_2255.py
new file mode 100644 (file)
index 0000000..3e0a2af
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 20:55
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('festival', '0015_auto_20160407_2249'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='featured',
+            old_name='blogpost',
+            new_name='blogposts',
+        ),
+    ]
diff --git a/app/festival/migrations/0017_auto_20160407_2256.py b/app/festival/migrations/0017_auto_20160407_2256.py
new file mode 100644 (file)
index 0000000..ec4ce28
--- /dev/null
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 20:56
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('festival', '0016_auto_20160407_2255'),
+    ]
+
+    operations = [
+        migrations.RenameField(
+            model_name='featured',
+            old_name='page',
+            new_name='pages',
+        ),
+    ]
diff --git a/app/festival/migrations/0018_auto_20160407_2301.py b/app/festival/migrations/0018_auto_20160407_2301.py
new file mode 100644 (file)
index 0000000..a449f01
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 21:01
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('festival', '0017_auto_20160407_2256'),
+    ]
+
+    operations = [
+        migrations.AlterModelTable(
+            name='pagecategory',
+            table='festival_page_category',
+        ),
+    ]
index 47abc3d61cf5a58444aded9de3c6b15e8ae3527b..85b6cba9a3ec5f5131656eb4a633cd9c118a5945 100644 (file)
@@ -6,6 +6,8 @@ from django.conf import settings
 from mezzanine.core.models import RichText, Displayable
 from mezzanine.core.fields import RichTextField, OrderField, FileField
 from mezzanine.utils.models import AdminThumbMixin, upload_to
+from mezzanine.blog.models import BlogPost
+from mezzanine.pages.models import Page
 
 from mezzanine_agenda.models import Event
 
@@ -56,6 +58,7 @@ class PageCategory(BaseNameModel):
 
     class Meta(MetaCore):
         verbose_name = _('page category')
+        db_table = app_label + '_page_category'
 
     def __unicode__(self):
         return self.name
@@ -71,7 +74,6 @@ class Artist(Displayable, RichText, AdminThumbMixin):
     photo_credits = models.CharField(_('photo credits'), max_length=255, blank=True, null=True)
     photo_alignment = models.CharField(_('photo alignment'), choices=ALIGNMENT_CHOICES, max_length=32, default="left", blank=True)
     photo_description = models.TextField(_('photo description'), blank=True)
-    featured = models.BooleanField(_('featured'), default=False)
     photo_featured = FileField(_('photo featured'), upload_to='images/photos', max_length=1024, blank=True, format="Image")
     photo_featured_credits = models.CharField(_('photo featured credits'), max_length=255, blank=True, null=True)
     events = models.ManyToManyField(Event, related_name='artists', verbose_name=_('events'), blank=True)
@@ -120,7 +122,6 @@ class Media(Displayable, RichText):
     media_id = models.CharField(_('media id'), max_length=128)
     open_source_url = models.URLField(_('open source URL'), max_length=1024, blank=True)
     closed_source_url = models.URLField(_('closed source URL'), max_length=1024, blank=True)
-    featured = models.BooleanField(_('featured'), default=False)
     poster_url = models.URLField(_('poster'), max_length=1024, blank=True)
 
     class Meta(MetaCore):
@@ -193,5 +194,19 @@ class Playlist(BaseTitleModel):
     audios = models.ManyToManyField(Audio, verbose_name=_('audios'), related_name='playlists', blank=True)
     event = models.ForeignKey(Event, related_name='playlists', verbose_name=_('event'), blank=True, null=True, on_delete=models.SET_NULL)
 
-    def __unicode__(self):
+    def __str__(self):
         return self.title
+
+
+class Featured(BaseNameModel):
+    """(Featured description)"""
+
+    artists = models.ManyToManyField(Artist, verbose_name=_('artists'), related_name='featured', blank=True)
+    events = models.ManyToManyField(Event, verbose_name=_('events'), related_name='featured', blank=True)
+    videos = models.ManyToManyField(Video, verbose_name=_('videos'), related_name='featured', blank=True)
+    blogposts = models.ManyToManyField(BlogPost, verbose_name=_('blog post'), related_name='featured', blank=True)
+    pages = models.ManyToManyField(Page, verbose_name=_('page'), related_name='featured', blank=True)
+    playlists = models.ManyToManyField(Playlist, verbose_name=_('playlists'), related_name='featured', blank=True)
+
+    def __unicode__(self):
+        return self.name
index b4b653b07d9c1e7b288b559fc4592b78ab8311f3..391b2e0ba760632f0f43e2bd85b15022bfbf602c 100644 (file)
@@ -33,21 +33,5 @@ def featured_events(*args):
     return featured
 
 @register.as_tag
-def featured_artist(*args):
-    return Artist.objects.filter(featured=True).order_by('?').first()
-
-@register.as_tag
-def featured_video(*args):
-    return Video.objects.filter(featured=True).order_by('?').first()
-
-@register.as_tag
-def featured_playlist(*args):
-    return Playlist.objects.filter(event=None).order_by('?').first()
-
-@register.as_tag
-def featured_pages(*args):
-    return Page.objects.filter(featured=True)
-
-@register.as_tag
-def featured_posts(*args):
-    return BlogPost.objects.all()[0]
+def featured(*args):
+    return Featured.objects.all().order_by('?').first()
diff --git a/app/migrations/forms/0006_auto_20160407_2249.py b/app/migrations/forms/0006_auto_20160407_2249.py
new file mode 100644 (file)
index 0000000..c8af308
--- /dev/null
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 20:49
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('forms', '0005_auto_20151223_1313'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='field',
+            name='placeholder_text',
+            field=models.CharField(blank=True, max_length=100, verbose_name='Placeholder Text'),
+        ),
+        migrations.AlterField(
+            model_name='field',
+            name='placeholder_text_en',
+            field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Placeholder Text'),
+        ),
+        migrations.AlterField(
+            model_name='field',
+            name='placeholder_text_fr',
+            field=models.CharField(blank=True, max_length=100, null=True, verbose_name='Placeholder Text'),
+        ),
+    ]
diff --git a/app/migrations/mezzanine_agenda/0006_remove_event_featured.py b/app/migrations/mezzanine_agenda/0006_remove_event_featured.py
new file mode 100644 (file)
index 0000000..f01b067
--- /dev/null
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.2 on 2016-04-07 20:49
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('mezzanine_agenda', '0005_auto_20160404_0043'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='event',
+            name='featured',
+        ),
+    ]
index b5557a6ca21c2a7bcc7fa40e35ca3144aab0b1c2..246e09f293841aed37c5f3371ea51ed4c6dbcfcc 100644 (file)
@@ -60,6 +60,9 @@ PAGE_MENU_TEMPLATES = (
 # EXTRA_MODEL_FIELDS = (
 #  )
 
+EXTRA_MODEL_FIELDS = (
+    )
+
 # Setting to turn on featured images for blog posts. Defaults to False.
 #
 BLOG_USE_FEATURED_IMAGE = True
index cbf7f7cac0c6f1cd349e6288be6db39963308494..8fbd97fb5e8ea31f612cb83070a02010899f3915 100644 (file)
 <a href="{% url 'page' edito.slug %}">{% trans "Read more" %}</a>
 <br>
 
+{% featured as featured %}
+
 <div class="last__media">
     <h2 class="page__related__title--inverse">{% trans "Last medias" %}</h2> <br>
 
+    {% for post in featured.blogposts.all %}
     <div class="last__media__entry">
-        {% featured_posts as post %}
-        <h3>{% trans "Article" %}</h3>
-        {% include 'blog/includes/post_card.html' %}
-        <a href="{% url 'blog_post_list' %}" class="btn btn-full">{% trans "All" %} {% trans "articles" %}</a>
+         <h3>{% trans "Article" %}</h3>
+         {% include 'blog/includes/post_card.html' %}
+         <a href="{% url 'blog_post_list' %}" class="btn btn-full">{% trans "All" %} {% trans "articles" %}</a>
     </div>
+    {% endfor %}
 
+    {% for artist in featured.artists.all %}
     <div class="last__media__entry">
-        {% featured_artist as artist %}
-        <h3>{% trans "Artist" %}</h3>
-        {% include "festival/inc/artist_card.html" %}
-        <a href="{% url 'festival-artist-list' %}" class="btn btn-full">{% trans "All" %} {% trans "artists" %}</a>
+         <h3>{% trans "Artist" %}</h3>
+         {% include "festival/inc/artist_card.html" %}
+         <a href="{% url 'festival-artist-list' %}" class="btn btn-full">{% trans "All" %} {% trans "artists" %}</a>
     </div>
+    {% endfor %}
 
+    {% for video in featured.videos.all %}
     <div class="last__media__entry">
-        {% featured_video as video %}
         <h3>{% trans "Video" %}</h3>
         {% include 'festival/inc/video_card.html' %}
         <a href="{% url 'festival-video-list' %}" class="btn btn-full">{% trans "All" %} {% trans "videos" %}</a>
     </div>
+    {% endfor %}
 </div>
 
-{% featured_playlist as playlist %}
+{% for playlist in featured.playlists.all %}
 <h2 class="page__related__title--inverse">{% trans "Playlist" %}</h2>
 {% include 'festival/inc/audio_playlist.html' %}
+{% endfor %}
 
 {% endblock %}