示例#1
0
 def toggle_email_notification_settings(user_id, value):
     """
     Settings will be toggled to database with proper User id
     """
     events = DataGetter.get_all_events()
     user = DataGetter.get_user(user_id)
     notification_ids = []
     for event in events:
         if user.is_speaker_at_event(event.id) or user.is_organizer(event.id):
             email_notification = DataGetter.get_email_notification_settings_by_event_id(user_id, event.id)
             if email_notification:
                 email_notification.next_event = value
                 email_notification.new_paper = value
                 email_notification.session_schedule = value
                 email_notification.session_accept_reject = value
                 email_notification.after_ticket_purchase = value
                 save_to_db(email_notification, "EmailSettings Toggled")
                 notification_ids.append(email_notification.id)
             else:
                 new_email_notification_setting = EmailNotification(next_event=value,
                                                                    new_paper=value,
                                                                    session_schedule=value,
                                                                    session_accept_reject=value,
                                                                    after_ticket_purchase=value,
                                                                    user_id=user_id,
                                                                    event_id=event.id)
                 save_to_db(new_email_notification_setting, "EmailSetting Toggled")
                 notification_ids.append(new_email_notification_setting.id)
     return notification_ids
def get_or_create_notification_settings(event_id):
    email_notification = DataGetter \
        .get_email_notification_settings_by_event_id(login.current_user.id, event_id)
    if email_notification:
        return email_notification
    else:
        email_notification = EmailNotification(next_event=1,
                                               new_paper=1,
                                               session_schedule=1,
                                               session_accept_reject=1,
                                               user_id=login.current_user.id,
                                               event_id=event_id)
        return email_notification
示例#3
0
def create_event_copy(event_id):
    old_event = DataGetter.get_event(event_id)
    event = clone_row(old_event)
    event.name = "Copy of " + event.name
    event.identifier = get_new_event_identifier()
    event.state = "Draft"
    save_to_db(event)

    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")

    sponsors_old = DataGetter.get_sponsors(event_id).all()
    tracks_old = DataGetter.get_tracks(event_id).all()
    microlocations_old = DataGetter.get_microlocations(event_id).all()
    call_for_paper_old = DataGetter.get_call_for_papers(event_id).first()
    social_links = DataGetter.get_social_links_by_event_id(event_id).all()
    custom_forms = DataGetter.get_custom_form_elements(event_id)

    for social_link in social_links:
        clone_row(social_link, event.id)

    for sponsor in sponsors_old:
        clone_row(sponsor, event.id)

    for track in tracks_old:
        clone_row(track, event.id)

    for microlocation in microlocations_old:
        clone_row(microlocation, event.id)

    if call_for_paper_old:
        clone_row(call_for_paper_old, event.id)

    if custom_forms:
        clone_row(custom_forms, event.id)

    return event
示例#4
0
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
    }