From 724f8731f74d347cca930c43ba2e72ffb8b680b4 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Tue, 31 Mar 2015 14:33:46 -0400 Subject: [PATCH] First commit! --- .gitignore | 2 + AUTHORS | 1 + COPYING | 69 ++++++++++++++++++ README.md | 4 + mediagoblin_libreplanet/__init__.py | 73 +++++++++++++++++++ .../templates/libreplanet/listing.html | 32 ++++++++ .../templates/libreplanet/root.html | 60 +++++++++++++++ mediagoblin_libreplanet/views.py | 46 ++++++++++++ setup.py | 26 +++++++ 9 files changed, 313 insertions(+) create mode 100644 .gitignore create mode 100644 AUTHORS create mode 100644 COPYING create mode 100644 README.md create mode 100644 mediagoblin_libreplanet/__init__.py create mode 100644 mediagoblin_libreplanet/templates/libreplanet/listing.html create mode 100644 mediagoblin_libreplanet/templates/libreplanet/root.html create mode 100644 mediagoblin_libreplanet/views.py create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d424c36 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.pyc +/mediagoblin_libreplanet.egg-info/ diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..0372119 --- /dev/null +++ b/AUTHORS @@ -0,0 +1 @@ +David Thompson diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..b80c5d7 --- /dev/null +++ b/COPYING @@ -0,0 +1,69 @@ +========= + COPYING +========= + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public +License along with this program, in the file ``licenses/AGPLv3.txt``. +If not, see . + + +Translation files located under ``mediagoblin/i18n/`` directory tree +are free software: you can redistribute it and/or modify it under the +terms of the GNU Affero General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at +your option) any later version. + +You should have received a copy of the GNU Affero General Public +License along with this program, in the file ``licenses/AGPLv3.txt``. +If not, see . + + +JavaScript files located in the ``mediagoblin/`` directory tree +are free software: you can redistribute and/or modify them under the +terms of the GNU Affero General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at +your option) any later version. + +You should have received a copy of the GNU Lesser General Public +License along with this program, in the file ``licenses/LGPLv3.txt``. +If not, see . + + +Documentation files located in the ``docs/`` directory tree and all +original documentation theme CSS and assets (including image files) +are released under a CC0 license. To the extent possible under law, +the author(s) have dedicated all copyright and related and neighboring +rights to these files to the public domain worldwide. These files are +distributed without any warranty. + +You should have received a copy of the CC0 license in the file +``licenses/CC0_1.0.txt``. If not, see +. + + +CSS, images and video located in the ``mediagoblin/`` directory tree are +released under a CC0 license. To the extent possible under law, the author(s) +have dedicated all copyright and related and neighboring rights to these +files to the public domain worldwide. These files are distributed without +any warranty. + +You should have received a copy of the CC0 license in the file +``licenses/CC0_1.0.txt``. If not, see +. + + +Additional library software has been made available in the ``extlib/`` +directory. All of it is Free Software and can be distributed under +liberal terms, but those terms may differ in detail from the AGPL's +particulars. See each package's license file in the extlib directory +for additional terms. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d0236c5 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +MediaGoblin for LibrePlanet +=========================== + +A simple plugin for https://media.libreplanet.org diff --git a/mediagoblin_libreplanet/__init__.py b/mediagoblin_libreplanet/__init__.py new file mode 100644 index 0000000..e27ba7e --- /dev/null +++ b/mediagoblin_libreplanet/__init__.py @@ -0,0 +1,73 @@ +# MediaGoblin for LibrePlanet +# Copyright (C) 2015 David Thompson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import logging +import os + +from mediagoblin import mg_globals +from mediagoblin.tools.pluginapi import get_config, register_template_path, register_routes +from mediagoblin.db.models import MediaEntry +from mediagoblin.db.util import media_entries_for_tag_slug +from mediagoblin.tools.pagination import Pagination +from mediagoblin.tools.response import render_to_response +from mediagoblin.decorators import uses_pagination, user_not_banned + +PLUGIN_DIR = os.path.dirname(__file__) +MAX_HOME_ITEMS = 20 +LP_TAG = 'libreplanet2014' + +_log = logging.getLogger(__name__) + +# This is the function that gets called when the setup +# hook fires. +def setup_plugin(): + _log.info("Setting up Libreplanet...") + + # Register the template path. + register_template_path(os.path.join(PLUGIN_DIR, 'templates')) + +def lp_media_for_type(db, type): + return media_entries_for_tag_slug(db, 'libreplanet2015').\ + filter(MediaEntry.media_type == type).\ + order_by(MediaEntry.created.desc()).\ + limit(MAX_HOME_ITEMS) + +@user_not_banned +def frontpage_view(request): + images = lp_media_for_type(request.db, u'mediagoblin.media_types.image') + videos = lp_media_for_type(request.db, u'mediagoblin.media_types.video') + + return render_to_response( + request, 'libreplanet/root.html', + {'images': images, + 'videos': videos, + 'allow_registration': mg_globals.app_config["allow_registration"]}) + +def frontpage_view_hook(): + return frontpage_view + +register_routes([('all-videos', '/videos', + 'mediagoblin_libreplanet.views:video_listing'), + ('all-photos', '/photos', + 'mediagoblin_libreplanet.views:image_listing') + ]) + +# This is a dict that specifies which hooks this plugin uses. +# This one only uses one hook: setup. +hooks = { + 'setup': setup_plugin, + 'frontpage_view': frontpage_view_hook +} diff --git a/mediagoblin_libreplanet/templates/libreplanet/listing.html b/mediagoblin_libreplanet/templates/libreplanet/listing.html new file mode 100644 index 0000000..80f58c7 --- /dev/null +++ b/mediagoblin_libreplanet/templates/libreplanet/listing.html @@ -0,0 +1,32 @@ +{# +# MediaGoblin for LibrePlanet +# Copyright (C) 2011, 2012 MediaGoblin contributors +# Copyright (C) 2015 David Thompson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% from "mediagoblin/utils/object_gallery.html" import object_gallery %} + +{% block title %} + {{ title }} — {{ super() }} +{% endblock %} + +{% block mediagoblin_content -%} +

