Example #1
0
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)
Example #2
0
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})
Example #3
0
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})
Example #4
0
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})
Example #5
0
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})
Example #6
0
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})
Example #7
0
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))
Example #8
0
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))
Example #9
0
    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))
Example #10
0
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})
Example #11
0
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()
        })