Exemple #1
0
def profile_edit(request):
    path = '/profile_edit/'  # to point the path in the base html template
    person_form = ProfileEditForm(request.POST or None, request.FILES or None, instance=request.user.person)
    user_form = UserForm(request.POST or None, instance=request.user)
    if request.method == 'POST':
        if person_form.is_valid() and user_form.is_valid():
            person_form.save()
            user_form.save()
            return redirect('/profile/'+request.user.username+'/')
    csrf(request)
    return render(request, 'profile_edit.html', locals())
Exemple #2
0
def profile_edit(request):
    path = '/profile_edit/'  # to point the path in the base html template
    person_form = ProfileEditForm(request.POST or None,
                                  request.FILES or None,
                                  instance=request.user.person)
    user_form = UserForm(request.POST or None, instance=request.user)
    if request.method == 'POST':
        if person_form.is_valid() and user_form.is_valid():
            person_form.save()
            user_form.save()
            return redirect('/profile/' + request.user.username + '/')
    csrf(request)
    return render(request, 'profile_edit.html', locals())
Exemple #3
0
def register_success(request):
    person_form = PersonRegisterForm(request.POST or None, request.FILES or None, instance=request.user.person)
    user_form = UserForm(request.POST or None, instance=request.user)
    if request.method == 'POST':
        if person_form.is_valid() and user_form.is_valid():
            person_form.save()
            user_form.save()
            NotificationInstance.objects.create(
                person=request.user.person,
                notification_type=NotificationTypes.get(name='periodical'),
                message="Wellcome! Don't hesitate to make your first check in.")
            NotificationInstance.objects.create(
                person=request.user.person,
                notification_type=NotificationTypes.get(name='tip'),
                message="Wellcome! Go to your profile settings if you don't want to get useful tips.")
            return redirect('/profile/'+request.user.username+'/')
    csrf(request)
    return render(request, 'register_success.html', locals())
Exemple #4
0
def register_success(request):
    person_form = PersonRegisterForm(request.POST or None,
                                     request.FILES or None,
                                     instance=request.user.person)
    user_form = UserForm(request.POST or None, instance=request.user)
    if request.method == 'POST':
        if person_form.is_valid() and user_form.is_valid():
            person_form.save()
            user_form.save()
            NotificationInstance.objects.create(
                person=request.user.person,
                notification_type=NotificationTypes.get(name='periodical'),
                message="Wellcome! Don't hesitate to make your first check in."
            )
            NotificationInstance.objects.create(
                person=request.user.person,
                notification_type=NotificationTypes.get(name='tip'),
                message=
                "Wellcome! Go to your profile settings if you don't want to get useful tips."
            )
            return redirect('/profile/' + request.user.username + '/')
    csrf(request)
    return render(request, 'register_success.html', locals())
Exemple #5
0
def register(request):
    # Like before, get the request's context.
    context = RequestContext(request)

    # A boolean value for telling the template whether the
    # registration was successful.
    # Set to False initially. Code changes value to True when
    # registration succeeds.
    registered = False

    # If it's a HTTP POST, we're interested in processing form data.
    if request.method == 'POST':
        # Attempt to grab information from the raw form information.
        # Note that we make use of both UserForm and UserProfileForm.
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():
            # Save the user's form data to the database.
            user = user_form.save()

            # Now we hash the password with the set_password method.
            # Once hashed, we can update the user object.
            user.set_password(user.password)
            user.save()

            # Now sort out the UserProfile instance.
            # Since we need to set the user attribute ourselves, we set
            # commit=False.
            # This delays saving the model until we're ready to avoid
            # integrity problems.
            profile = profile_form.save(commit=False)
            profile.user = user

            # Did the user provide a profile picture?
            # If so, we need to get it from the input form and put it in
            # the UserProfile model.
            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            # Now we save the UserProfile model instance.
            profile.save()

            # Update our variable to tell the template registration was successful.
            registered = True

        # Invalid form or forms - mistakes or something else?
        # Print problems to the terminal.
        # They'll also be shown to the user.
        else:
            print(user_form.errors, profile_form.errors)

    # Not a HTTP POST, so we render our form using two ModelForm instances.
    # These forms will be blank, ready for user input.
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    # Render the template depending on the context.
    #t = loader.get_template('register.html')
    #return HttpResponse(t.render(RequestContext(request, context)))
    return render_to_response(
            'register.html',
            {'user_form': user_form, 'profile_form': profile_form,
             'registered': registered},
            context)