def post_event(): form = EventForm() if 'email' not in session: flash("You need to login to post Events") return redirect(url_for('signin')) user = User.query.filter_by(email = session['email']).first() if user is None: return redirect(url_for()) if request.method == 'POST': if form.validate() == False: flash("Fill all the fields") return render_template('post_events.html',form=form) else: newevent = Event(form.name.data, form.location.data, form.date.data, form.description.data) db.session.add(newevent) flash("Event successfully posted") db.session.commit() return redirect(url_for('index')) elif request.method == 'GET': return render_template('post_events.html',form=form)
def add_event(): def _dup(l): return [(i, i) for i in l] session = create_session() form = EventForm(request.forms.decode()) form.continent.choices = _dup(CONTINENTS) # countries = session.query(Country) # XXX: why is countries never used? # form.country.choices = [(c.id, c.name) for c in countries.all()] # form.gender.choices = _dup(["male", "female", "all"]) if form.validate(): session = create_session() new_task = Event.from_form(form) try: for attachment in scan_attachments(request.files): print "saving attachment: ", attachment, attachment.filename new_task.attachments.append(Attachment( file_path=save_file(attachment), file_name=attachment.filename, file_type=attachment.content_type)) session.add(new_task) session.commit() return redirect("/") except InvalidFileUpload as e: form.errors['attachment'] = e.message print dict(request.forms) print form.errors print type(form.errors) return new(errors=form.errors)
def post_event(): form = EventForm() if 'email' not in session: flash("You need to login to post Events") return redirect(url_for('signin')) user = User.query.filter_by(email=session['email']).first() if user is None: return redirect(url_for()) if request.method == 'POST': if form.validate() == False: flash("Fill all the fields") return render_template('post_events.html', form=form) else: newevent = Event(form.name.data, form.location.data, form.date.data, form.description.data) db.session.add(newevent) flash("Event successfully posted") db.session.commit() return redirect(url_for('index')) elif request.method == 'GET': return render_template('post_events.html', form=form)
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 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 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 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(): """ 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 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 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(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 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 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 newEvent(): ''' Add an event, requires to be logged and makes the user the event owner. Fills the choices select field with all the available categories. Returns a redirect to show events after adding the event in case of POST or the add event html page in case of GET. ''' form = EventForm(request.form) form.category_id.choices = ([ (c.id, c.name) for c in Category.query.order_by(Category.name)]) form.category_id.choices.insert(0, (0, 'select')) if request.method == 'POST' and form.validate(): newEvent = Event( category_id=form.category_id.data, name=form.name.data, location=form.location.data, date=form.date.data, username=session['username'] ) db.session.add(newEvent) db.session.commit() flash('New event created') return redirect(url_for('showEvents')) else: return render_template('new_event.html', form=form)
def editEvent(event_id): ''' Edit an event, requires to be logged and checks if the user is the event owner in the html rendered file. event_id is the id of the category to be edited. Returns a redirect to show events after event edition in case of POST or the edit event html page in case of GET ''' event = Event.query.filter_by(id=event_id).one() form = EventForm(request.form) form.category_id.choices = ([ (c.id, c.name) for c in Category.query.order_by(Category.name) ]) form.category_id.choices.insert(0, (0, 'select')) if request.method == 'POST' and form.validate(): event.category_id = request.form['category_id'] event.name = request.form['name'] event.location = request.form['location'] event.date = datetime.datetime.strptime(request.form['date'], '%d/%m/%Y').date() db.session.commit() flash("Event updated") return redirect(url_for('showEvents')) else: return render_template('edit_event.html', event=event, form=form)
def edit_event(request, event_id): event = Event.objects.get(id=event_id) form = EventForm(request.POST or None, instance=event) if form.is_valid(): form.save() return view_event(request, event_id) return render(request, 'edit_event.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.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_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 createevent(request): #create form and enter into database if (request.user!=""): if request.method == 'POST': #print 'in request' #print request createevent_form=EventForm(request.POST,request.FILES) #print 'in request' print createevent_form if createevent_form.is_valid(): print 'in request' createevent_form.save() return redirect('dashboard') #return render_to_response('wrongpage.html', {},{}) else : s=User.objects.get(username=request.user) s1=Seek_User.objects.get(username=request.user) print s1.profilePhoto createevent_form={'createevent_form':EventForm({'username':request.user,'email':s.email,'status':'active','userid':s.id,'profilePhoto':s1.profilePhoto,'pubdate':timezone.now()})} # print createevent_form['createevent_form'] # createevent_form['createevent_form'].update({'profilePhoto' = s1.profilePhoto}) #createevent_form['createevent_form']['profilePhoto'] = s1.profilePhoto print createevent_form['createevent_form']['profilePhoto'].value() return render_to_response('CreateEvent.html',createevent_form,RequestContext(request)) #return render_to_response('wrongpage.html', {},{}) return HttpResponse('hello')
def edit_event(id): event = Event.query.filter(Event.id==id).first_or_404() user = event.user.first() if user.id == current_user.id: if request.method == 'POST': form = EventForm(formdata=request.form, obj=event) date_begin = request.form.get('date_begin') date_end = request.form.get('date_end') theme = request.form.get('theme') description = request.form.get('description') event.date_begin = date_begin event.date_end = date_end event.theme = theme event.description = description db.session.commit() return redirect(url_for('event_detail', id=event.id)) form = EventForm(obj=event) return render_template('edit_event.html', form=form, event=event) events = Event.query.all() flash('Please login another user.') return render_template('index.html', events=events)
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 edit_event(request, event_name): try: event = Event.objects.get(name=event_name) except Event.DoesNotExist: raise Http404('Event does not exist') if request.method == 'POST': form = EventForm(request.POST, instance=event) if (form.is_valid()): e = form.save(commit=False) events = Event.objects.filter(name=e.name) # To allow editing the same event and keeping its short name. alreadyExists = False for ev in events: if ev != event: alreadyExists = True break if not alreadyExists: e.save() return redirect('feedback:index', e.name) messages.add_message(request, messages.WARNING, 'Event with that short name already exists.') else: form = EventForm(instance=event) context = { 'form': form, 'event_name': event_name, } return render(request, 'feedback/edit_event.html', context)
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 today(request): form = EventForm() today = get_begining(datetime.datetime.now()) events = Event.objects.filter(author=request.user).filter( timestamp__gt=today) context = { 'form': form, 'events': events, } if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save(commit=False) event.author = request.user try: event.save() context['msgs'] = ['Event added successfully.',] except: context['msgs'] = ['Some error occured. Please enter \ valid data.',] context['form'] = form else: context['msgs'] = ['Error: You must enter a title.',] context['form'] = form return render_to_response('diary/today.html', RequestContext(request, context))
def create(request): if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): event = form.save() return HttpResponseRedirect('/agenda/%i/details/' % event.pk) else: form = EventForm() return render(request, 'personal_calendar/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 add_or_edit_event(request, event_pk=None, is_add=False): user = request.user event = None if not is_add: event = get_object_or_404(Event, pk=event_pk) if event.is_expired(): user.message_set.create(message="You cannot edit an expired event.") return HttpResponseRedirect("/events/") if(not user == event.promoter): user.message_set.create(message="Only an event's promoter can edit it.") return HttpResponseRedirect(request.META.get('HTTP_REFERER', '')) if request.method == 'POST': if is_add: event = Event(promoter=user) elif event.promoter != user: return oops(request, "Only a event's promoter can edit it.") form = EventForm(request.POST, request.FILES) if form.is_valid(): event.name = form.cleaned_data['name'] if 'image' in request.FILES: file = request.FILES['image'] file_content = ContentFile(request.FILES['image'].read()) event.image.save(request.FILES['image'].name, file_content) event.start_date = form.cleaned_data['start_date'] event.end_date = form.cleaned_data['end_date'] event.description_markdown = form.cleaned_data['description'] event.rsvp_link = form.cleaned_data['rsvp_link'] tags = form.cleaned_data['tags'] event.save() event.set_tags(tags) return HttpResponseRedirect(event.get_absolute_url()) elif not is_add: form = EventForm(initial={ 'name':event.name, 'description':event.description_markdown, 'image':event.image, 'start_date':event.start_date, 'end_date':event.end_date, 'tags':event.get_editable_tags, 'rsvp_link':event.rsvp_link, }) else: form = EventForm() return render_to_response('add_or_edit_event.html', {'form': form, 'is_editing': not is_add, 'page_title': (is_add and "Add" or "Edit") + " an Event", 'event': event}, context_instance=RequestContext(request))
def create(request): nav_selected = "events" form = EventForm(user=request.user, data=(request.POST or None)) if form.is_valid(): event = form.save() Record.objects.create_record(request.user, "event_create", event) messages.success(request, "%s has been created." % event) return redirect(event) return render_to_response("events/create.html", locals(), context_instance=RequestContext(request))
def edit(request, event_id): nav_selected = "events" event = get_object_or_404(Event, id=event_id) form = EventForm(user=request.user, instance=event, data=(request.POST or None)) if form.is_valid(): event = form.save() messages.success(request, "%s has been changed." % event) return redirect(event) return render_to_response("events/edit.html", locals(), context_instance=RequestContext(request))
def create(request): data = {} data["user"] = request.user form = EventForm(request.POST or None) data["form"] = form if form.is_valid(): obj = form.save(commit=False) # get an unbound object obj.save() return HttpResponseRedirect("/event/%s" % obj.id) return render_to_response("event/create.html", data)
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 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 createEvent(): form = EventForm(request.form) if request.method == "POST" and form.validate(): Events.insert(name=form.name.data, icon=base64.b64encode( request.files[form.icon.name].read()), date=form.date.data, description=form.description.data) return redirect(url_for("home")) return render_template("auth/events/create.html", form=form)
def new_event(request): from forms import EventForm if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): event = form.save(commit=False) event.save() return redirect('events', event.event_url) else: form = EventForm() return render(request, 'edit_event.html', {"form": form})
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 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 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(): 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 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 create(request): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save() inset_one(event) return HttpResponseRedirect(reverse('administration_events_index')) else: form = EventForm() return render(request, 'events/administration/events_create.html', {'form': form, 'active_module': 'events'})
def create_event(request): if request.method == 'POST': form = EventForm(request.POST) # check whether it's valid: if form.is_valid(): f = form.cleaned_data event = Event(name=f['name']) event.save() return HttpResponse("Creado") else: event_form = EventForm() return render(request, 'core/create-event.html', {'event_form': event_form})
def handle_event(request): if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): request.session['arkistoija']['event'] = { 'name': form.cleaned_data['name'], 'date': form.cleaned_data['date'], } request.session.modified = True return HttpResponseRedirect('/arkistoija/p/2/') else: form = EventForm() return {'eventform': 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 create(request): template_name = 'events/create.html' context = {} if request.method == 'POST': form = EventForm(request.POST) if form.is_valid(): event = form.save(commit=False) event.user = request.user event.save() next_url = event.get_absolute_url() return HttpResponseRedirect(next_url) else: form = EventForm() context['form'] = form return render(request, template_name, context)
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 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 edit(request, pk): template_name = 'events/edit.html' event = get_object_or_404(Event, pk=pk, user=request.user) context = {} context['event'] = event if request.method == 'POST': form = EventForm(data=request.POST, instance=event) if form.is_valid(): form.save() return redirect('events_my') else: form = EventForm(instance=event) context['form'] = form return render(request, template_name, context)
def create_event(request, calendar_id): if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): calendar = get_object_or_404(Calendar, pk=calendar_id) datetime = form.cleaned_data['datetime'] name = form.cleaned_data['name'] tags = form.cleaned_data['tags'] event = Event.objects.create(calendar=calendar, datetime=datetime, name=name, tags=tags) event.save() return HttpResponseRedirect(reverse("view_calendar", args=[calendar.id])) else: return HttpResponse(form.errors) form = EventForm() return render(request, 'create_event.html', {'form': form, 'calendar_id': calendar_id})
def create_event(request, library_code, managed_libraries=[]): library = org_utils.get_library(library_code, managed_libraries) if not library: return HttpResponseForbidden( u'Вы должны быть сотрудником этой организации') if request.method == 'POST': event_form = EventForm(request.POST, request.FILES, prefix='event_form') event_content_forms = [] for lang in settings.LANGUAGES: event_content_forms.append({ 'form': EventContentForm(request.POST, prefix='event_content' + lang[0]), 'lang': lang[0] }) if event_form.is_valid(): valid = False for event_content_form in event_content_forms: valid = event_content_form['form'].is_valid() if not valid: break if valid: event = event_form.save(commit=False) event.library = library event.save() for event_content_form in event_content_forms: event_content = event_content_form['form'].save( commit=False) event_content.lang = event_content_form['lang'] event_content.event = event event_content.save() event_form.save_m2m() return redirect( 'participant_events:administration:events_list', library_code=library_code) else: event_form = EventForm(prefix="event_form") event_content_forms = [] for lang in settings.LANGUAGES: event_content_forms.append({ 'form': EventContentForm(prefix='event_content' + lang[0]), 'lang': lang[0] }) return render( request, 'participant_events/administration/create_event.html', { 'library': library, 'event_form': event_form, 'event_content_forms': event_content_forms, })
def add(): """ Add a new event """ form = EventForm(request.form) if request.method == 'POST' and form.validate(): data = dict(name=form.name.data, sport=form.sport.data, level=form.level.data, where=form.where.data, contact=current_user.id) day = str(form.day.data) + " " + str(form.time.data) e = Event.objects(**data).modify(upsert=True, new=True, set__modified=datetime.now()) e.when = arrow.get(day, 'YYYY-MM-DD HH:mm:ss').datetime e.fees = form.fees.data e.restrictions = form.restrictions.data e.comments = form.comments.data e.will_host = True if form.will_host.data else False e.will_travel = True if form.will_travel.data else False e.text = True if form.text.data else False e.email = True if form.email.data else False e.call = True if form.call.data else False location = geocode(data['where']) if location: e.location = [location['lng'], location['lat']] else: e.location = current_user.location try: e.save() except Exception as err: logging.error("Exception {} trying to save event {}".format( str(err), e)) else: return redirect('/') sport = {sport: 'True' for sport in current_user.sports} context = {'form': form, 'sports': sport} content = render_template('event.html', **context) return content
def event(): form = EventForm(request.form, csrf_enabled=True) print request.method if request.method == 'POST': print form.target_group_id.data target_group = form.target_group_id.data type_event = form.type_event_id.data category = form.category_id.data district = form.district_id.data print target_group, type_event, category, district print "method POST - save data to database" # print form.district_id.enco de('utf8') form_tasks = Event(titlu=form.titlu.data, start_date=form.start_date.data, end_date=form.end_date.data, organizers=form.organizers.data, price=form.price.data, photo=form.photo.data, phone=form.phone.data, content=form.content.data, additional_info=form.additional_info.data, location=unicode(form.location.data), target_group_id=target_group.id, type_event_id=type_event.id, category_id=category.id, district_id=district.id) # form.populate_obj(form_tasks) db.session.add(form_tasks) db.session.commit() return redirect("/") return render_template("event.html", form=form)