Example #1
0
 def post(self, boragle_slug, question_slug):
     question = Question.find_by_slug(question_slug)
     avatar = self.get_avatar_for_boragle(question.boragle)
     assert avatar, question
     answer = self.read('answer')
     if not(answer and answer.strip()): raise PostingError('Please provide an answer')
     Answer.create(question = question, text = answer, creator = avatar)
     page = self.calc_last_page(question.answer_count, settings.answer_page_size)
     self.redirect(question.url+'?page='+str(page))
Example #2
0
 def test_voting_security(self):
     answer = Answer.create(question = self.question, text= 'fake answer', creator = self.avatar)
     self.app.get(answer.voting_url+'/up', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)
     self.logout()
     self.app.get(answer.voting_url+'/down', status = 302)
     answer = Answer.get(answer.key())
     self.assertEqual(answer.vote_count, 1)        
Example #3
0
def create_answer_view():
    next_page = request.form['next']

    text = request.form['text']
    thread_id = request.form['thread']

    if not (text and thread_id):
        abort(HTTPStatus.BAD_REQUEST)

    answer = Answer.create(
        text=text[:65535],
        thread=thread_id,
        author=current_user.id,
        created_at=datetime.now(),
    )

    current_user.msg_count += 1
    current_user.save()

    thread = Thread.get(thread_id)
    thread.last_answer_time = answer.created_at
    thread.save()

    return redirect(next_page)
Example #4
0
            possible_users = list(
                filter(
                    lambda usr: usr.registered_at and
                    (usr.registered_at > thread.created_at), users))

            if not possible_users:
                continue
            else:
                user = random.choice(possible_users)

                # TODO(a.telishev): Factory
                Answer.create(
                    text=fake.text(max_nb_chars=1024),
                    thread=thread.id,
                    author=user.id,
                    created_at=fake.date_between_dates(
                        date_start=thread.created_at),
                    rating=random.randint(0, 100),
                    is_off_topic=random.randint(0, 100) < 10,
                )
                break

        if i and (i % 20000) == 0:
            print(f' - Created {i} answers')

# Set last answer time for threads
if SET_LAST_ANSWERS_TIME:
    print('Set last answers times for threads')

    for i, thread in enumerate(Thread.all()):
        thread.set_last_answer_time()