def generate_users(cnt): names = [ 'john', 'peter', 'kolya', 'misha', 'pasha', 'ilja', 'trump', 'derek' ] snames = ['obama', 'trum', 'ivanov', 'prtrov', 'lomov', 'morgan'] mails = ['ya', 'ma', 'go'] nsize = len(names) ssize = len(snames) msize = len(mails) imgs = os.listdir('/home/hase/technopark/web/AskZaytsev/scripts/test_img') imgsc = len(imgs) for i in range(0, cnt): print(i) fname = names[random.randint(0, nsize - 1)] sname = snames[random.randint(0, ssize - 1)] email = names[random.randint( 0, nsize - 1)] + '@' + mails[random.randint(0, msize - 1)] + '.ru' pwd = str(random.randint(10000, 1000000)) u = User() u.username = fname + ' ' + sname + str(i) u.password = pwd u.email = email u.first_name = fname u.last_name = sname u.is_active = True u.is_superuser = False u.save() img = imgs[random.randint(0, imgsc - 1)] print(img) p = Profile(user=u, avatar=img) p.save() print(p.avatar)
def signup(request): if request.POST: form = UserForm(request.POST, request.FILES) if form.is_valid(): password = form.cleaned_data.get('password') repeat_password = form.cleaned_data.get('repeat_password') if (password == repeat_password): username = form.cleaned_data.get('login') try: username = User.objects.get(username = username) return render(request, 'signup.html', { 'form' : form, 'user_error' : True }) except User.DoesNotExist as error: email = form.cleaned_data.get('email') last_name = form.cleaned_data.get('nickname') u = User.objects.create_user(username, email, password) u.last_name = last_name p = Profile(user = u, avatar = request.FILES.get('upload_avatar')) p.save() user = auth.authenticate(username=username, password=password) auth.login(request, user) return redirect('/') else: return render(request, 'signup.html', { 'form' : form }) else: form = UserForm() return render(request, 'signup.html', { 'form' : form })
def handle(self, *args, **options): fake = Factory.create() fakeen = Factory.create('en_US') number = int(options['number']) imgs = os.listdir( '/home/hase/technopark/web/AskZaytsev/scripts/test_img') #imgsc = len(imgs) for i in range(0, number): profile = fake.simple_profile() u = User.objects.create_user(profile['username'] + str(i + 5000), profile['mail'], make_password('qwerty')) u.first_name = fakeen.first_name() u.last_name = fakeen.last_name() u.is_active = True u.is_superuser = False u.save() up = Profile() up.user = u up.avatar = choice(imgs) #up.info = '%s [%s]' % (fakeen.company(), fakeen.catch_phrase()) up.save() self.stdout.write('[%d] added user %s' % (u.id, u.username))
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 handle(self, *args, **options): login = options['login'] email = options['email'] nick = options['nick'] passwd = options['passwd'] user = User.objects.create_user(login, email, passwd, first_name=nick) profile = Profile(user=user) profile.save()
def save(self, commit=True): user = super(RegistrationForm, self).save(commit=False) print(self.cleaned_data['username']) print(self.cleaned_data['first_name']) print(self.cleaned_data['password1']) print(self.cleaned_data['title']) user_profile = Profile(user=user, title=self.cleaned_data['title']) if commit: user.save() user_profile.save() return user, user_profile
def save_user(self): if self.is_valid_(): user = User.objects.create_user( username=self.cleaned_data.get('login'), email=self.cleaned_data.get('email'), first_name=self.cleaned_data.get('nickName'), password=self.cleaned_data.get('password1'), ) user.avatar = self.cleaned_data.get('avatar') user.save() profile = Profile(user=user) profile.save() return True return False
def signup(request): if request.method == 'POST': form = SignupForm(request.POST, request.FILES) if form.is_valid(): data = form.cleaned_data user = User.objects.create_user(data['nick'], data['email'], data['password']) p = Profile(user=user, name=data['name'], avatar=request.FILES['avatar']) p.save() user = authenticate(username=data['nick'], password=data['password']) login(request, user) return redirect(reverse('index')) else: form = SignupForm() return render(request, 'signup.html', {'form': form})
def handle(self, *args, **options): fake = Factory.create() fakeen = Factory.create('en_US') number = int(options['number']) for i in range(0, number): profile = fake.simple_profile() u = User.objects.create_user(profile['username'], profile['mail'], make_password('qwerty')) u.first_name = fakeen.first_name() u.last_name = fakeen.last_name() u.is_active = True u.is_superuser = False u.save() up = Profile() up.user = u up.save()
def handle(self, *args, **options): fake = Faker('en_US') count = int(options['number']) added = 0 for i in range(count): profile = fake.simple_profile() user = User.objects.create_user(profile['username'], profile['mail'], make_password('test')) user.first_name = fake.first_name() user.last_name = fake.last_name() user.is_active = True user.is_superuser = False user.save() user_profile = Profile() user_profile.user = user user_profile.save() added += 1 print(added, " Users is added")
def save(self): data = self.cleaned_data password = data.get('password1') u = User() u.username = data.get('username') u.password = make_password(password) u.email = data.get('email') u.first_name = data.get('first_name') u.last_name = data.get('last_name') u.is_active = True u.is_superuser = False u.save() up = Profile() up.user = u up.info = data.get('info') if data.get('avatar') == None: up.avatar = "no-avatar.png" else: up.avatar = data.get('avatar') print(up.avatar) up.save() return authenticate(username=u.username, password=password)