From c4293e28d3a915e96f007ac8a87feff845172fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96zcan=20O=C4=9Fuz?= Date: Fri, 22 May 2020 08:33:10 +0300 Subject: [PATCH] WIP on config --- README.md | 19 +++++++++++++++++++ mediagoblin-oyd/__init__.py | 27 ++++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2be6a3d..3fb8b7b 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,22 @@ MediaGoblin for ÖYD =================== A simple plugin for https://medya.oyd.org.tr derived from LibrePlanet + +## Installation + +Copy `mediagoblin-oyd` directory to `$MEDIAGOBLIN_HOME/mediagoblin/plugins` +Add `[[mediagoblin.plugins.mediagoblin-oyd]]` to `mediagoblin.ini` file + +## Usage + +Example config: +``` +[[mediagoblin.plugins.mediagoblin-oyd]] +name = type, tag +``` + +Valid type inputs are `image, video, audio, pdf, raw_image, ascii, stl` +Please sure that you enabled these filetypes in your `mediagoblin.ini` file. + +In this configuration, `name` will be the shortcode for your category. You can use +this as `{{ media_grid(request, name) }}` in your templates such as `root.html`. diff --git a/mediagoblin-oyd/__init__.py b/mediagoblin-oyd/__init__.py index a209792..be6e4cc 100644 --- a/mediagoblin-oyd/__init__.py +++ b/mediagoblin-oyd/__init__.py @@ -74,26 +74,27 @@ def lp_media_for_type(db, type, tag=None, max_items=MAX_HOME_ITEMS_DEFAULT): @user_not_banned def frontpage_view(request): + config = get_config('mediagoblin.plugins.mediagoblin-oyd') + categories = config.items() + images = lp_media_for_type(request.db, u'mediagoblin.media_types.image', None, MAX_HOME_ALL_PHOTO_ITEMS) videos = lp_media_for_type(request.db, u'mediagoblin.media_types.video', None, MAX_HOME_ALL_VIDEO_ITEMS) - - logolar = lp_media_for_type(request.db, u'mediagoblin.media_types.image', "logo", MAX_HOME_LP_ITEMS) - bultenler = lp_media_for_type(request.db, u'mediagoblin.media_types.pdf', "bulten", MAX_HOME_LP_ITEMS) - yayinlar = lp_media_for_type(request.db, u'mediagoblin.media_types.pdf', "yayin", MAX_HOME_LP_ITEMS) + names = [] + for name, (type, tag) in categories: + globals()[name] = lp_media_for_type(request.db, u'mediagoblin.media_types.{}'.format(type), tag, MAX_HOME_FEATURED_ITEMS) + names.append(name) +# logolar = lp_media_for_type(request.db, u'mediagoblin.media_types.image', "logo", MAX_HOME_LP_ITEMS) +# bultenler = lp_media_for_type(request.db, u'mediagoblin.media_types.pdf', "bulten", MAX_HOME_LP_ITEMS) +# yayinlar = lp_media_for_type(request.db, u'mediagoblin.media_types.pdf', "yayin", MAX_HOME_LP_ITEMS) featured_images = lp_media_for_type(request.db, u'mediagoblin.media_types.image', FEATURED_TAG, MAX_HOME_FEATURED_ITEMS) featured_videos = lp_media_for_type(request.db, u'mediagoblin.media_types.video', FEATURED_TAG, MAX_HOME_FEATURED_ITEMS) - + send_dict = {'images': images, 'videos': videos, 'featured_videos': featured_videos, 'allow_registration': mg_globals.app_config["allow_registration"]} + for item in names: + send_dict[item] = item return render_to_response( request, 'oyd/root.html', - {'images': images, - 'videos': videos, - 'logolar': logolar, - 'bultenler': bultenler, - 'yayinlar': yayinlar, - 'featured_images': featured_images, - 'featured_videos': featured_videos, - 'allow_registration': mg_globals.app_config["allow_registration"]}) + send_dict) def frontpage_view_hook(): return frontpage_view