コード例 #1
0
ファイル: gallery.py プロジェクト: dyslab/flask-site-demo
def gallery_do_upload():
    res = JsonResponse()
    res.resMsg = 'Upload start.'
    if 'photo' in request.files:
        try:
            photos = UploadSet('photos', IMAGES)
            configure_uploads(current_app, (photos))
            filename = photos.save(request.files['photo'])
            gflag = GalleryMiddleware().save_one(
                link=photos.url(filename),
                tags=request.form.getlist('tags'),
                caption=request.form['caption']
            )
            if gflag:
                res.resMsg = 'Note: Photo saved successfully.'
            else:
                res.resMsg = 'Note: Failed to save photo.'
            res.data = {
                'link': photos.url(filename),
                'tags': request.form.getlist('tags'),
                'caption': request.form['caption']
            }
        except Exception:
            res.resCode = -1
            res.resMsg = 'Error: Upload failed.\n\n' + \
                'The file size maybe exceeds limited size [' + \
                '{0}'.format(current_app.config['MAX_CONTENT_LENGTH_MB']) + \
                'MB].'
            pass
    else:
        res.resCode = -1
        res.resMsg = 'Error: Cannot find the file field in your upload form.'
    # print(res.outputJsonString()) # Print for test.
    return res.outputJsonString()
コード例 #2
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_edit(id):
    res = JsonResponse()
    try:
        blog = BlogMiddleware().load_by_id(id=id)
        if blog is not None:
            res.data = blog
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString()) # Print for test.
    return res.outputJsonString()
コード例 #3
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_save_tags():
    res = JsonResponse()
    try:
        tags = request.form.getlist('tags[]')
        tags.reverse()
        if BTagsMiddleware().save_all(tags):
            res.resMsg = 'Note: Saved tags successfully.'
        else:
            res.resMsg = 'Note: Failed to save tags.'
    except Exception:
        res.resCode = -1
        res.resMsg = "Network error occurred."
        pass
    return res.outputJsonString()
コード例 #4
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_delete(id):
    res = JsonResponse()
    try:
        bflag = BlogMiddleware().delete_by_id(id=id)
        if bflag:
            res.resMsg = 'Note: Deleted blog successfully.'
        else:
            res.resMsg = 'Note: Failed to delete the blog.'
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString()) # Print for test.
    return res.outputJsonString()
コード例 #5
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_loadmore(page):
    res = JsonResponse()
    try:
        off = int(request.args.get('off', '0'))
        blist = BlogMiddleware().load_all(page, off,
                                          current_app.config['BLOG_PER_PAGE'])
        res.data = blist
        # print(res.data)  # Print for test.
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString())  # Print for test.
    return res.outputJsonString()
コード例 #6
0
ファイル: gallery.py プロジェクト: dyslab/flask-site-demo
def gallery_delete(id):
    res = JsonResponse()
    try:
        gflag = GalleryMiddleware().delete_by_id(id)
        if gflag:
            res.resMsg = 'Note: Deleted photo successfully.'
        else:
            res.resCode = -1
            res.resMsg = 'Note: Failed to delete the photo.'
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString())  # Print for test.
    return res.outputJsonString()
コード例 #7
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_new():
    res = JsonResponse()
    try:
        bflag = BlogMiddleware().save_one(title=request.form['blogtitle'],
                                          tags=request.form.getlist('tags'),
                                          content=request.form['blogcontent'])
        if bflag:
            res.resMsg = 'Note: New blog was saved successfully.'
        else:
            res.resMsg = 'Note: Failed to save the blog.'
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString()) # Print for test.
    return res.outputJsonString()
コード例 #8
0
ファイル: blog.py プロジェクト: dyslab/flask-site-demo
def blog_search():
    res = JsonResponse()
    try:
        blist = BlogMiddleware().search(
            1,
            0,
            current_app.config['BLOG_PER_PAGE'],
            request.form.getlist('searchtags'),
            request.form['searchterms'],
        )
        res.data = blist
        # print(res.data)  # Print for test.
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString())  # Print for test.
    return res.outputJsonString()
コード例 #9
0
ファイル: gallery.py プロジェクト: dyslab/flask-site-demo
def gallery_edit_save(id):
    res = JsonResponse()
    try:
        bflag = GalleryMiddleware().save_by_id(
            id=id,
            tags=request.form.getlist('tags'),
            caption=request.form['caption']
        )
        if bflag:
            res.resMsg = 'Note: Saved changes successfully.'
        else:
            res.resMsg = 'Note: Failed to save the changes.'
    except Exception:
        res.resCode = -1
        res.resMsg = 'Error: Network failed.' + \
            ' Check your network connection please.'
        pass
    # print(res.outputJsonString()) # Print for test.
    return res.outputJsonString()
コード例 #10
0
ファイル: gallery.py プロジェクト: dyslab/flask-site-demo
def gallery_list_photos():
    res = JsonResponse()
    try:
        keyword = request.form['keyword']
        if keyword == 'ALL':
            glist = GalleryMiddleware().load_all(
                int(request.form['page']),
                int(request.form['offset']),
                current_app.config['GALLERY_PER_PAGE'],
            )
        elif keyword == 'TAG':
            glist = GalleryMiddleware().load_by_tag(
                int(request.form['page']),
                int(request.form['offset']),
                current_app.config['GALLERY_PER_PAGE'],
                request.form['tag']
            )
        elif keyword == 'YEAR':
            glist = GalleryMiddleware().load_by_year(
                int(request.form['page']),
                int(request.form['offset']),
                current_app.config['GALLERY_PER_PAGE'],
                int(request.form['year'])
            )
        else:
            glist = None
        if glist is not None:
            res.resMsg = 'Note: Gallery loaded successfully.'
        else:
            res.resMsg = 'Note: Failed to load gallery.'
        res.data = glist
    except Exception:
        res.resCode = -1
        res.resMsg = "Network error occurred."
        pass
    return res.outputJsonString()

    return