コード例 #1
0
ファイル: views.py プロジェクト: exp-repos/Elections-IITR
def profile_complete_submit(request):
	if request.method=="POST":
		form=ProfileForm(request.POST)
		if form.is_valid():
			new_profile=UserDetails.objects.create(user=request.user,branch=request.POST['branch'],en_no=request.POST['en_no'],year=request.POST['year'],gender=request.POST['gender'],dob=request.POST['dob_year']+'-'+request.POST['dob_month']+'-'+request.POST['dob_day'])
			return HttpResponseRedirect('/authetication/signup')	
		else:
			return HttpResponseRedirect('/authentication/profile/complete')
	else:
		return HttpResponseRedirect('/authentication/	profile')	
コード例 #2
0
def update_user_profile(request, pk):
    profile = get_object_or_404(Profile, pk=pk)
    if request.user is profile.user:
        form = ProfileForm(request.POST)
        if form.is_valid():
            password = form.cleaned_data.get("password1")
            form.update()
            request.user.set_password(password)
        else:
            messages.error(request, "An Internal Server Error Occurred")
            return redirect("user-profile")
コード例 #3
0
ファイル: views.py プロジェクト: exp-repos/Elections-IITR
def profile_complete(request):
	if request.method=="POST":
		form=ProfileForm(request.POST)
		if form.is_valid():
			new_profile=UserDetails.objects.create(user=request.user,branch=request.POST['branch'],en_no=request.POST['en_no'],year=request.POST['year'],gender=request.POST['gender'],dob=request.POST['dob_year']+'-'+request.POST['dob_month']+'-'+request.POST['dob_day'])
			return HttpResponseRedirect('/authentication/signup')	
		else:
			return render(request,'authentication/complete.html',{'form':form})
	else:
		try:
			userdetails=get_object_or_404(UserDetails,user=request.user)
			return HttpResponseRedirect('authentication/signup')
		except(Http404):
			form=ProfileForm()
			return render(request,'authentication/complete.html',{'form':form})
コード例 #4
0
def settings(request):
    user = request.user
    if request.method == 'POST':
        first_name = request.POST.get('first_name')
        if first_name:
            user.first_name = first_name
        last_name = request.POST.get('last_name')
        if last_name:
            user.last_name = last_name
        job_title = request.POST.get('job_title')
        if job_title:
            user.profile.job_title = job_title
        email = request.POST.get('email')
        if email:
            user.email = email
        url = request.POST.get('url')
        if url:
            user.profile.url = url
        location = request.POST.get('location')
        if location:
            user.profile.location = location
        user.profile.save()
        user.save()
        return redirect('/authentication/settings/')

    else:
        form = ProfileForm(instance=user,
                           initial={
                               'job_title': user.profile.job_title,
                               'url': user.profile.url,
                               'location': user.profile.location
                           })
    return render(request, 'authentication/settings.html', {'form': form})
コード例 #5
0
def profile(response):
    if response.method == 'POST':
        form = ProfileForm(response.post)
        if form.is_valid():
            if response.user.is_authenticated:
                email = response.user.email
                pin = form.cleaned_data['pin']
                database(
                    'db.sqlite3', "UPDATE User SET security_pin = ? WHERE email = ?;", (str(pin), email))
                return redirect('settings:')
            else:
                return HttpResponseForbidden()
    else:
        if response.user.is_authenticated:
            email = response.user.email
            form = ProfileForm(initial={'email': email})
            context_vars = {'form': form}
            return render(response, "authentication/profile.html", context_vars)
        else:
            return HttpResponseForbidden()
コード例 #6
0
def register_view(request, *args, **kwargs):
    if request.method == "GET":
        context = {
            'user_form': RegistrationForm(),
            'profile_form': ProfileForm(),
        }

        return render(request, 'auth/register.html', context)

    elif request.method == 'POST':

        user_form = RegistrationForm(request.POST)
        profile_form = ProfileForm(request.POST, request.FILES)

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

            login(request, user)
            return redirect('home view')

    context = {
        'user_form': RegistrationForm(),
        'profile_form': ProfileForm(),
    }
    return render(request, 'auth/register.html', context)
コード例 #7
0
ファイル: views.py プロジェクト: reyblacua/eatsyPruebas
def myProfile(request):
    user = request.user
    perfil = get_object_or_404(Perfil, user=user)
    if request.method == 'POST':
        form = ProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['nombre']
            user.last_name = form.cleaned_data['apellidos']
            user.save()
            perfil.dietas.clear()
            for dieta in form.cleaned_data['dieta']:
                perfil.dietas.add(get_object_or_404(Dieta, nombre=dieta))
            perfil.save()
        else:
            return render(request, 'perfil.html', {'form': form})
    data = {
        'nombre': user.first_name,
        'apellidos': user.last_name,
        'dieta': [dieta.nombre for dieta in perfil.dietas.all()],
        'activada': perfil.activeAccount
    }
    form = ProfileForm(initial=data)
    return render(request, 'perfil.html', {'form': form})
コード例 #8
0
ファイル: views.py プロジェクト: Adelgh/Projet
def profile(request, username):
    if request.method == 'POST':
        form = ProfileForm(request.POST,
                           request.FILES,
                           instance=request.user.profile)

        if form.is_valid():
            obj = form.save(commit=False)
            request.user.username = request.POST[
                'username'] or request.user.username
            request.user.save()
            obj.save()
        return render(request, 'authentication/profile.html')

    form = ProfileForm(instance=request.user.profile)
    page_user = User.objects.get(username=username)
    data = {'page_user': page_user, 'page': 1, 'form': form}

    return render(request, 'authentication/profile.html', data)
コード例 #9
0
ファイル: views.py プロジェクト: Adelgh/Projet
def edit_user_view(request):

    if request.method == 'POST':
        form = ProfileForm(request.POST,
                           request.FILES,
                           instance=request.user.profile)

        if form.is_valid():
            obj = form.save(commit=False)
            request.user.username = request.POST[
                'username'] or request.user.username
            request.user.save()
            obj.save()
        return render(request, 'authentication/profile.html')

    form = ProfileForm(instance=request.user.profile)
    if request.user.username:
        return render(request, 'authentication/edit_profile.html',
                      {'form': form})
    else:
        return render(request, 'authentication/notuser.html')
コード例 #10
0
def register(request):
    if request.user.is_authenticated():
        messages.add_message(request, messages.INFO,
                             'You are already logged in.')
        return redirect(reverse('home'))
    if request.POST:
        userform = UserForm(request.POST)
        userprofileform = ProfileForm(request.POST)
        if userform.is_valid() and userprofileform.is_valid():
            user = userform.save()
            userprofile = userprofileform.save(commit=False)
            userprofile.user = user
            userprofile.save()
            return redirect(reverse('login'))
    else:
        userform = UserForm()
        userprofileform = ProfileForm()
    return render(request, 'auth/register.html', {
        'userform': userform,
        'userprofileform': userprofileform
    })