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 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 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_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_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_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(self): 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 edit_view(event_id, speaker_id): speaker = get_speaker_or_throw(speaker_id) event = DataGetter.get_event(event_id) form_elems = DataGetter.get_custom_form_elements(event_id) if not form_elems: flash( "Speaker form has been incorrectly configured for this event. Editing has been disabled", "danger") return redirect(url_for('.index_view', event_id=event_id)) speaker_form = json.loads(form_elems.speaker_form) if request.method == 'GET': return render_template('gentelella/admin/event/speakers/edit.html', speaker=speaker, event_id=event_id, event=event, speaker_form=speaker_form) if request.method == 'POST': # set photo if 'photo' in request.files and request.files['photo'].filename != '': speaker_img_file = request.files['photo'] speaker_img = upload( speaker_img_file, UPLOAD_PATHS['speakers']['photo'].format( event_id=int(event_id), id=int(speaker.id))) speaker.photo = speaker_img logo = request.form.get('photo', None) print logo if logo != '' and logo: filename = '{}.png'.format(time.time()) filepath = '{}/static/{}'.format(path.realpath('.'), logo[len('/serve_static/'):]) logo_file = UploadedFile(filepath, filename) print logo_file logo = upload( logo_file, 'events/%d/speakers/%d/photo' % (int(event_id), int(speaker.id))) speaker.photo = logo image_sizes = DataGetter.get_image_sizes_by_type(type='profile') if not image_sizes: image_sizes = ImageSizes(full_width=150, full_height=150, icon_width=35, icon_height=35, thumbnail_width=50, thumbnail_height=50, type='profile') save_to_db(image_sizes, "Image Sizes Saved") filename = '{}.jpg'.format(time.time()) filepath = '{}/static/{}'.format(path.realpath('.'), logo[len('/serve_static/'):]) logo_file = UploadedFile(filepath, filename) temp_img_file = upload_local( logo_file, 'events/{event_id}/speakers/{id}/temp'.format( event_id=int(event_id), id=int(speaker.id))) temp_img_file = temp_img_file.replace('/serve_', '') basewidth = image_sizes.full_width img = Image.open(temp_img_file) hsize = image_sizes.full_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] large_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_thumbnail_url = upload( large_file, UPLOAD_PATHS['speakers']['thumbnail'].format( event_id=int(event_id), id=int(speaker.id))) basewidth = image_sizes.thumbnail_width img = Image.open(temp_img_file) hsize = image_sizes.thumbnail_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_small_url = upload( thumbnail_file, UPLOAD_PATHS['speakers']['small'].format( event_id=int(event_id), id=int(speaker.id))) basewidth = image_sizes.icon_width img = Image.open(temp_img_file) hsize = image_sizes.icon_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] icon_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_icon_url = upload( icon_file, UPLOAD_PATHS['speakers']['icon'].format(event_id=int(event_id), id=int(speaker.id))) shutil.rmtree(path='static/media/' + 'events/{event_id}/speakers/{id}/temp'.format( event_id=int(event_id), id=int(speaker.id))) speaker.thumbnail = profile_thumbnail_url speaker.small = profile_small_url speaker.icon = profile_icon_url save_to_db(speaker, "Speaker photo saved") # set other fields speaker.name = request.form.get('name', None) speaker.short_biography = request.form.get('short_biography', None) speaker.long_biography = request.form.get('long_biography', None) speaker.email = request.form.get('email', None) speaker.mobile = request.form.get('mobile', None) speaker.website = request.form.get('website', None) speaker.twitter = request.form.get('twitter', None) speaker.facebook = request.form.get('facebook', None) speaker.github = request.form.get('github', None) speaker.linkedin = request.form.get('linkedin', None) speaker.organisation = request.form.get('organisation', None) speaker.featured = True if request.form.get( 'featured', 'false') == 'true' else False speaker.position = request.form.get('position', None) speaker.country = request.form.get('country', None) speaker.city = request.form.get('city', None) if request.form.get('heard_from', None) == "Other": speaker.heard_from = request.form.get('other_text', None) else: speaker.heard_from = request.form.get('heard_from', None) speaker.sponsorship_required = request.form.get( 'sponsorship_required', None) speaker.speaking_experience = request.form.get('speaking_experience', None) save_to_db(speaker, "Speaker has been updated") flash("Speaker has been saved", "success") return redirect(url_for('.index_view', event_id=event_id))
def update_user(form, user_id, contacts_only_update=False): user = User.query.filter_by(id=user_id).first() user_detail = UserDetail.query.filter_by(user_id=user_id).first() if user.email != form['email']: record_activity('update_user_email', user_id=user.id, old=user.email, new=form['email']) if user.email != form['email']: user.is_verified = False serializer = Helper.get_serializer() data = [form['email']] form_hash = serializer.dumps(data) link = url_for('admin.create_account_after_confirmation_view', hash=form_hash, _external=True) Helper.send_email_when_changes_email(user.email, form['email']) Helper.send_notif_when_changes_email(user, user.email, form['email']) Helper.send_email_confirmation(form, link) user.email = form['email'] user_detail.contact = form['contact'] if not contacts_only_update: user_detail.firstname = form['firstname'] user_detail.lastname = form['lastname'] if form.get('facebook', '').strip() != '': user_detail.facebook = 'https://facebook.com/' + form['facebook'].strip() else: user_detail.facebook = '' if form.get('twitter', '').strip() != '': user_detail.twitter = 'https://twitter.com/' + form['twitter'].strip() else: user_detail.twitter = '' if form.get('instagram', '').strip() != '': user_detail.instagram = 'https://instagram.com/' + form['instagram'].strip() else: user_detail.instagram = '' if form.get('google', '').strip() != '': user_detail.google = 'https://plus.google.com/' + form['google'].strip() else: user_detail.google = '' user_detail.details = form['details'] avatar_img = form.get('avatar-img', None) if string_not_empty(avatar_img) and avatar_img: user_detail.avatar_uploaded = "" user_detail.thumbnail = "" user_detail.small = "" user_detail.icon = "" filename = '{}.png'.format(get_image_file_name()) filepath = '{}/static/{}'.format(path.realpath('.'), avatar_img[len('/serve_static/'):]) # print "File path 1", filepath avatar_img_file = UploadedFile(filepath, filename) avatar_img_temp = upload(avatar_img_file, 'users/%d/avatar' % int(user_id)) user_detail.avatar_uploaded = avatar_img_temp image_sizes = DataGetter.get_image_sizes_by_type(type='profile') if not image_sizes: image_sizes = ImageSizes(full_width=150, full_height=150, icon_width=35, icon_height=35, thumbnail_width=50, thumbnail_height=50, type='profile') save_to_db(image_sizes, "Image Sizes Saved") filename = '{}.jpg'.format(get_image_file_name()) filepath = '{}/static/{}'.format(path.realpath('.'), avatar_img[len('/serve_static/'):]) # print "File path 1", filepath avatar_img_file = UploadedFile(filepath, filename) temp_img_file = upload_local(avatar_img_file, 'users/{user_id}/temp'.format(user_id=int(user_id))) temp_img_file = temp_img_file.replace('/serve_', '') basewidth = image_sizes.full_width img = Image.open(temp_img_file) hsize = image_sizes.full_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] large_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_thumbnail_url = upload( large_file, UPLOAD_PATHS['user']['thumbnail'].format( user_id=int(user_id) )) basewidth = image_sizes.thumbnail_width img = Image.open(temp_img_file) hsize = image_sizes.thumbnail_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_small_url = upload( thumbnail_file, UPLOAD_PATHS['user']['small'].format( user_id=int(user_id) )) basewidth = image_sizes.icon_width img = Image.open(temp_img_file) hsize = image_sizes.icon_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] icon_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_icon_url = upload( icon_file, UPLOAD_PATHS['user']['icon'].format( user_id=int(user_id) )) shutil.rmtree(path='static/media/' + 'users/{user_id}/temp'.format(user_id=int(user_id))) user_detail.thumbnail = profile_thumbnail_url user_detail.small = profile_small_url user_detail.icon = profile_icon_url user, user_detail, save_to_db(user, "User updated") record_activity('update_user', user=user)
def edit_view(event_id, speaker_id): speaker = get_speaker_or_throw(speaker_id) event = DataGetter.get_event(event_id) form_elems = DataGetter.get_custom_form_elements(event_id) if not form_elems: flash("Speaker form has been incorrectly configured for this event. Editing has been disabled", "danger") return redirect(url_for('.index_view', event_id=event_id)) speaker_form = json.loads(form_elems.speaker_form) if request.method == 'GET': return render_template('gentelella/admin/event/speakers/edit.html', speaker=speaker, event_id=event_id, event=event, speaker_form=speaker_form) if request.method == 'POST': # set photo if 'photo' in request.files and request.files['photo'].filename != '': speaker_img_file = request.files['photo'] speaker_img = upload( speaker_img_file, UPLOAD_PATHS['speakers']['photo'].format( event_id=int(event_id), id=int(speaker.id) )) speaker.photo = speaker_img logo = request.form.get('photo', None) print logo if logo != '' and logo: filename = '{}.png'.format(time.time()) filepath = '{}/static/{}'.format(path.realpath('.'), logo[len('/serve_static/'):]) logo_file = UploadedFile(filepath, filename) print logo_file logo = upload(logo_file, 'events/%d/speakers/%d/photo' % (int(event_id), int(speaker.id))) speaker.photo = logo image_sizes = DataGetter.get_image_sizes_by_type(type='profile') if not image_sizes: image_sizes = ImageSizes(full_width=150, full_height=150, icon_width=35, icon_height=35, thumbnail_width=50, thumbnail_height=50, type='profile') save_to_db(image_sizes, "Image Sizes Saved") filename = '{}.jpg'.format(time.time()) filepath = '{}/static/{}'.format(path.realpath('.'), logo[len('/serve_static/'):]) logo_file = UploadedFile(filepath, filename) temp_img_file = upload_local(logo_file, 'events/{event_id}/speakers/{id}/temp'.format( event_id=int(event_id), id=int(speaker.id))) temp_img_file = temp_img_file.replace('/serve_', '') basewidth = image_sizes.full_width img = Image.open(temp_img_file) hsize = image_sizes.full_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] large_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_thumbnail_url = upload( large_file, UPLOAD_PATHS['speakers']['thumbnail'].format( event_id=int(event_id), id=int(speaker.id) )) basewidth = image_sizes.thumbnail_width img = Image.open(temp_img_file) hsize = image_sizes.thumbnail_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_small_url = upload( thumbnail_file, UPLOAD_PATHS['speakers']['small'].format( event_id=int(event_id), id=int(speaker.id) )) basewidth = image_sizes.icon_width img = Image.open(temp_img_file) hsize = image_sizes.icon_height img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS) img.save(temp_img_file) file_name = temp_img_file.rsplit('/', 1)[1] icon_file = UploadedFile(file_path=temp_img_file, filename=file_name) profile_icon_url = upload( icon_file, UPLOAD_PATHS['speakers']['icon'].format( event_id=int(event_id), id=int(speaker.id) )) shutil.rmtree(path='static/media/' + 'events/{event_id}/speakers/{id}/temp'.format( event_id=int(event_id), id=int(speaker.id))) speaker.thumbnail = profile_thumbnail_url speaker.small = profile_small_url speaker.icon = profile_icon_url save_to_db(speaker, "Speaker photo saved") # set other fields speaker.name = request.form.get('name', None) speaker.short_biography = request.form.get('short_biography', None) speaker.long_biography = request.form.get('long_biography', None) speaker.email = request.form.get('email', None) speaker.mobile = request.form.get('mobile', None) speaker.website = request.form.get('website', None) speaker.twitter = request.form.get('twitter', None) speaker.facebook = request.form.get('facebook', None) speaker.github = request.form.get('github', None) speaker.linkedin = request.form.get('linkedin', None) speaker.organisation = request.form.get('organisation', None) speaker.featured = True if request.form.get('featured', 'false') == 'true' else False speaker.position = request.form.get('position', None) speaker.country = request.form.get('country', None) speaker.city = request.form.get('city', None) if request.form.get('heard_from', None) == "Other": speaker.heard_from = request.form.get('other_text', None) else: speaker.heard_from = request.form.get('heard_from', None) speaker.sponsorship_required = request.form.get('sponsorship_required', None) speaker.speaking_experience = request.form.get('speaking_experience', None) save_to_db(speaker, "Speaker has been updated") flash("Speaker has been saved", "success") return redirect(url_for('.index_view', event_id=event_id))