def create_sponsor_logo_upload(): if request.method == 'POST': logo_image = request.form['logo'] if logo_image: logo_file = uploaded_file(file_content=logo_image) logo = upload_local( logo_file, UPLOAD_PATHS['temp']['event'].format(uuid=uuid4())) return jsonify({'status': 'ok', 'logo': logo}) else: return jsonify({'status': 'no logo'})
def create_image_upload(): if request.method == 'POST': image = request.form['image'] if image: image_file = uploaded_file(file_content=image) image_url = upload_local( image_file, UPLOAD_PATHS['temp']['image'].format(uuid=uuid4())) return jsonify({'status': 'ok', 'image_url': image_url}) else: return jsonify({'status': 'no_image'})
def create_event_bgimage_upload(event_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload_local( background_file, UPLOAD_PATHS['temp']['event'].format(uuid=uuid4())) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'})
def create_event_logo_upload(self): if request.method == 'POST': logo_image = request.form['logo'] if logo_image: logo_file = uploaded_file(file_content=logo_image) logo = upload_local( logo_file, UPLOAD_PATHS['temp']['event'].format(uuid=uuid4()) ) return jsonify({'status': 'ok', 'logo': logo}) else: return jsonify({'status': 'no logo'})
def create_event_bgimage_upload(): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['temp']['event'].format(uuid=uuid4()) ) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'})
def create_image_upload(): if request.method == 'POST': image = request.form['image'] if image: image_file = uploaded_file(file_content=image) image_url = upload_local( image_file, UPLOAD_PATHS['temp']['image'].format(uuid=uuid4()) ) return jsonify({'status': 'ok', 'image_url': image_url}) else: return jsonify({'status': 'no_image'})
def placeholder_upload(): if request.method == 'POST': placeholder_image = request.form['placeholder'] filename = request.form['file_name'] if placeholder_image: placeholder_file = uploaded_file(file_content=placeholder_image) placeholder = upload(placeholder_file, 'placeholders/original/' + filename) try: os.mkdir(app.config['TEMP_UPLOADS_FOLDER']) except OSError as exc: if exc.errno != errno.EEXIST: raise exc pass placeholder_local = upload_local( placeholder_file, app.config['TEMP_UPLOADS_FOLDER'] + filename) temp_img_file = placeholder_local.replace('/serve_', '') basewidth = 300 img = Image.open(temp_img_file) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(app.config['TEMP_UPLOADS_FOLDER'] + '/temp.png') file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) background_thumbnail_url = upload_local( thumbnail_file, 'placeholders/thumbnail/' + filename) shutil.rmtree(path=app.config['TEMP_UPLOADS_FOLDER']) placeholder_db = DataGetter.get_custom_placeholder_by_name( request.form['name']) if placeholder_db: placeholder_db.url = placeholder placeholder_db.thumbnail = background_thumbnail_url else: placeholder_db = CustomPlaceholder( name=request.form['name'], url=placeholder, thumbnail=background_thumbnail_url) save_to_db(placeholder_db, 'Custom Placeholder saved') return jsonify({ 'status': 'ok', 'placeholder': placeholder, 'id': placeholder_db.id }) else: return jsonify({'status': 'no logo'})
def bgimage_upload(user_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['user']['avatar'].format(user_id=user_id)) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': profile = DataGetter.get_user(int(user_id)) profile.avatar_uploaded = '' save_to_db(profile) return jsonify({'status': 'ok'})
def photo_upload(event_id, speaker_id): speaker = get_speaker_or_throw(speaker_id) photo = request.form['photo'] if photo: photo_file = uploaded_file(file_content=photo) photo = upload( photo_file, UPLOAD_PATHS['speakers']['photo'].format(event_id=int(event_id), id=int(speaker.id))) speaker.photo = photo save_to_db(speaker) return jsonify({'status': 'ok', 'photo': photo}) else: speaker.photo = None save_to_db(speaker) return jsonify({'status': 'Removed'})
def bgimage_upload(event_id, speaker_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['speakers']['photo'].format( event_id=int(event_id), id=int(speaker_id))) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': speaker = DataGetter.get_speaker(int(speaker_id)) speaker.photo = '' save_to_db(speaker) return jsonify({'status': 'ok'})
def placeholder_upload(): if request.method == 'POST': placeholder_image = request.form['placeholder'] filename = request.form['file_name'] if placeholder_image: placeholder_file = uploaded_file(file_content=placeholder_image) placeholder = upload( placeholder_file, 'placeholders/original/' + filename ) try: os.mkdir(app.config['TEMP_UPLOADS_FOLDER']) except OSError as exc: if exc.errno != errno.EEXIST: raise exc pass placeholder_local = upload_local(placeholder_file, app.config['TEMP_UPLOADS_FOLDER'] + filename) temp_img_file = placeholder_local.replace('/serve_', '') basewidth = 300 img = Image.open(temp_img_file) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(app.config['TEMP_UPLOADS_FOLDER'] + '/temp.png') file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) background_thumbnail_url = upload_local( thumbnail_file, 'placeholders/thumbnail/' + filename ) shutil.rmtree(path=app.config['TEMP_UPLOADS_FOLDER']) placeholder_db = DataGetter.get_custom_placeholder_by_name(request.form['name']) if placeholder_db: placeholder_db.url = placeholder placeholder_db.thumbnail = background_thumbnail_url else: placeholder_db = CustomPlaceholder(name=request.form['name'], url=placeholder, thumbnail=background_thumbnail_url) save_to_db(placeholder_db, 'Custom Placeholder saved') return jsonify({'status': 'ok', 'placeholder': placeholder, 'id': placeholder_db.id}) else: return jsonify({'status': 'no logo'})
def photo_upload(event_id, speaker_id): speaker = get_speaker_or_throw(speaker_id) photo = request.form['photo'] if photo: photo_file = uploaded_file(file_content=photo) photo = upload( photo_file, UPLOAD_PATHS['speakers']['photo'].format( event_id=int(event_id), id=int(speaker.id) )) speaker.photo = photo save_to_db(speaker) return jsonify({'status': 'ok', 'photo': photo}) else: speaker.photo = None save_to_db(speaker) return jsonify({'status': 'Removed'})
def bgimage_upload(user_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['user']['avatar'].format( user_id=user_id )) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': profile = DataGetter.get_user(int(user_id)) profile.avatar_uploaded = '' save_to_db(profile) return jsonify({'status': 'ok'})
def bgimage_upload(event_id, speaker_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['speakers']['photo'].format( event_id=int(event_id), id=int(speaker_id) )) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': speaker = DataGetter.get_speaker(int(speaker_id)) speaker.photo = '' save_to_db(speaker) return jsonify({'status': 'ok'})
def placeholder_upload(self): if request.method == 'POST': placeholder_image = request.form['placeholder'] filename = request.form['file_name'] if placeholder_image: placeholder_file = uploaded_file( file_content=placeholder_image) placeholder = upload(placeholder_file, 'placeholders/original/' + filename) temp_img_file = placeholder.replace('/serve_', '') basewidth = 300 img = Image.open(temp_img_file) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) os.mkdir('static/media/temp/') img.save('static/media/temp/temp.png') file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) background_thumbnail_url = upload( thumbnail_file, 'placeholders/thumbnail/' + filename) shutil.rmtree(path='static/media/temp/') placeholder_db = DataGetter.get_custom_placeholder_by_name( request.form['name']) if placeholder_db: placeholder_db.url = placeholder placeholder_db.thumbnail = background_thumbnail_url else: placeholder_db = CustomPlaceholder( name=request.form['name'], url=placeholder, thumbnail=background_thumbnail_url) save_to_db(placeholder_db, 'Custom Placeholder saved') return jsonify({ 'status': 'ok', 'placeholder': placeholder, 'id': placeholder_db.id }) else: return jsonify({'status': 'no logo'})
def logo_upload(self, event_id): if request.method == 'POST': logo_image = request.form['logo'] if logo_image: logo_file = uploaded_file(file_content=logo_image) logo = upload( logo_file, UPLOAD_PATHS['event']['logo'].format(event_id=event_id)) event = DataGetter.get_event(event_id) event.logo = logo save_to_db(event) return jsonify({'status': 'ok', 'logo': logo}) else: return jsonify({'status': 'no logo'}) elif request.method == 'DELETE': event = DataGetter.get_event(event_id) event.logo = '' save_to_db(event) return jsonify({'status': 'ok'})
def sponsor_logo_upload(self, event_id, sponsor_id): if request.method == 'POST': logo_image = request.form['logo'] if logo_image: logo_file = uploaded_file(file_content=logo_image) logo = upload( logo_file, UPLOAD_PATHS['sponsors']['logo'].format(event_id=event_id, id=sponsor_id)) sponsor = DataGetter.get_sponsor(sponsor_id) sponsor.logo = logo save_to_db(sponsor) return jsonify({'status': 'ok', 'logo': logo}) else: return jsonify({'status': 'no logo'}) elif request.method == 'DELETE': sponsor = DataGetter.get_sponsor(sponsor_id) sponsor.logo = '' save_to_db(sponsor) return jsonify({'status': 'ok'})
def bgimage_upload(event_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['event']['background_url'].format( event_id=event_id)) event = DataGetter.get_event(event_id) event.background_url = background_url save_to_db(event) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': event = DataGetter.get_event(event_id) event.background_url = '' save_to_db(event) return jsonify({'status': 'ok'})
def logo_upload(self, event_id): if request.method == 'POST': logo_image = request.form['logo'] if logo_image: logo_file = uploaded_file(file_content=logo_image) logo = upload( logo_file, UPLOAD_PATHS['event']['logo'].format( event_id=event_id )) event = DataGetter.get_event(event_id) event.logo = logo save_to_db(event) return jsonify({'status': 'ok', 'logo': logo}) else: return jsonify({'status': 'no logo'}) elif request.method == 'DELETE': event = DataGetter.get_event(event_id) event.logo = '' save_to_db(event) return jsonify({'status': 'ok'})
def bgimage_upload(self, event_id): if request.method == 'POST': background_image = request.form['bgimage'] if background_image: background_file = uploaded_file(file_content=background_image) background_url = upload( background_file, UPLOAD_PATHS['event']['background_url'].format( event_id=event_id )) event = DataGetter.get_event(event_id) event.background_url = background_url save_to_db(event) return jsonify({'status': 'ok', 'background_url': background_url}) else: return jsonify({'status': 'no bgimage'}) elif request.method == 'DELETE': event = DataGetter.get_event(event_id) event.background_url = '' save_to_db(event) return jsonify({'status': 'ok'})
def placeholder_upload(self): if request.method == 'POST': placeholder_image = request.form['placeholder'] filename = request.form['file_name'] if placeholder_image: placeholder_file = uploaded_file(file_content=placeholder_image) placeholder = upload( placeholder_file, 'placeholders/original/'+filename ) temp_img_file = placeholder.replace('/serve_', '') basewidth = 300 img = Image.open(temp_img_file) wpercent = (basewidth / float(img.size[0])) hsize = int((float(img.size[1]) * float(wpercent))) img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) os.mkdir('static/media/temp/') img.save('static/media/temp/temp.png') file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) background_thumbnail_url = upload( thumbnail_file, 'placeholders/thumbnail/'+filename ) shutil.rmtree(path='static/media/temp/') placeholder_db = DataGetter.get_custom_placeholder_by_name(request.form['name']) if placeholder_db: placeholder_db.url = placeholder placeholder_db.thumbnail = background_thumbnail_url else: placeholder_db = CustomPlaceholder(name=request.form['name'], url=placeholder, thumbnail=background_thumbnail_url) save_to_db(placeholder_db, 'Custom Placeholder saved') return jsonify({'status': 'ok', 'placeholder': placeholder, 'id': placeholder_db.id}) else: return jsonify({'status': 'no logo'})