示例#1
0
文件: views.py 项目: ezl/ezl_alpha
 def wrapped_view(request):
     user_settings_form = UserSettingsForm(instance=request.user.get_profile())
     if request.POST.has_key("default_view"):
         # they submitted the user settings
         user_settings_form = UserSettingsForm(request.POST, instance=request.user.get_profile())
         if user_settings_form.is_valid():
             user_settings_form.save()
     return fn(request, user_settings_form=user_settings_form)
示例#2
0
def user_settings(request, template_name='profile/user_settings.html'):
    '''edit user's profile view'''
    template_var={}
    form = UserSettingsForm()
    avatar_url = None
    if request.method == 'POST':
        form = UserSettingsForm(request.POST.copy(), request.FILES)
        if form.is_valid():
            opts = {
                      'request': request,
                   }
            form.save(**opts)
            avatar_url = request.user.get_profile().avatar
    else:
        current_user = request.user
        
        try:
            current_profile = current_user.get_profile()#UserProfile.objects.get( user__exact = current_user )
            avatar_url = current_profile.avatar
        except UserProfile.DoesNotExist:
            current_profile = None
            
        initial_dict = { 'original_username': current_user.username,
                         'username': current_user.username,
                         'city':  None if current_profile==None else current_profile.city,
                         'avatar':  None if current_profile==None else current_profile.avatar,
                         'website':  None if current_profile==None else current_profile.website,
                         'qq':  None if current_profile==None else current_profile.qq,
                         'msn':  None if current_profile==None else current_profile.msn,
                         'intro':  None if current_profile==None else current_profile.intro
                       }
            
        form = UserSettingsForm(initial = initial_dict)
        
    template_var['form'] = form
    template_var['avatar_url'] = avatar_url
    #检测是不是新浪微博主
    access_token = request.session.get('oauth_access_token', None)
    if access_token is not None:
        template_var['weibo_user_ret'] = True
    return render_to_response(template_name, template_var, context_instance=RequestContext(request))