def speaker_image_sizes(): image_sizes = DataGetter.get_image_sizes_by_type(type='profile') if not image_sizes: image_sizes = ImageSizes(full_width=150, full_height=150, full_aspect='on', icon_width=35, icon_height=35, icon_aspect='on', thumbnail_width=50, thumbnail_height=50, thumbnail_aspect='on', type='profile') from app.helpers.data import save_to_db save_to_db(image_sizes, "Image Sizes Saved") return image_sizes
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 save_event_from_json(json, event_id=None): """ Save an event from a wizard json :param event_id: :param json: :return: """ event_data = json['event'] state = json['state'] if event_id and represents_int(event_id): event = DataGetter.get_event(event_id) is_edit = True else: event = Event() is_edit = False start_time = get_event_time_field_format(event_data, 'start_time') end_time = get_event_time_field_format(event_data, 'end_time') if event_data['name'].strip() == '' or not start_time or not end_time: abort(400) if start_time > end_time: abort(400) event.name = event_data['name'] if event_data['event_url'].strip() != "": if not event_data['event_url'].startswith("http"): event.event_url = "https://" + event_data['event_url'] else: event.event_url = event_data['event_url'] else: event.event_url = "" event.location_name = event_data['location_name'] event.show_map = 1 if event_data['show_map'] else 0 event.start_time = start_time event.end_time = end_time event.timezone = event_data['timezone'] event.description = event_data['description'] event.privacy = event_data['privacy'] event.type = event_data['type'] event.topic = event_data['topic'] event.sub_topic = event_data['sub_topic'] event.latitude = event_data['latitude'] event.longitude = event_data['longitude'] event.searchable_location_name = get_searchable_location_name(event) event.state = state if event_data['location_name'].strip() != '' else 'Draft' event.organizer_description = event_data['organizer_description'] if event_data['has_organizer_info'] else '' event.organizer_name = event_data['organizer_name'] if event_data['has_organizer_info'] else '' event.code_of_conduct = event_data['code_of_conduct'] if event_data['has_code_of_conduct'] else '' save_to_db(event, "Event Saved") record_activity('create_event', event_id=event.id) db.session.add(event) db.session.flush() db.session.refresh(event) copyright = event.copyright if not event.copyright: copyright = EventCopyright(event=event) year = datetime.now().year copyright.licence = event_data['copyright']['licence'] _, _, licence_url, logo, _ = EVENT_LICENCES.get(copyright.licence, ('',) * 5) copyright.holder = event.organizer_name copyright.year = year copyright.logo = logo copyright.licence_url = licence_url save_social_links(event_data['social_links'], event) event.ticket_include = event_data['ticket_include'] if event.ticket_include: event.ticket_url = url_for('event_detail.display_event_detail_home', identifier=event.identifier, _external=True) save_tickets(event_data['tickets'], event) else: event.ticket_url = event_data['ticket_url'] event.discount_code_id = event_data['discount_code_id'] event.payment_country = event_data['payment_country'] event.payment_currency = event_data['payment_currency'] event.pay_by_paypal = event_data['pay_by_paypal'] event.pay_by_cheque = event_data['pay_by_cheque'] event.pay_by_bank = event_data['pay_by_bank'] event.pay_onsite = event_data['pay_onsite'] event.pay_by_stripe = event_data['pay_by_stripe'] event.cheque_details = event_data['cheque_details'] if event.pay_by_cheque else '' event.bank_details = event_data['bank_details'] if event.pay_by_bank else '' event.onsite_details = event_data['onsite_details'] if event.pay_onsite else '' if event.pay_by_paypal: event.paypal_email = event_data['paypal_email'] else: event.paypal_email = None if event.pay_by_stripe and event_data['stripe']['linked']: stripe_data = event_data['stripe'] stripe = event.stripe if not stripe: stripe = StripeAuthorization(event_id=event.id) stripe.stripe_secret_key = stripe_data['stripe_secret_key'] stripe.stripe_refresh_token = stripe_data['stripe_refresh_token'] stripe.stripe_publishable_key = stripe_data['stripe_publishable_key'] stripe.stripe_user_id = stripe_data['stripe_user_id'] stripe.stripe_email = stripe_data['stripe_email'] db.session.add(stripe) else: if event.stripe: db.session.delete(event.stripe) event.tax_allow = bool(event_data['tax_allow'] == 1) if event.tax_allow: tax_data = event_data['tax'] tax = event.tax if not tax: tax = Tax(event_id=event.id) tax.country = tax_data['country'] tax.tax_name = tax_data['tax_name'] tax.send_invoice = tax_data['send_invoice'] tax.tax_id = tax_data['tax_id'] tax.registered_company = tax_data['registered_company'] tax.address = tax_data['address'] tax.state = tax_data['state'] tax.zip = tax_data['zip'] tax.tax_include_in_price = tax_data['tax_include_in_price'] tax.invoice_footer = tax_data['invoice_footer'] db.session.add(tax) else: if event.tax: db.session.delete(event.tax) if event.logo != event_data['logo']: if event_data['logo'] and event_data['logo'].strip() != '': event.logo = save_logo(event_data['logo'], event.id) elif event.logo != '': event.logo = '' save_to_db(event) image_sizes = DataGetter.get_image_sizes_by_type(type='event') if not image_sizes: image_sizes = ImageSizes(full_width=1300, full_height=500, full_aspect='on', icon_width=75, icon_height=30, icon_aspect='on', thumbnail_width=500, thumbnail_height=200, thumbnail_aspect='on', type='event') save_to_db(image_sizes, "Image Sizes Saved") if event.background_url != event_data['background_url']: if event_data['background_url'] and event_data['background_url'].strip() != '': background_url = event_data['background_url'] jpg_image = convert_background_to_jpg(background_url) event.background_url = save_untouched_background(background_url, event.id) event.large = save_resized_background(jpg_image, event.id, 'large', image_sizes) event.thumbnail = save_resized_background(jpg_image, event.id, 'thumbnail', image_sizes) event.icon = save_resized_background(jpg_image, event.id, 'icon', image_sizes) os.remove(jpg_image) save_to_db(event) elif event.background_url != '': event.background_url = '' event.large = '' event.thumbnail = '' event.icon = '' save_to_db(event) if not is_edit: role = Role.query.filter_by(name=ORGANIZER).first() uer = UsersEventsRoles(login.current_user, event, role) if save_to_db(uer, "Event saved"): new_email_notification_setting = EmailNotification(next_event=1, new_paper=1, session_schedule=1, session_accept_reject=1, after_ticket_purchase=1, user_id=login.current_user.id, event_id=event.id) save_to_db(new_email_notification_setting, "EmailSetting Saved") return { 'event_id': event.id }
def index_view(self): if request.method == 'POST': if 'thumbnail_width' in request.form: im_size = DataGetter.get_image_sizes() if im_size: im_size.full_width = request.form['large_width'] im_size.full_height = request.form['large_height'] im_size.icon_width = request.form['icon_width'] im_size.icon_height = request.form['icon_height'] im_size.thumbnail_width = request.form['thumbnail_width'] im_size.thumbnail_height = request.form['thumbnail_height'] else: im_size = ImageSizes( full_width=request.form['large_width'], full_height=request.form['large_height'], icon_width=request.form['icon_width'], icon_height=request.form['icon_width'], thumbnail_width=request.form['thumbnail_width'], thumbnail_height=request.form['thumbnail_width']) save_to_db(im_size, "Image Sizes saved") im_config = DataGetter.get_image_configs() if im_config: for config in im_config: config.size = request.form['size_' + config.page] save_to_db(config, "Image Config Saved") else: config = ImageConfig(page='front', size=request.form['size_front']) save_to_db(config, "Image Config Saved") config = ImageConfig(page='mysession', size=request.form['size_mysession']) save_to_db(config, "Image Config Saved") config = ImageConfig(page='event', size=request.form['size_event']) save_to_db(config, "Image Config Saved") config = ImageConfig( page='speaker_event', size=request.form['size_speaker_event']) save_to_db(config, "Image Config Saved") config = ImageConfig( page='speaker_dashboard', size=request.form['size_speaker_dashboard']) save_to_db(config, "Image Config Saved") if 'service_fee' in request.form: dic = ImmutableMultiDict(request.form) else: dic = dict(request.form.copy()) for i in dic: v = dic[i][0] if not v: dic[i] = None else: dic[i] = v set_settings(**dic) settings = get_settings() fees = DataGetter.get_fee_settings() event_view = EventsView() return self.render( '/gentelella/admin/super_admin/settings/settings.html', settings=settings, fees=fees, payment_currencies=DataGetter.get_payment_currencies(), included_settings=event_view.get_module_settings())
def index_view(): if request.method == 'POST': if 'super_admin_email' in request.form: super_admin = DataGetter.get_super_admin_user() super_admin.email = request.form['super_admin_email'] save_to_db(super_admin) if 'event-thumbnail_width' in request.form: im_size_profile = DataGetter.get_image_sizes_by_type(type='profile') im_size_event = DataGetter.get_image_sizes_by_type(type='event') if im_size_profile and im_size_event: im_size_profile.full_width = request.form['profile-large_width'] im_size_profile.full_height = request.form['profile-large_width'] im_size_profile.full_aspect = request.form.get('profile-large_aspect', 'off') im_size_profile.full_quality = request.form['profile-large_quality'] im_size_profile.icon_width = request.form['profile-icon_width'] im_size_profile.icon_height = request.form['profile-icon_width'] im_size_profile.icon_aspect = request.form.get('profile-icon_aspect', 'off') im_size_profile.icon_quality = request.form['profile-icon_quality'] im_size_profile.thumbnail_width = request.form['profile-thumbnail_width'] im_size_profile.thumbnail_height = request.form['profile-thumbnail_width'] im_size_profile.thumbnail_aspect = request.form.get('profile-thumbnail_aspect', 'off') im_size_profile.thumbnail_quality = request.form['profile-thumbnail_quality'] im_size_profile.logo_width = None im_size_profile.logo_height = None save_to_db(im_size_profile, "Image Sizes saved") im_size_event.full_width = request.form['event-large_width'] im_size_event.full_height = request.form['event-large_height'] im_size_event.full_aspect = request.form.get('event-large_aspect', 'off') im_size_event.full_quality = request.form['event-large_quality'] im_size_event.icon_width = request.form['event-icon_width'] im_size_event.icon_height = request.form['event-icon_height'] im_size_event.icon_aspect = request.form.get('event-icon_aspect', 'off') im_size_event.icon_quality = request.form['event-icon_quality'] im_size_event.thumbnail_width = request.form['event-thumbnail_width'] im_size_event.thumbnail_height = request.form['event-thumbnail_height'] im_size_event.thumbnail_aspect = request.form.get('event-thumbnail_aspect', 'off') im_size_event.thumbnail_quality = request.form['event-thumbnail_quality'] im_size_event.logo_width = request.form['logo_width'] im_size_event.logo_height = request.form['logo_height'] save_to_db(im_size_event, "Image Sizes saved") else: all_im_sizes = DataGetter.get_image_sizes() for sizes in all_im_sizes: delete_from_db(sizes, 'Delete Image Sizes') im_size = ImageSizes(type='profile', full_width=request.form['profile-large_width'], full_height=request.form['profile-large_width'], full_aspect=request.form.get('profile-large_aspect', 'off'), full_quality=request.form['profile-large_quality'], icon_width=request.form['profile-icon_width'], icon_height=request.form['profile-icon_width'], icon_aspect=request.form.get('profile-icon_aspect', 'off'), icon_quality=request.form['profile-icon_quality'], thumbnail_width=request.form['profile-thumbnail_width'], thumbnail_height=request.form['profile-thumbnail_width'], thumbnail_aspect=request.form.get('profile-thumbnail_aspect', 'off'), thumbnail_quality=request.form['profile-thumbnail_quality'], logo_width=None, logo_height=None) save_to_db(im_size, "Image Sizes saved") im_size = ImageSizes(type='event', full_width=request.form['event-large_width'], full_height=request.form['event-large_height'], full_aspect=request.form.get('event-large_aspect', 'off'), full_quality=request.form['profile-large_quality'], icon_width=request.form['event-icon_width'], icon_height=request.form['event-icon_height'], icon_aspect=request.form.get('event-icon_aspect', 'off'), icon_quality=request.form['profile-icon_quality'], thumbnail_width=request.form['event-thumbnail_width'], thumbnail_height=request.form['event-thumbnail_height'], thumbnail_aspect=request.form.get('event-thumbnail_aspect', 'off'), thumbnail_quality=request.form['profile-thumbnail_quality'], logo_width=request.form['logo_width'], logo_height=request.form['logo_height']) save_to_db(im_size, "Image Sizes saved") if 'service_fee' in request.form: dic = ImmutableMultiDict(request.form) else: dic = dict(request.form.copy()) for i in dic: v = dic[i][0] if not v: dic[i] = None else: dic[i] = v set_settings(**dic) settings = get_settings() fees = DataGetter.get_fee_settings() image_config = DataGetter.get_image_configs() event_image_sizes = DataGetter.get_image_sizes_by_type(type='event') profile_image_sizes = DataGetter.get_image_sizes_by_type(type='profile') return render_template( 'gentelella/admin/super_admin/settings/settings.html', settings=settings, fees=fees, s3_regions=boto.s3.regions(), payment_currencies=DataGetter.get_payment_currencies(), included_settings=get_module_settings(), image_config=image_config, super_admin_email=DataGetter.get_super_admin_user().email, event_image_sizes=event_image_sizes, profile_image_sizes=profile_image_sizes, navigation_bar=list_navbar() )