def thread_create():
    thread_form = ThreadCrudForm(csrf_enabled=False)
    current_app.logger.debug(thread_form.question_id.data)
    
    if thread_form.validate():
        author_id = thread_form.author_id.data if isinstance(thread_form.author_id.data, basestring) else thread_form.author_id.data[0]
        q = cdw.questions.with_id(thread_form.question_id.data)
        u = cdw.users.with_id(author_id)
        
        post = Post(yesNo=int(thread_form.yesno.data), 
                    text=thread_form.text.data, 
                    author=u,
                    likes=thread_form.likes.data,
                    origin=u.origin)
        cdw.create_thread(q, post)
        flash('Thread created successfully', 'info')
    else:
        current_app.logger.debug(thread_form.errors)
        flash('Error creating debate. Try again.', 'error')
    
    return redirect(request.referrer)
Beispiel #2
0
def thread_create():
    thread_form = ThreadCrudForm(csrf_enabled=False)
    current_app.logger.debug(thread_form.question_id.data)

    if thread_form.validate():
        author_id = thread_form.author_id.data if isinstance(
            thread_form.author_id.data,
            basestring) else thread_form.author_id.data[0]
        q = cdw.questions.with_id(thread_form.question_id.data)
        u = cdw.users.with_id(author_id)

        post = Post(yesNo=int(thread_form.yesno.data),
                    text=thread_form.text.data,
                    author=u,
                    likes=thread_form.likes.data,
                    origin=u.origin)
        cdw.create_thread(q, post)
        flash('Thread created successfully', 'info')
    else:
        current_app.logger.debug(thread_form.errors)
        flash('Error creating debate. Try again.', 'error')

    return redirect(request.referrer)
 def questions_threads_post(id):
     question = cdw.questions.with_id(id)
     form = PostForm(request.form, csrf_enabled=False)
     
     current_app.logger.debug(request.form.to_dict())
     
     if form.validate():
         post = form.to_post()
         follow_sms = form.get_follow_sms() 
         follow_email = form.get_follow_email()
         
         # The kiosk will send a phone number with the post if the user
         # wants to subscribe via SMS so we need to set the user's phone
         if form.origin.data == 'kiosk':
             follow_sms = True
         thread = cdw.create_thread(question, post, follow_sms, follow_email)
             
         return jsonify(thread)
     else:
         current_app.logger.debug("Error creating thread: %s" % form.errors)
         return jsonify({"error":form.errors}, 400)
Beispiel #4
0
    def questions_threads_post(id):
        question = cdw.questions.with_id(id)
        form = PostForm(request.form, csrf_enabled=False)

        current_app.logger.debug(request.form.to_dict())

        if form.validate():
            post = form.to_post()
            follow_sms = form.get_follow_sms()
            follow_email = form.get_follow_email()

            # The kiosk will send a phone number with the post if the user
            # wants to subscribe via SMS so we need to set the user's phone
            if form.origin.data == 'kiosk':
                follow_sms = True
            thread = cdw.create_thread(question, post, follow_sms,
                                       follow_email)

            return jsonify(thread)
        else:
            current_app.logger.debug("Error creating thread: %s" % form.errors)
            return jsonify({"error": form.errors}, 400)