Browse Source

pre-validate requests using EXT_validate

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
57828bc021
  1. 16
      pyweb/mumble/forms.py

16
pyweb/mumble/forms.py

@ -119,6 +119,10 @@ class MumbleForm( PropertyModelForm ):
model = Mumble model = Mumble
fields = ['name'] fields = ['name']
def EXT_validate( self, request ):
if not self.instance.isUserAdmin( request.user ):
return False
return True
class MumbleAdminForm( MumbleForm ): class MumbleAdminForm( MumbleForm ):
""" A Mumble Server admin form intended to be used by the server hoster. """ """ A Mumble Server admin form intended to be used by the server hoster. """
@ -153,13 +157,13 @@ 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 )
def __init__( self, *args, **kwargs ): def __init__( self, *args, **kwargs ):
ModelForm.__init__( self, *args, **kwargs ) ModelForm.__init__( self, *args, **kwargs )
# self.instance = instance of MumbleServer, NOT a server instance
if self.instance and self.instance.id: if self.instance and self.instance.id:
if self.instance.online: if self.instance.online:
confstr = "" confstr = ""
@ -183,6 +187,16 @@ class MumbleUserForm( ModelForm ):
ModelForm.__init__( self, *args, **kwargs ) ModelForm.__init__( self, *args, **kwargs )
self.server = None self.server = None
def EXT_validate( self, request ):
if "serverid" in request.POST:
try:
self.server = Mumble.objects.get( id=int(request.POST['serverid']) )
except Mumble.DoesNotExist:
return False
else:
return True
return False
def clean_name( self ): def clean_name( self ):
""" Check if the desired name is forbidden or taken. """ """ Check if the desired name is forbidden or taken. """

Loading…
Cancel
Save