Beispiel #1
0
def blog_category_create(request):
    user_id = authenticated_userid(request)
    category = Category()
    form = BlogCategoryCreateForm(request.POST)
    if request.method == 'POST' and form.validate():
        form.populate_obj(category)
        category.slug = urlify(category.name)
        DBSession.add(category)
        return HTTPFound(location=request.route_url('blog'))
    return {'user_id': user_id, 'action': 'create', 'form': form, }
Beispiel #2
0
def blog_category_edit(request):
    user_id = authenticated_userid(request)
    category_id = int(request.params.get('id', 1))
    category = Category.by_id(category_id)
    if not category:
        return HTTPNotFound()
    form = BlogCategoryUpdateForm(request.POST, category)
    if request.method == 'POST' and form.validate():
        form.populate_obj()
        DBSession.add(category)
        return HTTPFound(location=request.route_url('blog'))
    return {'user_id': user_id, 'action': 'edit', 'form': form, }
Beispiel #3
0
def blog_create(request):
    user_id = authenticated_userid(request)    
    blog_post = Post()
    form = BlogCreateForm(request.POST)
    
    
    if not blog_post:
        return HTTPNotFound()
    
    if request.method == 'POST' and form.validate():
        form.populate_obj(blog_post)
         # Add Tags
        tags = request.params['tags']
        update_tags(tags, blog_post)
        DBSession.add(blog_post)
        return HTTPFound(location=request.route_url('blog'))
    
    return {'form': form, 'action': 'create', 'user_id': user_id}
Beispiel #4
0
 def by_id(cls, post_id):
     return DBSession.query(Post).filter(cls.id == post_id).first()
Beispiel #5
0
 def get_recent(cls):
     return DBSession.query(Post).order_by(sa.desc(cls.created))[:5]
Beispiel #6
0
 def get_posts_by_tag(cls, tag):
     # return DBSession.query(Post).join(Post.tags).filter(sa.func.lower(Tag.name) == tag)
     return DBSession.query(Post).join(Post.tags).filter(Tag.slug == tag)
Beispiel #7
0
 def all(cls):
     return DBSession.query(Post).order_by(sa.desc(cls.created))
Beispiel #8
0
 def get_all(cls):
     return DBSession.query(Tag).order_by(sa.asc(cls.name))
Beispiel #9
0
 def get_by_name(cls, tag):
     return DBSession.query(Tag).filter(cls.name == tag).first()
Beispiel #10
0
 def get_posts_by_category_slug(cls, category_slug):
     return DBSession.query(Post).join(Category).filter(Category.slug == category_slug)
Beispiel #11
0
 def get_posts_by_category(cls, category):
     return DBSession.query(Post).join(Category).filter(sa.func.lower(Category.name) == category)
Beispiel #12
0
 def by_id(cls, category_id):
     return DBSession.query(Category).filter(cls.id == category_id).first()
Beispiel #13
0
 def by_name(cls, name):
     return DBSession.query(User).filter(User.name == name).first()
Beispiel #14
0
 def all(cls):
     return DBSession.query(User).order_by(sa.desc(cls.name))