def modify_form(request, form_id): if ('user_id' not in request.session): return HttpResponseRedirect("/") user_obj = User.objects.get(pk=request.session['user_id']) form_obj = Form.objects.get(pk=form_id) if (form_obj.user != user_obj): context = {'message': 'Permission Denied', 'user': user_obj} return render(request, 'main/message.html', context) if (request.method != 'POST'): date = timezone.now().date() data = xmltodict.parse(form_obj.data)['xml'] context = { 'form': form_obj, 'data': data, 'date': date, 'user': user_obj } #register if (form_obj.formType.id == 1): return render(request, 'main/register_modify_request_customer.html', context) #produce if (form_obj.formType.id == 5): return render(request, 'main/produce_modify_request_customer.html', context) #import if (form_obj.formType.id == 9): return render(request, 'main/import_modify_request_customer.html', context) #hold if (form_obj.formType.id == 13): return render(request, 'main/hold_modify_request_customer.html', context) #export if (form_obj.formType.id == 17): return render(request, 'main/export_modify_request_customer.html', context) formType_obj = FormType.objects.get(name=request.POST['form_type']) info = '<xml>' for key in request.POST: value = request.POST[key] info += '<' + key + '>' + value + '</' + key + '>' info += '<form_id>' + form_id + '</form_id>' info += '</xml>' form = Form(user=user_obj, formType=formType_obj, data=info, status=0, date=timezone.now()) form.save() for key in request.FILES.iterkeys(): print(key) if (uploadFile(request, form, key) == 0): context = {'message': 'Invalid Filetype.', 'user': user_obj} return render(request, 'main/message.html', context) context = {'message': 'Form have been Saved.', 'user': user_obj} return render(request, 'main/message.html', context)
def home(request): """Renders the home page.""" assert isinstance(request, HttpRequest) context = {'year': datetime.now().year } if request.method == "POST": name_surname = request.POST.get('nameSurname') email = request.POST.get('email') phone = request.POST.get('phone') message = request.POST.get('message') form = Form(name_surname=name_surname, email=email, phone=phone, message=message) form.save() context.update({'success':"Dziękujemy, skotaktujemy się z tobą!"}) return render( request, 'app/index.html', context)
def submit(self, form: models.Form, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None
def submit(self, form: models.Form, user, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) user_id = (user and not user.is_anonymous) and user.id or None v.user_id = user_id form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None
def test_select_field(self): opt1 = Option("男", 1) opt2 = Option("女", 0) field = SelectField(True, [opt1, opt2]) form = Form([field]) self.db.session.add(form) self.db.session.commit() self.assertEquals(form.id, 1) self.assertEquals(opt1.id, 1) self.assertEquals(opt2.id, 2) self.assertEquals(field.multiple, True)
def submit(self, form: models.Form, user, user_agent: UserAgent): """ 提交表单 """ if form.validate(): session = db.session v = form.values() v.assemble_from_user_agent(user_agent) user_id = (user and not user.is_anonymous) and user.id or None v.user_id = user_id # 查找所有的选项字段并保存选择的结果 def find_option_id(field, value): for option in field.options: if value == option.value: return option.id return -1 for field in form.select_fields: for value in field.value: choice = Choice(form_id=form.id, field_id=field.id, option_id=find_option_id( field, value['value']), value=value['value']) session.add(choice) form.increase_value_sequence() v.sequence = form.value_sequence session.add(v) session.commit() return v return None
def create_form(): id_user = request.form['id_user'] user = User.query.get(int(id_user)) form = Form(title="Untitled", description="Default description.", creator=user) db.session.add(form) db.session.commit() return Response('{"data":"Form created successfully."}', status=200, mimetype='application/json')
def test_create_form(self): form = Form() self.db.session.add(form) field = Field() field.name = 'title' form.fields.append(field) text = TextField() text.default = 'test' form.fields.append(text) self.db.session.add(field) self.db.session.add(text) self.db.session.commit()
def kyc(request): if request.method == 'POST': if request.POST.get('email') and request.POST.get('password'): form = Form() form.email = request.POST.get('email') form.password = request.POST.get('password') form.save() return render(request, "kyc.html") else: return render(request, "kyc.html")
def file_to_db(): try: with application.open_resource('static/forms.json') as json_file: all_forms = json.load(json_file) for form in all_forms: new_form = Form(**form) db.session.add(new_form) db.session.commit() curr_forms = Form.query.all() i = 0 for form in curr_forms: i += 1 print(form.name) return str(i) + ' total forms added into database' except Exception as e: return str(e)
def record_form(): ''' Requires matching API key. For POST requests, check the database for a result with a matching identifier and record the submiited form values. ''' tracker = request.form.get('tracker') form_data = request.form.get('data') result = Result.query.filter_by(tracker=tracker).first() # tracker string is not in db if result is None: return 'no tracker', 404 form = Form(data=form_data) result.forms.append(form) result.status = 'Submitted' db.session.commit() return 'updated'
def create_form(request, formtype_id): if ('user_id' not in request.session): return HttpResponseRedirect("/") user_obj = User.objects.get(pk=request.session['user_id']) if (request.method != 'POST'): #register if (formtype_id == '1'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/register_request_customer.html', context) #produce if (formtype_id == '5'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/produce_request_customer.html', context) #import if (formtype_id == '9'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/import_request_customer.html', context) #hold if (formtype_id == '13'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/hold_request_customer.html', context) #export if (formtype_id == '17'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/export_request_customer.html', context) #sample if (formtype_id == '21'): date = timezone.now().date() context = {'date': date, 'user': user_obj} return render(request, 'main/sample_produce_import_request_customer.html', context) info = '<xml>' # DO SOME INFOMATION CONVERT TO XML OR SOMETHING for key in request.POST: value = request.POST[key] info += '<' + key + '>' + value + '</' + key + '>' info += '</xml>' print formtype_id formType_obj = FormType.objects.get(pk=formtype_id) form = Form(user=user_obj, formType=formType_obj, data=info, status=0, date=timezone.now()) form.save() for key in request.FILES.iterkeys(): print(key) if (uploadFile(request, form, key) == 0): context = {'message': 'Invalid Filetype.', 'user': user_obj} return render(request, 'main/message.html', context) context = {'message': 'Form have been Saved.', 'user': user_obj} return render(request, 'main/message.html', context)
from app import db from app.models import Form from flask import json form = json.load(open('./app/forms/multiply.json')) formstring = json.dumps(form) f = Form(name='test', title='test form', subtitle='a test form loaded from sqlite', imageUrl='./assets/test.jpg', fields=formstring, calcmethod='test.getResult') db.session.add(f) db.session.commit()
c_file = os.path.abspath(os.path.join(folder, 'change.csv')) n_file = os.path.abspath(os.path.join(folder, 'notes.csv')) with open(i_file, encoding='utf-8') as i,\ open(f_file, encoding='utf-8') as f, \ open(c_file, encoding='utf-8') as c, \ open(n_file, encoding='utf-8') as n: i_reader = csv.reader(i) f_reader = csv.reader(f) c_reader = csv.reader(c) n_reader = csv.reader(n) for row in zip(i_reader, f_reader, c_reader, n_reader): f = Form(patient_id=row[0][0], session=row[0][2], name='A', date=row[0][3], section=None) db.session.add(f) db.session.commit() for num in range(4, 46): notes_to_add = row[3][num] if len(row[3]) > num else '' q = Question(form_id=f.id, question=num - 3, intensity=row[0][num], frequency=row[1][num], change=row[2][num], notes="{}".format(notes_to_add).replace( ',', '-').replace(';', '-')) db.session.add(q) db.session.commit()
def index(): f = MedicalForm() if f.validate_on_submit(): submit = Form( patient_name=f.patient_name.data, sex=f.sex.data, date_of_birth=f.date_of_birth.data, age=f.age.data, height=f.height.data, weight=f.weight.data, hand=f.hand.data, referred_by=f.referred_by.data, reason_for_visit=f.reason_for_visit.data, #symptoms limb_jerking=f.limb_jerking.data, tremors=f.tremors.data, depression=f.depression.data, headaches=f.headaches.data, sleep_difficulties=f.sleep_difficulties.data, increased_stress=f.increased_stress.data, memory_problems=f.memory_problems.data, back_neck_pain=f.back_neck_pain.data, numbness=f.numbness.data, numbness_optional=f.numbness_optional.data, head_injury=f.head_injury.data, dizziness=f.dizziness.data, unsteady_gait=f.unsteady_gait.data, balance_difficulties=f.balance_difficulties.data, fainting=f.fainting.data, word_finding=f.word_finding.data, episodes_of_confusion=f.episodes_of_confusion.data, hospital_recently=f.hospital_recently.data, medication_change=f.medication_change.data, other_symptoms=f.other_symptoms.data, #diseases hypertension=f.hypertension.data, heart_problems=f.heart_problems.data, diabetes_mellitus=f.diabetes_mellitus.data, high_cholesterol=f.high_cholesterol.data, stroke=f.stroke.data, seizure=f.seizure.data, depression_disease=f.depression_disease.data, migraine=f.migraine.data, #habits cigarettes=f.cigarettes.data, cigarettes_long=f.cigarettes_long.data, cigarettes_frequency=f.cigarettes_frequency.data, alcohol=f.alcohol.data, drugs=f.drugs.data, #medical systems weight_loss=f.weight_loss.data, fever=f.fever.data, palpitation=f.palpitation.data, chest_pain=f.chest_pain.data, cough=f.cough.data, sputum=f.sputum.data, abdominal_pain=f.abdominal_pain.data, nausea=f.nausea.data, vomiting=f.vomiting.data, diarrhea=f.diarrhea.data, hematuria=f.hematuria.data, urination_incontinence=f.urination_incontinence.data, over_eating=f.over_eating.data, over_sweating=f.over_sweating.data, over_urinating=f.over_urinating.data, always_thirsty=f.always_thirsty.data, skin_rash=f.skin_rash.data, lesion=f.lesion.data, easily_bleeds=f.easily_bleeds.data, bruises=f.bruises.data, blood_clots=f.blood_clots.data, joint_pain=f.joint_pain.data, muscle_pain=f.muscle_pain.data, #misc occupation=f.occupation.data, surgeries=f.surgeries.data, medication_allergies=f.medication_allergies.data, family_medical_problems=f.family_medical_problems.data, current_medications=f.current_medications.data, other_information=f.other_information.data, patient_signature=f.patient_signature.data, author=current_user) db.session.add(submit) db.session.commit() flash('Thank you for registering! Please return IPad to front desk.') return redirect(url_for('main.index')) return render_template('index.html', title='Patient Registration', form=f)