Exemple #1
0
def user_private(request):
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=request.user)
        profile_form = UserProfileForm(request.POST,
                                       instance=request.user.get_profile())
        
        # Forms are displayed together thus both of them
        # should be valid before saving the whole user data
        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()
            profile =  profile_form.save(commit=False)
            profile.user = request.user
            profile.save()
    
    user_profile = request.user.get_profile()
    profile_form = UserProfileForm(instance=user_profile)
    user_form = UserForm(instance=request.user)
    
    api_consumer = Consumer.objects.get(user=request.user)
    api_access_token = api_consumer.token_set.get(token_type=Token.ACCESS,
                                                     user=request.user)
        
    extra_context = {
        'profile_form': profile_form,
        'user_form': user_form,
        'api_consumer': api_consumer,
        'api_access_token': api_access_token
    }
    
    return object_detail(request, object_id=request.user.pk,
                         queryset=User.objects.all(),
                         template_name='users/user_private.html',
                         extra_context=extra_context)
Exemple #2
0
def signup(request):
    try:
        if request.method == 'POST':
            user_data = dict(zip(request.POST.keys(), request.POST.values()))
            import ipdb; ipdb.set_trace()
            dept_name = user_data.get('department', 'resistance') or 'resistance'
            designation = user_data.get('designation', 'Engineer') or 'Engineer'
            is_exists = Department.objects.filter(
                        designation=designation).exists()
            if is_exists:
                messages.error(request, """Sorry, Leader has been Set!!""")
                raise Exception('Leader Exists Error.')

            form = UserProfileForm(user_data)
            if form.is_valid():
                form.save()
                user = form.instance
                dept_details = {'name': dept_name, 
                                'designation': designation,
                                'user': user}
                dept_obj = Department.objects.create(**dept_details)
            return HttpResponseRedirect(reverse('login_view'))
    except Exception as ex:
        print ex.message
    form = UserProfileForm()
    return render_to_response('registration.html', {'form': form},
                          context_instance=RequestContext(request))
Exemple #3
0
def view_profile(request, pk=""):
    title = "Profiles"
    latest_data = fetch_latest()

    if not pk:
        try:
            profile = request.user.get_profile()
        except:
            return HttpResponseRedirect(reverse('profile-home'))
    else:
        try:
            # FIXME: UserProfile pk doesn't necessarily match that of the User's.
            # Solution: Grab User(pk=pk), then UserProfile from that
            profile = UserProfile.objects.get(pk=pk)
        except:
            return HttpResponseRedirect(reverse('profile-home'))

    if request.method == 'POST':
        f = UserProfileForm(request.POST, request.FILES, instance=profile)
        if f.is_valid():
            f.save()
    else:
        f = UserProfileForm(instance=profile)
    
    # TODO: set title based on User's name
    return render_to_response('profile.djt', locals(), context_instance=RequestContext(request))
Exemple #4
0
def edit_user_profile(request):
    user = get_object_or_404(User, username=request.user.username)
    profile = user.get_profile()
    if request.method == "POST":
        form = UserProfileForm(request.POST)
        if form.is_valid():
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()
            profile.bio = form.cleaned_data['bio']
            profile.save()
            return redirect("/profile/%s/" % request.user.username)
        else:
            pass
    else:
        initial_data = {
            'first_name' : user.first_name,
            'last_name' : user.last_name,
            'email' : user.email,
            'bio' : profile.bio,
            }
        form = UserProfileForm(initial=initial_data)
    return render_to_response(
        'userprofile/edit_profile.html', 
        {'form': form},
        context_instance=RequestContext(request))
Exemple #5
0
def add_user(request):
    
    if request.method == "POST":
        uform = UserForm(data = request.POST)
        pform = UserProfileForm(data = request.POST)
        if uform.is_valid() and pform.is_valid():
            user = uform.save()
            user.set_password(user.password)
            user.save()
            profile = UserProfile(user=user,
                                  country=pform.cleaned_data['country'],
                                  profile=pform.cleaned_data['profile'],
                                  dob=pform.cleaned_data['dob'])
            profile.save()
            return HttpResponseRedirect('/registration_success/') # Redirect after POST
    
    data, errors = {}, {}
    uform = UserForm()
    pform = UserProfileForm()
    pagequerydict = pushitem.objects.none()
    r = makepage(request,pagequerydict,{'title':LANGUAGE['Register'],
                                        'uform': uform,
                                        'pform': pform,
                                        'errors': {},},
                                        "registration/registration_form.html",
                                        )
    return r
Exemple #6
0
def send_update_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            userProfile = UserProfile.objects.get(user=request.user)
            description = form.cleaned_data['description']
            rank = form.cleaned_data['rank']
            weapon = form.cleaned_data['weapon']
            friend_code = form.cleaned_data['friend_code']
            hunter_name = form.cleaned_data['hunter_name']
            nintendo_name = form.cleaned_data['nintendo_name']
            skype_name = form.cleaned_data['skype_name']
            teamspeak_name = form.cleaned_data['teamspeak_name']
            userProfile.description = description
            userProfile.rank = rank
            userProfile.weapon = weapon
            userProfile.friend_code = friend_code
            userProfile.hunter_name = hunter_name
            userProfile.nintendo_name = nintendo_name
            userProfile.skype_name = skype_name
            userProfile.teamspeak_name = teamspeak_name
            userProfile.save()
            return redirect('/roster/profile/' + str(userProfile.id))

        else:
            form = UserProfileForm()

    return redirect('/roster/send_update_profile/')
