コード例 #1
0
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))
コード例 #2
0
def record_user_login_logout(template, user):
    req_stats = get_request_stats()
    record_activity(
        template,
        user=user,
        **req_stats
    )
コード例 #3
0
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))
コード例 #4
0
def unpublish_event(event_id):
    event = DataGetter.get_event(event_id)
    event.state = 'Draft'
    save_to_db(event, 'Event Unpublished')
    record_activity('publish_event', event_id=event.id, status='un-published')
    flash("Your event has been unpublished.", "warning")
    return redirect(url_for('.details_view', event_id=event_id))
コード例 #5
0
def unpublish_event(event_id):
    event = DataGetter.get_event(event_id)
    event.state = 'Draft'
    save_to_db(event, 'Event Unpublished')
    record_activity('publish_event', event_id=event.id, status='un-published')
    flash("Your event has been unpublished.", "warning")
    return redirect(url_for('.details_view', event_id=event_id))
コード例 #6
0
 def post(self, event_id):
     """Create a session"""
     item = DAO.create(
         event_id,
         self.api.payload,
         self.api.url_for(self, event_id=event_id)
     )
     record_activity('create_session', session=item[0], event_id=event_id)
     return item
コード例 #7
0
 def post(self, event_id):
     """Create a session"""
     item = DAO.create(
         event_id,
         self.api.payload,
         self.api.url_for(self, event_id=event_id)
     )
     record_activity('create_session', session=item[0], event_id=event_id)
     return item
コード例 #8
0
 def get(self, event_id, path):
     if not path.startswith('/'):
         path = '/' + path
     if not os.path.isfile(path):
         return 'Not Found', 404
     response = make_response(send_file(path))
     response.headers['Content-Disposition'] = 'attachment; filename=event%d.zip' % event_id
     record_activity('export_event', event_id=event_id)
     return response
コード例 #9
0
def import_event_task_base(task_handle, file_path, source_type='json', current_user=None):
    new_event = None
    if source_type == 'json':
        new_event = import_event_json(task_handle, file_path)
    elif source_type == 'pentabarf':
        new_event = ImportHelper.import_from_pentabarf(file_path=file_path, task_handle=task_handle,
                                                       creator=current_user)
    if new_event:
        record_activity('import_event', event_id=new_event.id)
        return marshal(new_event, EVENT)
    else:
        return None
コード例 #10
0
def import_event_task_base(task_handle, file_path, source_type='json', creator_id=None):
    new_event = None
    if source_type == 'json':
        new_event = import_event_json(task_handle, file_path)
    elif source_type == 'pentabarf':
        new_event = PentabarfImporter.import_data(file_path=file_path, task_handle=task_handle, creator_id=creator_id)
    elif source_type == 'ical':
        new_event = ICalImporter.import_data(file_path=file_path, task_handle=task_handle, creator_id=creator_id)
    if new_event:
        record_activity('import_event', event_id=new_event.id)
        return marshal(new_event, EVENT)
    else:
        return None
