Example #1
0
    def handle(self, *args, **options):
        fake = Factory.create()

        number = int(options['number'])

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

        starts = ('How do I Sort a Multidimensional', 'What is Vlad?',
                  'SQL Server')

        for i in range(0, number):
            q = Question()

            q.title = fake.sentence(nb_words=randint(2, 4),
                                    variable_nb_words=True)
            q.text = u"%s %s %s" % (
                choice(starts),
                os.linesep,
                fake.paragraph(nb_sentences=randint(1, 4),
                               variable_nb_sentences=True),
            )
            q.user = choice(users)
            q.rating = randint(0, 1500)
            q.is_published = True
            q.id = i
            q.save()
            self.stdout.write('add question [%d]' % (q.id))
Example #2
0
    def handle(self, *args, **options):
        fake = Factory.create()

        number = int(options['number'])

        users = Profile.objects.all()

        starts = (
                u'Help! Nothing happens!',
                u'I tried all, help',
                u'I do not find any solutions on the Internet, save',
                u'Following problem:',
                u'I think that someone of you faced with the question',
                u'Sorry, but I am a novice in this matters',
                u'Hi! Dates burn, need advice',
                )

        for i in range(0, number):
            q = Question()

            q.title = fake.sentence(nb_words=randint(4, 6), variable_nb_words=True)[:40]
            q.text = u"%s %s %s" % (
                    choice(starts),
                    os.linesep,
                    fake.paragraph(nb_sentences=randint(4, 17), variable_nb_sentences=True),
                    )
            q.owner = choice(users)
            q.save()
            tag_cnt = randint(1,5)
            for i in range(0, tag_cnt):
                tq = Tag.objects.filter(id=randint(1, tag_cnt))[0]
                q.tags.add(tq)
            self.stdout.write('added question [%d]' % (q.id))
Example #3
0
    def handle(self, *args, **options):
        fake = Factory.create()

        number = int(options['number'])

        users = User.objects.all()[1:]
        for i in range(0, number):
            q = Question()

            q.title = fake.sentence(nb_words=randint(2, 4),
                                    variable_nb_words=True)
            q.text = fake.paragraph(nb_sentences=randint(4, 17),
                                    variable_nb_sentences=True)
            q.auth = choice(users)
            q.save()
Example #4
0
    def save(self, owner):
        data = self.cleaned_data
        title = data.get('title')
        text = data.get('text')
        tags_list = data.get('tags')
        if tags_list:
            tags_list = [tag.replace(' ', '') for tag in tags_list]
            tags_list = [tag.replace('-', '_') for tag in tags_list]

        q = Question()
        q.title = title
        q.text = text
        q.owner = Profile.objects.get(user_id=owner.id)
        q.save()

        for tag in tags_list:
            tag_obj = Tag.objects.get_or_create(tag)
            q.tags.add(tag_obj)

        return q