Browse Source

implement the administration form teh ext.direct wayz

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
941a16c511
  1. 28
      htdocs/js/mumble.js
  2. 6
      pyweb/mumble/forms.py
  3. 2
      pyweb/mumble/templates/mumble/mumble.html
  4. 2
      pyweb/mumble/templatetags/mumble_extras.py
  5. 2
      pyweb/mumble/urls.py
  6. 11
      pyweb/mumble/views.py

28
htdocs/js/mumble.js

@ -1,6 +1,23 @@
// kate: space-indent on; indent-width 4; replace-tabs on; // kate: space-indent on; indent-width 4; replace-tabs on;
function render_mumble( divname, urls ){ 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({ var mainpanel = new Ext.Panel({
renderTo: divname, renderTo: divname,
height: 600, height: 600,
@ -28,15 +45,7 @@ function render_mumble( divname, urls ){
xtype: "textfield", xtype: "textfield",
inputType: "password", inputType: "password",
}], }],
}, {
title: gettext("Administration"),
xtype: "form",
items: [{
name: "test",
fieldLabel: "testing",
xtype: "textfield",
}],
}, {
}, adminform, {
title: gettext("User texture"), title: gettext("User texture"),
layout: "border", layout: "border",
items: [{ items: [{
@ -75,4 +84,5 @@ function render_mumble( divname, urls ){
} ], } ],
}], }],
}); });
adminform.getForm().load({ params: {pk: 1} });
} }

6
pyweb/mumble/forms.py

@ -25,6 +25,9 @@ from django.utils.translation import ugettext_lazy as _
from mumble.models import MumbleServer, Mumble, MumbleUser from mumble.models import MumbleServer, Mumble, MumbleUser
from extdirect import Provider
EXT_FORMS_PROVIDER = Provider(name="Ext.app.MUMBLE_FORMS_API")
class PropertyModelForm( ModelForm ): class PropertyModelForm( ModelForm ):
""" ModelForm that gets/sets fields that are not within the model's """ ModelForm that gets/sets fields that are not within the model's
@ -69,7 +72,7 @@ class PropertyModelForm( ModelForm ):
if fldname not in instfields: if fldname not in instfields:
setattr( inst, fldname, self.cleaned_data[fldname] ) setattr( inst, fldname, self.cleaned_data[fldname] )
@EXT_FORMS_PROVIDER.register_form
class MumbleForm( PropertyModelForm ): class MumbleForm( PropertyModelForm ):
""" The Mumble Server admin form that allows to configure settings which do """ The Mumble Server admin form that allows to configure settings which do
not necessarily have to be reserved to the server hoster. not necessarily have to be reserved to the server hoster.
@ -150,6 +153,7 @@ class MumbleAdminForm( MumbleForm ):
return None return None
@EXT_FORMS_PROVIDER.register_form
class MumbleServerForm( ModelForm ): class MumbleServerForm( ModelForm ):
defaultconf = forms.CharField( label=_("Default config"), required=False, widget=forms.Textarea ) defaultconf = forms.CharField( label=_("Default config"), required=False, widget=forms.Textarea )

2
pyweb/mumble/templates/mumble/mumble.html

@ -13,6 +13,8 @@
{% block HeadTag %} {% block HeadTag %}
<script type="text/javascript" src="/jsi18n/"></script> <script type="text/javascript" src="/jsi18n/"></script>
<script type="text/javascript" src="/mumble/api/api.js"></script> <script type="text/javascript" src="/mumble/api/api.js"></script>
<script type="text/javascript" src="/mumble/forms/api.js"></script>
<script type="text/javascript" src="/mumble/forms/mumbleform.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/channelviewer.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/channelviewer.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/usereditor.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/usereditor.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/mumble.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/mumble.js"></script>

2
pyweb/mumble/templatetags/mumble_extras.py

@ -61,3 +61,5 @@ def mmversion_eq( obj, version ):
def mmversion_gt( obj, version ): def mmversion_gt( obj, version ):
""" return True if the given Server's version is greater than the given 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('.')]) return tuple(obj.version[:3]) > tuple([int(v) for v in version.split('.')])

2
pyweb/mumble/urls.py

@ -17,6 +17,7 @@
from django.conf.urls.defaults import patterns, include from django.conf.urls.defaults import patterns, include
from views import EXT_DIRECT_PROVIDER from views import EXT_DIRECT_PROVIDER
from forms import EXT_FORMS_PROVIDER
urlpatterns = patterns( urlpatterns = patterns(
'mumble.views', 'mumble.views',
@ -24,6 +25,7 @@ urlpatterns = patterns(
( r'(?P<server>\d+)/users', 'users' ), ( r'(?P<server>\d+)/users', 'users' ),
( r'api/', include(EXT_DIRECT_PROVIDER.urls) ), ( r'api/', include(EXT_DIRECT_PROVIDER.urls) ),
( r'forms/', include(EXT_FORMS_PROVIDER.urls) ),
( r'(?P<server>\d+)/(?P<userid>\d+)/texture.png', 'showTexture' ), ( r'(?P<server>\d+)/(?P<userid>\d+)/texture.png', 'showTexture' ),

11
pyweb/mumble/views.py

@ -255,6 +255,17 @@ def showTexture( request, server, userid ):
img.save( buf, "PNG" ) img.save( buf, "PNG" )
return HttpResponse( buf.getvalue(), "image/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 @login_required
@EXT_DIRECT_PROVIDER.register_method( "Mumble" ) @EXT_DIRECT_PROVIDER.register_method( "Mumble" )

Loading…
Cancel
Save