From 941a16c5118611c76f11f460353854e4166f62ae Mon Sep 17 00:00:00 2001 From: Michael Ziegler Date: Sat, 3 Jul 2010 13:28:48 +0200 Subject: [PATCH] implement the administration form teh ext.direct wayz --- htdocs/js/mumble.js | 28 +++++++++++++++------- pyweb/mumble/forms.py | 6 ++++- pyweb/mumble/templates/mumble/mumble.html | 2 ++ pyweb/mumble/templatetags/mumble_extras.py | 2 ++ pyweb/mumble/urls.py | 2 ++ pyweb/mumble/views.py | 11 +++++++++ 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/htdocs/js/mumble.js b/htdocs/js/mumble.js index ab4cf82..88c598b 100644 --- a/htdocs/js/mumble.js +++ b/htdocs/js/mumble.js @@ -1,6 +1,23 @@ // kate: space-indent on; indent-width 4; replace-tabs on; function render_mumble( divname, urls ){ + Ext.QuickTips.init(); + + var adminform = new Ext.ux.MumbleForm({ + title: gettext("Administration"), + buttons: [{ + text: "doit", + handler: function( btn ){ + this.ownerCt.ownerCt.getForm().load({ params: {pk: 1} }); + } + }, { + text: "submit", + handler: function( btn ){ + this.ownerCt.ownerCt.getForm().submit({ params: {pk: 1} }); + } + }] + }); + var mainpanel = new Ext.Panel({ renderTo: divname, height: 600, @@ -28,15 +45,7 @@ function render_mumble( divname, urls ){ xtype: "textfield", inputType: "password", }], - }, { - title: gettext("Administration"), - xtype: "form", - items: [{ - name: "test", - fieldLabel: "testing", - xtype: "textfield", - }], - }, { + }, adminform, { title: gettext("User texture"), layout: "border", items: [{ @@ -75,4 +84,5 @@ function render_mumble( divname, urls ){ } ], }], }); + adminform.getForm().load({ params: {pk: 1} }); } diff --git a/pyweb/mumble/forms.py b/pyweb/mumble/forms.py index 340bd34..aa339cf 100644 --- a/pyweb/mumble/forms.py +++ b/pyweb/mumble/forms.py @@ -25,6 +25,9 @@ from django.utils.translation import ugettext_lazy as _ from mumble.models import MumbleServer, Mumble, MumbleUser +from extdirect import Provider + +EXT_FORMS_PROVIDER = Provider(name="Ext.app.MUMBLE_FORMS_API") class PropertyModelForm( ModelForm ): """ ModelForm that gets/sets fields that are not within the model's @@ -69,7 +72,7 @@ class PropertyModelForm( ModelForm ): if fldname not in instfields: setattr( inst, fldname, self.cleaned_data[fldname] ) - +@EXT_FORMS_PROVIDER.register_form class MumbleForm( PropertyModelForm ): """ The Mumble Server admin form that allows to configure settings which do not necessarily have to be reserved to the server hoster. @@ -150,6 +153,7 @@ class MumbleAdminForm( MumbleForm ): return None +@EXT_FORMS_PROVIDER.register_form class MumbleServerForm( ModelForm ): defaultconf = forms.CharField( label=_("Default config"), required=False, widget=forms.Textarea ) diff --git a/pyweb/mumble/templates/mumble/mumble.html b/pyweb/mumble/templates/mumble/mumble.html index b509f40..33656d1 100644 --- a/pyweb/mumble/templates/mumble/mumble.html +++ b/pyweb/mumble/templates/mumble/mumble.html @@ -13,6 +13,8 @@ {% block HeadTag %} + + diff --git a/pyweb/mumble/templatetags/mumble_extras.py b/pyweb/mumble/templatetags/mumble_extras.py index 6637267..a6b4051 100644 --- a/pyweb/mumble/templatetags/mumble_extras.py +++ b/pyweb/mumble/templatetags/mumble_extras.py @@ -61,3 +61,5 @@ def mmversion_eq( obj, version ): def mmversion_gt( obj, version ): """ return True if the given Server's version is greater than the given version. """ return tuple(obj.version[:3]) > tuple([int(v) for v in version.split('.')]) + + diff --git a/pyweb/mumble/urls.py b/pyweb/mumble/urls.py index 9c63988..e8af967 100644 --- a/pyweb/mumble/urls.py +++ b/pyweb/mumble/urls.py @@ -17,6 +17,7 @@ from django.conf.urls.defaults import patterns, include from views import EXT_DIRECT_PROVIDER +from forms import EXT_FORMS_PROVIDER urlpatterns = patterns( 'mumble.views', @@ -24,6 +25,7 @@ urlpatterns = patterns( ( r'(?P\d+)/users', 'users' ), ( r'api/', include(EXT_DIRECT_PROVIDER.urls) ), + ( r'forms/', include(EXT_FORMS_PROVIDER.urls) ), ( r'(?P\d+)/(?P\d+)/texture.png', 'showTexture' ), diff --git a/pyweb/mumble/views.py b/pyweb/mumble/views.py index 2f562d9..c886f6d 100644 --- a/pyweb/mumble/views.py +++ b/pyweb/mumble/views.py @@ -255,6 +255,17 @@ def showTexture( request, server, userid ): img.save( buf, "PNG" ) return HttpResponse( buf.getvalue(), "image/png" ) +@login_required +@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) +def get_admin( request, server ): + srv = get_object_or_404( Mumble, id=int(server) ) + if not srv.isUserAdmin( request.user ): + raise Exception( 'Access denied' ) + adminform = MumbleForm( request.POST, instance=srv ) + data = {} + for fld in adminform.fields: + data[fld] = getattr( srv, fld ) + return { 'data': data, 'success': True } @login_required @EXT_DIRECT_PROVIDER.register_method( "Mumble" )