Exemplo n.º 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'))
Exemplo n.º 2
0
def admin_contact_rotator_add(request):
    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 (IMAGE).')
        return HTTPFound(location=request.route_url('admin_contact_rotator'))

    new_filename_with_path = storage_helper.get_new_filename_with_path(file_content)
    
    Photos.save_original(new_filename_with_path, file_content)
    photo = Photos.save_to_db(new_filename_with_path)
    
    img = storage_helper.get_pil_object(new_filename_with_path)
    Photos.resize(img, Photos.ROTATOR_THUMBNAIL, storage_helper.new_filename, 'rotator_')
    
    PicturesProvided.add(photo, PicturesProvided.TYPE_CONTACT_ROTATOR)
    
    request.session.flash(u'INFO: Photo is added!')
    return HTTPFound(location=request.route_url('admin_contact_rotator'))
Exemplo n.º 3
0
def admin_gallery_add(request):
    file = request.POST.get('file', '')
    
    if type(file) is type(''): 
        request.session.flash(u'ERROR: File error.')
        return HTTPFound(location=request.route_url('admin_gallery_edit'))
        
    file_content = file.file.read()
    if len(file_content) == 0: 
        request.session.flash(u'ERROR: File error.')
        return HTTPFound(location=request.route_url('admin_gallery_edit'))

    filename, ext = os.path.splitext(file.filename)
    md5_ = md5.md5(str(file_content)).hexdigest()
    
    new_filename = md5_ + '_' + filename.lower() + ext.lower()
    
    if not os.path.exists(Photos.BASE_STORAGE_PATH + new_filename[0]):
        os.makedirs(Photos.BASE_STORAGE_PATH + new_filename[0])
    
    new_filename_with_path = Photos.BASE_STORAGE_PATH + new_filename[0] + '/' + new_filename
    
    Photos.save_original(new_filename_with_path, file_content)
    
    img = Image.open(new_filename_with_path)
    if img.mode != "RBG":
        img = img.convert("RGB")
        
    Photos.resize(img, Photos.TINY_THUMBNAIL, new_filename, 'tiny_')
    Photos.resize(img, Photos.SMALL_THUMBNAIL, new_filename, 'small_')
    Photos.resize(img, Photos.BIG_THUMBNAIL, new_filename, 'big_')
    Photos.resize(img, Photos.MAXI_THUMBNAIL, new_filename, 'maxi_')

    photo = Photos.save_to_db(new_filename_with_path)
    
    PicturesProvided.add(photo, PicturesProvided.TYPE_GALLERY)
    
    request.session.flash(u'INFO: Photo is added!')
    return HTTPFound(location=request.route_url('admin_gallery_edit'))
Exemplo n.º 4
0
def admin_events_rotator_add(request):
    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 (IMAGE).")
        return HTTPFound(location=request.route_url("admin_menu_edit"))

    new_filename_with_path = storage_helper.get_new_filename_with_path(file_content)

    Photos.save_original(new_filename_with_path, file_content)

    Photos.save_original(new_filename_with_path, file_content)
    photo = Photos.save_to_db(new_filename_with_path)

    img = storage_helper.get_pil_object(new_filename_with_path)
    Photos.resize(img, Photos.ROTATOR_THUMBNAIL, storage_helper.new_filename, "rotator_")

    PicturesProvided.add(photo, PicturesProvided.TYPE_EVENTS_ROTATOR)

    request.session.flash(u"INFO: Photo is added!")
    return HTTPFound(location=request.route_url("admin_events_rotator"))
Exemplo n.º 5
0
def admin_contact_rotator_del(request):
    PicturesProvided.delete_one(request.matchdict.get('id'))
    request.session.flash(u'INFO: Deleted!')
    return HTTPFound(location=request.route_url('admin_contact_rotator'))
Exemplo n.º 6
0
def admin_contact_rotator(request):
    rotators = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_CONTACT_ROTATOR)
    return {
        'photos': [rotator.photos for rotator in rotators]
    }
Exemplo n.º 7
0
def admin_events_rotator_del(request):
    PicturesProvided.delete_one(request.matchdict.get("id"))
    request.session.flash(u"INFO: Deleted!")
    return HTTPFound(location=request.route_url("admin_events_rotator"))
Exemplo n.º 8
0
def admin_events_rotator(request):
    rotators = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_EVENTS_ROTATOR)
    return {"photos": [rotator.photos for rotator in rotators]}
Exemplo n.º 9
0
def admin_about_us_rotator(request):
    rotators = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_ABOUT_US_ROTATOR)
    return {
        'photos': [rotator.photos for rotator in rotators]
    }
Exemplo n.º 10
0
def admin_location_gallery_delete(request):
    PicturesProvided.delete_one(request.matchdict.get('id'))
    request.session.flash(u'INFO: Deleted!')
    return HTTPFound(location=request.route_url('admin_location_gallery_edit'))
Exemplo n.º 11
0
def admin_location_gallery_edit(request):
    galleries = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_LOCATION)
    return {
        'photos': [gallery.photos for gallery in galleries]
    }
Exemplo n.º 12
0
def admin_gallery_edit(request):
    galleries = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_GALLERY)
    return {
        'photos': [gallery.photos for gallery in galleries]
    }
Exemplo n.º 13
0
def admin_booking_rotator(request):
    rotators = PicturesProvided.get_rotator_photos(PicturesProvided.TYPE_BOOKING_ROTATOR)
    return {
        'photos': [rotator.photos for rotator in rotators]
    }