1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 23:20:51 +00:00

Modify profile

This commit is contained in:
xiez
2012-06-21 20:53:13 +08:00
parent d8c5604687
commit d477e543e7
13 changed files with 90 additions and 67 deletions

View File

@@ -8,8 +8,10 @@ from django.contrib.auth.decorators import login_required
from seaserv import ccnet_rpc, get_binding_peerids
from pysearpc import SearpcError
from utils import go_error
from forms import ProfileForm
from models import Profile
from utils import go_error
from seahub.contacts.models import Contact
@login_required
def list_userids(request):
@@ -33,61 +35,68 @@ def logout_relay(request):
return HttpResponseRedirect(reverse('list_userids'))
@login_required
def edit_profile(request):
profile = Profile.objects.filter(user=request.user.username)
if not profile:
Profile.objects.create(user=request.user.username, nickname='', intro='')
profile = Profile.objects.filter(user=request.user.username)[0]
if request.method == 'GET':
pass
if request.method == 'POST':
new_nickname = request.POST.get('nickname', '')
new_intro = request.POST.get('intro', '')
if new_nickname != profile.nickname:
profile.nickname = new_nickname
profile.save()
if new_intro != profile.intro:
profile.intro = new_intro
form = ProfileForm(request.POST)
if form.is_valid():
nickname = form.cleaned_data['nickname']
intro = form.cleaned_data['intro']
try:
profile = Profile.objects.get(user=request.user.username)
except Profile.DoesNotExist:
profile = Profile()
profile.user = request.user.username
profile.nickname = nickname
profile.intro = intro
profile.save()
else:
try:
profile = Profile.objects.get(user=request.user.username)
form = ProfileForm({
'nickname': profile.nickname,
'intro': profile.intro,
})
except Profile.DoesNotExist:
form = ProfileForm()
return render_to_response('profile/set_profile.html', {
'nickname':profile.nickname,
'intro':profile.intro,
},
context_instance=RequestContext(request))
'form': form,
}, context_instance=RequestContext(request))
def user_profile(request):
user = request.GET.get('user', '')
@login_required
def user_profile(request, user):
user_nickname = ''
user_intro = ''
err_msg = ''
if user:
try:
user_check = ccnet_rpc.get_emailuser(user)
except:
user_check = None
try:
user_check = ccnet_rpc.get_emailuser(user)
except:
user_check = None
if user_check:
profile = Profile.objects.filter(user=user)
if profile:
profile = profile[0]
user_nickname = profile.nickname
user_intro = profile.intro
else:
err_msg = '该用户不存在'
if user_check:
profile = Profile.objects.filter(user=user)
if profile:
profile = profile[0]
user_nickname = profile.nickname
user_intro = profile.intro
else:
err_msg = '该用户不存在'
if user == request.user.username or \
Contact.objects.filter(user_email=request.user.username,
contact_email=user).count() > 0:
new_user = False
else:
new_user = True
return render_to_response('profile/user_profile.html', {
'email': user,
'nickname':user_nickname,
'intro':user_intro,
'new_user': new_user,
'err_msg':err_msg,
},
context_instance=RequestContext(request))