예제 #1
0
파일: admin.py 프로젝트: RTNelo/dev_blog2
def album_detail(album_id):
    """Album Detail Admin Page.

    Used for upload new photos to UpYun and set deail about album.Also, if
    the album index is not set, use the first photo.

    Methods:
        GET and POST

    Args:
        GET:
            album ObjectID

        PSOT(*for ajax only):
            files: [name: 'Filedata']
            album_id: album ObjectID

    Returns:
        GET:
            album data

        POST:
            status: {success: true/false, url: url}
    """
    if request.method == 'POST':
        data = request.files['Filedata']
        album_id = request.form['album_id']
        filename = secure_filename(data.filename)
        helper = UpYunHelper()
        url = helper.up_to_upyun('gallery', data, filename)
        if url:
          photo = PhotoEm(
                    path = url,
                    title = filename
                  )
          Gallery.objects(pk=album_id).update(set__index=url)
          Gallery.objects(pk=album_id).update_one(push__content=photo)
          return json.dumps({'success': 'true', 'url': url})
        else:
          return json.dumps({'success': 'false'})
    else:
        album = Gallery.objects(pk=album_id)[0]

        return render_template('admin/gallery/detail.html', album=album)
예제 #2
0
def gallery():
    """Gallery Admin Page.

    Used for upload new photos to UpYun.

    Methods:
        GET and POST

    Args:
        GET:
            none

        PSOT(*for ajax only):
            files: [name: 'Filedata']

    Returns:
        GET:
            photos

        POST:
            status: {success: true/false, url: url}
    """
    if request.method == 'POST':
        re_helper = ReHelper()
        data = request.files['Filedata']
        filename = re_helper.r_slash(data.filename.encode('utf-8'))
        helper = UpYunHelper()
        url = helper.up_to_upyun('gallery', data, filename)

        if url:
            photo = Photo(url=url)
            photo.title = filename
            photo.save()

            return json.dumps({'success': 'true', 'url': url})
        else:
            return json.dumps({'success': 'false'})
    else:
        photos = Photo.objects.order_by('-publish_time')

        return render_template('admin/gallery/detail.html', photos=photos)
예제 #3
0
def gallery():
    """Gallery Admin Page.

    Used for upload new photos to UpYun.

    Methods:
        GET and POST

    Args:
        GET:
            none

        PSOT(*for ajax only):
            files: [name: 'Filedata']

    Returns:
        GET:
            photos

        POST:
            status: {success: true/false, url: url}
    """
    if request.method == 'POST':
        re_helper = ReHelper()
        data = request.files['Filedata']
        filename = re_helper.r_slash(data.filename.encode('utf-8'))
        helper = UpYunHelper()
        url = helper.up_to_upyun('gallery', data, filename)

        if url:
            photo = Photo(url=url)
            photo.title = filename
            photo.save()

            return json.dumps({'success': 'true', 'url': url})
        else:
            return json.dumps({'success': 'false'})
    else:
        photos = Photo.objects.order_by('-publish_time')

        return render_template('admin/gallery/detail.html', photos=photos)
예제 #4
0
파일: admin.py 프로젝트: RTNelo/dev_blog2
def diary_add_photo():
    """Admin Diary Add Photo Action.

    *for Ajax only.

    Methods:
        POST

    Args:
        files: [name: 'userfile']

    Returns:
        status: {success: true/false}
    """
    if request.method == 'POST':
        data = request.files['userfile']
        filename = secure_filename(data.filename)
        helper = UpYunHelper()
        url = helper.up_to_upyun('diary', data, filename)
        if url:
          return json.dumps({'success': 'true', 'url': url})
        else:
          return json.dumps({'success': 'false'})
예제 #5
0
def account_upload_avatar():
    """Admin Account Upload Avatar Action.

    *for Ajax only.

    Methods:
        POST

    Args:
        files: [name: 'userfile']

    Returns:
        status: {success: true/false}
    """
    if request.method == 'POST':
        data = request.files['userfile']
        filename = secure_filename(data.filename)
        helper = UpYunHelper()
        url = helper.up_to_upyun('account', data, filename)
        if url:
          return json.dumps({'success': 'true', 'url': url})
        else:
          return json.dumps({'success': 'false'})
예제 #6
0
def diary_add_photo():
    """Admin Diary Add Photo Action.

    *for Ajax only.

    Methods:
        POST

    Args:
        files: [name: 'userfile']

    Returns:
        status: {success: true/false}
    """
    if request.method == 'POST':
        re_helper = ReHelper()
        data = request.files['userfile']
        filename = re_helper.r_slash(data.filename.encode('utf-8'))
        helper = UpYunHelper()
        url = helper.up_to_upyun('diary', data, filename)
        if url:
            return json.dumps({'success': 'true', 'url': url})
        else:
            return json.dumps({'success': 'false'})