def base_view(request): context = {} users = User.objects.all() current_page = Paginator(users, 5) page = request.GET.get('page') try: users = current_page.page(page) except PageNotAnInteger: users = current_page.page(1) except EmptyPage: users = current_page.page(current_page.num_pages) form = NewUserForm(request.POST or None) if form.is_valid(): full_name = form.cleaned_data['full_name'] birth_day = form.cleaned_data['birth_day'] phone = form.cleaned_data['phone'] middle_name = form.cleaned_data['middle_name'] email = form.cleaned_data['email'] User.objects.create( full_name=full_name, birth_day=birth_day, phone=phone, middle_name=middle_name, email=email) return HttpResponseRedirect(reverse('base')) context = { 'users': users, 'form': form } return render(request, 'base.html', context)
def other(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) return home(request) return render(request, 'other.html', {'form': form})
def users(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) return index(request) return render(request, 'form.html', {'form': form})
def signup_users(request): form = NewUserForm() if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): form.save(commit=True) # this will save the form return index(request) # this will returns are to the index page return render(request, 'app/signup.html', {'form': form})
def user(request): form = NewUserForm() if (request.method == "POST"): form = NewUserForm(request.POST) if (form.is_valid()): form.save(commit=True) return index(request) else: print("something went wrong") return render(request, 'app/abc.html', {'form': form})
def users(request): form = NewUserForm() if request.method == 'POST': form = NewUserForm(request.POST) if form.is_valid(): print("Password:" + form.cleaned_data['password']) form.save(commit=True) return end(request) return render(request, 'form.html', {'form': form})
def createUser(request): """Method for to sign up in the platform""" logout(request) if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): nickName = form.cleaned_data['nickname'] emailUser = form.cleaned_data['emailUser'] passUser = form.cleaned_data['passUser'] user = User.objects.create_user(nickName, emailUser, passUser) return render_to_response("profile.html", {'user': user}, context_instance=RC(request))
def test_cant_create_two_accounts_with_same_user(self): user_data = { 'name': fake.name(), 'username': '******', 'password': '******', 'email': fake.safe_email() } response = self.client.post(reverse('log-in'), data=user_data) self.assertEqual(302, response.status_code) form = NewUserForm(data=user_data) self.assertFalse(form.is_valid()) self.assertTrue(form.has_error('username', USER_EXISTS_ERROR_CODE))
def signup(request): if request.method == "POST": form = NewUserForm(request.POST) if form.is_valid(): user = form.save() login(request, user) messages.success(request, "Registration successful.") return redirect("/list_diagram") messages.error(request, "Unsuccessful registration. Invalid information.") form = NewUserForm() return render(request=request, template_name="signup.html", context={"register_form": form})
def addUser(request): if request.method == 'POST': Users = User.objects.all() form = NewUserForm(request.POST) if form.is_valid(): form.save() # render Home Page assert isinstance(request, HttpRequest) return render(request, 'app/home.html', { 'title': 'Home Page', 'year': datetime.now().year, }) else: assert isinstance(request, HttpRequest) return render(request, 'app/newUser.html', { 'title': 'New User', 'year': datetime.now().year, 'user': User() })