def editprofile(request):
    user = User.objects.get(username=request.user)
    if request.method == "POST":
        email = request.POST['email']
        try:
            existent_email = User.objects.get(email=email)
        except:
            existent_email = None

        if existent_email:
            return render(request, 'fhs/editprofile.html', {"existent": True})

        form = EmailForm(data=request.POST, instance=request.user)
        picform = UserProfileForm(data=request.POST, instance=request.user)
        try:
            up = UserProfile.objects.get(user=request.user)
        except:
            up = None
        if form.is_valid() and picform.is_valid():
            if email:
                user = form.save(commit=False)
                user.save()
            if 'picture' in request.FILES:
                up.picture = request.FILES['picture']
                up.save()
            return HttpResponseRedirect('/fhs/profile/' + user.username)
    else:
        return render(request, 'fhs/editprofile.html', {})
def editprofile(request):
    user = User.objects.get(username=request.user)
    if request.method == "POST":
        email = request.POST['email']
        try:
            existent_email = User.objects.get(email=email)
        except:
            existent_email = None

        if existent_email:
            return render(request, 'fhs/editprofile.html',{"existent": True})

        form = EmailForm(data=request.POST, instance=request.user)
        picform = UserProfileForm(data=request.POST, instance=request.user)
        try:
            up = UserProfile.objects.get(user=request.user)
        except:
            up = None
        if form.is_valid() and picform.is_valid():
            if email:
                user = form.save(commit=False)
                user.save()
            if 'picture' in request.FILES:
                up.picture = request.FILES['picture']
                up.save()
            return HttpResponseRedirect('/fhs/profile/'+user.username)
    else:
        return render(request, 'fhs/editprofile.html',{})
