示例#1
0
文件: views.py 项目: abdelhai/dyform
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'
示例#2
0
文件: views.py 项目: abdelhai/dyform
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 ''
示例#3
0
文件: views.py 项目: abdelhai/dyform
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))