From eebd8fe3edb3cce4675f58eb02fe1d96229af0d5 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Thu, 12 Dec 2013 18:56:36 +0100 Subject: [PATCH] Rename a few files and minor cleanup Within the blog plugin, rename a few files and clean up a few things that can be cleaned up. --- mediagoblin/media_types/blog/__init__.py | 2 +- .../mediagoblin/blog/blog_post_listing.html | 8 +++--- .../blog/url_to_blogs_dashboard.html | 2 +- ...to_blogging.html => url_to_dashboard.html} | 0 mediagoblin/media_types/blog/views.py | 25 ++++++++----------- 5 files changed, 17 insertions(+), 20 deletions(-) rename mediagoblin/media_types/blog/templates/mediagoblin/blog/{url_to_blogging.html => url_to_dashboard.html} (100%) diff --git a/mediagoblin/media_types/blog/__init__.py b/mediagoblin/media_types/blog/__init__.py index 0dd9708c..859c2162 100644 --- a/mediagoblin/media_types/blog/__init__.py +++ b/mediagoblin/media_types/blog/__init__.py @@ -87,7 +87,7 @@ def setup_plugin(): pluginapi.register_routes(routes) pluginapi.register_template_path(os.path.join(PLUGIN_DIR, 'templates')) pluginapi.register_template_hooks({"user_profile": "mediagoblin/blog/url_to_blogs_dashboard.html", - "blog_dashboard_home": "mediagoblin/blog/url_to_blogging.html", + "blog_dashboard_home": "mediagoblin/blog/url_to_dashboard.html", }) diff --git a/mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_post_listing.html b/mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_post_listing.html index 3ec84006..8d7a405e 100644 --- a/mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_post_listing.html +++ b/mediagoblin/media_types/blog/templates/mediagoblin/blog/blog_post_listing.html @@ -19,9 +19,9 @@ {% import "/mediagoblin/utils/wtforms.html" as wtforms_util %} {% from "mediagoblin/utils/pagination.html" import render_pagination %} - +{% set blog_owner_name = blog_owner.username %} {% block title -%} - {% trans %}{{ blog_owner }} 's Blog{% endtrans %} — {{ super() }} + {% trans %}{{ blog_owner_name }}'s Blog{% endtrans %} — {{ super() }} {%- endblock %} {% block mediagoblin_head -%} @@ -36,7 +36,7 @@ {%- endblock %} {% block mediagoblin_content %} -

{{ blog.title }} by {{ blog_owner }}

+

{{ blog.title }} by {{ blog_owner_name }}

{% for post in blog_posts %}
@@ -59,7 +59,7 @@

{% set blog_about_url = request.urlgen('mediagoblin.media_types.blog.blog_about', - blog_slug=blog.slug, user=blog_owner) %} + blog_slug=blog.slug, user=blog_owner_name) %}
About Blog
{{ render_pagination(request, pagination) }} diff --git a/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html b/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html index cb781b53..839b8a5a 100644 --- a/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html +++ b/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogs_dashboard.html @@ -18,7 +18,7 @@ {%if blogs %}

Blog

{% set blogs_url = request.urlgen('mediagoblin.media_types.blog.blog_admin_dashboard', - blogs=blogs, user=user.username) %} + user=user.username) %}

Go to user's blog

{%endif%} diff --git a/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogging.html b/mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_dashboard.html similarity index 100% rename from mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_blogging.html rename to mediagoblin/media_types/blog/templates/mediagoblin/blog/url_to_dashboard.html diff --git a/mediagoblin/media_types/blog/views.py b/mediagoblin/media_types/blog/views.py index cb34b490..042881e4 100644 --- a/mediagoblin/media_types/blog/views.py +++ b/mediagoblin/media_types/blog/views.py @@ -209,19 +209,18 @@ def blogpost_edit(request): }) +@active_user_from_url @uses_pagination -def blog_dashboard(request, page): +def blog_dashboard(request, page, url_user=None): """ Dashboard for a blog, only accessible to the owner of the blog. """ - url_user = request.matchdict.get('user') - user = request.db.User.query.filter_by(username=url_user).one() blog_slug = request.matchdict.get('blog_slug', None) - blogs = request.db.Blog.query.filter_by(author=user.id) + blogs = request.db.Blog.query.filter_by(author=url_user.id) config = pluginapi.get_config('mediagoblin.media_types.blog') max_blog_count = config['max_blog_count'] - if request.user and (request.user.id == user.id or request.user.has_privilege(u'admin')): + if request.user and (request.user.id == url_user.id or request.user.has_privilege(u'admin')): if blog_slug: blog = blogs.filter(Blog.slug==blog_slug).first() if not blog: @@ -238,32 +237,30 @@ def blog_dashboard(request, page): {'blog_posts_list': blog_posts_on_a_page, 'blog_slug':blog_slug, 'blog':blog, - 'user':user, + 'user':url_user, 'pagination':pagination }) - if not request.user or request.user.id != user.id or not blog_slug: + if not request.user or request.user.id != url_user.id or not blog_slug: blogs = blogs.all() return render_to_response( request, 'mediagoblin/blog/list_of_blogs.html', { 'blogs':blogs, - 'user':user, + 'user':url_user, 'max_blog_count':max_blog_count }) +@active_user_from_url @uses_pagination -def blog_post_listing(request, page): +def blog_post_listing(request, page, url_user=None): """ Page, listing all the blog posts of a particular blog. """ - blog_owner = request.matchdict.get('user') blog_slug = request.matchdict.get('blog_slug', None) - owner_user = User.query.filter_by(username=blog_owner).one() blog = request.db.Blog.query.filter_by(slug=blog_slug).first() - - if not owner_user or not blog: + if not blog: return render_404(request) all_blog_posts = blog.get_all_blog_posts(u'processed').order_by(MediaEntry.created.desc()) @@ -276,7 +273,7 @@ def blog_post_listing(request, page): 'mediagoblin/blog/blog_post_listing.html', {'blog_posts': blog_posts_on_a_page, 'pagination': pagination, - 'blog_owner': blog_owner, + 'blog_owner': url_user, 'blog':blog }) -- 2.25.1