Example #1
0
    def create_answers(self):
        faker = Faker()

        question_set = Question.objects.all()
        author_set = User.objects.all()

        for i in range(100):
            answer = Answer()
            answer.author = random.choice(author_set)
            answer.question = random.choice(question_set)
            answer.text = faker.text(max_nb_chars=200, ext_word_list=None)
            try:
                answer.save()
            except:
                print("Answer repeated")
    def handle(self, *args, **options):
        fake_factory = Factory.create('en_US')

        min_number = int(options['min_number'])
        max_number = int(options['max_number'])

        users = User.objects.all()[1:]
        questions = Question.objects.all()

        for question in questions:
            for i in range(randint(min_number, max_number)):
                answer = Answer()

                answer.text = fake_factory.paragraph(nb_sentences=randint(2, 10), variable_nb_sentences=True)
                answer.author = choice(users)
                answer.question = question
                answer.date = fake_factory.date()
                answer.save()
                self.stdout.write('[%d] ans[%d]' % (question.id, answer.id))
Example #3
0
    def fill_answers(self):
        fake = Factory.create()

        min_number = 10
        max_number = 20


        questions = Question.objects.all()
        is_correct = (True, False)
        counter = 1
        for q in questions:
            for i in range(0, randint(min_number, max_number)):
                ans = Answer()

                ans.text = fake.paragraph(nb_sentences=randint(2, 4), variable_nb_sentences=True)
                ans.author = Profile.objects.first()
                ans.question = q
                ans.rating = randint(0, 1500)
                ans.is_correct = choice(is_correct)
                ans.id = counter
                counter += 1
                ans.save()
                self.stdout.write('in question [%d] add ans [%d]' % (q.id, ans.id))
Example #4
0
def comment(request, id):
    comment_form = CommentForm(request.POST or None)
    args = {}
    args['form'] = comment_form

    if request.POST and comment_form.is_valid():
        user = auth.get_user(request)
        a = Question.objects.all().filter(id=id)

        answer = Answer(text=comment_form.cleaned_data['text'])
        answer.author = user
        answer.answers_question=a[0]
        answer.save()

        # sending mail
        str = "User " + user.username + " answer your question " + a[0].title + "\n" + \
                  "Text: " + answer.text
        send_mail('New Comment!', str, '*****@*****.**', [a[0].author.email], fail_silently=False)

        # return redirect('questionGet' + '#text', question_id=a[0].id)
        return redirect('/question/get/%s#text' % id)
    else:
        return redirect('/question/get/%s#text' % id)
    return render(request, 'question_render.html', args)