示例#1
0
def thumbnail(id, width, height, ext):
    key = db.Key(id)
    picture = Picture.get(key)
    img = images.Image(picture.data)

    if width != '0':
        w = int(width)
    else:
        w = img.width

    if height != '0':
        h = int(height)
    else:
        h = img.height

    if img.height > h and h != 0:
        w = (int(width) * img.width) / img.height

    if img.width > w:
        h = (int(height) * img.height) / img.width

    thumb = images.resize(picture.data, width=w, height=h)
    response = make_response(thumb)
    response.headers['Content-Type'] = picture.content_type
    return response
示例#2
0
def download_file(request, key, name):
    """ Отдаем картинку из БД по ключу и имени файла получаемые из запроса по url'у"""

    file = memcache.get("full_" + key)
    if file is not None:
        current_time = datetime.datetime.utcnow()
        response = HttpResponse()
        last_modified = current_time - datetime.timedelta(days=1)
        response['Content-Type'] = 'image/jpg'
        response['Last-Modified'] = last_modified.strftime(
            '%a, %d %b %Y %H:%M:%S GMT')
        response['Expires'] = current_time + datetime.timedelta(days=30)
        response['Cache-Control'] = 'public, max-age=315360000'
        response['Date'] = current_time
        response.content = file
        return response
    else:
        file = Picture.get(db.Key(key))
        memcache.add("full_" + key, file.data)
        if file.name != name:
            raise Http404(
                'Could not find file with this name!'
            )  # если имя файла не соответсвует существующему то выводим сообщение
        return HttpResponse(
            file.data,
            #                            content_type='image/png',
            mimetype='image/png')
示例#3
0
def thumbnail(id, width, height, ext):
    key = db.Key(id)
    picture = Picture.get(key)
    img = images.Image(picture.data)
      
    if width != '0':
        w = int(width)
    else:
        w = img.width
        
    if height != '0':
        h = int(height)
    else:
        h = img.height
          
    if img.height > h and h != 0:
        w = (int(width) * img.width) / img.height;
                  
    if img.width > w:
        h = (int(height)  * img.height) / img.width;
        
    thumb = images.resize(picture.data, width=w, height=h)    
    response = make_response(thumb)
    response.headers['Content-Type'] = picture.content_type
    return response
示例#4
0
def edit_picture(id):
    key = db.Key(id)
    picture = Picture.get(key)
    form = PictureForm(request.form, picture)
    return render_template('admin/pictures/edit.html',
                           title=u'Редактировать рисунок',
                           form=form,
                           picture=picture)
示例#5
0
def delete_picture(request, key):
    """ Удаление изображения по ключу передаваемого из url'а """
    if request.user.is_authenticated():
        pic = Picture.get(db.Key(key))
        size = len(pic.data)+len(pic.data_cover)+len(pic.data_small)
        return delete_object(request, Picture, object_id=db.Key(key),
            post_delete_redirect=reverse('gallery.views.delete_picture_ok', args=[size]))
    else:
        return HttpResponseRedirect('/account/login/')
示例#6
0
def delete_picture(request, key):
    """ Удаление изображения по ключу передаваемого из url'а """
    if request.user.is_authenticated():
        pic = Picture.get(db.Key(key))
        size = len(pic.data) + len(pic.data_cover) + len(pic.data_small)
        return delete_object(request,
                             Picture,
                             object_id=db.Key(key),
                             post_delete_redirect=reverse(
                                 'gallery.views.delete_picture_ok',
                                 args=[size]))
    else:
        return HttpResponseRedirect('/account/login/')
示例#7
0
def update_picture(id):
    key = db.Key(id)
    picture = Picture.get(key)
    form  = PictureForm(request.form, picture)
    if form.validate():
        form.populate_obj(picture)
        if request.files['file']:
            picture.data = request.files['file'].read()
            picture.ext = request.files['file'].filename.rsplit('.', 1)[1]
            picture.content_type = request.files['file'].content_type                
        picture.put()
        flash(u'Рисунок успешно сохранен', 'correct')
        return redirect(url_for("edit_picture", id=picture.key()))
    else:
        return render_template('admin/pictures/edit.html', title=u'Редактировать рисунок', form=form, picture=picture)
示例#8
0
def review_picture(request, key, name):
    picture = Picture.get(db.Key(key))
    query_list_image = Picture.all().filter("album", picture.album).fetch(999)
    try:
        next = query_list_image[query_list_image.index(picture)+1]
    except:
        next = False
    try:
        if not query_list_image.index(picture)==0:
            last = query_list_image[query_list_image.index(picture)-1]
        else:
            last = False
    except:
        last = False
    return render_to_response('view_picture.html', {'picture':picture, 'next':next, 'last':last, 'user': request.user})
示例#9
0
def update_picture(id):
    key = db.Key(id)
    picture = Picture.get(key)
    form = PictureForm(request.form, picture)
    if form.validate():
        form.populate_obj(picture)
        if request.files['file']:
            picture.data = request.files['file'].read()
            picture.ext = request.files['file'].filename.rsplit('.', 1)[1]
            picture.content_type = request.files['file'].content_type
        picture.put()
        flash(u'Рисунок успешно сохранен', 'correct')
        return redirect(url_for("edit_picture", id=picture.key()))
    else:
        return render_template('admin/pictures/edit.html',
                               title=u'Редактировать рисунок',
                               form=form,
                               picture=picture)
示例#10
0
def review_picture(request, key, name):
    picture = Picture.get(db.Key(key))
    query_list_image = Picture.all().filter("album", picture.album).fetch(999)
    try:
        next = query_list_image[query_list_image.index(picture) + 1]
    except:
        next = False
    try:
        if not query_list_image.index(picture) == 0:
            last = query_list_image[query_list_image.index(picture) - 1]
        else:
            last = False
    except:
        last = False
    return render_to_response('view_picture.html', {
        'picture': picture,
        'next': next,
        'last': last,
        'user': request.user
    })
示例#11
0
def download_small(request, key, name):
    """ Отдаем картинку из БД по ключу и имени файла получаемые из запроса по url'у"""
    file = memcache.get("small_" + key)
    if file is not None:
        current_time = datetime.datetime.utcnow()
        response = HttpResponse()
        last_modified = current_time - datetime.timedelta(days=1)
        response['Content-Type'] = 'image/jpg'
        response['Last-Modified'] = last_modified.strftime('%a, %d %b %Y %H:%M:%S GMT')
        response['Expires'] = current_time + datetime.timedelta(days=30)
        response['Cache-Control']  = 'public, max-age=315360000'
        response['Date']           = current_time
        response.content = file
        return response
    else:
        file = Picture.get(db.Key(key))
        memcache.add("small_" + key, file.data)
        if file.name != name:
            raise Http404('Could not find file with this name!')
        return HttpResponse(file.data_small,
                            content_type='image/png',
                            mimetype='image/png')
示例#12
0
def edit_picture(id):
    key = db.Key(id)
    picture = Picture.get(key)
    form  = PictureForm(request.form, picture)     
    return render_template('admin/pictures/edit.html', title=u'Редактировать рисунок', form=form, picture=picture)