def test_settings_form(self): """ Tests whether the settings form can be submitted without errors """ user = baker.make(UserProfile, email="*****@*****.**") delegate = baker.make(UserProfile, email="*****@*****.**") self.assertFalse( user.delegates.filter( email="*****@*****.**").exists()) form_data = get_form_data_from_instance(DelegatesForm, user) form_data["delegates"] = [delegate.pk] # add delegate form = DelegatesForm(form_data, instance=user) self.assertTrue(form.is_valid()) form.save() user = UserProfile.objects.get( email="*****@*****.**") self.assertTrue( user.delegates.filter( email="*****@*****.**").exists())
def settings_edit(request): user = request.user form = DelegatesForm(request.POST or None, request.FILES or None, instance=user) if form.is_valid(): form.save() messages.success(request, _("Successfully updated your settings.")) return redirect('contributor:index') else: return render(request, "contributor_settings.html", dict(form=form, user=user))
def settings_edit(request): user = request.user form = DelegatesForm(request.POST or None, request.FILES or None, instance=user) if form.is_valid(): form.save() messages.success(request, _("Successfully updated your settings.")) return redirect('contributor:index') else: return render(request, "contributor_settings.html", dict(form=form))
def settings_edit(request): user = request.user form = DelegatesForm(request.POST or None, request.FILES or None, instance=user) if form.is_valid(): form.save() messages.success(request, _("Successfully updated your settings.")) return redirect('contributor:settings_edit') else: return render(request, "contributor_settings.html", dict( form=form, delegate_of=user.represented_users.all(), cc_users=user.cc_users.all(), ccing_users=user.ccing_users.all(), ))
def test_settings_form(self): """ Tests whether the settings form can be submitted without errors """ user = mommy.make(UserProfile, username="******") delegate = mommy.make(UserProfile, username="******") self.assertFalse(user.delegates.filter(username="******").exists()) form_data = get_form_data_from_instance(DelegatesForm, user) form_data["delegates"] = [delegate.pk] # add delegate form = DelegatesForm(form_data, instance=user) self.assertTrue(form.is_valid()) form.save() user = UserProfile.objects.get(username="******") self.assertTrue(user.delegates.filter(username="******").exists())