Beispiel #1
0
def back_last_page(back_index):
    referer_url = ctx.request.cookie("referer_url")
    logging.info("##############%s " % referer_url)
    ctx.response.delete_cookie("referer_url")
    if referer_url:
        try:
            url = referer_url.split(",")[back_index - 1]
        except IndexError:
            raise seeother("/")
        logging.info("##############%s " % url)
        raise seeother(url)
    else:
        raise seeother("/")
Beispiel #2
0
def back_last_page(back_index):
    referer_url = ctx.request.cookie('referer_url')
    logging.info('##############%s ' % referer_url)
    ctx.response.delete_cookie('referer_url')
    if referer_url:
        try:
            url=referer_url.split(',')[back_index-1]
        except IndexError:
            raise seeother('/')
        logging.info('##############%s ' % url)
        raise seeother(url)
    else:
        raise seeother('/')
Beispiel #3
0
def back_last_page(back_index):
    referer_url = ctx.request.cookie('referer_url')
    logging.info('##############%s ' % referer_url)
    ctx.response.delete_cookie('referer_url')
    if referer_url:
        try:
            url = referer_url.split(',')[back_index - 1]
        except IndexError:
            raise seeother('/')
        logging.info('##############%s ' % url)
        raise seeother(url)
    else:
        raise seeother('/')
Beispiel #4
0
def api_edit_blog(id):
    check_admin()
    i = ctx.request.input()
    logging.info(i)
    title = i.title.strip()
    content = i.content.strip()
    image = i.image
    tags = i.tags
    try:
        tag_checkbox = ctx.request.gets('tag_checkbox')
    except KeyError:
        tag_checkbox = []
    logging.info("##################")
    logging.info(tag_checkbox)
    if not title:
        raise APIValueError('name', 'name cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog.get(id)
    if not blog:
        raise notfound()
    blog.title = title
    blog.content = content
    if image:
        delete_upload(blog.image)
        filename = upload(image)
        blog.image = filename
    blog.update()
    update_tags(blog,tag_checkbox,tags.split(' '))
    raise seeother('/blog/%s' % blog.id)
Beispiel #5
0
def api_edit_blog(id):
    check_admin()
    i = ctx.request.input()
    logging.info(i)
    title = i.title.strip()
    content = i.content.strip()
    image = i.image
    tags = i.tags
    try:
        tag_checkbox = ctx.request.gets('tag_checkbox')
    except KeyError:
        tag_checkbox = []
    logging.info("##################")
    logging.info(tag_checkbox)
    if not title:
        raise APIValueError('name', 'name cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog.get(id)
    if not blog:
        raise notfound()
    blog.title = title
    blog.content = content
    if image:
        delete_upload(blog.image)
        filename = upload(image)
        blog.image = filename
    blog.update()
    update_tags(blog, tag_checkbox, tags.split(' '))
    raise seeother('/blog/%s' % blog.id)
Beispiel #6
0
def api_create_blog():
    check_admin()
    i = ctx.request.input(title='', content='')
    logging.info(i)
    title = i.title.strip()
    content = i.content.strip()
    image = i.image
    tags = i.tags.strip()
    if image:
        logging.info("upload image name:%s,type:%s" %
                     (image.filename, type(image.filename)))
    if not title:
        raise APIValueError('name', 'name cannot be empty.')
    #if not summary:
    #raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    if not image:
        raise APIValueError('image', 'image cannot be empty.')
    filename = upload(image)
    user = ctx.request.user
    blog = Blog(user_id=user.id, title=title, content=content, image=filename)
    blog.insert()
    add_tags(blog.id, tags.split(' '))
    raise seeother('/blog/%s' % blog.id)
Beispiel #7
0
def api_create_blog():
    check_admin()
    i = ctx.request.input(title='', content='')
    logging.info(i)
    title = i.title.strip()
    content = i.content.strip()
    image = i.image
    tags = i.tags.strip()
    if image:
        logging.info("upload image name:%s,type:%s" % (image.filename,type(image.filename)))
    if not title:
        raise APIValueError('name', 'name cannot be empty.')
    #if not summary:
        #raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    if not image:
        raise APIValueError('image', 'image cannot be empty.')
    filename = upload(image)
    user = ctx.request.user
    blog = Blog(user_id=user.id,  title=title,  content=content,image=filename)
    blog.insert()
    add_tags(blog.id,tags.split(' '))
    raise seeother('/blog/%s' % blog.id)
Beispiel #8
0
def manage_interceptor(next):
    user = ctx.request.user
    if user and user.admin:
        return next()
    raise seeother('/signin')
Beispiel #9
0
def signout():
    ctx.response.delete_cookie(_COOKIE_NAME)
    raise seeother('/')
Beispiel #10
0
def manage_interceptor(next):
    user = ctx.request.user
    if user and user.admin:
        return next()
    raise seeother('/signin')
Beispiel #11
0
def signout():
    ctx.response.delete_cookie(_COOKIE_NAME)
    raise seeother('/')