예제 #1
0
파일: views.py 프로젝트: decadecity/ct
def profile(request):
    password_form = PasswordChangeForm(request.user)
    user_form = UserChangeForm(instance=request.user)

    if request.method == 'POST':
        if request.GET.get('type', 'password'):
            password_form = PasswordChangeForm(request.user, request.POST)
            if not password_form.is_valid():
                messages.error(request, 'There was a problem changing the password.')
            else:
                messages.success(request, 'Password changed.')
                return HttpResponseGetAfterPost('%s' % (request.path))
        if request.GET.get('type', 'details'):
            user_form = PasswordChangeForm(request.POST, instance=request.user)
            if not user_form.is_valid():
                messages.error(request, 'There was a problem updating your details.')
            else:
                messages.success(request, 'Details updated.')
                return HttpResponseGetAfterPost('%s' % (request.path))

    context = {
        'password_form': password_form,
        'user_form': user_form
    }
    return render(request, 'user/profile.html', context)
 def test_username_validity(self):
     user = User.objects.get(username='******')
     data = {'username': '******'}
     form = UserChangeForm(data, instance=user)
     self.assertFalse(form.is_valid())
     validator = next(v for v in User._meta.get_field('username').validators if v.code == 'invalid')
     self.assertEqual(form["username"].errors, [force_text(validator.message)])