コード例 #11
0
def save_speaker(request,
                 event_id=None,
                 speaker=None,
                 user=None,
                 no_name=False):
    if not speaker and not event_id:
        raise Exception('event_id or speaker is required')

    from app.helpers.data import save_to_db, record_activity

    if not speaker:
        if no_name:
            speaker = Speaker(event_id=event_id,
                              user=user,
                              name='',
                              email=trim_get_form(request.form, 'email', None))
        else:
            speaker = Speaker(event_id=event_id,
                              user=user,
                              name=trim_get_form(request.form, 'name', None),
                              email=trim_get_form(request.form, 'email', None))
        save_to_db(speaker)

    speaker.email = trim_get_form(request.form, 'email', None)
    if trim_get_form(request.form, 'name', None):
        speaker.name = trim_get_form(request.form, 'name', speaker.name)

    if not speaker.user:
        if user:
            speaker.user = user
        else:
            speaker.user = DataGetter.get_or_create_user_by_email(
                speaker.email, {
                    'firstname': speaker.name,
                    'lastname': ''
                })

    if not event_id:
        event_id = speaker.event_id

    image_sizes = speaker_image_sizes()

    if not speaker.photo:
        photo = trim_get_form(request.form, 'photo', None)
        if photo and photo.strip() != '':
            if speaker.photo != photo:
                file_path = get_path_of_temp_url(photo)
                speaker.photo = save_untouched_photo(photo, event_id,
                                                     speaker.id)
                speaker.small = save_resized_photo(file_path, event_id,
                                                   speaker.id, 'small',
                                                   image_sizes)
                speaker.thumbnail = save_resized_photo(file_path, event_id,
                                                       speaker.id, 'thumbnail',
                                                       image_sizes)
                speaker.icon = save_resized_photo(file_path, event_id,
                                                  speaker.id, 'icon',
                                                  image_sizes)
        else:
            speaker.photo = ''
            speaker.small = ''
            speaker.thumbnail = ''
            speaker.icon = ''

    speaker.short_biography = trim_get_form(request.form, 'short_biography',
                                            speaker.short_biography)
    speaker.long_biography = trim_get_form(request.form, 'long_biography',
                                           speaker.long_biography)
    speaker.mobile = trim_get_form(request.form, 'mobile', speaker.mobile)
    speaker.website = trim_get_form(request.form, 'website', speaker.website)
    speaker.twitter = trim_get_form(request.form, 'twitter', speaker.twitter)
    speaker.facebook = trim_get_form(request.form, 'facebook',
                                     speaker.facebook)
    speaker.github = trim_get_form(request.form, 'github', speaker.github)
    speaker.linkedin = trim_get_form(request.form, 'linkedin',
                                     speaker.linkedin)
    speaker.organisation = trim_get_form(request.form, 'organisation',
                                         speaker.organisation)
    speaker.featured = True if request.form.get(
        'featured', speaker.featured) == 'true' else False
    speaker.position = trim_get_form(request.form, 'position',
                                     speaker.position)
    speaker.country = trim_get_form(request.form, 'country', speaker.country)
    speaker.city = trim_get_form(request.form, 'city', speaker.city)
    speaker.gender = trim_get_form(request.form, 'gender', speaker.gender)
    if trim_get_form(request.form, 'heard_from', None) == "Other":
        speaker.heard_from = trim_get_form(request.form, 'other_text',
                                           speaker.other_text)
    else:
        speaker.heard_from = trim_get_form(request.form, 'heard_from',
                                           speaker.heard_from)
    speaker.sponsorship_required = trim_get_form(request.form,
                                                 'sponsorship_required',
                                                 speaker.sponsorship_required)
    speaker.speaking_experience = trim_get_form(request.form,
                                                'speaking_experience',
                                                speaker.speaking_experience)
    speakers_modified.send(app._get_current_object(), event_id=event_id)
    save_to_db(speaker, "Speaker has been updated")
    record_activity('update_speaker', speaker=speaker, event_id=event_id)
    return speaker
コード例 #12
0
def import_event_task_base(task_handle, file):
    new_event = import_event_json(task_handle, file)
    record_activity('import_event', event_id=new_event.id)
    return marshal(new_event, EVENT)
コード例 #13
0
 def put(self, user_id):
     """Update a user given its id"""
     user = DAO.update(user_id, self.api.payload)
     record_activity('update_user', user=user)
     return user
コード例 #14
0
 def post(self):
     """Create an event"""
     item = DAO.create(self.api.payload, self.api.url_for(self))
     record_activity('create_event', event_id=item[0].id)
     return item
コード例 #15
0
 def delete(self, event_id):
     """Delete an event given its id"""
     event = DAO.delete(event_id)
     record_activity('delete_event', event_id=event_id)
     return event
コード例 #16
0
 def delete(self, event_id):
     """Delete an event given its id"""
     event = DAO.delete(event_id)
     record_activity('delete_event', event_id=event_id)
     return event
コード例 #17
0
 def put(self, event_id):
     """Update an event given its id"""
     event = DAO.update(event_id, self.api.payload)
     record_activity('update_event', event_id=event_id)
     return event
コード例 #18
0
 def put(self, event_id):
     """Update an event given its id"""
     event = DAO.update(event_id, self.api.payload)
     record_activity('update_event', event_id=event_id)
     return event
