Example #1
0
def admin_location_gallery_add(request):
    
    count = PicturesProvided.count(PicturesProvided.TYPE_LOCATION)
    if count >= 6:
        request.session.flash(u'ERROR: Max pics count in this gallery is 6, sorry Dude...')
        return HTTPFound(location=request.route_url('admin_location_gallery_edit'))
        
    photo_file = request.POST.get('file', '')
    storage_helper = StorageHelper(photo_file)
    try:
        file_content = storage_helper.get_file_content()
    except BadFile:
        request.session.flash(u'ERROR: File error.')
        return HTTPFound(location=request.route_url('admin_location_gallery_edit'))
    
    new_filename_with_path = storage_helper.get_new_filename_with_path(file_content)
    
    Photos.save_original(new_filename_with_path, file_content)
    
    img = storage_helper.get_pil_object(new_filename_with_path)
    Photos.resize(img, Photos.TINY_THUMBNAIL, storage_helper.new_filename, 'tiny_')
    Photos.resize(img, Photos.SMALL_THUMBNAIL, storage_helper.new_filename, 'small_')
    Photos.resize(img, Photos.BIG_THUMBNAIL, storage_helper.new_filename, 'big_')
    Photos.resize(img, Photos.MAXI_THUMBNAIL, storage_helper.new_filename, 'maxi_')


    photo = Photos.save_to_db(new_filename_with_path)
    PicturesProvided.add(photo, PicturesProvided.TYPE_LOCATION)
    
    request.session.flash(u'INFO: Photo is added!')
    return HTTPFound(location=request.route_url('admin_location_gallery_edit'))