def dispatch_request(self, person_id): Usr = users.get_current_user() if Usr.email() == '*****@*****.**' or Usr.email() == '*****@*****.**': person = Person.get_by_id(person_id) form = PersonForm(obj=person.key.id()) form.title.data = person.title form.first.data = person.first form.last.data = person.last form.rsvp.data = person.rsvp form.food.data = person.food form.party.data = person.party if request.method == "POST" and form.validate_on_submit(): person.title = form.data.get('title') person.first = form.data.get('first') person.last = form.data.get('last') person.rsvp = form.data.get('rsvp') person.food = form.data.get('food') person.party = form.data.get('party') person.put() flash(u'Person %s successfully saved.' % person_id, 'success') return redirect(url_for('admin')) return render_template('edit_person.html', person=person, form=form) else: flash(u'Sorry, no admission!') return redirect(url_for('index'))
def edit_index_data_ajax(request): if request.method != 'POST': return HttpResponseNotAllowed("Method not allowed") person = Person.objects.get() other = person.othercontact_set.all().get() form = PersonForm(request.POST, instance=person) contact_formset = ContactFormSet(request.POST, instance=person) othercontact_form = OtherContactForm(request.POST, instance=other) if form.is_valid() and contact_formset.is_valid() and \ othercontact_form.is_valid(): form.save() contact_formset.save() othercontact_form.save() ret = {"status": "ok"} else: err = form.errors for form in contact_formset: for field in form.errors: err["%s-%s" % (form.prefix, field)] = form.errors[field] err.update(othercontact_form.errors) ret = {"status": "error", "fields": err} json = simplejson.dumps(ret) return HttpResponse(json, mimetype='application/json')
def refugee(request): """ View to add a refugee to the crisis communicator db """ if request.method == 'POST': person_form = PersonForm(request.POST) refugee_form = RefugeeForm(request.POST) valid_person_form = person_form.is_valid() valid_refugee_form = refugee_form.is_valid() if valid_person_form and valid_refugee_form: person_form.save() refugee_form_data = refugee_form.save(commit=False) refugee_form_data.gid = generate_gid() refugee_form_data.person_id = get_object_or_404(Person, person_id= \ person_form.cleaned_data['person_id']) refugee_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/refugee.html', {'person_form':person_form, 'refugee_form':refugee_form}, RequestContext(request)) else: return render_to_response('person/refugee.html', {'person_form':PersonForm(), 'refugee_form':RefugeeForm()}, RequestContext(request))
def deceased(request): """ View to add deceased people details. """ if request.method == 'POST': person_form = PersonForm(request.POST) deceased_form = DeceasedForm(request.POST) valid_person_form = person_form.is_valid() valid_deceased_form = deceased_form.is_valid() if valid_person_form and valid_deceased_form: person_form.save() deceased_form_data = deceased_form.save(commit=False) deceased_form_data.gid = generate_gid() deceased_form_data.person_id = get_object_or_404(Person, person_id= \ person_form.cleaned_data['person_id']) deceased_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/deceased.html', {'deceased_form':deceased_form, 'person_form': person_form, 'error1':person_form, 'error2':deceased_form}, RequestContext(request)) else: return render_to_response('person/deceased.html', {'deceased_form':DeceasedForm(), 'person_form': PersonForm()}, RequestContext(request))
def test_ifreversed(self): first_person = Person.objects.all()[0] form = PersonForm(instance=first_person) rendered_data = form.as_table() birthdate_pos = rendered_data.find("id_birthdate") name_pos = rendered_data.find("id_name") self.failUnless(birthdate_pos < name_pos, 'Fields are not reversed')
def person_edit(request, person_id=None, template='poll/person_form.html'): """ edit person """ if person_id: instance = Person.objects.get(id=person_id) action = _('Edit') else: instance = None action = _('Add') if request.method == 'POST': form = PersonForm(request.POST, instance=instance) if form.is_valid(): person = form.save(commit=False) person.save() form.save_m2m() messages.add_message(request, messages.SUCCESS, ugettext("Successfully saved person: %s") % person.name) return HttpResponseRedirect(reverse('person-list')) elif instance: form = PersonForm(instance=instance) else: form = PersonForm() data = {'form': form, 'action':action} return render_to_response(template, data, context_instance=RequestContext(request))
def add_persons(request): person = Person() form = PersonForm(request.POST) if request.method == 'POST' and form.validate(): form.populate_obj(person) DBSession.add(person) return HTTPFound(location=request.route_url('index')) return {'form' : form}
def add_person(request): form = PersonForm(request.POST or None) if form.is_valid(): form.save() return redirect(reverse('list_person')) return direct_to_template(request, 'add.html', { 'form': form, 'title': Person._meta.verbose_name, })
def edit_person(request): person = get_object_or_404(Person) form = PersonForm(instance=person) if request.method == 'POST' and form.is_valid(): form.save() return HttpResponseRedirect(reverse('startpage')) return direct_to_template(request, 'myapp/edit_info.html', { 'form': form })
def new(request): if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): form.save() return redirect('people:index') else: form = PersonForm() return render(request, 'people/person_new.html', {'form': form})
def edit(id): person = Person.query.get_or_404(id) personForm = PersonForm(obj=person) if request.method == 'POST': if personForm.validate_on_submit(): personForm.populate_obj(person) app.logger.debug(f'Update Person: {person}') db.session.commit() return redirect(url_for('index')) return render_template('edit.html', form=personForm)
def create_person(request): form = PersonForm() if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): form.save() c = {'form': form} c.update(csrf(request)) return render_to_response('my_app/create.html', c)
def add(): person = Person() personForm = PersonForm(obj=person) if request.method == 'POST': if personForm.validate_on_submit(): personForm.populate_obj(person) app.logger.debug(f'Insert Person: {person}') db.session.add(person) db.session.commit() return redirect(url_for('index')) return render_template('add.html', form=personForm)
def Page5(request): if CheckAccess(request,'5') != 'OK': return render_to_response("notaccess.html") try: contract_id = request.session['contract_id'] except: return HttpResponseRedirect('/contract') ### --- Проверка доступа именно к этой заявке --- if CheckAccess(request,'4') != 'OK' and CheckDAccess(GetUserKod(request),contract_id) != 'OK': return HttpResponseRedirect('/contract') if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): person = form.cleaned_data['person'] r = AddDPerson(request,GetUserKod(request),contract_id,person) ### --- Уведомление согласующиму --- if r == 'OK': EmailToPerson(contract_id) if request.method == 'GET': try: delete_id = request.GET['delete_id'] r = DelDPerson(request,GetUserKod(request),delete_id) ### --- Уведомление согласующиму --- if r == 'OK': EmailToPerson(contract_id) except: pass ### --- Получение данных заявки --- data = GetDData(contract_id) form = PersonForm() #form.fields['status'].choices = status_list ### --- Получение истории статусов --- d = GetDPerson(contract_id) ### --- Получение следующего согласующего --- n = GetDPersonNext(contract_id) c = RequestContext(request,{'data':data,'form':form,'d':d,'n':n}) c.update(csrf(request)) return render_to_response("contract/page5.html",c)
def post(self, request): form = PersonForm(request.POST, request.FILES, instance=self.instance) if form.is_valid(): object_to_save = form.save(commit=False) object_to_save.save() logout(request) return HttpResponseRedirect(reverse('home-page')) else: form = PersonForm(request.POST, request.FILES, instance=self.instance) data = { 'form':form, } return TemplateResponse(request, self.template_name, data)
def create_new_account(request, itemId=None): """ View for saving new Person entry :param itemId: :param request: :return: """ entry = None try: entry = Person.objects.get(id=itemId) except Person.DoesNotExist: pass if request.is_ajax(): form = PersonForm(request.POST, request.FILES, instance=entry) if form.is_valid(): if request.FILES: form.cleaned_data['photo'] = request.FILES['photo'] form.save() return HttpResponse( json.dumps(dict(status=0, redirect=reverse('persons')))) else: errors = form.errors return HttpResponse(json.dumps({'status': 1, 'errors': errors})) else: form = PersonForm(instance=entry) return render(request, 'edit.html', locals())
def add(request): if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): cd = form.cleaned_data new_person = form.save() if cd.get('person'): rs = Relationship.objects.create(person1=cd.get('person'), person2=new_person, status=cd.get('status')) return HttpResponseRedirect('/') else: form = PersonForm() return {'form': form}
def register_person(request): if request.method == 'GET': form = list(PersonForm()) return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request)) if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): person = form.save() request.session['person_id'] = person.id return redirect(reverse('list_polls')) form = list(form) return render_to_response('register.html', {'form': form}, context_instance=RequestContext(request))
def me(request): if request.method == 'POST': # If the form has been submitted... # ContactForm was defined in the the previous section form = PersonForm(request.POST) # A form bound to the POST data if form.is_valid(): # All validation rules pass # Process the data in form.cleaned_data # ... form.save() return HttpResponseRedirect('/') # Redirect after POST else: form = PersonForm() # An unbound form return render(request, 'gpgsign/person.html', { 'form': form, })
def register_person(request): person_form = PersonForm(prefix="prs") if request.method == 'POST': person_form = PersonForm(request.POST, prefix="prs") if person_form.is_valid(): person = person_form.save(commit=False) person.save() return redirect('locker_manager.views.person_details', matriculation=person.matriculation) else: messages.error(request, "Error") return render(request, 'locker_manager/register_person.html',{'person_form':person_form}) else: return render(request, 'locker_manager/register_person.html',{'person_form':person_form})
def edit_view(request): c = tools.get_default_context(request, 'm_edit') if request.method == 'POST': form = PersonForm(request.POST, instance=Person.objects.all()[0]) if form.is_valid(): form.save() if request.is_ajax(): return HttpResponse("Saved!") return HttpResponseRedirect('/') else: p = Person.objects.all()[0] form = PersonForm(instance=p) c['form'] = form return render_to_response('edit.html', c, context_instance=RequestContext(request))
def edit_profile(request): person = util.current_person(request) if request.method == "POST": form = PersonForm(request.POST, instance=person) form.save() return redirect('your_profile') else: form = PersonForm(instance=person) d = { "person": person, "form": form } return render_with_extra_info(request, d, 'edit_profile.html')
def person_edit(request, template="contact/person_edit.html"): """ Renders person edit template with person form, validate and save form. """ detail_url = reverse('person_detail') person = get_object_or_404(Person, pk=settings.DEFAULT_PERSON_PK) form = PersonForm(request.POST or None, request.FILES or None, instance=person) if request.is_ajax() and request.POST: return HttpResponse(json.dumps(form.errors or None)) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('person_detail')) return direct_to_template(request, template, {'form': form, 'next': request.GET.get('next', detail_url), })
def save_person(request): if not request.user.is_authenticated(): return {'saved': False, 'errors': ['Not authenticated']} try: person = Person.objects.latest('id') except: person = Person() post = request.POST or None data = request.FILES or None form = PersonForm(post, data, instance=person) if form.is_valid(): form.save() return {'saved': True} else: return {'saved': False, 'errors': form.errors}
def create_person(request): if request.POST: form = PersonForm(request.POST) if form.is_valid(): user = request.POST['username'] pwd = request.POST['password'] form.save() user = User.objects.create_user(user, '*****@*****.**',pwd) user.save() user = authenticate(username=user, password=pwd) auth_login(request, user) return HttpResponseRedirect('/appwptn/') else: form = PersonForm() args = {} args.update(csrf(request)) args['form'] = form return render_to_response('create_person.html',args)
def edit(id): try: person = Person.get(Person.id == id) except Person.DoesNotExist: abort(404) form = PersonForm(request.form, person) if request.method == "POST" and form.validate(): person.firstname = form.firstname.data person.lastname = form.lastname.data person.birthday = form.birthday.data person.zipcode = form.zipcode.data person.save() return redirect(url_for('index')) return render_template('edit.html', form=form, person=person)
def add_person(request): if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/add_person/thanks/') else: form = PersonForm() return render_to_response('holidays/add_person.html', {'form': form},context_instance=RequestContext(request))
def add_profile(request): 'Add user profile.' if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): cd = form.cleaned_data #un = str(uuid.uuid4()).split('-')[0] #new_user = User.objects.create(username=un, email=cd['email'], first_name=cd['first_name'], # last_name=cd['last_name'], password='******') new_person = form.save(commit=False) #new_person.user = new_user new_person.save() return HttpResponseRedirect(reverse('get-profile', args=[new_person.id])) #else: # print form.errors['email'] else: context = {'phone': '40xxxxxxxxx'} form = PersonForm(initial=context) return render_to_response('profile.html', {'form': form}, context_instance=RequestContext(request))
def create(request): #if request.POST: if request.method == 'POST': form = PersonForm(request.POST , request.FILES) if form.is_valid(): form.save() messages.add_message(request, messages.SUCCESS, "Your person added") return HttpResponseRedirect('/persons/all') else: raise Http404 #else: #form = PersonForm() args = {} args.update(csrf(request)) args['form'] = PersonForm() print args return render_to_response('create_person.html', args)
def create(request): #if request.POST: if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect('/persons/all') else: raise Http404 #else: #form = PersonForm() args = {} args.update(csrf(request)) args['form'] = PersonForm() print args return render_to_response('create_person.html', args)
def create(): form = PersonForm(request.form) if request.method == 'POST' and form.validate(): person = Person.create( firstname=form.firstname.data, lastname=form.lastname.data, birthday=form.birthday.data, zipcode=form.zipcode.data) if request.is_xhr: return jsonify(success=True, person=person.serialize()) else: return redirect(url_for('index')) # if it's an ajax request and if fails # form validation return message to client if request.is_xhr and request.method == 'POST' and not form.validate(): return jsonify(success=False, errors=form.errors) return render_template('create.html', form=form)
def refugee(request): """ View to add a refugee to the crisis communicator db """ if request.method == 'POST': person_form = PersonForm(request.POST) refugee_form = RefugeeForm(request.POST) valid_person_form = person_form.is_valid() valid_refugee_form = refugee_form.is_valid() if valid_person_form and valid_refugee_form: person_form.save() refugee_form_data = refugee_form.save(commit=False) refugee_form_data.gid = generate_gid() refugee_form_data.person_id = get_object_or_404(Person, person_id= \ person_form.cleaned_data['person_id']) refugee_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/refugee.html', { 'person_form': person_form, 'refugee_form': refugee_form }, RequestContext(request)) else: return render_to_response('person/refugee.html', { 'person_form': PersonForm(), 'refugee_form': RefugeeForm() }, RequestContext(request))
def signupView(request, carid, eventid): event = EventModel.getEvent(eventid) user = request.user car = Car.cars.get(event=event, carid=carid) if memberCheck(request.user, event) == False: return render(request, 'invite/notMember.html') if request.method == 'GET': instance = Person.objects.filter(event=event, personid=user) if instance.count() == 0: personform = PersonForm() else: personform = PersonForm(instance = instance[0]) context = {'menu' : getMenuInfo(request), 'title' : "Sign Up", 'personform' : personform, 'event' : event, 'user' : request.user} return render(request, 'ride_share/sign_up_form.html', context) if request.method == 'POST': instance = Car.cars.car(event = event,carid=carid) if instance.count() == 0: personform = PersonForm(request.POST) else: personform = PersonForm(request.POST, instance = instance[0]) if personform.is_valid(): form = personform.save(commit=False) form.user = request.user form.event = event form.save() return HttpResponseRedirect(reverse('events:tools:rideshare:executeSignup', kwargs={'eventid':eventid, 'carid':carid}))
def create_new_account(request, itemId=None): """ View for saving new Person entry :param itemId: :param request: :return: """ entry = None try: entry = Person.objects.get(id=itemId) except Person.DoesNotExist: pass if request.is_ajax(): form = PersonForm(request.POST, request.FILES, instance=entry) if form.is_valid(): if request.FILES: form.cleaned_data['photo'] = request.FILES['photo'] form.save() return HttpResponse(json.dumps(dict(status=0, redirect=reverse('persons')))) else: errors = form.errors return HttpResponse(json.dumps({'status': 1, 'errors': errors})) else: form = PersonForm(instance=entry) return render(request, 'edit.html', locals())
def deceased(request): """ View to add deceased people details. """ if request.method == 'POST': person_form = PersonForm(request.POST) deceased_form = DeceasedForm(request.POST) valid_person_form = person_form.is_valid() valid_deceased_form = deceased_form.is_valid() if valid_person_form and valid_deceased_form: person_form.save() deceased_form_data = deceased_form.save(commit=False) deceased_form_data.gid = generate_gid() deceased_form_data.person_id = get_object_or_404(Person, person_id= \ person_form.cleaned_data['person_id']) deceased_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response( 'person/deceased.html', { 'deceased_form': deceased_form, 'person_form': person_form, 'error1': person_form, 'error2': deceased_form }, RequestContext(request)) else: return render_to_response('person/deceased.html', { 'deceased_form': DeceasedForm(), 'person_form': PersonForm() }, RequestContext(request))
def register(request): personform = PersonForm() if request.method=='POST': personform = PersonForm(request.POST) if personform.is_valid(): profile = personform.save(commit=False) profile.save() personform.save_m2m() return HttpResponseRedirect(reverse('thanks')) else: personform = PersonForm() return render(request, "register/reg.html", {'PersonForm': personform})
def register(request): """Main view.""" if not request.user.is_authenticated(): raise PermissionDenied if request.method == 'POST': is_update = Person.objects.filter(user=request.user).exists() if is_update: form = PersonForm(request.POST, instance=Person.objects.get(user=request.user)) else: form = PersonForm(request.POST) data = {'form': form} if form.is_valid(): person = form.save(commit=False) if is_update: person.save() return redirect('intro.home') else: person.user = auth.get_user(request) person.save() return redirect('user.register.complete') elif Person.objects.filter(user=request.user).exists(): data = {'form': PersonForm(instance=request.user.get_profile())} else: fbAuth = UserSocialAuth.objects.filter(user=request.user, provider='facebook') initData = {} if fbAuth.exists(): token = fbAuth.get().tokens['access_token'] if token: graph = facebook.GraphAPI(token) me = graph.get_object('me', locale='zh_TW') if 'name' in me: initData['fullname'] = me['name'] if 'gender' in me and me['gender'] in genderMap.keys(): initData['gender'] = genderMap[me['gender']] data = {'form': PersonForm(initial=initData)} # You'd add data here that you're sending to the template. return render(request, 'person/register.html', data)
def registration(request, template_name="faca_parte.html"): person_form = PersonForm(request.POST or None) if request.method == "POST" and request.POST['action'] == "send": email_typed = person_form['email'].value() if Person.objects.filter(email=email_typed).exists(): messages.error(request, _("E-mail already registered")) if person_form.is_valid(): person_form.save() messages.success(request, _('Registration created successfully!')) redirect_url = reverse("registration") return HttpResponseRedirect(redirect_url) else: messages.warning(request, _('Information not saved.')) context = {"person_form": person_form} return render(request, template_name, context)
def missing(request): """ The view is to file missing person, in the diseaster area. """ if request.method == 'POST': person_form = PersonForm(request.POST) missing_form = MissingForm(request.POST) comment_form = CommentForm(request.POST) valid_person_form = person_form.is_valid() valid_missing_form = missing_form.is_valid() valid_comment_form = comment_form.is_valid() if valid_person_form and valid_missing_form and valid_comment_form: person_form_data = person_form.save() missing_form_data = missing_form.save(commit=False) missing_form_data.gid = generate_gid() missing_form_data.person_id = get_object_or_404(Person, person_id= \ person_form_data.person_id) comment_form_data = comment_form.save(commit=False) _comment_id = randint(1, 1000) comment_form_data.comment_id = _comment_id comment_form_data.user_id = get_object_or_404( User, user_id=request.session['user_id']) comment_form_data.save() missing_form_data.comment = get_object_or_404( Comment, comment_id=_comment_id) missing_form_data.save() return HttpResponseRedirect('/crisis/') else: return render_to_response('person/missing.html', {'person_form': person_form,\ 'missing_form':missing_form, 'comment_form':\ comment_form, 'error':person_form, 'error1':missing_form, 'error2':comment_form},RequestContext(request)) else: return render_to_response('person/missing.html', {'person_form': PersonForm(),\ 'missing_form':MissingForm(), 'comment_form': \ CommentForm()}, RequestContext(request))
def person_create_view(request): if request.method == "POST": form = PersonForm(request.POST) if form.is_valid(): person = form.save() return redirect("person-detail", person.pk) else: form = PersonForm() context = {"form": form} return render(request, "case/person/create.html", context)
def edit_person(request, matriculation): person_form = PersonForm(prefix="prs") person = get_object_or_404(Person, matriculation=matriculation) if request.method == 'POST': person_form = PersonForm(request.POST, prefix="prs", instance=person) if person_form.is_valid(): person = person_form.save(commit=False) person.save() return redirect('locker_manager.views.person_details', matriculation=person.matriculation) else: messages.error(request, "Error") return render(request, 'locker_manager/register_person.html', {'person_form': person_form}) else: person_form = PersonForm(prefix="prs", instance=person) return render(request, 'locker_manager/register_person.html', {'person_form': person_form})
def edit_people(request, id=None): context = { 'page_title': u'Pessoas', 'edit_name': 'people', 'has_back': False, 'features': get_user_features(request) } t = get_template('edit.html') person = None form = PersonForm() try: if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): cd = form.cleaned_data person = _save_person(cd) messages.success(request, 'Pessoa salva com sucesso.') # initial = person.__dict__ # initial['institution'] = person.institution.id # initial['role'] = person.role.id form = PersonForm(initial={}) elif id: person = Person.objects.get(id=id) initial = person.__dict__ initial['institution'] = person.institution.id initial['role'] = person.role.id form = PersonForm(initial=initial) except Exception as e: log.error(e) messages.error( request, u'Ocorreu um erro ao processar a requisição, por favor tente novamente.' ) context = _set_person_form_context(person, form, context) return render_to_response('edit.html', context, context_instance=RequestContext(request))
def post(self, request): form = PersonForm(request.POST, request.FILES, instance=self.instance) if form.is_valid(): object_to_save = form.save(commit=False) object_to_save.save() logout(request) return HttpResponseRedirect(reverse('home-page')) else: form = PersonForm(request.POST, request.FILES, instance=self.instance) data = { 'form': form, } return TemplateResponse(request, self.template_name, data)
def home(request): if request.method == 'POST': form = PersonForm(request.POST) if form.is_valid(): person = form.save(commit=False) person.save() return HttpResponseRedirect('/techsite/home/') else: form = PersonForm() list_people = Person.objects.all() context = {'list_people': list_people, 'form': form} return render(request, 'home.html', context) # Create your views here.
def edit_index_data(request): person = Person.objects.all().get() other = person.othercontact_set.all().get() if request.method == 'GET': form = PersonForm(instance=person) contact_formset = ContactFormSet(instance=person) othercontact_form = OtherContactForm(instance=other) kw = { "form": form, "contact": contact_formset, "other": othercontact_form, } return render(request, 'edit_person.html', kw) form = PersonForm(request.POST, instance=person) contact_formset = ContactFormSet(request.POST, instance=person) othercontact_form = OtherContactForm(request.POST, instance=other) if form.is_valid() and contact_formset.is_valid() and \ othercontact_form.is_valid(): form.save() contact_formset.save() othercontact_form.save() return redirect('/') kw = { "form": form, "contact": contact_formset, "other": othercontact_form, } return render(request, 'edit_person.html', kw)
def get(self, request): form = PersonForm(instance=self.instance) return TemplateResponse(request, self.template_name, {'form': form})
def home(): form = PersonForm() if form.validate_on_submit(): # Get User input fname = request.form.get('fname') lname = request.form.get('lname') id_num = request.form.get('id_num') sex = request.form.get('sex') dob = request.form.get('dob') phone = request.form.get('phone') ethnicity = request.form.get('ethnicity') marital_status = request.form.get('marital_status') medical = request.form.get('medical') # Verifier info v_fname = request.form.get('v_fname') v_lname = request.form.get('v_lname') v_id = request.form.get('v_id') v_phone = request.form.get('v_phone') v_address = request.form.get('v_address') v_city = request.form.get('v_city') v_state = request.form.get('v_state') v_zipcode = request.form.get('v_zipcode') # Shelter History Info shelter = request.form.get('shelter') date_in = request.form.get('date_in') date_out = request.form.get('date_out') plan = request.form.get('plan') # Create the SQL statement # Person info stmt = sqlalchemy.text("INSERT INTO Person(Fname,Lname,id,sex,dob,phone,ethnicity,admission_id,marital_status,med_id,verifier_id,history_id)" "VALUES(:Fname,:Lname,:id,:sex,:dob,:phone,:ethnicity,:admission_id,:marital_status,:med_id,:verifier_id,:history_id)") # Verifier Info stmt2 = sqlalchemy.text("INSERT INTO Verifier(verifier_id,Fname,Lname,phone,Vaddress_id)" "VALUES(:verifier_id,:Fname,:Lname,:phone,:Vaddress_id)") # Verifier Address stmt3 = sqlalchemy.text("INSERT INTO VerifierAddress(Vaddress_id, address, state, city, zipcode)" "VALUES(:Vaddress_id, :address, :state, :city, :zipcode)") # Shelter History for Person stmt4 = sqlalchemy.text("INSERT INTO ShelterHistory(history_id,shelterID,date_in,date_out)" "VALUES(:history_id,:shelterID,:date_in,:date_out)") # Person's medical details stmt5 = sqlalchemy.text("INSERT INTO Medical(med_id,allergy)" "VALUES(:med_id,:allergy)") # Free trial or subscription plan stmt6 = sqlalchemy.text("INSERT INTO FreeTrial(trial_id,trial_start,trial_end)" "VALUES(:trial_id,:trial_start,:trial_end)") stmt7 = sqlalchemy.text("INSERT INTO Subscription(subscription_id, start, end)" "VALUES(:subscription_id, :start, :end)") stmt8 = sqlalchemy.text("INSERT INTO Admission(admission_id,trial_id,subscription_id)" "VALUES(:admission_id,:trial_id,:subscription_id)") # To check if verifier data already exist or not stmt9 = sqlalchemy.text("SELECT verifier_id FROM Verifier where verifier_id=:verifier_id") try: with db.connect() as conn: conn.execute(stmt,Fname=fname,Lname=lname,id=id_num,sex=sex,dob=dob,phone=phone,ethnicity=ethnicity,admission_id=id_num,marital_status=marital_status,med_id=id_num,verifier_id=v_id,history_id=id_num) conn.execute(stmt8,admission_id=id_num,trial_id=id_num,subscription_id=id_num) # Check if Verifier already exists or not # If verifier doesn't exist, enter verifier data into table # else ignore if exists verifier_check = conn.execute(stmt9, verifier_id=v_id) if verifier_check[0] != '': conn.execute(stmt2,verifier_id=v_id, Fname=v_fname, Lname=v_lname, phone=v_phone, Vaddress_id=v_id) conn.execute(stmt3, Vaddress_id=v_id, address=v_address, state=v_state, city=v_city, zipcode=v_zipcode) # If there are medical details, insert data into table if medical != '': conn.execute(stmt5, med_id=id_num,allergy=medical) # If there is shelter history, insert data into table if shelter != '0': conn.execute(stmt4, history_id=id_num, shelterID=shelter, date_in=date_in, date_out=date_out) # Add to Free Trial if plan == 'F': start_date = date.today() end_date = date.today() + timedelta(7) conn.execute(stmt6,trial_id=id_num, trial_start=start_date, trial_end=end_date) # Add to Subscription if plan == 'S': start_date = date.today() end_date = date.today() + timedelta(30) conn.execute(stmt7,subscription_id=id_num, start=start_date, end=end_date) except Exception as e: logger.exception(e) return redirect(url_for('success')) return render_template('home.html',form=form)