From e6e44185d2c8c9d915bfef637ac65f0cb15e5813 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 7 Apr 2016 23:26:28 +0200 Subject: [PATCH] add global featured model instead of unit --- app/festival/admin.py | 9 +++ .../migrations/0015_auto_20160407_2249.py | 71 +++++++++++++++++++ .../migrations/0016_auto_20160407_2255.py | 20 ++++++ .../migrations/0017_auto_20160407_2256.py | 20 ++++++ .../migrations/0018_auto_20160407_2301.py | 19 +++++ app/festival/models.py | 21 +++++- app/festival/templatetags/festival_tags.py | 20 +----- .../forms/0006_auto_20160407_2249.py | 30 ++++++++ .../0006_remove_event_featured.py | 19 +++++ app/sandbox/settings.py | 3 + app/templates/index.html | 26 ++++--- 11 files changed, 227 insertions(+), 31 deletions(-) create mode 100644 app/festival/migrations/0015_auto_20160407_2249.py create mode 100644 app/festival/migrations/0016_auto_20160407_2255.py create mode 100644 app/festival/migrations/0017_auto_20160407_2256.py create mode 100644 app/festival/migrations/0018_auto_20160407_2301.py create mode 100644 app/migrations/forms/0006_auto_20160407_2249.py create mode 100644 app/migrations/mezzanine_agenda/0006_remove_event_featured.py diff --git a/app/festival/admin.py b/app/festival/admin.py index fa18242d..45593b33 100644 --- a/app/festival/admin.py +++ b/app/festival/admin.py @@ -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 index 00000000..7f6bd1da --- /dev/null +++ b/app/festival/migrations/0015_auto_20160407_2249.py @@ -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 index 00000000..3e0a2af8 --- /dev/null +++ b/app/festival/migrations/0016_auto_20160407_2255.py @@ -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 index 00000000..ec4ce28e --- /dev/null +++ b/app/festival/migrations/0017_auto_20160407_2256.py @@ -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 index 00000000..a449f01a --- /dev/null +++ b/app/festival/migrations/0018_auto_20160407_2301.py @@ -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', + ), + ] diff --git a/app/festival/models.py b/app/festival/models.py index 47abc3d6..85b6cba9 100644 --- a/app/festival/models.py +++ b/app/festival/models.py @@ -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 diff --git a/app/festival/templatetags/festival_tags.py b/app/festival/templatetags/festival_tags.py index b4b653b0..391b2e0b 100644 --- a/app/festival/templatetags/festival_tags.py +++ b/app/festival/templatetags/festival_tags.py @@ -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 index 00000000..c8af308a --- /dev/null +++ b/app/migrations/forms/0006_auto_20160407_2249.py @@ -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 index 00000000..f01b0672 --- /dev/null +++ b/app/migrations/mezzanine_agenda/0006_remove_event_featured.py @@ -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', + ), + ] diff --git a/app/sandbox/settings.py b/app/sandbox/settings.py index b5557a6c..246e09f2 100644 --- a/app/sandbox/settings.py +++ b/app/sandbox/settings.py @@ -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 diff --git a/app/templates/index.html b/app/templates/index.html index cbf7f7ca..8fbd97fb 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -16,33 +16,39 @@ {% trans "Read more" %}
+{% featured as featured %} +

+ {% for post in featured.blogposts.all %}
- {% featured_posts as post %} -

{% trans "Article" %}

- {% include 'blog/includes/post_card.html' %} - {% trans "All" %} {% trans "articles" %} +

{% trans "Article" %}

+ {% include 'blog/includes/post_card.html' %} + {% trans "All" %} {% trans "articles" %}
+ {% endfor %} + {% for artist in featured.artists.all %}
- {% featured_artist as artist %} -

{% trans "Artist" %}

- {% include "festival/inc/artist_card.html" %} - {% trans "All" %} {% trans "artists" %} +

{% trans "Artist" %}

+ {% include "festival/inc/artist_card.html" %} + {% trans "All" %} {% trans "artists" %}
+ {% endfor %} + {% for video in featured.videos.all %}
- {% featured_video as video %}

{% trans "Video" %}

{% include 'festival/inc/video_card.html' %} {% trans "All" %} {% trans "videos" %}
+ {% endfor %}
-{% featured_playlist as playlist %} +{% for playlist in featured.playlists.all %} {% include 'festival/inc/audio_playlist.html' %} +{% endfor %} {% endblock %} -- 2.39.5