def publish_event(event_id): event = DataGetter.get_event(event_id) if string_empty(event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect(url_for('.edit_view', event_id=event.id) + "#highlight=location_name") if not current_user.can_publish_event(): flash("You don't have permission to publish event.") return redirect(url_for('.details_view', event_id=event_id)) event.state = 'Published' save_to_db(event, 'Event Published') organizers = DataGetter.get_user_event_roles_by_role_name(event_id, 'organizer') speakers = DataGetter.get_user_event_roles_by_role_name(event_id, 'speaker') link = url_for('.details_view', event_id=event_id, _external=True) for organizer in organizers: send_event_publish(organizer.user.email, event.name, link) for speaker in speakers: send_event_publish(speaker.user.email, event.name, link) record_activity('publish_event', event_id=event.id, status='published') flash("Your event has been published.", "success") return redirect(url_for('.details_view', event_id=event_id))
def get_locations_of_events(): names = [] for event in DataGetter.get_live_and_public_events(): if not string_empty(event.location_name) and not string_empty(event.latitude) and not string_empty(event.longitude): response = requests.get( "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + str(event.latitude) + "," + str( event.longitude)).json() if response['status'] == u'OK': for addr in response['results'][0]['address_components']: if addr['types'] == ['locality', 'political']: names.append(addr['short_name']) cnt = Counter() for location in names: cnt[location] += 1 return [v for v, k in cnt.most_common()][:10]
def publish_event(event_id): event = DataGetter.get_event(event_id) if string_empty(event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect( url_for('.edit_view', event_id=event.id) + "#highlight=location_name") if not current_user.can_publish_event(): flash("You don't have permission to publish event.") return redirect(url_for('.details_view', event_id=event_id)) event.state = 'Published' save_to_db(event, 'Event Published') organizers = DataGetter.get_user_event_roles_by_role_name( event_id, 'organizer') speakers = DataGetter.get_user_event_roles_by_role_name( event_id, 'speaker') link = url_for('.details_view', event_id=event_id, _external=True) for organizer in organizers: send_event_publish(organizer.user.email, event.name, link) for speaker in speakers: send_event_publish(speaker.user.email, event.name, link) record_activity('publish_event', event_id=event.id, status='published') flash("Your event has been published.", "success") event_json_modified.send(current_app._get_current_object(), event_id=event_id) return redirect(url_for('.details_view', event_id=event_id))
def get_locations_of_events(): names = [] try: for event in DataGetter.get_live_and_public_events(): if not string_empty(event.location_name) and not string_empty(event.latitude) and not string_empty( event.longitude): response = requests.get( "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + str(event.latitude) + "," + str( event.longitude)).json() if response['status'] == u'OK': for addr in response['results'][0]['address_components']: if addr['types'] == ['locality', 'political']: names.append(addr['short_name']) cnt = Counter() for location in names: cnt[location] += 1 return [v for v, __ in cnt.most_common()][:10] except: return names
def create_view(self, ): if request.method == 'POST': if not current_user.can_create_event(): flash("You don't have permission to create event.") return redirect(url_for('.index_view')) img_files = [] imd = ImmutableMultiDict(request.files) if 'sponsors[logo]' in imd and request.files[ 'sponsors[logo]'].filename != "": for img_file in imd.getlist('sponsors[logo]'): img_files.append(img_file) event = DataManager.create_event(request.form, img_files) if request.form.get('state', u'Draft') == u'Published' and string_empty( event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect( url_for('.edit_view', event_id=event.id) + "#step=location_name") if event: return redirect(url_for('.details_view', event_id=event.id)) return redirect(url_for('.index_view')) hash = get_random_hash() if CallForPaper.query.filter_by(hash=hash).all(): hash = get_random_hash() match = geolite2.lookup(get_real_ip(True) or '127.0.0.1') if match is not None: current_timezone = match.timezone else: current_timezone = 'UTC' return self.render( '/gentelella/admin/event/new/new.html', current_date=datetime.datetime.now(), start_date=datetime.datetime.now() + datetime.timedelta(days=10), event_types=DataGetter.get_event_types(), event_licences=DataGetter.get_event_licences(), event_topics=DataGetter.get_event_topics(), event_sub_topics=DataGetter.get_event_subtopics(), timezones=DataGetter.get_all_timezones(), cfs_hash=hash, current_timezone=current_timezone, payment_countries=DataGetter.get_payment_countries(), payment_currencies=DataGetter.get_payment_currencies(), included_settings=self.get_module_settings())
def create_order(form, from_organizer=False): order = Order() order.status = 'pending' order.identifier = TicketingManager.get_new_order_identifier() order.event_id = form.get('event_id') if from_organizer: order.paid_via = form.get('payment_via') ticket_ids = form.getlist('ticket_ids[]') ticket_quantity = form.getlist('ticket_quantities[]') ticket_discount=form.get('promo_code','') discount=None if ticket_discount: discount=TicketingManager.get_discount_code(form.get('event_id'), form.get('promo_code','')) if not discount: flash('The promotional code entered is not valid. No offer has been applied to this order.', 'danger') else: flash('The promotional code entered is valid.offer has been applied to this order.', 'success') ticket_subtotals = [] if from_organizer: ticket_subtotals = form.getlist('ticket_subtotals[]') amount = 0 for index, id in enumerate(ticket_ids): if not string_empty(id) and int(ticket_quantity[index]) > 0: with db.session.no_autoflush: order_ticket = OrderTicket() order_ticket.ticket = TicketingManager.get_ticket(id) order_ticket.quantity = int(ticket_quantity[index]) order.tickets.append(order_ticket) if from_organizer: amount += int(ticket_subtotals[index]) else: amount += (order_ticket.ticket.price * order_ticket.quantity) if discount and discount.type=="amount": order.amount = max(amount-discount.value,0) elif discount: order.amount=amount-(discount.value*amount/100) else: order.amount=amount if login.current_user.is_authenticated: order.user_id = login.current_user.id save_to_db(order) return order
def create_view(self,): ticket_include = [] if request.method == 'POST': img_files = [] imd = ImmutableMultiDict(request.files) if 'sponsors[logo]' in imd and request.files['sponsors[logo]'].filename != "": for img_file in imd.getlist('sponsors[logo]'): img_files.append(img_file) event = DataManager.create_event(request.form, img_files) if request.form.get('state', u'Draft') == u'Published' and string_empty(event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect(url_for( '.edit_view', event_id=event.id) + "#step=location_name") if event: return redirect(url_for('.details_view', event_id=event.id)) return redirect(url_for('.index_view')) module = DataGetter.get_module() if module is not None: if module.ticket_include: ticket_include.append('ticketing') hash = get_random_hash() if CallForPaper.query.filter_by(hash=hash).all(): hash = get_random_hash() return self.render( '/gentelella/admin/event/new/new.html', start_date=datetime.datetime.now() + datetime.timedelta(days=10), event_types=DataGetter.get_event_types(), event_licences=DataGetter.get_event_licences(), event_topics=DataGetter.get_event_topics(), event_sub_topics=DataGetter.get_event_subtopics(), timezones=DataGetter.get_all_timezones(), cfs_hash=hash, ticket_include_setting=ticket_include)
def create_order(form, from_organizer=False): order = Order() order.status = 'pending' order.identifier = TicketingManager.get_new_order_identifier() order.event_id = form.get('event_id') if from_organizer: order.paid_via = form.get('payment_via') ticket_ids = form.getlist('ticket_ids[]') ticket_quantity = form.getlist('ticket_quantities[]') ticket_subtotals = [] if from_organizer: ticket_subtotals = form.getlist('ticket_subtotals[]') amount = 0 for index, id in enumerate(ticket_ids): if not string_empty(id) and int(ticket_quantity[index]) > 0: with db.session.no_autoflush: order_ticket = OrderTicket() order_ticket.ticket = TicketingManager.get_ticket(id) order_ticket.quantity = int(ticket_quantity[index]) order.tickets.append(order_ticket) if from_organizer: amount += int(ticket_subtotals[index]) else: amount += (order_ticket.ticket.price * order_ticket.quantity) order.amount = amount if login.current_user.is_authenticated: order.user_id = login.current_user.id save_to_db(order) return order
def create_order(form, from_organizer=False): order = Order() order.status = 'pending' order.identifier = TicketingManager.get_new_order_identifier() order.event_id = form.get('event_id') if from_organizer: order.paid_via = form.get('payment_via') ticket_ids = form.getlist('ticket_ids[]') ticket_quantity = form.getlist('ticket_quantities[]') ticket_discount = form.get('promo_code', '') discount = None if ticket_discount: discount = TicketingManager.get_discount_code(form.get('event_id'), form.get('promo_code', '')) access_code = TicketingManager.get_access_code(form.get('event_id'), form.get('promo_code', '')) if access_code and discount: order.discount_code = discount flash('Both access code and discount code have been applied. You can make this order now.', 'success') elif discount: order.discount_code = discount flash('The promotional code entered is valid. Offer has been applied to this order.', 'success') elif access_code: flash('Your access code is applied and you can make this order now.', 'success') else: flash('The promotional code entered is not valid. No offer has been applied to this order.', 'danger') ticket_subtotals = [] if from_organizer: ticket_subtotals = form.getlist('ticket_subtotals[]') amount = 0 total_discount = 0 fees = DataGetter.get_fee_settings_by_currency(DataGetter.get_event(order.event_id).payment_currency) for index, id in enumerate(ticket_ids): if not string_empty(id) and int(ticket_quantity[index]) > 0: with db.session.no_autoflush: order_ticket = OrderTicket() order_ticket.ticket = TicketingManager.get_ticket(id) order_ticket.quantity = int(ticket_quantity[index]) order.tickets.append(order_ticket) if order_ticket.ticket.absorb_fees or not fees: ticket_amount = (order_ticket.ticket.price * order_ticket.quantity) amount += (order_ticket.ticket.price * order_ticket.quantity) else: order_fee = fees.service_fee * (order_ticket.ticket.price * order_ticket.quantity) / 100 if order_fee > fees.maximum_fee: ticket_amount = (order_ticket.ticket.price * order_ticket.quantity) + fees.maximum_fee amount += (order_ticket.ticket.price * order_ticket.quantity) + fees.maximum_fee else: ticket_amount = (order_ticket.ticket.price * order_ticket.quantity) + order_fee amount += (order_ticket.ticket.price * order_ticket.quantity) + order_fee if from_organizer: amount += float(ticket_subtotals[index]) else: if discount and str(order_ticket.ticket.id) in discount.tickets.split(","): if discount.type == "amount": total_discount += discount.value * order_ticket.quantity else: total_discount += discount.value * ticket_amount / 100 if discount: order.amount = max(amount - total_discount, 0) elif discount: order.amount = amount - (discount.value * amount / 100.0) else: order.amount = amount if login.current_user.is_authenticated: order.user_id = login.current_user.id save_to_db(order) return order
def add_session_to_event(request, event_id, state=None, use_current_user=True): """ Session will be saved to database with proper Event id :param use_current_user: :param state: :param request: The request :param event_id: Session belongs to Event by event id """ form = request.form slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1]) if video_temp_url: video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1]) if audio_temp_url: audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1]) if not state: state = form.get('state', 'draft') event = DataGetter.get_event(event_id) new_session = Session(title=form.get('title', ''), subtitle=form.get('subtitle', ''), long_abstract=form.get('long_abstract', ''), start_time=event.start_time, end_time=event.start_time + timedelta(hours=1), event_id=event_id, short_abstract=form.get('short_abstract', ''), level=form.get('level', ''), comments=form.get('comments', ''), language=form.get('language', ''), state=state) if form.get('track', None) != "": new_session.track_id = form.get('track', None) if form.get('session_type', None) != "": new_session.session_type_id = form.get('session_type', None) speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first() speaker = save_speaker( request, event_id=event_id, speaker=speaker, user=login.current_user if use_current_user else None ) new_session.speakers.append(speaker) save_to_db(new_session, "Session saved") if state == 'pending': trigger_new_session_notifications(new_session.id, event=event) if slide_temp_url != "" and slide_file: slide_url = upload( slide_file, UPLOAD_PATHS['sessions']['slides'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.slides = slide_url if audio_temp_url != "" and audio_file: audio_url = upload( audio_file, UPLOAD_PATHS['sessions']['audio'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.audio = audio_url if video_temp_url != "" and video_file: video_url = upload( video_file, UPLOAD_PATHS['sessions']['video'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.video = video_url record_activity('create_session', session=new_session, event_id=event_id) update_version(event_id, False, 'sessions_ver') invite_emails = form.getlist("speakers[email]") for index, email in enumerate(invite_emails): if not string_empty(email): new_invite = Invite(event_id=event_id, session_id=new_session.id) hash = random.getrandbits(128) new_invite.hash = "%032x" % hash save_to_db(new_invite, "Invite saved") link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True) Helper.send_email_invitation(email, new_session.title, link) # If a user is registered by the email, send a notification as well user = DataGetter.get_user_by_email(email, no_flash=True) if user: cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier) Helper.send_notif_invite_papers(user, event.name, cfs_link, link)
def add_session_to_event(request, event_id, state=None, use_current_user=True, no_name=False): """ Session will be saved to database with proper Event id :param use_current_user: :param state: :param request: The request :param event_id: Session belongs to Event by event id """ form = request.form slide_temp_url = form.get('slides_url') video_temp_url = form.get('video_url') audio_temp_url = form.get('audio_url') slide_file = '' video_file = '' audio_file = '' if slide_temp_url: slide_file = UploadedFile(get_path_of_temp_url(slide_temp_url), slide_temp_url.rsplit('/', 1)[1]) if video_temp_url: video_file = UploadedFile(get_path_of_temp_url(video_temp_url), video_temp_url.rsplit('/', 1)[1]) if audio_temp_url: audio_file = UploadedFile(get_path_of_temp_url(audio_temp_url), audio_temp_url.rsplit('/', 1)[1]) if not state: state = form.get('state', 'draft') event = DataGetter.get_event(event_id) new_session = Session(title=form.get('title', ''), subtitle=form.get('subtitle', ''), long_abstract=form.get('long_abstract', ''), start_time=event.start_time, end_time=event.start_time + timedelta(hours=1), event_id=event_id, short_abstract=form.get('short_abstract', ''), level=form.get('level', ''), comments=form.get('comments', ''), language=form.get('language', ''), state=state) if form.get('track', None) != "": new_session.track_id = form.get('track', None) if form.get('session_type', None) != "": new_session.session_type_id = form.get('session_type', None) if form.get('email', '') != '': speaker = Speaker.query.filter_by(email=form.get('email', '')).filter_by(event_id=event_id).first() speaker = save_speaker( request, event_id=event_id, speaker=speaker, user=login.current_user if use_current_user else None, no_name=no_name ) new_session.speakers.append(speaker) save_to_db(new_session, "Session saved") if state == 'pending': trigger_new_session_notifications(new_session.id, event=event) if slide_temp_url != "" and slide_file: slide_url = upload( slide_file, UPLOAD_PATHS['sessions']['slides'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.slides = slide_url if audio_temp_url != "" and audio_file: audio_url = upload( audio_file, UPLOAD_PATHS['sessions']['audio'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.audio = audio_url if video_temp_url != "" and video_file: video_url = upload( video_file, UPLOAD_PATHS['sessions']['video'].format( event_id=int(event_id), id=int(new_session.id) )) new_session.video = video_url record_activity('create_session', session=new_session, event_id=event_id) update_version(event_id, False, 'sessions_ver') invite_emails = form.getlist("speakers[email]") for index, email in enumerate(invite_emails): if not string_empty(email): new_invite = Invite(event_id=event_id, session_id=new_session.id) hash = random.getrandbits(128) new_invite.hash = "%032x" % hash save_to_db(new_invite, "Invite saved") link = url_for('event_sessions.invited_view', session_id=new_session.id, event_id=event_id, _external=True) Helper.send_email_invitation(email, new_session.title, link) # If a user is registered by the email, send a notification as well user = DataGetter.get_user_by_email(email, no_flash=True) if user: cfs_link = url_for('event_detail.display_event_cfs', identifier=event.identifier) Helper.send_notif_invite_papers(user, event.name, cfs_link, link)
def string_empty(string): from app.helpers.helpers import string_empty return string_empty(string)
def edit_view_stepped(self, event_id, step): event = DataGetter.get_event(event_id) session_types = DataGetter.get_session_types_by_event_id( event_id).all() tracks = DataGetter.get_tracks(event_id).all() social_links = DataGetter.get_social_links_by_event_id(event_id) microlocations = DataGetter.get_microlocations(event_id).all() call_for_speakers = DataGetter.get_call_for_papers(event_id).first() sponsors = DataGetter.get_sponsors(event_id) custom_forms = DataGetter.get_custom_form_elements(event_id) speaker_form = json.loads(custom_forms.speaker_form) session_form = json.loads(custom_forms.session_form) tax = DataGetter.get_tax_options(event_id) ticket_types = DataGetter.get_ticket_types(event_id) preselect = [] required = [] for session_field in session_form: if session_form[session_field]['include'] == 1: preselect.append(session_field) if session_form[session_field]['require'] == 1: required.append(session_field) for speaker_field in speaker_form: if speaker_form[speaker_field]['include'] == 1: preselect.append(speaker_field) if speaker_form[speaker_field]['require'] == 1: required.append(speaker_field) if request.method == 'GET': hash = get_random_hash() if CallForPaper.query.filter_by(hash=hash).all(): hash = get_random_hash() match = geolite2.lookup(get_real_ip(True) or '127.0.0.1') if match is not None: current_timezone = match.timezone else: current_timezone = 'UTC' return self.render( '/gentelella/admin/event/edit/edit.html', event=event, session_types=session_types, tracks=tracks, social_links=social_links, microlocations=microlocations, call_for_speakers=call_for_speakers, sponsors=sponsors, event_types=DataGetter.get_event_types(), event_licences=DataGetter.get_event_licences(), event_topics=DataGetter.get_event_topics(), event_sub_topics=DataGetter.get_event_subtopics(), preselect=preselect, current_timezone=current_timezone, timezones=DataGetter.get_all_timezones(), cfs_hash=hash, step=step, required=required, included_settings=self.get_module_settings(), tax=tax, payment_countries=DataGetter.get_payment_countries(), current_date=datetime.datetime.now(), start_date=datetime.datetime.now() + datetime.timedelta(days=10), payment_currencies=DataGetter.get_payment_currencies(), ticket_types=ticket_types) if request.method == "POST": img_files = [] imd = ImmutableMultiDict(request.files) if 'sponsors[logo]' in imd and request.files[ 'sponsors[logo]'].filename != "": for img_file in imd.getlist('sponsors[logo]'): img_files.append(img_file) old_sponsor_logos = [] old_sponsor_names = [] for sponsor in sponsors: old_sponsor_logos.append(sponsor.logo) old_sponsor_names.append(sponsor.name) try: event = DataManager.edit_event( request, event_id, event, session_types, tracks, social_links, microlocations, call_for_speakers, sponsors, custom_forms, img_files, old_sponsor_logos, old_sponsor_names, tax) except Exception: traceback.print_exc() if (request.form.get('state', u'Draft') == u'Published') and string_empty(event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect( url_for('.edit_view', event_id=event.id) + "#highlight=location_name") return redirect(url_for('.details_view', event_id=event_id))
def edit_view_stepped(self, event_id, step): event = DataGetter.get_event(event_id) session_types = DataGetter.get_session_types_by_event_id(event_id).all( ) tracks = DataGetter.get_tracks(event_id).all() social_links = DataGetter.get_social_links_by_event_id(event_id) microlocations = DataGetter.get_microlocations(event_id).all() call_for_speakers = DataGetter.get_call_for_papers(event_id).first() sponsors = DataGetter.get_sponsors(event_id) custom_forms = DataGetter.get_custom_form_elements(event_id) speaker_form = json.loads(custom_forms.speaker_form) session_form = json.loads(custom_forms.session_form) tax = DataGetter.get_tax_options(event_id) ticket_types = DataGetter.get_ticket_types(event_id) preselect = [] required = [] for session_field in session_form: if session_form[session_field]['include'] == 1: preselect.append(session_field) if session_form[session_field]['require'] == 1: required.append(session_field) for speaker_field in speaker_form: if speaker_form[speaker_field]['include'] == 1: preselect.append(speaker_field) if speaker_form[speaker_field]['require'] == 1: required.append(speaker_field) print preselect if request.method == 'GET': hash = get_random_hash() if CallForPaper.query.filter_by(hash=hash).all(): hash = get_random_hash() return self.render('/gentelella/admin/event/edit/edit.html', event=event, session_types=session_types, tracks=tracks, social_links=social_links, microlocations=microlocations, call_for_speakers=call_for_speakers, sponsors=sponsors, event_types=DataGetter.get_event_types(), event_licences=DataGetter.get_event_licences(), event_topics=DataGetter.get_event_topics(), event_sub_topics=DataGetter.get_event_subtopics(), preselect=preselect, timezones=DataGetter.get_all_timezones(), cfs_hash=hash, step=step, required=required, included_settings=self.get_module_settings(), tax=tax, payment_countries=DataGetter.get_payment_countries(), start_date=datetime.datetime.now() + datetime.timedelta(days=10), payment_currencies=DataGetter.get_payment_currencies(), ticket_types=ticket_types) if request.method == "POST": img_files = [] imd = ImmutableMultiDict(request.files) if 'sponsors[logo]' in imd and request.files['sponsors[logo]'].filename != "": for img_file in imd.getlist('sponsors[logo]'): img_files.append(img_file) old_sponsor_logos = [] old_sponsor_names = [] for sponsor in sponsors: old_sponsor_logos.append(sponsor.logo) old_sponsor_names.append(sponsor.name) event = DataManager.edit_event( request, event_id, event, session_types, tracks, social_links, microlocations, call_for_speakers, sponsors, custom_forms, img_files, old_sponsor_logos, old_sponsor_names, tax) if (request.form.get('state', u'Draft') == u'Published') and string_empty( event.location_name): flash( "Your event was saved. To publish your event please review the highlighted fields below.", "warning") return redirect(url_for('.edit_view', event_id=event.id) + "#highlight=location_name") return redirect(url_for('.details_view', event_id=event_id))