コード例 #1
0
 def add_role_to_event(form, event_id, record=True):
     user = User.query.filter_by(email=form['user_email']).first()
     role = Role.query.filter_by(name=form['user_role']).first()
     uer = UsersEventsRoles(event=Event.query.get(event_id),
                            user=user, role=role)
     save_to_db(uer, "UserEventRole saved")
     if record:
         record_activity('create_role', role=role, user=user, event_id=event_id)
コード例 #2
0
def user_logged_in(user):
    speakers = DataGetter.get_speaker_by_email(user.email).all()
    for speaker in speakers:
        if not speaker.user:
            speaker.user = user
            role = Role.query.filter_by(name='speaker').first()
            event = DataGetter.get_event(speaker.event_id)
            uer = UsersEventsRoles(user=user, event=event, role=role)
            save_to_db(uer)
            save_to_db(speaker)
    return True
コード例 #3
0
 def test_role_delete(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         save_to_db(event, "Event saved")
         user = ObjectMother.get_user()
         save_to_db(user, "New user saved")
         populate()
         role = Role.query.filter_by(name='coorganizer').first()
         uer = UsersEventsRoles(user, event, role)
         save_to_db(uer, "UER Saved")
         rv = self.app.get(url_for('event_roles.delete_view',
                                   uer_id=uer.id,
                                   event_id=event.id),
                           follow_redirects=True)
         uer = UsersEventsRoles.query.get(uer.id)
         self.assertTrue(uer is None, msg=rv.data)
コード例 #4
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
コード例 #5
0
 def test_role_update(self):
     with app.test_request_context():
         event = ObjectMother.get_event()
         save_to_db(event, "Event saved")
         user = ObjectMother.get_user()
         save_to_db(user, "New user saved")
         populate()
         role = Role.query.filter_by(name='coorganizer').first()
         uer = UsersEventsRoles(user, event, role)
         save_to_db(uer, "UER Saved")
         data = {'user_email': user.email, 'user_role': 'track_organizer'}
         rv = self.app.post(url_for('event_roles.edit_view',
                                    uer_id=uer.id,
                                    event_id=event.id),
                            data=data,
                            follow_redirects=True)
         uer = DataGetter.get_user_event_roles_by_role_name(
             event.id, 'track_organizer').first()
         self.assertTrue(uer is not None, msg=rv.data)
コード例 #6
0
 def create(self, data, url):
     data = self.validate(data)
     payload = self.fix_payload(data)
     # save copyright info
     payload['copyright'] = CopyrightDAO.create(payload.get('copyright', {}), validate=False)
     # save cfs info
     if payload.get('call_for_papers'):  # don't create if call_for_papers==null
         payload['call_for_papers'] = CFSDAO.create(payload['call_for_papers'], validate=False)
     # save event
     new_event = self.model(**payload)
     save_to_db(new_event, "Event saved")
     # set organizer
     role = Role.query.filter_by(name=ORGANIZER).first()
     uer = UsersEventsRoles(g.user, new_event, role)
     save_to_db(uer, 'UER saved')
     # Return created resource with a 201 status code and its Location
     # (url) in the header.
     resource_location = url + '/' + str(new_event.id)
     return self.get(new_event.id), 201, {'Location': resource_location}
コード例 #7
0
def own_event(event, user_id):
    role = Role.query.filter_by(name=ORGANIZER).first()
    uer = UsersEventsRoles(user_id=user_id, event=event, role=role)
    save_to_db(uer, 'UER saved')
コード例 #8
0
 def add_attendee_role_to_event(user, event_id):
     role = Role.query.filter_by(name=ATTENDEE).first()
     uer = UsersEventsRoles(event=Event.query.get(event_id), user=user, role=role)
     save_to_db(uer, "Attendee saved")
コード例 #9
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
    }