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)
def event_create(): form = EventForm() if request.method == 'POST': if form.validate_on_submit(): event = Event( title=form.title.data, title_cal=form.title_cal.data, content=form.content.data, host=form.host.data, category_char=form.category_char.data, category_host=form.category_host.data, date_start=form.date_start.data, date_end=form.date_end.data, location=form.location.data, link=form.link.data, poster=form.poster.data, contact=form.contact.data, contact_open=form.contact_open.data, ) db.session.add(event) db.session.commit() flash(u'이벤트를 등록했습니다.', 'success') return redirect(url_for('event_list')) return render_template('event/create.html', form=form)
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)
def add_event_page(): """ the admin interface for adding event """ if not current_user.is_authenticated: return redirect(url_for('admin_login')) if not current_user.is_admin: return redirect(url_for('admin_login')) form = EventForm() if form.validate_on_submit(): header = form.data["header"] content = form.data["content"] date = form.data["date"] if 'image' in request.files: image = request.files['image'].read() binary_image = dbapi2.Binary(image) else: binary_image = "" event = Event(header=header, content=content, date=date, image=binary_image) db = current_app.config["db"] db.add_event(event, current_user.id) flash('event added to the database') return redirect(url_for("admin_page")) return render_template("event_add.html", form=form)
def add_event(): """ Add a event to the database """ check_admin() add_event = True form = EventForm() if form.validate_on_submit(): event = Event(event_name=form.event_name.data, event_description=form.event_description.data, event_date=form.event_date.data) try: # Create an Attendance object for every student # and add them to event for student in Student.query.filter( Student.forum == current_user.forum).all(): attendance = Attendance(TF_comment="", is_attended=False) attendance.student = student event.attendance.append(attendance) db.session.add(event) db.session.commit() flash('You have successfully added a new event.') except: flash('Error: can not add event.') # redirect to events page return redirect(url_for('teaching_fellow.list_events')) # load student template return render_template('teaching_fellow/events/event.html', action="Add", add_event=add_event, form=form, title="Add Event")
def edit_event(id): """ Edit an Event """ check_admin() add_event = False event = Event.query.get_or_404(id) form = EventForm(obj=event) if form.validate_on_submit(): event.fullnames = form.fullname.data event.mobilenumber = form.mobileno.data event.nationalid = form.nationalid.data event.deptamount = form.deptamount.data event.description = form.description.data db.session.commit() flash('You have successfully edited an event.') # redirect to the events page return redirect(url_for('admin.list_events')) form.fullname.data = event.fullnames form.mobileno.data = event.mobilenumber form.nationalid.data = event.nationalid form.deptamount.data = event.deptamount form.description.data = event.description return render_template('admin/events/addeditevent.html', action="Edit", add_event=add_event, form=form, event=event, title="Edit Event")
def create(): logging.info("create start") form = EventForm() if request.method == 'POST': logging.info("Method: POST") if form.validate_on_submit(): event = Event( title = form.title.data, title_cal = form.title_cal.data, content = form.content.data, host = form.host.data, category_char = form.category_char.data, category_host = form.category_host.data, date_start = form.date_start.data, date_end = form.date_end.data, location = form.location.data, link = form.link.data, poster = form.poster.data, contact = form.contact.data, contact_open = form.contact_open.data, ) print event logging.info(""); db.session.add(event) db.session.commit() print "11111111" logging.info(""); flash(u'이벤트를 등록했습니다.', 'success') return redirect(url_for('index'))
def edit_event(id): """ Edit an event """ check_admin() add_event = False event = Event.query.get_or_404(id) form = EventForm(obj=event) if form.validate_on_submit(): event.name = form.name.data event.timeD = form.timeD.data event.date = form.date.data event.location = form.location.data event.description = form.description.data event.menus = 'menus/'+form.menu.data db.session.commit() flash('You have successfully edited the event.') # redirect to the events page return redirect(url_for('admin.list_events')) form.description.data = event.description form.name.data = event.name form.timeD.data = event.timeD form.date.data = event.date form.location.data = event.location menu = re.sub('menus/', '', event.menus) form.menu.data= menu return render_template('admin/events/event.html', action="Edit", add_event=add_event, form=form, event=event, title="Edit Event")
def add_event(): """ Add an event to the database """ check_admin() add_event = True form = EventForm() if form.validate_on_submit(): event = Event( fullnames=form.fullname.data, mobilenumber=form.mobileno.data, nationalid=form.nationalid.data, deptamount=form.deptamount.data, description=form.description.data, ) try: # add event to the database db.session.add(event) db.session.commit() flash('You have successfully added a new event request.') except: # in case event name already exists flash('Error: event name already exists.') # redirect to events page return redirect(url_for('admin.list_events')) # load event template return render_template('admin/events/addeditevent.html', action="Add", add_event=add_event, form=form, title="Add Event")
def add_event(): """ Add an event to the database """ check_admin() add_event = True form = EventForm() if form.validate_on_submit(): event = Event(name=form.name.data, timeD = form.timeD.data, date = form.date.data, location = form.location.data, description=form.description.data, menus = 'menus/'+form.menu.data) try: # add event to the database db.session.add(event) db.session.commit() flash('You have successfully added a new event.') except: # in case event name already exists flash('Error: event name already exists.') # redirect to events page return redirect(url_for('admin.list_events')) # load event template return render_template('admin/events/event.html', action="Add", add_event=add_event, form=form, title="Add Event")
def create(): logging.info("create start") form = EventForm() if request.method == 'POST': logging.info("Method: POST") if True or form.validate_on_submit(): event = Event( title=form.title.data, title_cal=form.title_cal.data, content=form.content.data, host=form.host.data, category_char=form.category_char.data, category_host=form.category_host.data, date_start=form.date_start.data, date_end=form.date_end.data, location=form.location.data, link=form.link.data, poster=form.poster.data, contact=form.contact.data, contact_open=form.contact_open.data, ) print event logging.info("") db.session.add(event) db.session.commit() print "11111111" logging.info("") flash(u'이벤트를 등록했습니다.', 'success') return redirect(url_for('index'))
def add(): if get_cookie('event_app'): username = get_cookie('event_app').split('=')[1] if username_legit(username): form = EventForm() if request.method == 'POST': if form.validate_on_submit(): new_data = form.data new_data['start'] = str(new_data['start']) new_data['end'] = str(new_data['end']) del new_data['csrf_token'] del new_data['submit'] f = File('events') data = f.read() data.append(new_data) data = json.dumps(data) f.write(data) return data else: return 'FORM FAILED' else: return flask.render_template('add.html', form=form, user=username) else: return flask_redirect('/login')
def event_new(): '''Add a new Event.''' user = g.user if user.is_director or user.is_admin: form = EventForm() bands = [(band.id, band.name) for band in Band.query.all()] event_types = [(typ.id, typ.name) for typ in EventType.query.all()] form.band_id.choices = bands form.event_type_id.choices = event_types if form.validate_on_submit(): date = form.date.data time = form.calltime.data calltime = datetime(year=date.year, month=date.month, day=date.day, hour=time.hour, minute=time.minute) band_id = form.band_id.data event_type_id = form.event_type_id.data opponent = form.opponent.data event_id = add_event(date=date, calltime=calltime, band_id=band_id, event_type_id=event_type_id, opponent=opponent) return redirect(url_for('event', event_id=event_id)) return render_template('event/create_update.html', form=form, user=user) abort(404)
def create_event(user_id): """Used by users to create job posts""" if not g.user: flash("Access unauthorized.", "danger") return redirect("/") if g.user and session[CURR_USER_KEY] == user_id: genres = Genre.query.all() genre_list = [(j.id, j.genre) for j in genres] regions = Region.query.all() # list of tuples for selectfield region_list = [(i.id, i.city) for i in regions] form = EventForm() #passing selectfield choice into the form form.region_id.choices = region_list form.genre_id.choices = genre_list if form.validate_on_submit(): event = EventPost(title=form.title.data, description=form.description.data, address=form.address.data, date=form.date.data, region_id=form.region_id.data, user_id=user_id, genre_id=form.genre_id.data) db.session.add(event) db.session.commit() return redirect(f"/users/{user_id}") return render_template("events/event-form.html", form=form) else: flash("Access unauthorized.", "danger") return redirect("/")
def add_event(): if g.user is None: return redirect(url_for("index")) form = EventForm() if form.validate_on_submit(): what = form.what.data where = form.where.data length = form.length.data wait_time = form.wait_time.data pre_delay = form.pre_delay.data required_people = form.required_people.data description = form.description.data if form.public.data: public = 1 else: public = 0 event = models.Event(what=what, where=where, length=length, wait_time=wait_time, pre_delay=pre_delay, required_people=required_people, description=description, public=public) db.session.add(event) db.session.commit() user = models.User.query.get(g.user['id']) event_req = models.EventSubscription(user=user, event=event) db.session.add(event_req) db.session.commit() flash("Event successfully created") return redirect(url_for("event", id=event.id)) return render_template("add_event.html", app_id=FB_APP_ID, name=FB_APP_NAME, user = g.user, form=form)
def event_examples(): """List all events""" event = Event.query() form = EventForm() if form.validate_on_submit(): event = Event( #event_id= title=form.title.data, day=form.day.data, location=form.location.data, description=form.descrtiption.data, anchor_amount=form.anchor_amount.data, amount_min=form.amount_min.data, max_attendees=form.max_attendees.data, registration_start=form.registration_start.data, registration_end=form.registration_end.data, added_by=users.get_current_user() ) try: event.put() event_id = event.key.id() flash(u'Event %s successfully saved.' % event_id, 'success') return redirect(url_for('event_examples')) except CapabilityDisabledError: flash(u'App Engine Datastore is currently in read-only mode.', 'info') return redirect(url_for('event_examples')) return render_template('event_gae.html', event=event, form=form)
def edit_event(id): """ Edit an event """ check_admin() add_event = False event = Event.query.get_or_404(id) form = EventForm(obj=event) if form.validate_on_submit(): event.event_name = form.event_name.data db.session.commit() flash('You have successfully edited the event.') # redirect to the events page return redirect(url_for('teaching_fellow.list_events')) form.event_name.data = event.event_name return render_template('teaching_fellow/events/event.html', action="Edit", add_event=add_event, form=form, event=event, title="Edit Event")
def event_create(): form = EventForm() if request.method == 'POST': if form.validate_on_submit(): event = Event( title = form.title.data, title_cal = form.title_cal.data, content = form.content.data, host = form.host.data, category_char = form.category_char.data, category_host = form.category_host.data, date_start = form.date_start.data, date_end = form.date_end.data, location = form.location.data, link = form.link.data, poster = form.poster.data, contact = form.contact.data, contact_open = form.contact_open.data, ) db.session.add(event) db.session.commit() flash(u'이벤트를 등록했습니다.', 'success') return redirect(url_for('event_list')) return render_template('event/create.html', form=form)
def events_create(): event_create_form = EventForm() if event_create_form.validate_on_submit(): new_event = Event(owner=current_user) event_create_form.populate_obj(new_event) db.session.add(new_event) db.session.commit() return redirect(url_for('.events_owned')) return render_template('events/create.html', event_create_form=event_create_form)
def events_manage(event_id): event = Event.query.get_or_404(event_id) if current_user != event.owner: abort(403) event_form = EventForm(obj=event) if event_form.validate_on_submit(): event_form.populate_obj(event) db.session.commit() return redirect(url_for('.events_detail', event_id=event_id)) return render_template('events/manage.html', event=event, event_form=event_form)
def event_update(id): event = Event.query.get(id) form = EventForm(request.form, obj=event) if request.method == 'POST': if form.validate_on_submit(): form.populate_obj(event) db.session.commit() flash(u'이벤트 정보를 수정하였습니다.', 'success') return redirect(url_for('event_list')) return render_template('event/update.html', form=form)
def create_event(): form = EventForm() if form.validate_on_submit(): event = Event() event.name = unicode(form.name.data) event.description = unicode(form.description.data) event.registration_opens = form.registration_opens.data event.registration_closes = form.registration_closes.data db_session.add(event) db_session.commit() return redirect(url_for('dashboard')) return render_template("admin/create_event.html", form=form)
def create_event(): user = g.user if not user.is_admin(): return redirect(url_for('dashboard')) form = EventForm() event = Event() if form.validate_on_submit(): event = Event(user_id = user.id, name = request.form.get('name'), description = request.form.get('description'), starttime = request.form.get('starttime'), endtime = request.form.get('endtime'), location = request.form.get('location'), max_team = request.form.get('max_team'), max_member_per_team = request.form.get('max_member_per_team'), department = request.form.get('department')) sqldb.session.add(event) sqldb.session.commit() return redirect(url_for('event', event_id = event.id)) return render_template("event.html", form = form, event = event)
def edit_event(event_id): event = Event.query.get(event_id) form = EventForm(obj=event) if form.validate_on_submit(): event.name = unicode(form.name.data) event.description = unicode(form.description.data) event.registration_opens = form.registration_opens.data event.registration_closes = form.registration_closes.data db_session.add(event) db_session.commit() return redirect(url_for('show_event', event_id=event.id)) return render_template("admin/edit_event.html", **locals())
def createEvent(): form = EventForm() def add_event(name, category, time, location): event = Event(name=name, category=category, time=time, location=location) sqldb.session.add(event) sqldb.session.commit() return event.id if form.validate_on_submit(): eventId = add_event(form.name.data, form.category.data, form.time.data, form.location.data) #flash('Event Created.' + " Event ID: " + str(eventId)) return redirect("addStep/"+str(eventId)) return render_template("createEvent.html", form=form)
def family_group_add(fg_id): if request.method == 'GET': form = EventForm(request.args) else: form = EventForm(coerce=int) if form.validate_on_submit(): event = SmallGroupEvent(name=form.name.data, description=form.description.data, weekNumber=form.week.data, quarter=form.quarter.data, small_group_id=fg_id) db.session.add(event) db.session.commit() flash(('Event added successfully.')) return redirect(url_for('family_group_leader_manage', fg_id=fg_id)) return render_template("smallgroup/add.html", user=g.user, form=form, fg_id=fg_id)
def update_event(id): db_session = db.get_session() form = EventForm() event = db_session.query(Event).get(id) form.id.data = event.id form.populate_obj(event) if form.validate_on_submit(): db_session.add(event) db_session.commit() return redirect('events') else: return render_template('events/edit.html', event=event, form=form)
def event_update(event_id): form = EventForm() if form.validate_on_submit(): do_update_event(event_id, form) if form.token.data != database.Event(event_id).token: flash("Invalid token.") return redirect(url_for("event_admin", event_id=event_id)) return redirect(url_for('event_index', event_id=event_id)) else: flash("There's been errors validating your request. Look below for details.") #for field, errors in form.errors.items(): # for error in errors: # flash(field + " " + error) return render_template("event_edit.html", event=database.Event(event_id), form=form)
def create_event(): db_session = db.get_session() event = Event() form = EventForm() form.new_record = True form.populate_obj(event) if form.validate_on_submit(): db_session.add(event) db_session.commit() flash('The event has been created successfully.', 'alert-success') return redirect('events') else: return render_template('events/new.html', form=form)
def edit_event(event_id): event = get_event(event_id=event_id) form = EventForm(obj=event) if form.validate_on_submit(): updated, error = update_event(event, form.data) if updated: flash('Evento atualizado com sucesso', 'success') return redirect(url_for('web.index')) else: flash(error, 'danger') return render_template('events/form.html', form=form, title='Editar evento', action='Editar')
def edit_event_page(event_id): """ the admin interface for editing event """ if not current_user.is_authenticated: return redirect(url_for('admin_login')) if not current_user.is_admin: return redirect(url_for('admin_login')) try: form = EventForm() db = current_app.config["db"] event = db.get_event_info(event_id) img_update = True if form.validate_on_submit(): header = form.data["header"] content = form.data["content"] date = form.data["date"] if 'image' in request.files: if request.files['image'].filename == None or request.files[ 'image'].filename == "": img_update = False image = request.files['image'].read() binary_image = dbapi2.Binary(image) else: binary_image = "" _event = Event(header=header, content=content, date=date, image=binary_image) db.update_event(event_id=event_id, event=_event, img_update=img_update) return redirect(url_for("admin_page")) form.header.data = event[2] form.content.data = event[3] with connection.cursor() as cursor: cursor.execute( "SELECT ENCODE(events.blob_image, 'base64') FROM events WHERE id = %s", (event_id, )) img = cursor.fetchone() image = [] image.append(img[0]) image = "data:image/png;base64," + image[0] return render_template("event_edit.html", form=form, img=image) except Exception as e: print(e)
def create_event(): '''Create the event the user posted''' form = EventForm(request.form) #only create the event if they entered in a name for it if not form.validate_on_submit(): return render_template('events.html', user=g.user, form=form, message='Please enter name for event') #user can't create two events with the same name elif Event.query.filter( Event.name == form.name.data and Event.creator == g.user.id ).first(): return render_template('events.html', user=g.user, form=form, message='Event name already exists.') else: db_utilities.create_event(event_name = form.name.data, user_id = g.user.id) return redirect(url_for('events'))
def new_event(): form = EventForm() if form.validate_on_submit(): created, event = create_event(name=form.name.data, category=form.category.data, date_time=form.date_time.data, address=form.address.data, description=form.description.data, image_url=upload_photo(form.image.data)) if created: flash('Evento criado com sucesso', 'success') return redirect(url_for('web.index')) else: flash(event, 'danger') return render_template('events/form.html', form=form, title='Novo evento', action='Criar')
def edit_event(event_id): event = Event.get_by_id(event_id) form = EventForm(obj=example) if request.method == "POST": if form.validate_on_submit(): event.title=form.data.get('title') event.day=form.data.get('day') event.location=form.data.get('location') event.description=form.data.get('descrtiption') event.anchor_amount=form.data.get('anchor_amount') event.amount_min=form.data.get('amount_min') event.max_attendees=form.data.get('max_attendees') event.registration_start=form.data.get('registration_start') event.registration_end=form.data.get('registration_end') event.put() flash(u'Event %s successfully saved.' % event_id, 'success') return redirect(url_for('event_examples')) return render_template('edit_event.html', event=event, form=form)
def update_event_schedule(): form = EventForm() summerEventQuery = SummerPageSchedule.query.first() indexEventQuery = HomePageSchedule.query.first() form.indexName.data = indexEventQuery.name form.indexContent.data = indexEventQuery.content form.summerName.data = summerEventQuery.name form.summerContent.data = summerEventQuery.content if form.validate_on_submit(): indexEventQuery.name = request.form["indexName"] indexEventQuery.content = request.form["indexContent"] summerEventQuery.name = request.form["summerName"] summerEventQuery.content = request.form["summerContent"] db.session.commit() redirect(url_for('update_event_schedule')) return render_template('authentication/event-schedule.html', form=form)
def event_edit(event_id): '''Route to edit an event.''' user = g.user if user.is_director or user.is_admin: form = EventForm() bands = [(band.id, band.name) for band in Band.query.all()] event_types = [(typ.id, typ.name) for typ in EventType.query.all()] form.band_id.choices = bands form.event_type_id.choices = event_types if form.validate_on_submit(): event = Event.query.get(event_id) event.date = form.date.data time = form.calltime.data event.calltime = datetime(year=event.date.year, month=event.date.month, day=event.date.day, hour=time.hour, minute=time.minute) event.band_id = form.band_id.data event.event_type_id = form.event_type_id.data event.opponent = form.opponent.data db.session.commit() return redirect(url_for('event', event_id=event_id)) event = Event.query.get(event_id) if event: form.event_id.data = event.id form.date.data = event.date form.calltime.data = event.calltime form.band_id.data = event.band_id form.event_type_id.data = event.event_type_id form.opponent.data = event.opponent return render_template('event/create_update.html', form=form, user=user) abort(404)
def edit_event(event_id): user = g.user form = EventForm() event = Event.query.get(event_id) #assert event != null, "SHIT" if not user.is_admin(): if user.id != event.user_id: return redirect(url_for('dashboard')) if form.validate_on_submit(): event.name = form.name.data event.description = form.description.data event.starttime = form.starttime.data event.endtime = form.endtime.data event.max_team = form.max_team.data event.max_member_per_team = form.max_member_per_team.data event.department = form.department.data sqldb.session.commit() return redirect(url_for('event', event_id = event_id)) if event == None: # TODO NOT WORKING return "Event not found!" return render_template("edit_event.html", event = event, form = form)
def eventform(): form = EventForm() if form.validate_on_submit(): session['eventurl'] = form.url.data return redirect(url_for('playlist')) return render_template('partials/eventform.html', form=form)
def validate_form(self, rform, dates_good): from forms import EventForm form = EventForm(rform) return form, form.validate_on_submit() and dates_good