Ticket #5014: issue_5014.patch

File issue_5014.patch, 5.5 KB (added by srudolph, 9 years ago)

Implementation

  • mediagoblin.example.ini

    From 1aff1b3694ca46bb0eb80192cc0815223b812240 Mon Sep 17 00:00:00 2001
    From: srudolph <Stephen.Rudolph@gmail.com>
    Date: Sat, 21 Feb 2015 17:57:41 -0600
    Subject: [PATCH] This feature would add a mediagoblin.ini configuration
     variable named 'most_recent_media_view' that, by default, shows the main
     landing page the way it is always shown now: with a paginated and reverse
     chronological list of media entries. It could be changed to 'Collection' to
     instead show a reverse chronological list of non-empty collections.
    
    For now, a random media entry from the collection will be shown to represent the collection. In the future, this could be improved to allow the collection's creator to select a key entry to always show.
    
    Some benefits of this change:
    -Default behavior remains as-is
    -Discoverability of collections is enhanced
    -Allows increased customizability
    ---
     mediagoblin.example.ini     |  4 ++++
     mediagoblin/config_spec.ini |  3 +++
     mediagoblin/db/mixin.py     | 18 ++++++++++++++++++
     mediagoblin/db/models.py    |  6 +++++-
     mediagoblin/views.py        | 10 +++++++---
     5 files changed, 37 insertions(+), 4 deletions(-)
    
    diff --git a/mediagoblin.example.ini b/mediagoblin.example.ini
    index 17b123f..06b788a 100644
    a b allow_registration = true  
    2929# Set to false to disable the ability for users to report offensive content
    3030allow_reporting = true
    3131
     32## Uncomment this to change the main page's most recent media display from
     33## MediaEntry to Collection
     34# most_recent_media_view = "Collection"
     35
    3236## Uncomment this to put some user-overriding templates here
    3337# local_templates = %(data_basedir)s/templates/
    3438
  • mediagoblin/config_spec.ini

    diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
    index f769e4e..0db803d 100644
    a b theme_web_path = string(default="/theme_static/")  
    9898theme_linked_assets_dir = string(default="%(data_basedir)s/theme_static/")
    9999theme = string()
    100100
     101# Main page, most recent media display
     102most_recent_media_view = string(default="MediaEntry")
     103
    101104# plugin default assets directory
    102105plugin_web_path = string(default="/plugin_static/")
    103106plugin_linked_assets_dir = string(default="%(data_basedir)s/plugin_static/")
  • mediagoblin/db/mixin.py

    diff --git a/mediagoblin/db/mixin.py b/mediagoblin/db/mixin.py
    index 4602c70..a753915 100644
    a b real objects.  
    2929
    3030import uuid
    3131import re
     32import random
    3233from datetime import datetime
    3334
    3435from pytz import UTC
    class CollectionMixin(GenerateSlugMixin):  
    369370            collection=self.slug_or_id,
    370371            **extra_args)
    371372
     373    @property
     374    def thumb_url(self):
     375        """Return the thumbnail URL (for usage in templates)
     376        Will return either the real thumbnail or a default fallback icon."""
     377        # TODO: implement generic fallback in case MEDIA_MANAGER does
     378        # not specify one?
     379        item = random.choice(self.collection_items).get_media_entry
     380        if u'thumb' in item.media_files:
     381            thumb_url = item._app.public_store.file_url(
     382                            item.media_files[u'thumb'])
     383        else:
     384            # No thumbnail in media available. Get the media's
     385            # MEDIA_MANAGER for the fallback icon and return static URL
     386            # Raises FileTypeNotSupported in case no such manager is enabled
     387            manager = item.media_manager
     388            thumb_url = item._app.staticdirector(manager[u'default_thumb'])
     389        return thumb_url
    372390
    373391class CollectionItemMixin(object):
    374392    @property
  • mediagoblin/db/models.py

    diff --git a/mediagoblin/db/models.py b/mediagoblin/db/models.py
    index e8fb17a..bff1415 100644
    a b class CollectionItem(Base, CollectionItemMixin):  
    907907                                     "collection_items",
    908908                                     cascade="all, delete-orphan"))
    909909
    910     get_media_entry = relationship(MediaEntry)
     910    get_media_entry = relationship(MediaEntry,
     911                                 backref=backref(
     912                                     "collection_items",
     913                                     lazy="dynamic",
     914                                     cascade="all, delete-orphan"))
    911915
    912916    __table_args__ = (
    913917        UniqueConstraint('collection', 'media_entry'),
  • mediagoblin/views.py

    diff --git a/mediagoblin/views.py b/mediagoblin/views.py
    index 9e893d5..d849fb3 100644
    a b  
    1515# along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1616
    1717from mediagoblin import mg_globals
    18 from mediagoblin.db.models import MediaEntry
     18from mediagoblin.db.models import (MediaEntry, Collection)
    1919from mediagoblin.tools.pagination import Pagination
    2020from mediagoblin.tools.pluginapi import hook_handle
    2121from mediagoblin.tools.response import render_to_response, render_404
    from mediagoblin.decorators import uses_pagination, user_not_banned  
    2525@user_not_banned
    2626@uses_pagination
    2727def default_root_view(request, page):
    28     cursor = request.db.query(MediaEntry).filter_by(state=u'processed').\
    29         order_by(MediaEntry.created.desc())
     28    if mg_globals.app_config['most_recent_media_view'] == 'Collection':
     29        cursor = Collection.query.filter(Collection.items > 0).\
     30            order_by(Collection.created.desc())
     31    else:
     32        cursor = request.db.query(MediaEntry).filter_by(state=u'processed').\
     33            order_by(MediaEntry.created.desc())
    3034
    3135    pagination = Pagination(page, cursor)
    3236    media_entries = pagination()