{{ title }}

+ + {{ object_gallery(request, media_entries, pagination) }} + +{% endblock %} diff --git a/mediagoblin_libreplanet/templates/libreplanet/root.html b/mediagoblin_libreplanet/templates/libreplanet/root.html new file mode 100644 index 0000000..73896a4 --- /dev/null +++ b/mediagoblin_libreplanet/templates/libreplanet/root.html @@ -0,0 +1,60 @@ +{# +# MediaGoblin for LibrePlanet +# Copyright (C) 2011, 2012 MediaGoblin contributors +# Copyright (C) 2015 David Thompson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +#} +{% extends "mediagoblin/base.html" %} + +{% from "mediagoblin/utils/object_gallery.html" import media_grid %} + +{% set feed_url = request.urlgen('mediagoblin.listings.atom_feed') %} + +{% block mediagoblin_head -%} + {% set feed_url = request.urlgen('mediagoblin.listings.atom_feed') -%} + +{%- endblock mediagoblin_head %} + +{% block mediagoblin_content %} +

{% trans %}LibrePlanet{% endtrans %}

+ +

+ {% trans %}The videos on this site were recorded during  + LibrePlanet, an annual + conference for free software enthusiasts held by the Free + Software Foundation in Cambridge, MA. This site is running + MediaGoblin, a great piece + of free media hosting software.{% endtrans %} +

+
+ +

{% trans %}Videos{% endtrans %}

+ {{ media_grid(request, videos) }} +
+

+ View all LibrePlanet videos +

+ +

{% trans %}Photos{% endtrans %}

+ {{ media_grid(request, images) }} +
+

+ View all LibrePlanet photos +

+ + {#- Need to set feed_url within this block so template can use it. -#} + {%- set feed_url = feed_url -%} + {%- include "mediagoblin/utils/feed_link.html" -%} +{% endblock %} diff --git a/mediagoblin_libreplanet/views.py b/mediagoblin_libreplanet/views.py new file mode 100644 index 0000000..78e4d0e --- /dev/null +++ b/mediagoblin_libreplanet/views.py @@ -0,0 +1,46 @@ +# MediaGoblin for LibrePlanet +# Copyright (C) 2015 David Thompson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from mediagoblin import mg_globals +from mediagoblin.db.models import MediaEntry +from mediagoblin.db.util import media_entries_for_tag_slug +from mediagoblin.tools.pagination import Pagination +from mediagoblin.tools.response import render_to_response +from mediagoblin.decorators import uses_pagination + +def type_listing(type, title, request, page): + cursor = MediaEntry.query.\ + filter(MediaEntry.media_type == type).\ + order_by(MediaEntry.created.desc()) + + pagination = Pagination(page, cursor) + media_entries = pagination() + + return render_to_response( + request, + 'libreplanet/listing.html', + {'title': title, + 'media_entries': media_entries, + 'pagination': pagination}) + + +@uses_pagination +def image_listing(request, page): + return type_listing(u'mediagoblin.media_types.image', 'Photos', request, page) + +@uses_pagination +def video_listing(request, page): + return type_listing(u'mediagoblin.media_types.video', 'Videos', request, page) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..59bd3f5 --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +# MediaGoblin for LibrePlanet +# Copyright (C) 2015 David Thompson +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +from setuptools import setup, find_packages + +setup( + name='mediagoblin_libreplanet', + version='0.1', + packages=find_packages(), + include_package_data=True, + install_requires=[], + license='AGPLv3', + ) -- 2.25.1