Ejemplo n.º 1
0
def create_event(template_id):
    form = EventForm()
    populate_select_boxes(form)

    if request.method == 'GET':
        if not template_id:
            return redirect(url_for('create_event')+'/1')
        form.loadTemplates()
        template = EventTemplate.query.filter_by(id=template_id).first()
        set_select_box_defaults(template, form)
        form.process()
        form.populate(template)
        return render_template('create_event.html', title='Create Event',
                               form=form, event=template)

    if request.method == 'POST':
        if form.validate_on_submit():
            indicatorValue = request.form.get('ts_indicator', '')

            if indicatorValue == "save_template" or indicatorValue == "save_copy_template" :
                if indicatorValue == "save_template":
                    event_template = EventTemplate.query.get(template_id)
                elif indicatorValue == "save_copy_template":
                    event_template = EventTemplate()
                update_event_details(event_template, form)
                folder = 't' + str(event_template.id)
                save_picture(form.image_file.data, folder)
                event_template.update()

                flash(f"{event_template.title} [{event_template.host_name}]  saved!", 'success')

                form.loadTemplates()
                form.populate(event_template)
                return render_template('create_event.html', title='Create Event',
                                       form=form, event=event_template)

            elif indicatorValue == "delete_template":
                event_template = EventTemplate.query.get(template_id)
                t_name = f"{event_template.title} [{event_template.host_name}]" 
                db.session.delete(event_template)
                db.session.commit()
                flash(f"{t_name} has been deleted!", 'success')

                return redirect(url_for('create_event')+'/1')
            else:
                event = Event()
                update_event_details(event, form)
                db.session.add(event)
                db.session.commit()
                folder = 'e' + str(event.id)
                save_picture(form.image_file.data, folder)

                flash(f'Class created for {form.eventTitle.data}!', 'success')
                return redirect(url_for('upcoming_events'))
        else:
            flash(f'Event failed to post! Check form for errors.', 'danger')

    form.loadTemplates()
    return render_template('create_event.html', title='Create Event',
                           form=form)
Ejemplo n.º 2
0
def edit_event(event_id):
    event = Event.query.get(event_id)
    if not event:
        # TODO: 404
        pass

    form = EventForm()
    populate_select_boxes(form)

    if request.method == 'GET':
        form.populate(event)
        set_select_box_defaults(event, form)
        form.process()
        form.populate(event)

    if request.method == 'POST':
        if form.validate_on_submit():
            update_event_details(event, form)

            folder = 'e' + str(event.id)
            save_picture(form.image_file.data, folder)
            event.update()

            flash(f'{form.eventTitle.data} has been updated!', 'success')
            return redirect(url_for('upcoming_events'))
        else:
            flash(f'Event failed to update! Check form for errors.', 'danger')

    return render_template('edit_event.html', title='Edit Event',
                           form=form, event=event)