def ask(request): if request.method == 'POST': form = AskQuestionForm(request.POST) if form.is_valid() and request.user.is_authenticated(): kw = { "name": form.cleaned_data["title"], "content": form.cleaned_data["content"], "author": request.user, } q = question(**kw) q.save() for tg in form.cleaned_data["tags"].split(","): tg_c = tg.replace(" ", "") t = Tag.objects.all().filter(tagName=tg_c) if t: q.tags.add(t[0]) else: t = Tag(tagName=tg_c) t.save() q.tags.add(t) return HttpResponseRedirect('/question/' + str(q.id)) else: form = AskQuestionForm() return render(request, 'ask.html', {'form': form})
def handle(self, *args, **options): tags = [ 'JavaScript', 'Java', 'Django', 'Nginx', 'Gunicorn', 'php', 'Android', 'Jquery', 'Python', 'HTML', 'CSS', 'ios', 'MySQL', 'Windows', 'Docker' ] for tag in tags: if len(Tag.objects.filter(text=tag)) == 0: t = Tag() t.text = tag t.style_number = randint(1, 8) t.save() number = int(options['number']) tags = Tag.objects.all() questions = Question.objects.all() for q in questions: if len(q.tags.all()) < number: for i in range(0, number - len(q.tags.all())): t = choice(tags) if t not in q.tags.all(): q.tags.add(t) q.save() self.stdout.write('in question [%d] add tags' % q.id)
def fill_db(self): for i in range(0, 30): usr = User(username='******' + str(i), password='******' + str(i), first_name='User') usr.save() prof = Profile(avatar='avatar.jpeg', user=usr) prof.save() try: tbag = Tag.objects.get(name='Bucket' + str(i % 20)) tbag.popularity += 1 except Exception: tbag = Tag(name='Bucket' + str(i % 20), popularity=1) tbag.save() quest = Question(title=str(i) + 'bucket', text='see my bucket, I have a' + str(10000 - i) + ' bucket remains', author=prof, votes=i) quest.save() quest.liked.add(prof) quest.tag.add(tbag) for j in range(0, 20): ans = Answer(text='Test answer' + str(i), author=prof, question=quest) ans.votes = int(((i + j) * 6) % 40) ans.save() ans.voted.add(prof)
def connectTags(q, tags): _tags = tags.split(',') for tag in _tags: tag = tag.strip(' ') t = Tag(text = tag) t.save() q.tags.add(t)
def handle(self, *args, **options): user = User.objects.get(email='*****@*****.**') list_tags = ["Perl", "Python", "TechnoPark", "MySQL", "Django", "Mailru", "Voloshin", "Firefox", "black-jack", "bender"] Question.objects.all().delete() Answer.objects.all().delete() Tag.objects.all().delete() for i in range(0, 100): q=Question( author=user, body='body ' + str(i), title = 'title ' + str(i), ) q.save() for j in range(1, 3): a=Answer( text='answer ' + str(i) + ' ' + str(j), author=user, question=q, ) a.save() tmp = i%10 t=Tag( name = list_tags[tmp], rating = tmp, ) t.save() t.question.add(q)
def _fill_tag(self): print('FILLING TAG MODEL...') for ix in range(500): temp_tag = Tag(name='Tag{}'.format(ix + 1), path='tag{}'.format(ix + 1)) temp_tag.save() print('ADDED {} TAGS'.format(Tag.objects.count()))
def handle(self, *args, **options): tags = [ 'java', 'php', 'android', 'jquery', 'python', 'html', 'css', 'ios', 'mysql', 'sql', ] for tag in tags: if len(Tag.objects.filter(name=tag)) == 0: t = Tag() t.name = tag t.save() number = int(options['number']) tags = Tag.objects.all() for q in Question.objects.all(): if len(q.tags.all()) < number: for i in range(0, number - len(q.tags.all())): t = choice(tags) if t not in q.tags.all(): q.tags.add(t)
def generate_tags(n): arr = open('/home/hase/technopark/web/AskZaytsev/scripts/tags', 'r').read().split('\n') asize = len(arr) for i in range(0, asize): t = Tag(title=arr[i]) print(t.title) t.save() print('tag')
def generateTags(n): import urllib2 url = "http://randomword.setgetgo.com/get.php" for i in range(n): urldata = urllib2.urlopen(url) word = urldata.readlines()[0][:-2] #removed \r\n tag = Tag(tagName=word) #print word, tag tag.save() if i % 5 == 0: print i
def handle(self, *args, **options): tags = [ 'javascript', 'java', 'cshp', 'php', 'android', 'jquery', 'python', 'html', 'css', 'cpp', 'ios', 'mysql', 'objective_c', 'sql', 'asp_net', 'ruby_on_rails', 'iphone', 'angularjs', 'regexp' ] number = int(options['number']) for i in range(0, number): t = Tag() t.title = choice(tags) + str(i+2000) t.save() self.stdout.write('[%d] added tag %s' % (t.id, t.title))
def ask(request): if request.POST: form = QuestionForm(request.POST, author=request.user) if form.is_valid(): question = form.save() tag = request.POST.get('tags') for word in tag.split(" "): t = Tag(name = word) t.save() t.question.add(question) return redirect('/') form = QuestionForm() return render(request, 'ask.html', { 'form' : form })
def handle(self, *args, **options): (amount,) = args count = int(amount) #EXCEPTIONS if count < 1: raise ValueError('incorrect parameter') #relations_q_t=0 createdTags=0 #generate tags for i in range(count): tag_text = randomWord(random.randint(3,7)) t = Tag(text=tag_text) t.save() createdTags += 1 print('was created : ' + str(createdTags) + ' tags') print('was created : ' + str(createdTags) + ' tags')
def setup(): f = Faker() tags = f.words(nb=20) for i in tags: a = Tag(tag=i) a.save() for i in range(100): tt = f.text(50) te = f.text() a = Question(title=tt, text=te, author_id=randint(2, 4)) a.save() a.tags.add(randint(1, 20), randint(1, 20), randint(1, 20)) for i in range(300): te = f.text() an = Answer(text=te, author_id=randint(2, 4), question_id=randint(1, 100)) an.save()
def handle(self, *args, **options): def get_rand_color(): return random.choice([ 'red', 'orange', 'blue', 'green', 'cyan', 'violet', 'teal', 'maroon', 'indigo', 'peru' ]) tags = [ 'Technopark', 'C++', 'Java', 'Python', 'Perl', 'Django', 'Apple', 'Android', 'Haskell', 'CSS', 'HTML', 'Bootstrap', 'Twitter', 'Vkontakte', 'Facebook', 'IOS', 'Windows' ] added = 0 for tag in tags: if len(Tag.objects.filter(title=tag)) == 0: t = Tag() t.title = tag t.color = get_rand_color() t.save() added += 1 print(added, " Tags is added")
def handle(self, *args, **options): name = options['name'] tag = Tag(name=name) tag.save()
def create_qusetion_answer_and_connect_user(how_many): does_NOT_exist_users = '' for j in range(how_many): ### User get random user_id = random.randint(1, 10362) try: u = User.objects.get(id=user_id) except: does_NOT_exist_users = does_NOT_exist_users + str(user_id) + ' ' user_id = random.randint(1, 10362) try: u = User.objects.get(id=user_id) except: does_NOT_exist_users = does_NOT_exist_users + str(user_id) + ' ' user_id = random.randint(1, 10362) u = User.objects.get(id=user_id) ### End User get random ### Tag create start_tag_lenght = 3 end_tag_lenght = 6 t_text = randomword(start_tag_lenght, end_tag_lenght) t = Tag(text = t_text) t.save() ### End Tag create ### Question create question_length_low = 8 question_length_high = 15 q_title = randomword(question_length_low, question_length_high) for i in range(random.randint(0, 2)): q_title = q_title + ' ' + randomword(question_length_low, question_length_high) q_title = q_title + '?' q_text = randomword(question_length_low, question_length_high) for i in range(random.randint(3, 20)): q_text = q_text + ' ' + randomword(question_length_low, question_length_high) q_rating = random.randint(-10, 150) q = Question(title = q_title, text = q_text, author = u, rating = q_rating ) q.save() q.tags.add(t) q.save() ### End Question create ### User get random ser_id = random.randint(1, 10362) try: u = User.objects.get(id=user_id) except: does_NOT_exist_users = does_NOT_exist_users + str(user_id) + ' ' user_id = random.randint(1, 10362) try: u = User.objects.get(id=user_id) except: does_NOT_exist_users = does_NOT_exist_users + str(user_id) + ' ' user_id = random.randint(1, 10362) u = User.objects.get(id=user_id) ### End User get random ### Answer create answer_length_low = 8 answer_length_high = 15 a_text = randomword(answer_length_low, answer_length_high) for i in range(random.randint(7, 25)): a_text = a_text + ' ' + randomword(answer_length_low, answer_length_high) a_right_answer = True a = Answer(question = q, text = a_text, right_answer = a_right_answer, author = u ) a.save() ### End asnwer create print('Create: ' + str(j)) print('Create: ' + str(how_many)) print(does_NOT_exist_users)
def handle(self, *args, **options): user_range = 25 ask_range = 37 answers_range = 97 f_name = [ 'Red', 'Mad', 'Dummy', 'Crazy', 'Big', 'Black', 'Lonely', 'Shiz', 'Drunken', 'Wicked', 'Brainless', 'Rich', 'Stubborn', 'Stupid', 'Fat', 'Wooden', 'Donald', 'American', 'Dead', 'Lucky', 'Night' ] l_name = [ 'Sailor', 'Rat', 'Man', 'Rabbit', 'Donkey', 'Policeman', 'Child', 'Penguin', 'Joker', 'Lawmaker', 'Judge', 'Iron', 'President', 'Trump', 'Duck', 'Timmy', 'Kartman', 'Kenny', 'Orc', 'Illuminati', 'Band', 'Slave', 'Coffee', 'Aviato', 'Redneck', 'Camper', 'King' ] for i in range(0, user_range): username = u'{0}{1}'.format( f_name[random.randrange(0, len(f_name))], l_name[random.randrange(0, len(l_name))]) email = u'{0}@e-corp.com'.format(username) password = u'{0}123'.format(username) try: User.object.create_user(username=username, email=email, password=password) except: username = u'{0}{1}'.format(username, i) email = u'{0}@e-corp.com'.format(username) User.object.create_user(username=username, email=email, password=password) tags_list = [ 'LOL', 'mad', 'wazzzup', 'DonaldTrump', 'luxury', 'shaurma', 'Skynet', 'TheyAreWatchingYou', 'illuminati', 'Futurama', 'Bender', 'BlackJack', 'TacoBell', 'BreakingBad', ] for tag in tags_list: try: new_tag = Tag() new_tag.title = tag new_tag.save() except: pass f_question = ['How to', 'Why to', 'Can I', 'What if'] l_question = ['fly', 'run', 'jump', 'degrade', 'capture the world'] users = User.object.all() users_count = len(users) tags_list = Tag.objects.all() tags_count = len(tags_list) for i in range(0, ask_range): ask = Ask() random_pk = random.randrange(1, users_count) ask.author = users[random_pk] ask.question = u'{0} {1}'.format( f_question[random.randrange(0, len(f_question))], l_question[random.randrange(0, len(l_question))]) ask.text = u'{0} question by {1}'.format(ask.question, ask.author.username) ask_tags = [] tags_range = random.randrange(1, 4) for i in range(0, tags_range): ask_tags.append(tags_list[random.randrange(0, tags_count)]) ask.rating = random.randrange( -10, 30) # temporary remove later by UserVote ask.save() ask.tags = set(ask_tags) ask.save() asks = Ask.objects.all() asks_count = len(asks) f_answer = ['Just', 'I dont', 'May be', 'You should'] l_answer = ['do it', 'know', 'know', 'forget it'] for i in range(0, answers_range): answer = Answer() random_pk = random.randrange(1, users_count) answer.author = users[random_pk] ask_pk = random.randrange(1, asks_count) answer.ask = asks[ask_pk] answer.text = u'{0} {1}'.format( f_answer[random.randrange(0, len(f_answer))], l_answer[random.randrange(0, len(l_answer))]) answer.save()