コード例 #1
0
ファイル: views.py プロジェクト: kperi/META-SHARE
def edit_profile(request):
    """
    Edits user account profile for the logged in user.
    """
    # The "virtual" MetaShareUser cannot edit profile information!
    if request.user.username == 'MetaShareUser':
        return redirect('metashare.views.frontpage')
    
    # Check if the edit form has been submitted.
    if request.method == "POST":
        # If so, bind the creation form to HTTP POST values.
        form = UserProfileForm(request.POST)
        
        # Check if the form has validated successfully.
        if form.is_valid():
            # Get UserProfile instance corresponding to the current user.
            profile = request.user.get_profile()
            
            # Loop over all editable fields and check for updates.
            _profile_requires_save = False
            for __field__ in profile.__editable_fields__:
                # Check if the form contains new data for the current field.
                if form.cleaned_data.has_key(__field__):
                    _value = form.cleaned_data.get(__field__)
                    
                    # If field data has changed, update the field.
                    if _value != getattr(profile, __field__):
                        _profile_requires_save = True
                        setattr(profile, __field__, _value)
            
            # Check if the profile needs to saved.
            if _profile_requires_save:
                profile.save()
                
                # Add a message to the user after successful creation.
                messages.success(request,
                  "You have successfully updated your profile information.")
            
            # Redirect the user to the front page.
            return redirect('metashare.views.frontpage')
    
    # Otherwise, fill UserProfileForm instance from current UserProfile.
    else:
        # Get UserProfile instance corresponding to the current user.
        profile = request.user.get_profile()
        
        # Fill UserProfileForm from current UserProfile instance.
        form = UserProfileForm({'birthdate': profile.birthdate,
          'affiliation': profile.affiliation, 'position': profile.position,
          'homepage': profile.homepage})
    
    dictionary = {'title': 'Edit profile information', 'form': form}
    return render_to_response('accounts/edit_profile.html', dictionary,
      context_instance=RequestContext(request))
コード例 #2
0
def edit_profile(request):
    """
    Edits user account profile for the logged in user.
    """
    # Get UserProfile instance corresponding to the current user.
    profile = request.user.userprofile

    # Check if the edit form has been submitted.
    if request.method == "POST":
        # If so, bind the creation form to HTTP POST values.
        form = UserProfileForm(request.POST)
        
        # Check if the form has validated successfully.
        if form.is_valid():

            # Loop over all editable fields and check for updates.
            _profile_requires_save = False
            for __field__ in profile.__editable_fields__:
                # Check if the form contains new data for the current field.
                if form.cleaned_data.has_key(__field__):
                    _value = form.cleaned_data.get(__field__)
                    
                    # If field data has changed, update the field.
                    if _value != getattr(profile, __field__):
                        _profile_requires_save = True
                        setattr(profile, __field__, _value)
            
            # Check if the profile needs to saved.
            if _profile_requires_save:
                profile.save()
                
                # Add a message to the user after successful creation.
                messages.success(request,
                  _("You have successfully updated your profile information."))
            
            # Redirect the user to the front page.
            return redirect('metashare.views.frontpage')
    
    # Otherwise, fill UserProfileForm instance from current UserProfile.
    else:
        form = UserProfileForm({'birthdate': profile.birthdate,
          'affiliation': profile.affiliation, 'position': profile.position,
          'homepage': profile.homepage})

    if request.user.has_perm('accounts.ms_full_member'):
        ms_membership = _('full member')
    elif request.user.has_perm('accounts.ms_associate_member'):
        ms_membership = _('associate member')
    else:
        ms_membership = None
    dictionary = {'title': _('Edit Profile Information'), 'form': form,
        'metashare_membership': ms_membership,
        'groups_applied_for': [edt_reg.editor_group.name for edt_reg
                in EditorGroupApplication.objects.filter(user=profile.user)],
        'organizations_applied_for': [org_reg.organization.name for org_reg
                in OrganizationApplication.objects.filter(user=profile.user)],
        'editor_groups_member_of': [{'name': eg.name, 'default':
                profile.default_editor_groups.filter(name=eg.name).count() != 0}
            for eg in EditorGroup.objects.filter(name__in=
                        profile.user.groups.values_list('name', flat=True))],
        'editor_group_managers_member_of': [edt_grp_mgrs.name for edt_grp_mgrs
                in EditorGroupManagers.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))],
        'organizations_member_of': [orga.name for orga
                in Organization.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))],
        'organization_managers_member_of': [org_mgrs.name for org_mgrs
                in OrganizationManagers.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))]}
    if request.user.is_superuser or request.user.has_perm('auth.access_api'):
        dictionary['API_KEY'] = REST_API_KEY

    return render_to_response('accounts/edit_profile.html', dictionary,
      context_instance=RequestContext(request))
コード例 #3
0
ファイル: views.py プロジェクト: MiltosD/CEFELRC
def edit_profile(request):
    """
    Edits user account profile for the logged in user.
    """
    # Get UserProfile instance corresponding to the current user.
    profile = request.user.get_profile()
    # Check if the edit form has been submitted.
    if request.method == "POST":
        # If so, bind the creation form to HTTP POST values.
        form = UserProfileForm(request.POST)
        
        # Check if the form has validated successfully.
        if form.is_valid():

            # Loop over all editable fields and check for updates.
            _profile_requires_save = False
            for __field__ in profile.__editable_fields__:
                # Check if the form contains new data for the current field.
                if form.cleaned_data.has_key(__field__):
                    _value = form.cleaned_data.get(__field__)
                    
                    # If field data has changed, update the field.
                    if _value != getattr(profile, __field__):
                        _profile_requires_save = True
                        setattr(profile, __field__, _value)
            
            # Check if the profile needs to saved.
            if _profile_requires_save:
                profile.save()
                
                # Add a message to the user after successful creation.
                messages.success(request,
                  _("You have successfully updated your profile information."))
            
            # Redirect the user to the front page.
            return redirect('metashare.views.frontpage')
    
    # Otherwise, fill UserProfileForm instance from current UserProfile.
    else:
        form = UserProfileForm({'birthdate': profile.birthdate,
          'affiliation': profile.affiliation, 'phone_number': profile.phone_number, 'country': profile.country, 'position': profile.position,
          'homepage': profile.homepage})

    if request.user.has_perm('accounts.ms_full_member'):
        ms_membership = _('full member')
    elif request.user.has_perm('accounts.ms_associate_member'):
        ms_membership = _('associate member')
    else:
        ms_membership = None
    dictionary = {'title': _('Edit Profile Information'), 'form': form,
        'metashare_membership': ms_membership,
        'groups_applied_for': [edt_reg.editor_group.name for edt_reg
                in EditorGroupApplication.objects.filter(user=profile.user)],
        'organizations_applied_for': [org_reg.organization.name for org_reg
                in OrganizationApplication.objects.filter(user=profile.user)],
        'editor_groups_member_of': [{'name': eg.name, 'default':
                profile.default_editor_groups.filter(name=eg.name).count() != 0}
            for eg in EditorGroup.objects.filter(name__in=
                        profile.user.groups.values_list('name', flat=True))],
        'editor_group_managers_member_of': [edt_grp_mgrs.name for edt_grp_mgrs
                in EditorGroupManagers.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))],
        'organizations_member_of': [orga.name for orga
                in Organization.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))],
        'organization_managers_member_of': [org_mgrs.name for org_mgrs
                in OrganizationManagers.objects.filter(name__in=profile.user.groups.values_list('name', flat=True))]}
    
    return render_to_response('accounts/edit_profile.html', dictionary,
      context_instance=RequestContext(request))