From: Joseph Spiros Date: Tue, 22 Mar 2011 19:12:27 +0000 (-0400) Subject: Fixed the password change form on the client side, and fixed form handling in the... X-Git-Url: http://git.ithinksw.org/philo.git/commitdiff_plain/457864d91747076c222916d35071f53cb3f700f8 Fixed the password change form on the client side, and fixed form handling in the auth and models plugins server-side. --- diff --git a/contrib/gilbert/media/gilbert/plugins/auth.js b/contrib/gilbert/media/gilbert/plugins/auth.js index 6983748..97e1785 100644 --- a/contrib/gilbert/media/gilbert/plugins/auth.js +++ b/contrib/gilbert/media/gilbert/plugins/auth.js @@ -32,39 +32,44 @@ Gilbert.lib.plugins.auth.Plugin = Ext.extend(Gilbert.lib.plugins.Plugin, { for (var item_index in formspec.items) { var item = formspec.items[item_index]; Ext.apply(item, { - plugins: [ Ext.ux.FieldLabeler ], + anchor: '100%', }); } - var change_password_window = application.create_window({ - layout: 'fit', - resizable: true, + var change_password_form = new Gilbert.lib.ui.DjangoForm(Ext.applyIf({ title: 'Change password', + header: false, iconCls: 'icon-key--pencil', + bodyStyle: 'padding: 10px;', + baseCls: 'x-plain', + autoScroll: true, + api: { + submit: Gilbert.api.plugins.auth.save_passwd_form, + }, + }, formspec)); + var change_password_window = application.create_window({ + layout: 'fit', + title: change_password_form.title, + iconCls: change_password_form.iconCls, + bodyStyle: 'padding: 5px; background: solid;', width: 360, - height: 100, - items: change_password_form = new Ext.FormPanel(Ext.applyIf({ - layout: { - type: 'vbox', - align: 'stretch', - }, - baseCls: 'x-plain', - bodyStyle: 'padding: 5px;', - frame: true, - buttons: [{ + height: 240, + maximizable: false, + items: [change_password_form], + bbar: [ + '->', + { text: 'Change password', iconCls: 'icon-key--pencil', handler: function(button, event) { change_password_form.getForm().submit({ success: function(form, action) { Ext.MessageBox.alert('Password changed', 'Your password has been changed.'); + change_password_window.close(); }, }); }, - }], - api: { - submit: Gilbert.api.plugins.auth.save_passwd_form, - }, - }, formspec)) + } + ], }); change_password_window.doLayout(); change_password_window.show(button.el); diff --git a/contrib/gilbert/plugins/auth.py b/contrib/gilbert/plugins/auth.py index 0daaf85..66cfebc 100644 --- a/contrib/gilbert/plugins/auth.py +++ b/contrib/gilbert/plugins/auth.py @@ -40,10 +40,10 @@ class Auth(Plugin): @ext_method(form_handler=True) def save_passwd_form(self, request): form = PasswordChangeForm(request.user, data=request.POST) - try: + if form.is_valid(): form.save() return True, None - except: + else: return False, form.errors @ext_method diff --git a/contrib/gilbert/plugins/models.py b/contrib/gilbert/plugins/models.py index b765482..5217df3 100644 --- a/contrib/gilbert/plugins/models.py +++ b/contrib/gilbert/plugins/models.py @@ -215,10 +215,10 @@ class ModelAdmin(Plugin): form = self.form_class(request.POST, request.FILES, instance=instance) - try: + if form.is_valid(): saved = form.save() return True, None, saved.pk - except ValueError: + else: return False, form.errors def data_serialize_object(self, obj):