コード例 #19
0
 def post(self):
     """Create an event"""
     item = DAO.create(self.api.payload, self.api.url_for(self))
     record_activity('create_event', event_id=item[0].id)
     return item
コード例 #20
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
    }
コード例 #21
0
def save_speaker(request, event_id=None, speaker=None, user=None, no_name=False):
    if not speaker and not event_id:
        raise Exception('event_id or speaker is required')

    from app.helpers.data import save_to_db, record_activity

    if not speaker:
        if no_name:
            speaker = Speaker(
                event_id=event_id,
                user=user,
                name='',
                email=trim_get_form(request.form, 'email', None)
            )
        else:
            speaker = Speaker(
                event_id=event_id,
                user=user,
                name=trim_get_form(request.form, 'name', None),
                email=trim_get_form(request.form, 'email', None)
            )
        save_to_db(speaker)

    speaker.email = trim_get_form(request.form, 'email', None)
    if trim_get_form(request.form, 'name', None):
        speaker.name = trim_get_form(request.form, 'name', None)

    if not speaker.user:
        if user:
            speaker.user = user
        else:
            speaker.user = DataGetter.get_or_create_user_by_email(speaker.email, {
                'firstname': speaker.name,
                'lastname': ''
            })

    if not event_id:
        event_id = speaker.event_id

    image_sizes = speaker_image_sizes()

    photo = trim_get_form(request.form, 'photo', None)
    if photo and photo.strip() != '':
        if speaker.photo != photo:
            file_path = get_path_of_temp_url(photo)
            speaker.photo = save_untouched_photo(photo, event_id, speaker.id)
            speaker.small = save_resized_photo(file_path, event_id, speaker.id, 'small', image_sizes)
            speaker.thumbnail = save_resized_photo(file_path, event_id, speaker.id, 'thumbnail', image_sizes)
            speaker.icon = save_resized_photo(file_path, event_id, speaker.id, 'icon', image_sizes)
    else:
        speaker.photo = ''
        speaker.small = ''
        speaker.thumbnail = ''
        speaker.icon = ''

    speaker.short_biography = trim_get_form(request.form, 'short_biography', None)
    speaker.long_biography = trim_get_form(request.form, 'long_biography', None)
    speaker.mobile = trim_get_form(request.form, 'mobile', None)
    speaker.website = trim_get_form(request.form, 'website', None)
    speaker.twitter = trim_get_form(request.form, 'twitter', None)
    speaker.facebook = trim_get_form(request.form, 'facebook', None)
    speaker.github = trim_get_form(request.form, 'github', None)
    speaker.linkedin = trim_get_form(request.form, 'linkedin', None)
    speaker.organisation = trim_get_form(request.form, 'organisation', None)
    speaker.featured = True if trim_get_form(request.form, 'featured', 'false') == 'true' else False
    speaker.position = trim_get_form(request.form, 'position', None)
    speaker.country = trim_get_form(request.form, 'country', None)
    speaker.city = trim_get_form(request.form, 'city', None)
    speaker.gender = trim_get_form(request.form, 'gender', None)
    if trim_get_form(request.form, 'heard_from', None) == "Other":
        speaker.heard_from = trim_get_form(request.form, 'other_text', None)
    else:
        speaker.heard_from = trim_get_form(request.form, 'heard_from', None)
    speaker.sponsorship_required = trim_get_form(request.form, 'sponsorship_required', None)
    speaker.speaking_experience = trim_get_form(request.form, 'speaking_experience', None)
    save_to_db(speaker, "Speaker has been updated")
    record_activity('update_speaker', speaker=speaker, event_id=event_id)
    return speaker
コード例 #22
0
def record_user_login_logout(template, user):
    req_stats = get_request_stats()
    record_activity(template, user=user, **req_stats)
コード例 #23
0
 def put(self, user_id):
     """Update a user given its id"""
     user = DAO.update(user_id, self.api.payload)
     record_activity('update_user', user=user)
     return user
コード例 #24
0
def import_event_task_base(task_handle, file):
    new_event = import_event_json(task_handle, file)
    record_activity('import_event', event_id=new_event.id)
    return marshal(new_event, EVENT)