From: Aditi Date: Fri, 19 Jul 2013 11:07:22 +0000 (+0530) Subject: Add view for blog edit and create page. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=af8f995f38953318885fa196468481fbb69a763f;p=mediagoblin.git Add view for blog edit and create page. --- diff --git a/mediagoblin/media_types/blog/views.py b/mediagoblin/media_types/blog/views.py index 5a9498cd..35ed5809 100644 --- a/mediagoblin/media_types/blog/views.py +++ b/mediagoblin/media_types/blog/views.py @@ -14,15 +14,19 @@ # 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 import messages from mediagoblin import mg_globals from mediagoblin.media_types.blog import forms as blog_forms -from mediagoblin.messages import add_message, SUCCESS +from mediagoblin.media_types.blog.models import Blog +from mediagoblin.messages import add_message, SUCCESS, ERROR #from mediagoblin.edit.lib import may_edit_media from mediagoblin.decorators import (require_active_login, active_user_from_url, get_media_entry_by_id, user_may_alter_collection, @@ -35,96 +39,69 @@ from mediagoblin.tools.text import ( convert_to_tag_list_of_dicts, media_tags_as_string) from mediagoblin.tools.url import slugify from mediagoblin.db.util import check_media_slug_used, check_collection_slug_used -from mediagoblin.db.models import User, Collection +from mediagoblin.db.models import User, Collection, MediaEntry + @require_active_login -def blog_create(request, media=None): +def blog_edit(request): """ - View to create and edit a blog + View for editing the existing blog or automatically + creating a new blog if user does not have any yet. """ + url_user = request.matchdict.get('user', None) + blog_slug = request.matchdict.get('blog_slug', None) - blog_form = blog_forms.BlogEditForm(request.form) - - if request.method == 'POST' and blog_form.validate(): - blog = request.db.Collection() - - blog.title = unicode(blog_form.title.data) - blog.description = unicode(blog_form.description.data) - blog.creator = request.user.id - blog.generate_slug() - - # Make sure this user isn't duplicating an existing collection - existing_blog_name = request.db.Collection.find_one({ - 'creator': request.user.id, - 'title':blog.title}) - - if existing_blog_name: - add_message(request, messages.ERROR, - _('You already have a blog called "%s"!') \ - % blog.title) + max_blog_count = 1 + form = blog_forms.BlogEditForm(request.form) + # the blog doesn't exists yet + if not blog_slug: + if Blog.query.filter_by(author=request.user.id).count()