예제 #3
0
 def test_username_validity(self):
     user = User.objects.get(username='******')
     data = {'username': '******'}
     form = UserChangeForm(data, instance=user)
     self.assertFalse(form.is_valid())
     self.assertEqual(form['username'].errors,
                      [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
예제 #4
0
파일: forms.py 프로젝트: LUMC/django
 def test_username_validity(self):
     user = User.objects.get(username='******')
     data = {'username': '******'}
     form = UserChangeForm(data, instance=user)
     self.assertFalse(form.is_valid())
     self.assertEqual(form['username'].errors,
                      [force_text(form.fields['username'].error_messages['invalid'])])
예제 #5
0
파일: views.py 프로젝트: wmantly/notes
    def post( self, request ):
        form = UserChangeForm( request.POST, instance=request.user )
        if form.is_valid():
            form.save()

            return redirect( '/users/profile' )

        request.context_dict['form'] = form

        return render( request, 'users/profile.html', request.context_dict )
예제 #6
0
 def test_with_custom_user_model(self):
     with override_settings(AUTH_USER_MODEL='auth_tests.ExtensionUser'):
         from django.contrib.auth.forms import UserChangeForm
         self.assertEqual(UserChangeForm.Meta.model, ExtensionUser)
         data = {
             'username': '******',
             'date_joined': '1998-02-24',
             'date_of_birth': '1998-02-24',
         }
         form = UserChangeForm(data, instance=self.u7)
         self.assertTrue(form.is_valid())
예제 #7
0
 def test_customer_user_model_with_different_username_field(self):
     with override_settings(AUTH_USER_MODEL='auth_tests.CustomUser'):
         from django.contrib.auth.forms import UserChangeForm
         self.assertEqual(UserChangeForm.Meta.model, CustomUser)
         user = CustomUser.custom_objects.create(email='*****@*****.**', date_of_birth='1998-02-24')
         data = {
             'email': '*****@*****.**',
             'date_of_birth': '1998-02-24',
         }
         form = UserChangeForm(data, instance=user)
         self.assertTrue(form.is_valid())
예제 #8
0
파일: views_admin.py 프로젝트: ky0p/k6
def edit_user(request, userID):
  user = None
  try:
    user = User.objects.get(id=userID)
    edit_form = UserChangeForm(request.POST or None, instance=user)
    if request.method == 'POST':
      if edit_form.is_valid():
        edit_form.save()
        return HttpResponseRedirect('/admin/users')
    return render(request,'staff/edit_user.html',{'form':edit_form})
  except Challenge.DoesNotExist:
    print "User "+ userID +" not found"
    return HttpResponseRedirect('/admin/users')
예제 #9
0
파일: views.py 프로젝트: angelreyes/glipy
def myinfo( request, template_name = 'accounts/settings.html' ):
    """
    Processes requests for the settings page, where users
    can edit their profiles.
    """
    page_title = 'Account Settings'
    if request.method == 'POST':
#        postdata = request.POST.copy()
        form = UserChangeForm(request.POST, instance=request.user)
        if form.is_valid():
            form.save()
    else:
        form = UserChangeForm(instance=request.user)
    title = 'Settings'
    return render_to_response( template_name, locals(), context_instance = RequestContext( request) )
    def test_bug_19133(self):
        "The change form does not return the password value"
        # Use the form to construct the POST data
        user = User.objects.get(username='******')
        form_for_data = UserChangeForm(instance=user)
        post_data = form_for_data.initial

        # The password field should be readonly, so anything
        # posted here should be ignored; the form will be
        # valid, and give back the 'initial' value for the
        # password field.
        post_data['password'] = '******'
        form = UserChangeForm(instance=user, data=post_data)

        self.assertTrue(form.is_valid())
        self.assertEqual(form.cleaned_data['password'], 'sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161')
예제 #11
0
def view_account(request, user_id):
    try:
        view_user = User.objects.get(pk=user_id)
    except ObjectDoesNotExist:
        raise Http404
    
    if request.method == "POST":
        form = UserChangeForm(request.POST, instance=view_user)
        if form.is_valid():
            form.save()
    else:
        form = UserChangeForm(instance=view_user)
    
    return render_to_response("account/view.html",
                                {"view_user": view_user, "form": form,},
                                context_instance=RequestContext(request)
                            )
예제 #12
0
    def test_bug_19133(self):
        "The change form does not return the password value"
        # Use the form to construct the POST data
        user = User.objects.get(username='******')
        form_for_data = UserChangeForm(instance=user)
        post_data = form_for_data.initial

        # The password field should be readonly, so anything
        # posted here should be ignored; the form will be
        # valid, and give back the 'initial' value for the
        # password field.
        post_data['password'] = '******'
        form = UserChangeForm(instance=user, data=post_data)

        self.assertTrue(form.is_valid())
        # original hashed password contains $
        self.assertIn('$', form.cleaned_data['password'])
예제 #13
0
파일: views.py 프로젝트: CHOQUERC/Sermul
def EditUser(request, slug=None):
    """
    Editar usuario de forma simple.
    """
    user = request.user
    if request.method == 'POST':
        form = UserChangeForm(request.POST, instance=user)
        if form.is_valid():
            #Actualizar el objeto
            user = form.save()
            messages.success(request, 'Usuario actualizado exitosamente.', extra_tags='html_dante')
            return HttpResponseRedirect(reverse('home:listar_usuarios'))
    else:
        form = UserChangeForm(instance=user)
    context = {
        'form': form,
    }
    return render(request, 'home/user_change.html', context)
예제 #14
0
def profile(request):
    profile = get_object_or_404(UserProfile, user=request.user)
    if request.method == 'POST':
        user_form = UserChangeForm(request.POST, instance=request.user)
        profile_form = UserProfileForm(request.POST, request.FILES,
            instance=profile)
        if user_form.is_valid() and profile_form.is_valid():
            request.user.save()
            profile.save()
            print profile.avatar
            return HttpResponseRedirect("/")
    else:
        user_form = UserChangeForm(instance=request.user)
        profile_form = UserProfileForm(instance=profile)

    return render(request, "profile.html", {
        "user_form": user_form,
        "profile_form": profile_form,
        })
예제 #15
0
파일: views.py 프로젝트: cronco/lib_admin
def edit_user(request, user_id = 0):
	c = RequestContext(request, dictionary)
	auto_form = AutoUserForm()
	auto_form.fields['user'].widget.attrs = {
						"data-role" : "edit-user",
						"class" : "edit-user autocomplete"
						}
	if request.method == "POST" and (user_id or 'user_1' in request.POST):
		u = User.objects.get(pk = user_id or request.POST['user_1'])
		if request.method == "POST":
			form = UserChangeForm(data = request.POST, instance = u)
			if form.is_valid():
				u = form.save()
		else:
			form = UserChangeForm(instance = u)
	else:
		form = UserChangeForm()
	c['form'] = auto_form
	c['big-form'] = form
	return render_to_response('lib_admin/edit_user.html', {}, c)
예제 #16
0
파일: views.py 프로젝트: job-s/ccreservas
def user_modify(request, user_id):
    try:
        user = User.objects.get(id=user_id)
    except User.DoesNotExist:
        messages.error(request, 'Usuario no existente.')
        return HttpResponseRedirect('/administracion/users/')

    if request.POST:
        f = UserChangeForm(request.POST, instance = user)
        if f.errors:
            return render_to_response('users/modify.html', {'form':f}, RequestContext(request))
        else:
            f.save()
            messages.success(request, 'Usuario editado exitosamente.')
            if 'add_another' in request.POST.keys():
                return HttpResponseRedirect('/administracion/users/crear/')
            return HttpResponseRedirect('/administracion/users/')

    else:
        f = UserChangeForm(instance = user)
        return render_to_response('users/modify.html', {'form':f, 'obj':user}, RequestContext(request))
예제 #17
0
def profile_update(request, user_id):
    print request.method
    user = User.objects.get(id=user_id)
    print user_id
    print user
    print user.first_name
    if request.method == "POST":
        form = UserChangeForm(request.POST, instance=user)
        print form.is_valid()
        if form.is_valid():
            print '2valid form'
            user.first_name = form.cleaned_data['first_name']
            user.last_name = form.cleaned_data['last_name']
            user.email = form.cleaned_data['email']
            user.save()

            print '3valid form'
            return redirect("profile")
    else:
        form = UserChangeForm(instance=user)
    data = {"user": request.user, "form": form}
    return render(request, "profile/profile_update.html", data)
예제 #18
0
	def user_edit(self, form_values, user_id):
		logged_in_employee = Subscriber.objects.get(user=self.user)
		subscriber_to_save = Subscriber.objects.get(user__id__exact=int(user_id))
		is_company_admin = UserGroupManager.is_company_admin(self.user)
		if logged_in_employee.id != subscriber_to_save.id:
			if not is_company_admin:
				return self.respond(is_saved=False, auth_errors='Permission Denied')

		subscriber_form = SubscriberCreationForm(data=form_values)
		subscriber_form.is_company_admin = is_company_admin
		subscriber_form.logged_in_employee = logged_in_employee
		subscriber_form.user_changed = subscriber_to_save.user
		# all fields in User model are required for UserChangeForm. Hence the addition.
		form_values['date_joined'] = subscriber_to_save.user.date_joined
		form_values['last_login'] = subscriber_to_save.user.last_login
		user_form = UserChangeForm(
			form_values,
			instance=subscriber_to_save.user
		)
		if subscriber_form.is_valid() and user_form.is_valid():
			# the m2m fields will be cleared if we save using model form. Hence the hack.
			user_group = copy.copy(subscriber_to_save.user.groups.all())
			user_form.save()
			if is_company_admin:
				subscriber_to_save.save()
				subscriber_to_save.user.groups.clear()
				user_group = [Group.objects.get(pk=subscriber_form.cleaned_data['role'])]
			subscriber_to_save.user.groups.add(*user_group)
			return self.respond(
				is_saved=True,
				subscriber=subscriber_to_save.serialize()
			)
		return self.respond(
			is_saved=False,
			subscriber_form_errors=subscriber_form.errors,
			user_form_errors=user_form.errors
		)
예제 #19
0
 def test_username_field_autocapitalize_none(self):
     form = UserChangeForm()
     self.assertEqual(
         form.fields['username'].widget.attrs.get('autocapitalize'), 'none')
 def test_bug_17944_unknown_password_algorithm(self):
     user = User.objects.get(username='******')
     form = UserChangeForm(instance=user)
     self.assertIn(_("Invalid password format or unknown hashing algorithm."),
         form.as_table())
 def test_bug_17944_empty_password(self):
     user = User.objects.get(username='******')
     form = UserChangeForm(instance=user)
     self.assertIn(_("No password set."), form.as_table())
 def test_unusable_password(self):
     user = User.objects.get(username='******')
     user.set_unusable_password()
     user.save()
     form = UserChangeForm(instance=user)
     self.assertIn(_("No password set."), form.as_table())
예제 #23
0
파일: test_forms.py 프로젝트: zalew/django
 def test_bug_17944_empty_password(self):
     user = User.objects.get(username='******')
     form = UserChangeForm(instance=user)
     self.assertIn(_("No password set."), form.as_table())
예제 #24
0
파일: test_forms.py 프로젝트: zalew/django
 def test_bug_17944_unknown_password_algorithm(self):
     user = User.objects.get(username='******')
     form = UserChangeForm(instance=user)
     self.assertIn(_("Invalid password format or unknown hashing algorithm."),
         form.as_table())
예제 #25
0
 def test_unsuable_password(self):
     user = User.objects.get(username='******')
     user.set_unusable_password()
     user.save()
     form = UserChangeForm(instance=user)
     self.assertIn(_("No password set."), form.as_table())
예제 #26
0
 def test_username_validity(self):
     user = User.objects.get(username="******")
     data = {"username": "******"}
     form = UserChangeForm(data, instance=user)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["username"].errors, [force_unicode(form.fields["username"].error_messages["invalid"])])
예제 #27
0
 def test_bug_17944_unknown_password_algorithm(self):
     user = User.objects.get(username="******")
     form = UserChangeForm(instance=user)
     # Just check that no error is raised.
     form.as_table()
예제 #28
0
 def test_bug_17944_empty_password(self):
     user = User.objects.get(username="******")
     form = UserChangeForm(instance=user)
     # Just check that no error is raised.
     form.as_table()