def check_slug_used(self, slug):
return check_blog_slug_used(self.author, slug, self.id)
+
class Blog(Base, BlogMixin):
__tablename__ = "mediatype__blogs"
id = Column(Integer, primary_key=True)
author = Column(Integer, ForeignKey(User.id), nullable=False, index=True) #similar to uploader
created = Column(DateTime, nullable=False, default=datetime.datetime.now, index=True)
slug = Column(Unicode)
-
+
+ @property
+ def slug_or_id(self):
+ return (self.slug or u'blog_{0}'.format(self.id))
def get_all_blog_posts(self, state=None):
blog_posts = Session.query(MediaEntry).join(BlogPostData)\
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.media_types.blog.lib import (
+ may_edit_blogpost, set_blogpost_state, get_all_blogposts_of_blog,
+ get_blog_by_slug)
from mediagoblin.messages import add_message, SUCCESS, ERROR
from mediagoblin.decorators import (require_active_login, active_user_from_url,
#Blog already exists.
else:
- blog = request.db.Blog.query.filter_by(slug=blog_slug).first()
+ blog = get_blog_by_slug(request, blog_slug)
if not blog:
return render_404(request)
if request.method == 'GET':
if request.method == 'POST' and form.validate():
blog_slug = request.matchdict.get('blog_slug')
- blog = request.db.Blog.query.filter_by(slug=blog_slug,
- author=request.user.id).first()
+ blog = get_blog_by_slug(request, blog_slug, author=request.user.id)
if not blog:
return render_404(request)
blog_post_slug = request.matchdict.get('blog_post_slug', None)
blogpost = request.db.MediaEntry.query.filter_by(slug=blog_post_slug, uploader=request.user.id).first()
- blog = request.db.Blog.query.filter_by(slug=blog_slug, author=request.user.id).first()
+ blog = get_blog_by_slug(request, blog_slug, author=request.user.id)
if not blogpost or not blog:
return render_404(request)
max_blog_count = config['max_blog_count']
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()
+ blog = get_blog_by_slug(request, blog_slug)
if not blog:
return render_404(request)
else:
Page, listing all the blog posts of a particular blog.
"""
blog_slug = request.matchdict.get('blog_slug', None)
- blog = request.db.Blog.query.filter_by(slug=blog_slug).first()
+ blog = get_blog_by_slug(request, blog_slug, author=request.user.id)
if not blog:
return render_404(request)
@require_active_login
def draft_view(request):
-
blog_slug = request.matchdict.get('blog_slug', None)
blog_post_slug = request.matchdict.get('blog_post_slug', None)
user = request.matchdict.get('user')
-
- blog = request.db.Blog.query.filter_by(author=request.user.id, slug=blog_slug).first()
+ blog = get_blog_by_slug(request, blog_slug, author=request.user.id)
blogpost = request.db.MediaEntry.query.filter_by(state = u'failed', uploader=request.user.id, slug=blog_post_slug).first()
if not blog or not blogpost:
owner_user = request.db.User.query.filter_by(username=url_user).first()
blog_slug = request.matchdict.get('blog_slug', None)
- blog = request.db.Blog.query.filter_by(slug=blog_slug, author=owner_user.id).first()
+ blog = get_blog_by_slug(request, blog_slug, author=owner_user.id)
if not blog:
return render_404(reequest)
url_user = request.matchdict.get('user', None)
user = request.db.User.query.filter_by(username=url_user).first()
- blog = request.db.Blog.query.filter_by(author=user.id, slug=blog_slug).first()
+ blog = get_blog_by_slug(request, blog_slug, author=user.id)
if not user or not blog:
return render_404(request)