示例#1
0
文件: app.py 项目: haydenkh/Sir-Vey-1
def create_form():
    
    if request.method == 'GET':
            return render_template("test-create2.html")

    else:
       question = request.form['question']
       qtype = request.form['qtype']

       try:
           length = request.form['length']

       except:
           print "null"
           
       #if anon isn't checked set to null
       try:
           anon = request.form['anon']
       except:
           anon = ''
       #set answers null incase text
       answers = []
       i = 1
       if qtype =='mc':
           #iterate through answers written depending on length
           while(i < int(length) + 1):
               answer = request.form['Answer%d' %i]
               answers.append(str(answer))
               i = i+1
       #save form        
       db.add_form(question,qtype,answers,anon)
       
       return redirect(url_for('director'))
示例#2
0
    def post(self) -> dict:
        self.req_parse.add_argument('title', type=str, required=True)
        self.req_parse.add_argument('date', type=int, required=True)
        self.req_parse.add_argument('expiry', type=int, required=True)
        self.req_parse.add_argument('owner', type=str, required=True)
        self.req_parse.add_argument('email', type=str, required=True)
        self.req_parse.add_argument('form_obj', type=list, location="json", required=True)

        self.args = self.req_parse.parse_args()
        self.args["edit_key"] = str(uuid.uuid4())
        self.args["uuid"] = str(uuid.uuid4())

        try:
            add_form(self.args)
            edit_key = self.args["edit_key"]
            viewer_key = self.args["uuid"]
            time.sleep(2)
       
            viewer_link = f"{FRONT_END_URI}/formviewer?uuid={viewer_key}"
            response_link = f"{FRONT_END_URI}/formresponse?uuid={edit_key}"
            sender = os.environ["MAIL_DEFAULT_SENDER"]
            recipient = self.args["email"]
            message = f"""
            <p>
            Hi {self.args["owner"]},<br></br>
            Your form has been successfully published.<br></br>
            People can view the form using the viewer link.<br></br>
            You can view your responses to the form in the response link.<br></br>
            This form will expire in 7 days and all links will stop working
            after this.<br></br><br></br>
            Viewer Link: {viewer_link}<br></br>
        
            Response Link: {response_link}<br></br><br></br>
            Kind Regards,<br></br>
            Flex Forms Team
            </p>
            """
            subject = "Your Form has been published"
            if send_email(sender, recipient, message, subject):
                logger.debug("Email Sent")
            else:
                logger.debug("Email Not Sent")

            return {
                'message': 'Created',
                'viewer_link': viewer_link,
                'response_link': response_link ,
                }, 201
        except Exception as e:
            logger.error(e)
            return {'error': str(e)}, 409
示例#3
0
文件: forms.py 项目: mbsdev/helper
def index():
    form = UploadForm() if not loggedin() else NoCaptchaUploadForm()
    if form.validate_on_submit():
        filename = make_form_filename()
        while db.form_exists(filename):
            filename = make_form_filename()

        form.upload.data.save('static/forms/' + filename)
        db.add_form(form.filename.data, filename)
        flash('Your form was uploaded: %s' %
              url_for('static', filename='forms/%s' % filename))
    return render_template('forms.html',
                           form=form,
                           forms=db.get_forms(),
                           logged_in=loggedin(),
                           title='Forms')
示例#4
0
import db

db.drop_collection2()
db.drop_collection1()

db.add_form("How do you do?","Text", ['good'] , False )
db.add_form("How do you do?","mc",['hood'], False)
db.add_form("How is the weather?","mc",['good','great'], True)


id = db.get_question_id("How do you do?")
q = db.get_question(id)



#db.send_question("This should not exsist",["allo","*****@*****.**"])
db.send_question("How is the weather?",["*****@*****.**","Patrick"])
#db.send_question("What?",['*****@*****.**'])
#x = db.get_results()
#print db.get_recipient(x[0])
print db.get_recipient_questions("*****@*****.**")
print db.get_recipient_questions("Patrick")
#print "answer id"
#print x
#print x[0]
#print "ready"
#db.set_answer(x[0],'3')
#print db.get_answer(x[0])
#print db.get_recipient_questions("*****@*****.**")