def data_view(fid, tid): formlinks = FormLink.objects(creator=current_user.to_dbref()) formlink = FormLink.objects(fid=fid).first() # print 'formlink:', formlink threads = Thread.objects(formlink=formlink) thread = Thread.objects(tid=tid).first() datas = FormData.objects(thread=thread).order_by('id') main = FormData.objects(thread=thread).order_by('id').first() # for x in mains: # print 'hhhhhh', x.load # main = None return render_template('forms/dashboard.html', fid=fid, datas=datas, threads=threads, formlinks=formlinks, tid=tid, main=main)
def form(fid): if FormLink.objects(fid=fid): if request.method == 'POST': form_data = FormData() formlink = FormLink.objects(fid=fid).first().to_dbref() form_data.thread = Thread(formlink=formlink).save() form_data.load = semiflatten(request.form) form_data.headers = dict(request.headers.items()) form_data.ip = request.remote_addr form_data.save() return redirect(url_for('forms.data', fid=fid)) return render_template('forms/test_form.html', fid=url_for('forms.form', fid=fid)) else: return 'no form found'
def profile(): myform = MyForm() if request.method == 'POST': if myform.validate_on_submit(): firstname = myform.firstname.data lastname = myform.lastname.data email = myform.email.data location = myform.location.data biography = myform.biography.data gender = myform.gender.data photo = myform.photo.data filename = secure_filename(photo.filename) photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) userid = random.getrandbits(16) #str(uuid.uuid4()) created_on = format_date_joined() #db = connect_db() #cur = db.cursor() #query = "insert into Profiles (firstname, lastname, email, location, biography, gender, photo, userid, created_on) values (%s, %s, %s, %s, %s, %s, %s, %s, %s);" #data = (firstname, lastname, email, location, biography, gender, filename, userid, created_on) #cur.execute(query, data) #db.commit() new_profile = FormData(firstname=firstname, lastname=lastname, email=email, location=location, biography=biography, gender=gender, photo=filename, userid=userid, created_on=created_on) db.session.add(new_profile) db.session.commit() flash('Profile successfully added!', 'success') return redirect(url_for("profiles")) flash_errors(myform) return render_template('profile.html', form=myform)
def send_email(fid, tid): body = request.form.get('message') thread = Thread.objects(tid=tid).first() data = FormData.objects(thread=thread).order_by('id').first() email = data.load['email'] email_address = current_user.username + '@mail.dyform.co' subject = 'Reply To: ' + '[DFNR:' + str(fid) + '-' + str(tid) + ']' message = sendgrid.Mail(to=email, subject=subject, text=body, from_email=email_address) status, msg = sg.send(message) form_data = FormData() form_data.thread = thread.to_dbref() form_data.load = {"message": body, "from": current_user.username + '@mail.dyform.co'} form_data.save() return redirect(url_for('forms.data_view', fid=fid, tid=tid))
def inbound(): if request.method == 'POST': InboundData(raw=request.form).save() text = None subject = request.form['subject'].decode('utf-8') print subject reg = re.compile(ur"[\[]DFNR:(\d+)[-](\d+)[\]]".decode('utf-8')) fid = int(re.search(reg, subject).group(1)) tid = int(re.search(reg, subject).group(2)) if request.form['text']: text = request.form['text'].split('\n')[0] form_data = FormData() form_data.thread = Thread.objects(tid=tid).first().to_dbref() form_data.load = {'message': text} form_data.save() return ''
def get_form_class(self): if self.form_class is None: return FormData.get(self.kwargs['uuid']).form_class
def form_valid(self, form): self.form_data = FormData.get(self.kwargs['uuid']) self.form_data.form_data = form.cleaned_data return http.HttpResponseRedirect(self.get_success_url())
def get_initial(self): return FormData.get(self.kwargs['uuid']).form_data
def get_context_data(self, **kwargs): context = super(FormDataDetailView, self).get_context_data(**kwargs) context['form_data'] = FormData.get(kwargs['uuid']) return context
def form_valid(self, form): self.form_data = FormData(self.form_class, form.cleaned_data) return http.HttpResponseRedirect(self.get_success_url())