Пример #1
0
def update_profile(request):
    submitted = False
    inst = UserProfile.objects.get(user=request.user)

    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST, instance=inst)
        if profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user= request.user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            submitted=True
            return HttpResponseRedirect(reverse('dashboard'))

        else:
            print profile_form.errors
        
    else:
        profile_form = UserProfileForm(instance=inst)
    
    return render(request, 'update_profile.html', {'profile_form': profile_form, 'submitted': submitted})
Пример #2
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print user_form.errors, profile_form.errors
    
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'register.html',
			{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
def register(request):

    registered = False

    if request.method == "POST":
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if "picture" in request.FILES:
                profile.picture = request.FILES["picture"]

            profile.save()

            registered = True

        else:
            print user_form.erros, profile_forms.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, "register.html", {"user_form": user_form, "profile_form": profile_form, "registered": registered}
    )
Пример #4
0
def register(request):

    registered = False 

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)


        if user_form.is_valid() and profile_form.is_valid():

            profile = profile_form.save(commit=False)
            user = user_form.save()
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            #Email confirmation to user
            subject = 'PVSAT: Author registration confirmation'

            text_content = render_to_string("user_sub_conf.txt", {'user': user, 'URL': settings.SITE_URL})
            html_content = render_to_string("user_sub_conf.html", {'user': user, 'URL': settings.SITE_URL})

            email = user.email

            msg1 = EmailMultiAlternatives(subject, text_content, '', [email])
            msg1.attach_alternative(html_content, "text/html")

            #Email confirmation to admin

            subject = 'New Author'

            text_content = render_to_string("user_to_admin.txt", {'user': user, 'profile': profile, 'URL': settings.SITE_URL})

            msg2 = EmailMultiAlternatives(subject, text_content, '', [settings.ADMIN_EMAIL])

            if settings.EMAIL_STATUS:
                msg1.send()
                msg2.send()

            registered = True

        else:
            print user_form.errors, profile_form.errors
    
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'register.html',
			{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Пример #5
0
def author_manage(request):
    context = RequestContext(request)
    profile = Profile.objects.get(user_id=request.user.id)
    updated = False

    if request.user.is_authenticated():
        my_profile = Profile.objects.get(user=request.user)

    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST)

        if profile_form.is_valid():
            profile.displayname = profile_form.cleaned_data['displayname']
            profile.body = profile_form.cleaned_data['body']
            profile.birthdate = profile_form.cleaned_data['birthdate']
            profile.gender = profile_form.cleaned_data['gender']
            newclear = request.POST.get('image-clear')
            print(newclear)
            #profile.image = profile_form.cleaned_data['image']
            try:
                profile.image = request.FILES['image']
            except:
                if newclear == "on":
                    profile.image=""

            profile.github = profile_form.cleaned_data['github']
            profile.workspace = profile_form.cleaned_data['workspace']
            profile.school = profile_form.cleaned_data['school']
            profile.save()

            updated = True
        else:
            print profile_form.errors

    else:
        profile_form = UserProfileForm(instance=profile)

    if updated == True:
        return HttpResponse("<script>alert(\"Profile Successfully edited!\"); window.location = \'/author/%s\';</script>" %profile.uuid)
    else:
        return render_to_response('authors/manage.html',
            {'profile_form': profile_form, 'my_profile':my_profile}, context)
Пример #6
0
def update_profile(request):
    submitted = False
    inst = UserProfile.objects.get(user=request.user)

    if request.method == 'POST':
        profile_form = UserProfileForm(data=request.POST, instance=inst)
        if profile_form.is_valid():
            profile = profile_form.save(commit=False)
            profile.user = request.user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            submitted = True
            return HttpResponseRedirect(reverse('dashboard'))

        else:
            print profile_form.errors

    else:
        profile_form = UserProfileForm(instance=inst)

    return render(request, 'update_profile.html', {
        'profile_form': profile_form,
        'submitted': submitted
    })
Пример #7
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print user_form.erros, profile_forms.errors
    
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
            'register.html',
			{'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Пример #8
0
def register(request):

    registered = False

    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)

        if user_form.is_valid() and profile_form.is_valid():

            profile = profile_form.save(commit=False)
            user = user_form.save()
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            #Email confirmation to user
            subject = 'PVSAT: Author registration confirmation'

            text_content = render_to_string("user_sub_conf.txt", {
                'user': user,
                'URL': settings.SITE_URL
            })
            html_content = render_to_string("user_sub_conf.html", {
                'user': user,
                'URL': settings.SITE_URL
            })

            email = user.email

            msg1 = EmailMultiAlternatives(subject, text_content, '', [email])
            msg1.attach_alternative(html_content, "text/html")

            #Email confirmation to admin

            subject = 'New Author'

            text_content = render_to_string("user_to_admin.txt", {
                'user': user,
                'profile': profile,
                'URL': settings.SITE_URL
            })

            msg2 = EmailMultiAlternatives(subject, text_content, '',
                                          [settings.ADMIN_EMAIL])

            if settings.EMAIL_STATUS:
                msg1.send()
                msg2.send()

            registered = True

        else:
            print user_form.errors, profile_form.errors

    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(
        request, 'register.html', {
            'user_form': user_form,
            'profile_form': profile_form,
            'registered': registered
        })