def register(request):
    registerd = False
    context_dict = {}
    context_dict['registerd'] = registerd
    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(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['pictures']
            profile.save()
            registerd = True
            context_dict['registerd'] = registerd
        else:
            print user_form.errors, profile_form.errors
    else:
        context_dict['user_form'] = UserForm
        context_dict['profile_form'] = UserProfileForm

    return render(request, 'rango/register.html', context_dict)
Exemple #10
0
def user_profile(request):
	user = User.objects.get(email = request.user.email)
	try:
		profiles = UserProfile.objects.get(user = user)
	except:
		profiles = ""
	if request.method == 'POST':
		email = request.user.email
		form = UserProfileForm(request.POST,request.FILES,instance=request.user.profile)
		if form.is_valid():
			save_it = form.save(commit = False)
			save_it.email_id = email
			save_it.save()

			return HttpResponseRedirect('/profile/')

	else:
		user = request.user
		profile = user.profile
		form = UserProfileForm(instance=profile)

	args = {}
	args.update(csrf(request))
	args['form'] = form
	args['profiles'] = profiles
	try:
		profile_name = UserProfile.objects.get(user = user)
		args['email'] = profile_name.name
	except:
		args['email'] = request.user.email
	return render_to_response('profile/profile.html', args,context_instance=RequestContext(request))
def register(request):
    registerd = False
    context_dict = {}
    context_dict["registerd"] = registerd
    if request.method == "POST":
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(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["pictures"]
            profile.save()
            registerd = True
            context_dict["registerd"] = registerd
        else:
            print user_form.errors, profile_form.errors
    else:
        context_dict["user_form"] = UserForm
        context_dict["profile_form"] = UserProfileForm

    return render(request, "rango/register.html", context_dict)
Exemple #12
0
def register(request):
    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']
                print profile.picture
                print type(profile.picture)
            profile.save()
            username = request.POST.get('username')
            password = request.POST.get('password')
            user = authenticate(username=username, password=password)
            login(request, user)
            return redirect('/blog/')
        else:
            print user_form.errors
            error = user_form.errors.as_data().values()[0][0].messages[0]
            print type(error)
            return render(request, 'blog/auth/register.html',
                          {'error': error})
    else:
        return render(request, 'blog/auth/register.html')
Exemple #13
0
def profile():
    u = g.user
    mc = g.user.mark_count()
    bc = g.user.bookmark_count()
    fc = g.user.feed_count()
    lcm = g.user.mark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash('User %s updated' % (form.username.data), category='info')
        return redirect(url_for('profile'))
    return render_template('account/profile.html',
                           form=form,
                           title='Profile',
                           mc=mc,
                           bc=bc,
                           fc=fc,
                           lcm=lcm,
                           )
Exemple #14
0
def user_profile():
    #修改教师/学生资料
    if request.method == 'GET':
        uid=request.args.get('id')
        if uid is None:
            return redirect("/admin/userlist")
        user=Student.query.get(uid)
        if user is None:
            user=Teacher.query.get(uid)
            if user is None:
                return redirect("/admin/userlist")
            return render_template('admin/user_profile.html',stu=None,tea=user)
        return render_template('admin/user_profile.html',stu=user,tea=None)

    form=UserProfileForm(request.form)

    if form.validate():
        form.save()
        flash(u"资料成功更新!")
    #current_app.logger.debug(3)
    for fieldName, errorMessages in form.errors.iteritems():
        for err in errorMessages:
            flash(err)
    #current_app.logger.debug(2)
    if form.stuid is not None and form.stuid.data!='':
        user=Student.query.get(form.stuid.data)
        return render_template('admin/user_profile.html',stu=user,tea=None)
    else:
        user=Teacher.query.get(form.teaid.data)
        return render_template('admin/user_profile.html',stu=None,tea=user)
Exemple #15
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.save_initials()

            registered = True

        else:
            print user_form.errors, profile_form.errors

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

    return render(request, 'lendborrow/register.html',
            {'user_form': user_form,
             'profile_form': profile_form,
             'registered': registered},
            )
Exemple #16
0
def user_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/diary/%s' % request.user.profile.id)
    else:
        user = request.user
        profile = user.profile
        form = UserProfileForm(instance=profile)

    args = {}
    args.update(csrf(request))

    args['form'] = form
    args['username'] = request.user.username
    args['user_profile_id'] = request.user.profile.id
    return render_to_response('profile.html', args)


# def list_api(request):
#     item_list = UserProfile.objects.all()
#     output_list = []
#
#     for item in item_list:
#         output_item = {}
#         output_item["system_id"] = item.id
#         output_item["first_name"] = item.first_name
#         output_list.append(output_item)
#
#     return HttpResponse(
#         json.dumps(output_list),
#         content_type="application/json"
#     )
Exemple #17
0
def edit_profile(request):
	if request.method == "POST":
		form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile)

		#succesful profil update view
		if form.is_valid():
			originalform = UserProfileForm(instance = request.user.profile)
			form.save()
			return HttpResponseRedirect('/accounts/profile')

	else:
		user = request.user
		profile = user.profile
		form = UserProfileForm(instance = profile)

	args = {}
	args.update(csrf(request))

	u = User.objects.get(username=user.username) # Get the first user in the system

	args['uname'] = u.username 
	args['name'] = u.first_name
	args['last'] = u.last_name
	args['email'] = u.email
	args['thumbnail'] = request.user.profile.user_avatar
	args['form'] = form

	return render_to_response('edit_profile.html', args, context_instance=RequestContext(request))
Exemple #18
0
def register(request):
    if request.user.is_authenticated():
        return redirect('index')
    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.groups.add(Group.objects.get(name="Author"))

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

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

            registered = True

        else:
            print user_form.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
        
    return render_to_response(
        'account/signup.html',
        {'user_form': user_form, 'profile_form': profile_form, 'registered': registered}, RequestContext(request))
def login(request):  
    if request.user.is_authenticated(): # if there is a user logged in already
        user_name = UserProfile(name=request.user.username)
        
        if request.POST:
            form = UserProfileForm(request.POST, instance=user_name)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/')
        else:
            form = UserProfileForm(instance=user_name)
    
        args = {}
        args.update(csrf(request))
    
        args['form'] = UserProfileForm()
        print args
        context = {"full_name": request.user.username, "args" :args}
        return HttpResponseRedirect("", context) 
    else:
        c={}
        
        c.update(csrf(request))
        
        context = {"c": c}
        return render(request, "login.html", context)
Exemple #20
0
def profile_form(request,username,use_openid=False):
    if request.user.username != username:
        return HttpResponse( "You cannot access another user's profile.", status=401)
    else:
        user = User.objects.get(username=username)
        try:
            user_profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            user_profile = UserProfile.objects.create(user=user)

    user_assoc = UserAssociation.objects.filter(user__id=user.id)
    
    if request.method == 'GET':
        uform = UserForm(instance=user)
        pform = UserProfileForm(instance=user_profile)
        return render_to_response('user_profile/user_profile_form.html', 
                {'profile': user_profile, 'assoc': user_assoc, 'uform': uform, 'pform': pform, 
                    'group_request_email': settings.GROUP_REQUEST_EMAIL, 'use_openid': use_openid, 'MEDIA_URL':settings.MEDIA_URL}) 

    elif request.method == 'POST':
        uform = UserForm(data=request.POST, instance=user)
        pform = UserProfileForm(data=request.POST, instance=user_profile)
        if uform.is_valid():
            user.save()
        if pform.is_valid():
            user_profile.save()

        #return HttpResponseRedirect(reverse('user_profile-form', args=[username]))
        return HttpResponseRedirect(reverse('map'))
    else:
        return HttpResponse( "Received unexpected " + request.method + " request.", status=400 )
Exemple #21
0
def edit():
    pcfg = {"title": gettext("Edit my profile")}

    user = User.query.filter(User.id == current_user.id).first()
    if not user:
        flash(gettext("User not found"), "error")
        return redirect(url_for("bp_main.home"))

    form = UserProfileForm(request.form, obj=user)
    form.timezone.choices = [[str(i), str(i)] for i in pytz.all_timezones]

    if form.validate_on_submit():
        user.timezone = form.timezone.data
        user.locale = form.locale.data
        user.display_name = form.display_name.data

        db.session.commit()

        # log
        add_user_log(user.id, user.id, "user", "info", "Edited user profile")

        flash(gettext("Profile updated"), "success")

        return redirect(url_for("bp_users.profile", name=user.name))

    return render_template("users/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           user=user)
Exemple #22
0
def user_(request):

    # user = User.objects.get(pk=get_user(request).pk)
    # u_profile = MyUserModel.objects.get(user=user)
    # profile_form = MultiUserForm(instance=u_profile)
    # return render(request, 'userprofile/user.html', {'profile_form': profile_form})

    user = User.objects.get(pk=get_user(request).pk)
    try:
        u_profile = MyUserModel.objects.get(user=user)
    except(Exception):
        u_profile = MyUserModel(user=user)
    if request.method == "POST":

        profile_form = UserProfileForm(request.POST, request.FILES, instance=u_profile)
        if profile_form.is_valid():
            profile_form.save()

        user_form = UserForm(request.POST, instance=user)
        if user_form.is_valid():
            user_form.save(commit=False)
            if "password" in request.POST:
                user.set_password(request.POST["password"])
            user_form.save()

    else:
        profile_form = UserProfileForm(instance=u_profile)
        user_form = UserForm(instance=user)

    return render(request, 'userprofile/user.html', {'profile_form': profile_form, 'user_form': user_form})
Exemple #23
0
def editProfile(id):
    user = User.query.get(id)
    form = UserProfileForm()
    if form.validate_on_submit():
        f = form.photo.data
        filename = secure_filename(f.filename)
        user.name = form.name.data
        user.surname = form.surname.data
        user.gender = form.gender.data
        user.weight = form.weight.data
        user.height = form.height.data
        user.location = form.location.data
        user.email = form.email.data
        user.bio = form.about_me.data
        user.pic = filename
        f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        db.session.add(user)
        db.session.commit()
        flash('Updates were saved', 'message')
        return redirect(url_for('home'))
    form.name.data = user.name
    form.surname.data = user.surname
    form.gender.data = user.gender
    form.weight.data = user.weight
    form.height.data = user.height
    form.location.data = user.location
    form.email.data = user.email
    form.about_me.data = user.bio
    form.photo.data = user.pic
    return render_template('editProfile.html', user=user, form=form)
Exemple #24
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(request.POST,request.FILES)
       # p = UserProfileForm(data=request.FILES)
        # If the two forms are valid...
        if user_form.is_valid() and profile_form.is_valid():# and p.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:
               # p.picture = request.FILES['picture']
               # p.save()
               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.
    return render_to_response(
            'registration.html',
            {'user_form': user_form, 'profile_form': profile_form, 'registered': registered},
            context)
Exemple #25
0
def user_profile_edit(request):

    instance1 = get_object_or_404(User, id=request.user.id)
    instance2 = get_object_or_404(UserProfile, id=request.user.profile.id)
    args = {}

    args.update(csrf(request))
    if request.method == "POST":
        form1 = RegistrationForm(request.POST, instance=instance1)
        form2 = UserProfileForm(request.POST,
                                request.FILES,
                                instance=instance2)
        args["err"] = form1.errors
        args["err2"] = form2.errors
        if form1.is_valid() * form2.is_valid():
            user = form1.save()
            userprofile = form2.save(commit=False)
            userprofile.user = user
            userprofile.save()
            return HttpResponseRedirect('/dashboard')

    args["form"] = RegistrationForm(instance=instance1)
    args["form2"] = UserProfileForm(instance=instance2)
    args["form_title"] = "Edit Profile Info"
    return render(request, 'register.html', args, RequestContext(request))
Exemple #26
0
def profile(request):
    # We always have the user, but not always the profile. And we need a bit
    # of a hack around the normal forms code since we have two different
    # models on a single form.
    (profile, created) = UserProfile.objects.get_or_create(pk=request.user.pk)

    if request.method == "POST":
        # Process this form
        userform = UserForm(data=request.POST, instance=request.user)
        profileform = UserProfileForm(data=request.POST, instance=profile)

        if userform.is_valid() and profileform.is_valid():
            userform.save()
            profileform.save()
            return HttpResponseRedirect("/account/")
    else:
        # Generate form
        userform = UserForm(instance=request.user)
        profileform = UserProfileForm(instance=profile)

    return render_to_response(
        "account/userprofileform.html",
        {"userform": userform, "profileform": profileform},
        NavContext(request, "account"),
    )
Exemple #27
0
def send_update_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST)
        if form.is_valid():
            userProfile = UserProfile.objects.get(user=request.user)
            description = form.cleaned_data['description']
            rank = form.cleaned_data['rank']
            weapon = form.cleaned_data['weapon']
            friend_code = form.cleaned_data['friend_code']
            hunter_name = form.cleaned_data['hunter_name']
            nintendo_name = form.cleaned_data['nintendo_name']
            skype_name = form.cleaned_data['skype_name']
            teamspeak_name = form.cleaned_data['teamspeak_name']
            userProfile.description = description
            userProfile.rank = rank
            userProfile.weapon = weapon
            userProfile.friend_code = friend_code
            userProfile.hunter_name = hunter_name
            userProfile.nintendo_name = nintendo_name
            userProfile.skype_name = skype_name
            userProfile.teamspeak_name = teamspeak_name
            userProfile.save()
            return redirect('/roster/profile/' + str(userProfile.id))

        else:
            form = UserProfileForm()

    return redirect('/roster/send_update_profile/')
Exemple #28
0
def create_event(request):
    event_data = json.loads(request.POST.get('event'))
    user_profile_data = json.loads(request.POST.get('user_profile'))

    user_profile = None
    if USER_TOKEN in request.COOKIES:
        try:
            user_profile = UserProfile.objects.get(
                token=request.COOKIES[USER_TOKEN])
        except UserProfile.DoesNotExist:
            pass
    if not user_profile:
        user_profile = UserProfileForm(user_profile_data, request.FILES).save()

    # Create event
    event = process_event_data(event_data)
    if not event:
        return HttpResponseBadRequest()

    data = {
        'event': event.as_dict(host='http://' + request.get_host()),
        'user_profile': user_profile.as_dict(),
    }
    cookie_dict = {
        USER_TOKEN: user_profile.token
    }
    return render_as_json(data, cookie_dict)
Exemple #29
0
def profile_form(request,username,use_openid=False):
    if request.user.username != username:
        return HttpResponse("You cannot access another user's profile.", status=401)
    else:
        user = User.objects.get(username=username)
        try:
            user_profile = UserProfile.objects.get(user=user)
        except UserProfile.DoesNotExist:
            user_profile = UserProfile.objects.create(user=user)

    user_assoc = UserAssociation.objects.filter(user__id=user.id)

    if request.method == 'GET':
        uform = UserForm(instance=user)
        pform = UserProfileForm(instance=user_profile)
        return render_to_response('user_profile/user_profile_form.html', 
                {'profile': user_profile, 'assoc': user_assoc, 'uform': uform, 'pform': pform, 
                    'group_request_email': settings.GROUP_REQUEST_EMAIL, 'use_openid': use_openid, 'MEDIA_URL':settings.MEDIA_URL}) 

    elif request.method == 'POST':
        uform = UserForm(data=request.POST, instance=user)
        pform = UserProfileForm(data=request.POST, instance=user_profile)
        if uform.is_valid():
            user.save()
        if pform.is_valid():
            user_profile.save()

        #return HttpResponseRedirect(reverse('user_profile-form', args=[username]))
        return HttpResponseRedirect(reverse('map'))
    else:
        return HttpResponse("Received unexpected " + request.method + " request.", status=400)
Exemple #30
0
def my_profile(request):
    context = get_context(request)
    if not request.user.is_authenticated():
        return redirect('login')
    else:
        user_profile = UserProfile.objects.get(user=request.user)
        if request.method == "POST":
            user_form = UserForm(request.POST, instance=request.user)
            user_profile_form = UserProfileForm(request.POST, instance=user_profile)
            if user_form.is_valid() and user_profile_form.is_valid():
                user_form.save()
                user_profile_form.save()

            return redirect_after_profile_save(request, 'data')
        else:
            user_form = UserForm(instance=request.user)
            user_profile_form = UserProfileForm(instance=user_profile)
            user_form.helper.form_tag = False
            user_profile_form.helper.form_tag = False
            context['user_form'] = user_form
            context['user_profile_form'] = user_profile_form
            context['user_profile_page_form'] = UserProfilePageForm(instance=user_profile)
            context['user_cover_letter_form'] = UserCoverLetterForm(instance=user_profile)
            context['user_info_page_form'] = UserInfoPageForm(instance=user_profile.user_info)
            context['is_editing_profile'] = True
            context['title'] = u'Mój profil'

            return render(request, 'profile.html', context)
Exemple #31
0
def edit_profile(request):

    user = User.objects.get(username=request.user)

    if request.method == "POST":
        form = UserProfileForm(request.POST, request.FILES)
        if form.is_valid():

            model_instance = form.save(commit=False)
            user_profile = UserProfile.objects.filter(user=user)[0]
            model_instance.id = user_profile.id
            model_instance.user_id = user_profile.user_id
            if request.FILES:
                model_instance.picture = request.FILES['picture']
            else:
                model_instance.picture = user_profile.picture

            if request.POST['description']:
                model_instance.description = request.POST['description']
            else:
                model_instance.description = user_profile.description

            model_instance.save()

            message = 'Your edit was successful!'

            context = {'message' : message, 'model_instance' : model_instance}
            return render(request, "thanks.html", context)
    else:
        form = UserProfileForm()

    context = { 'form' : form}

    return render(request, "edit_profile.html", context)
Exemple #32
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.errors, profile_form.errors

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

    return render(request, 'rango/register.html',
                  {'user_form': user_form, 'profile_form': profile_form, 'registered': registered})
Exemple #33
0
def profile():
    u = g.user
    mc = g.user.mark_count()
    bc = g.user.bookmark_count()
    fc = g.user.feed_count()
    lcm = g.user.mark_last_created()
    form = UserProfileForm(obj=u)
    if form.validate_on_submit():
        form.populate_obj(u)
        if form.password.data:
            pm = bMan()
            u.password = pm.encode(form.password.data)
        else:
            del u.password
        db.session.add(u)
        db.session.commit()
        flash('User %s updated' % (form.username.data), category='info')
        return redirect(url_for('profile'))
    return render_template(
        'account/profile.html',
        form=form,
        title='Profile',
        mc=mc,
        bc=bc,
        fc=fc,
        lcm=lcm,
    )
Exemple #34
0
def user_profile(request):
    if request.session['email']:
        if request.method =='POST':
            a=Join.objects.get(email=request.session['email'])
            try:
                b=UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b=UserProfile.objects.get(user=a)
            form = UserProfileForm(request.POST,instance=b)
            if form.is_valid():
                f= form.save(commit=False)
                f.user=a
                f.save()
                return HttpResponseRedirect('/fb/login/')
            else:
                return render(request,'fb/profile.html',{'form':form})
        else:
            a=Join.objects.get(email=request.session['email'])
            try:
                b=UserProfile.objects.get(user=a)
            except:
                b = UserProfile(user=a)
                b.save()
                b=UserProfile.objects.get(user=a)
            form=UserProfileForm(instance=b)
            return render(request,'fb/profile.html',{'form':form})
    else:
        return HttpResponseRedirect('/fb/login/')
Exemple #35
0
def user_profile(request):
    user = User.objects.get(pk=request.user.id)
    user_profile_form = UserProfileForm(instance=user)

    ProfileInlineFormset = inlineformset_factory(User, UserProfile, fields=("phone_number",))
    UserProfileFormset = ProfileInlineFormset(instance=user)

    if request.user.is_authenticated():  # and request.user.id == user.id:
        if request.method == "POST":
            user_profile_form = UserProfileForm(request.POST, request.FILES, instance=user)
            UserProfileFormset = ProfileInlineFormset(request.POST, request.FILES, instance=user)

            if user_profile_form.is_valid():
                created_user = user_profile_form.save(commit=False)
                UserProfileFormset = ProfileInlineFormset(request.POST, request.FILES, instance=created_user)

                if UserProfileFormset.is_valid():
                    created_user.save()
                    UserProfileFormset.save()
                    return HttpResponseRedirect("/", user.username)

        context = {
            "user_name": user.username,
            "user_profile_form": user_profile_form,
            "user_profile_formset": UserProfileFormset,
        }
        return render(request, "user_profile.html", context)
    else:
        raise PermissionDenied
Exemple #36
0
def profile_edit(request, username=None, dialog=False):
    if dialog is True:
        t = loader.get_template("torpedo/profile_dlg.html")
    else:
        t = loader.get_template("torpedo/profile.html")
    user = get_user(request, username)
    user_profile = user.profile
    if request.method == "POST":  # If the form has been submitted...
        form = UserProfileForm(request.POST)  # A form bound to the POST data
        if form.is_valid():  # All validation rules pass
            # Process the data in form.cleaned_data
            user.first_name = form.cleaned_data["firstname"]
            user.last_name = form.cleaned_data["lastname"]
            user.email = form.cleaned_data["email"]
            user_profile.phonenumber = form.cleaned_data["phonenumber"]
            user.save()
            user_profile.save()
            return HttpResponseRedirect(request.META["HTTP_REFERER"])  # Redirect after POST
    else:
        form = UserProfileForm(
            initial={
                "firstname": user.first_name,
                "lastname": user.last_name,
                "email": user.email,
                "phonenumber": user.profile.phonenumber,
            }
        )
    c = RequestContext(request, {"form": form, "profileuser": user})
    return HttpResponse(t.render(c))
Exemple #37
0
def register(request):
    context = RequestContext(request)
    registered = False
    cat_list = get_category_list()

    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.errors, profile_form.errors
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()
    return render_to_response(
            'rango/register.html', 
            {'user_form': user_form, 'profile_form':profile_form, 'cat_list':cat_list, 'registered': registered},
            context)
Exemple #38
0
def profile_set(request):
    user = request.user
    if not user.is_authenticated():
        return HttpResponseNotFound('You must be logged in to see this page.')

    profile = user.get_profile()
    is_journalist = profile.is_journalist()

    if request.method == 'POST': # If the form has been submitted...
        profile_form = UserProfileForm(request.POST, request.FILES)

        if profile_form.is_valid(): # All validation rules pass
            # Process the data in form.cleaned_data and return to the admin
            profile.full_name = profile_form.cleaned_data['full_name']
            profile.avatar = request.POST.get('avatar')
            #profile.bio = profile_form.cleaned_data['bio']
            #profile.major = profile_form.cleaned_data['major']
            profile.profile_set = True

            user.email = profile_form.cleaned_data['email']
            user.save()
            profile.save()
        return HttpResponseRedirect('/') # Redirect after POST
    else:
        if profile.profile_set == False: # if the user has not submitted their information
            profile_form = UserProfileForm(initial={'full_name': profile.full_name, 'email': user.email}) # An unbound form
            return render_to_response('journalism/user_profile_edit.html', {
               'profile_form': profile_form,
            },  context_instance=RequestContext(request))
        else:
            return HttpResponseRedirect('/')
Exemple #39
0
def profile_data_save(request):
    form = UserProfileForm(data=request.POST.copy() or None,
                           instance=request.user.get_profile())

    if form.is_bound and form.is_valid() and form.save(request.user):
        request.session['user_timezone'] = pytz.timezone(
            form.data.get('timezone'))
        messages.success(request, _(u'Changed your profile data.'))

    return redirect('app_auth_profile')
Exemple #40
0
def profile(request):
    form = UserProfileForm(request.POST)
    if request.method == 'POST':
        if form.is_valid():
            userprofile = form.save(commit=False)
            userprofile.user = request.user
            userprofile.save()
        else:
            print(messages.error(request, "Error"))
    return render(request, "profileform.html", RequestContext(request, {'form': form, 'profile': profile,}))
Exemple #41
0
def update_usermessage(request):
    if request.method == "POST":
        umessage_form = UserProfileForm(request.POST,
                                        instance=request.user.get_profile())
        print umessage_form.errors
        if umessage_form.is_valid():
            userprofile = umessage_form.save()

            #return HttpResponseRedirect("/accounts/userinfo/" + str(request.user.id))
            return HttpResponse(userprofile.message)

    return HttpResponse(request.user.get_profile().message)
Exemple #42
0
def update_userprofileimg(request):
    if request.method == "POST":
        uprofile_form = UserProfileForm(request.POST,
                                        request.FILES,
                                        instance=request.user.get_profile())
        print uprofile_form.errors
        if uprofile_form.is_valid():
            uprofile_form.save()

            return HttpResponseRedirect("/accounts/userinfo/" +
                                        str(request.user.id))

    raise Http404
Exemple #43
0
def create_profile(request):
    title = "Create a new Profile"
    form = UserProfileForm(request.POST or None,
                           request.FILES or None,
                           initial={'name': request.user.get_full_name()})
    if form.is_valid():
        instance = form.save(commit=False)
        instance.user = User.objects.get(id=request.user.id)
        UserProfile.location = form.cleaned_data.get(
            'city') + ', ' + form.cleaned_data.get('country')
        instance.save()
        return HttpResponseRedirect(
            reverse("profiles:profile", args=[request.user.id]))
    return render(request, 'forms.html', {"form": form, "title": title})
Exemple #44
0
def login(request):
    if request.user.is_authenticated():  # if there is a user logged in already
        user_name = UserProfile(name=request.user.username)

        if request.POST:
            form = UserProfileForm(request.POST, instance=user_name)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect('/')
        else:
            form = UserProfileForm(instance=user_name)

        args = {}
        args.update(csrf(request))

        args['form'] = UserProfileForm()
        print args
        context = {"full_name": request.user.username, "args": args}
        return HttpResponseRedirect("", context)
    else:
        c = {}

        c.update(csrf(request))

        context = {"c": c}
        return render(request, "login.html", context)
Exemple #45
0
 def post(self,request):
     user = request.user
     userprofile = UserProfile.objects.get(user=user)
     form = UserProfileForm(request.POST)
     tzchoices = [choice[0] for choice in form.fields['preferredtz'].choices]
     favchoices = sorted([choice[0] for choice in form.fields['favorite_team'].choices])
     context = {'form': form, 'tzchoices': tzchoices, 'favchoices': favchoices, 'userprofile': userprofile}
     if form.is_valid():
         cd = form.cleaned_data
         userprofile.company = cd['company']
         userprofile.preferredtz = cd['preferredtz']
         userprofile.favorite_team = cd['favorite_team']
         userprofile.save()
         return redirect('/pick10/')
     return render(request, 'pick10/profile_form.html', context)
Exemple #46
0
def order_info(request, template_name="registration/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
        page_title = 'Edit Order Information'
        return render_to_response(template_name,
                                  locals(),
                                  context_instance=RequestContext(request))
Exemple #47
0
def order_info(request):
    if request.method == 'POST':
        post_data = request.POST.copy()
        form = UserProfileForm(None, post_data)
        if form.is_valid():
            profile.set_profile(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.get_profile(request)
        form = UserProfileForm(email_from_user=request.user.email,
                               instance=user_profile)
    page_title = 'Edit Order Information'
    return render_to_response("registration/order_info.html",
                              locals(),
                              context_instance=RequestContext(request))
Exemple #48
0
def profile(request):
    try:
        user_profile = UserProfile.objects.get(user=request.user)
    except UserProfile.DoesNotExist:
        user_profile = UserProfile.objects.create(user=request.user)
    feed_list = Action.objects.filter(actor_object_id=request.user.userprofile.
                                      id).order_by('-timestamp')[:20]

    user_profile_form = UserProfileForm(instance=user_profile)
    user_form = UserForm(instance=request.user)
    who_to_follow = get_suggested_followers(user_profile)

    pledges = Pledge.objects.filter(user=request.user.userprofile)
    message_list = Message.objects.inbox_for(request.user)
    followers = UserProfile.objects.filter(follows__in=[user_profile.id])
    user_profile = UserProfile.objects.get(user=request.user)
    rewards = Reward.objects.filter(user=user_profile)
    context_dict = {
        'viewed_user': request.user,
        'user_profile': user_profile,
        'user_profile_form': user_profile_form,
        'user_form': user_form,
        'completed_pledges': pledges,
        'public': False,
        'message_list': message_list,
        'followers': followers,
        'who_to_follow': who_to_follow,
        'feeds': feed_list,
        'rewards': rewards
    }
    return render(request, 'users/profile_alt.html', context_dict)
Exemple #49
0
def profile(request):
    authenticated_user_jobs = Job.objects.filter(user=request.user)
    user_pro = UserProfileForm()
    return render(request, "forms/profile.html", {
        'user_pro': user_pro,
        'job': authenticated_user_jobs
    })
Exemple #50
0
 def get(self,request):
     user = request.user
     userprofile, created = UserProfile.objects.get_or_create(user=user)
     form = UserProfileForm(instance=userprofile)
     tzchoices = [choice[0] for choice in form.fields['preferredtz'].choices]
     favchoices = sorted([choice[0] for choice in form.fields['favorite_team'].choices])
     context = {'form': form, 'tzchoices': tzchoices, 'favchoices': favchoices, 'userprofile': userprofile}
     return render(request,"pick10/profile_form.html", context)
Exemple #51
0
def user_profile(request):

    if request.method == 'POST':
        basicform = UserBasicForm(request.POST, instance=request.user)
        extraform = UserProfileForm(request.POST,
                                    request.FILES,
                                    instance=request.user.profile)

        if extraform.is_valid() and basicform.is_valid():
            basicform.save()
            extraform.save()
            messages.success(request, "Changes saved")
            return HttpResponseRedirect('/')
    else:
        user = request.user
        profile = user.profile
        basicform = UserBasicForm(instance=user)
        extraform = UserProfileForm(instance=profile)

        args = {}
        args.update(csrf(request))
        args['basicform'] = basicform
        args['extraform'] = extraform

        return render(request, 'profile.html', args)
Exemple #52
0
def profile_edit(request):

    if request.method == "POST":
        user_form = UserEditForm(request.POST,
                                 request.FILES,
                                 instance=request.user)
        profile_form = UserProfileForm(request.POST,
                                       request.FILES,
                                       instance=request.user.user)

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

        return redirect('profile')
    else:
        if not request.user:
            return redirect('login')
        else:
            user_form = UserEditForm(instance=request.user)
            profile_form = UserProfileForm(instance=request.user.user)
            return render(request, 'campusthrift/profile_edit.html', {
                'user_form': user_form,
                'profile_form': profile_form
            })
def user_profile(request):
    if request.method == 'POST':
        form = UserProfileForm(request.POST, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/diary/%s' % request.user.profile.id)
    else:
        user = request.user
        profile = user.profile
        form = UserProfileForm(instance=profile)

    args = {}
    args.update(csrf(request))

    args['form'] = form
    args['username'] = request.user.username
    args['user_profile_id'] = request.user.profile.id
    return render_to_response('profile.html', args)


# def list_api(request):
#     item_list = UserProfile.objects.all()
#     output_list = []
#
#     for item in item_list:
#         output_item = {}
#         output_item["system_id"] = item.id
#         output_item["first_name"] = item.first_name
#         output_list.append(output_item)
#
#     return HttpResponse(
#         json.dumps(output_list),
#         content_type="application/json"
#     )
def my_profile(request):
    context = get_context(request)
    if not request.user.is_authenticated():
        return redirect('login')
    else:
        user_profile = UserProfile.objects.get(user=request.user)
        if request.method == "POST":
            user_form = UserForm(request.POST, instance=request.user)
            user_profile_form = UserProfileForm(request.POST,
                                                instance=user_profile)
            if user_form.is_valid() and user_profile_form.is_valid():
                user_form.save()
                user_profile_form.save()

            return redirect_after_profile_save(request, 'data')
        else:
            user_form = UserForm(instance=request.user)
            user_profile_form = UserProfileForm(instance=user_profile)
            user_form.helper.form_tag = False
            user_profile_form.helper.form_tag = False
            context['user_form'] = user_form
            context['user_profile_form'] = user_profile_form
            context['user_profile_page_form'] = UserProfilePageForm(
                instance=user_profile)
            context['user_cover_letter_form'] = UserCoverLetterForm(
                instance=user_profile)
            context['user_info_page_form'] = UserInfoPageForm(
                instance=user_profile.user_info)
            context['is_editing_profile'] = True
            context['title'] = u'Mój profil'

            return render(request, 'profile.html', context)
Exemple #55
0
def edit_profile(request):
    args = {}
    args.update(csrf(request))
    if request.method == 'POST':
        form = UserProfileForm(request.POST,
                               request.FILES,
                               instance=request.user.profile)
        follow = userFollowActivity.objects.get(user=request.user)
        generes = Generes.objects.get(user=request.user)

        first_name = request.user.first_name
        last_name = request.user.last_name
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/accounts/loggedin/')
    else:
        form = UserProfileForm(instance=request.user.profile)
        generes = Generes.objects.get(user=request.user)
        follow = userFollowActivity.objects.get(user=request.user)
        first_name = request.user.first_name
        last_name = request.user.last_name

    args = {}
    args.update(csrf(request))
    args['form'] = form

    return render_to_response('editprofilepage.html', {
        'form': form,
        'follow': follow,
        'first_name': first_name,
        'last_name': last_name,
        'generes': generes
    },
                              context_instance=RequestContext(request))
Exemple #56
0
def register_profile(request):
    context = {}
    if not request.method == 'POST':
        context['profile_form'] = UserProfileForm(request.GET)
        return render(request, 'registration/profile_registration.html',
                      context)
    else:
        profile_form = UserProfileForm(request.POST)
        user = User.objects.get(id=request.user.id)
        if profile_form.is_valid():
            try:  # Does a profile exist?
                profile = UserProfile.objects.get(user=user)
            except:  # No?
                profile = profile_form.save(commit=False)
                profile.user = user
            if 'picture' in request.FILES and request.FILES.get('picture'):
                profile.picture = request.FILES.get('picture')
            profile.save()
        return render(request, 'index.html', context)
Exemple #57
0
def get_userinfo(request, author_id):
    # fields = ('user', 'writer', 'text',)

    try:
        owner = User.objects.get(id=author_id)
    except User.DoesNotExist:
        raise Http404

    # TODO: Make function and move to there
    if request.method == "POST":
        uinfo_form = UserCommentForm(request.POST)
        print uinfo_form.errors
        if uinfo_form.is_valid():
            uinfo_form.save()

            return HttpResponseRedirect('/accounts/userinfo/' + author_id)

    usercomments = UserComment.objects.filter(user=owner)

    # 친구 관계가 맺어져 있는지 일단 검사
    is_friend = False
    try:
        fu = FavoriteUser.objects.get(user=owner, follower=request.user)
        if fu.follower == request.user:
            is_friend = True
    except FavoriteUser.DoesNotExist:
        pass

    uinfo_form = UserCommentForm({'user': owner, 'writer': request.user})

    umessage_form = UserProfileForm({
        'user': owner,
    })

    # 집필한 책  / 참여 브랜치  / 따르는 유저 수
    numofBook = Book.objects.filter(creator=owner).exclude(
        root_branch=None).count()
    numofBranch = Branch.objects.filter(author=owner,
                                        is_temporary=False).count()
    numofFollow = FavoriteUser.objects.filter(user=owner).count()

    return render_to_response(
        "accounts/userinfo.html",
        RequestContext(
            request, {
                'uinfo_form': uinfo_form,
                'umessage_form': umessage_form,
                'owner': owner,
                'is_self': owner == request.user,
                'is_friend': is_friend,
                'comments': usercomments,
                'numofBook': numofBook,
                'numofBranch': numofBranch,
                'numofFollow': numofFollow,
            }))
Exemple #58
0
 def get(self, request, *args, **kwargs):
     if 'user' in request.GET:
         user = User.objects.get(pk = request.GET['user'])
         profile = Profile.objects.get( user = user )
         
         uform = UserForm(instance = user)
         pform = UserProfileForm( instance = profile )
         
         return self.render_to_response( {'pform':pform, 'uform':uform} )
     
     return HttpResponseRedirect('/')   
Exemple #59
0
def edit():
    pcfg = {"title": "Edit my profile"}

    user = User.query.filter(User.id == current_user.id).first()
    if not user:
        flash("User not found", "error")
        return redirect(url_for("bp_main.home"))

    form = UserProfileForm(request.form, obj=user)
    form.timezone.choices = [[str(i), str(i)] for i in pytz.all_timezones]

    if form.validate_on_submit():
        user.callsign = form.callsign.data.upper()
        user.lastname = form.lastname.data
        user.firstname = form.firstname.data
        user.timezone = form.timezone.data
        user.locator = form.locator.data.upper()

        user.lotw_name = form.lotw_name.data
        user.lotw_password = form.lotw_password.data

        user.eqsl_name = form.eqsl_name.data
        user.eqsl_password = form.eqsl_password.data

        user.hamqth_name = form.hamqth_name.data
        user.hamqth_password = form.hamqth_password.data

        user.swl = form.swl.data
        user.zone = form.zone.data

        db.session.commit()
        return redirect(url_for("bp_users.profile"))

    logbooks = (db.session.query(Logbook.id, Logbook.name, func.count(
        Log.id)).join(Log).filter(Logbook.user_id == current_user.id).group_by(
            Logbook.id).all())
    return render_template("users/edit.jinja2",
                           pcfg=pcfg,
                           form=form,
                           user=user,
                           logbooks=logbooks)