# GNU MediaGoblin -- federated, autonomous media hosting # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS. # # 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 _log = logging.getLogger(__name__) from datetime import datetime from werkzeug.exceptions import Forbidden from mediagoblin.tools import pluginapi from mediagoblin import mg_globals from mediagoblin.media_types.blog import forms as blog_forms from mediagoblin.media_types.blog.models import Blog, BlogPostData from mediagoblin.media_types.blog.lib import may_edit_blogpost, set_blogpost_state, get_all_blogposts_of_blog from mediagoblin.messages import add_message, SUCCESS, ERROR from mediagoblin.decorators import (require_active_login, active_user_from_url, get_media_entry_by_id, user_may_alter_collection, get_user_collection, uses_pagination) from mediagoblin.tools.pagination import Pagination from mediagoblin.tools.response import (render_to_response, redirect, render_404) from mediagoblin.tools.translate import pass_to_ugettext as _ from mediagoblin.tools.template import render_template from mediagoblin.tools.text import ( convert_to_tag_list_of_dicts, media_tags_as_string, clean_html, cleaned_markdown_conversion) from mediagoblin.db.util import check_media_slug_used, check_collection_slug_used from mediagoblin.db.models import User, Collection, MediaEntry from mediagoblin.notifications import add_comment_subscription @require_active_login def blog_edit(request): """ View for editing an existing blog or creating a new blog if user have not exceeded maximum allowed acount of blogs. """ url_user = request.matchdict.get('user', None) blog_slug = request.matchdict.get('blog_slug', None) config = pluginapi.get_config('mediagoblin.media_types.blog') max_blog_count = config['max_blog_count'] form = blog_forms.BlogEditForm(request.form) # creating a blog if not blog_slug: if Blog.query.filter_by(author=request.user.id).count()