check jid-single and jid-multi fields when filling ad-hoc commands. Fixes #5829
This commit is contained in:
parent
effa7cedfb
commit
61b26858d5
2 changed files with 54 additions and 6 deletions
|
@ -331,7 +331,14 @@ class CommandWindow:
|
||||||
|
|
||||||
def stage3_submit_form(self, action='execute'):
|
def stage3_submit_form(self, action='execute'):
|
||||||
self.data_form_widget.set_sensitive(False)
|
self.data_form_widget.set_sensitive(False)
|
||||||
|
|
||||||
if self.data_form_widget.get_data_form():
|
if self.data_form_widget.get_data_form():
|
||||||
|
df = self.data_form_widget.get_data_form()
|
||||||
|
if not df.is_valid():
|
||||||
|
dialogs.ErrorDialog(_('Invalid Form'),
|
||||||
|
_('The form is not filled correctly.'))
|
||||||
|
self.data_form_widget.set_sensitive(True)
|
||||||
|
return
|
||||||
self.data_form_widget.data_form.type = 'submit'
|
self.data_form_widget.data_form.type = 'submit'
|
||||||
else:
|
else:
|
||||||
self.data_form_widget.hide()
|
self.data_form_widget.hide()
|
||||||
|
|
|
@ -27,6 +27,7 @@ information how to use them, read documentation
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import xmpp
|
import xmpp
|
||||||
|
import helpers
|
||||||
|
|
||||||
# exceptions used in this module
|
# exceptions used in this module
|
||||||
# base class
|
# base class
|
||||||
|
@ -65,8 +66,8 @@ def Field(typ, **attrs):
|
||||||
'hidden': StringField,
|
'hidden': StringField,
|
||||||
'text-private': StringField,
|
'text-private': StringField,
|
||||||
'text-single': StringField,
|
'text-single': StringField,
|
||||||
'jid-multi': ListMultiField,
|
'jid-multi': JidMultiField,
|
||||||
'jid-single': ListSingleField,
|
'jid-single': JidSingleField,
|
||||||
'list-multi': ListMultiField,
|
'list-multi': ListMultiField,
|
||||||
'list-single': ListSingleField,
|
'list-single': ListSingleField,
|
||||||
'text-multi': TextMultiField,
|
'text-multi': TextMultiField,
|
||||||
|
@ -87,8 +88,8 @@ def ExtendField(node):
|
||||||
'hidden': StringField,
|
'hidden': StringField,
|
||||||
'text-private': StringField,
|
'text-private': StringField,
|
||||||
'text-single': StringField,
|
'text-single': StringField,
|
||||||
'jid-multi': ListMultiField,
|
'jid-multi': JidMultiField,
|
||||||
'jid-single': ListSingleField,
|
'jid-single': JidSingleField,
|
||||||
'list-multi': ListMultiField,
|
'list-multi': ListMultiField,
|
||||||
'list-single': ListSingleField,
|
'list-single': ListSingleField,
|
||||||
'text-multi': TextMultiField,
|
'text-multi': TextMultiField,
|
||||||
|
@ -247,6 +248,9 @@ class DataField(ExtendedNode):
|
||||||
self.delChild(t)
|
self.delChild(t)
|
||||||
|
|
||||||
return locals()
|
return locals()
|
||||||
|
|
||||||
|
def is_valid(self):
|
||||||
|
return True
|
||||||
|
|
||||||
class Uri(xmpp.Node):
|
class Uri(xmpp.Node):
|
||||||
def __init__(self, uri_tag):
|
def __init__(self, uri_tag):
|
||||||
|
@ -405,13 +409,28 @@ class ListField(DataField):
|
||||||
|
|
||||||
class ListSingleField(ListField, StringField):
|
class ListSingleField(ListField, StringField):
|
||||||
"""
|
"""
|
||||||
Covers list-single and jid-single fields
|
Covers list-single field
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class JidSingleField(ListSingleField):
|
||||||
|
"""
|
||||||
|
Covers jid-single fields
|
||||||
|
"""
|
||||||
|
def is_valid(self):
|
||||||
|
if self.value:
|
||||||
|
try:
|
||||||
|
helpers.parse_jid(self.value)
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
if self.required:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
class ListMultiField(ListField):
|
class ListMultiField(ListField):
|
||||||
"""
|
"""
|
||||||
Covers list-multi and jid-multi fields
|
Covers list-multi fields
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@nested_property
|
@nested_property
|
||||||
|
@ -440,6 +459,22 @@ class ListMultiField(ListField):
|
||||||
for element in self.getTags('value'):
|
for element in self.getTags('value'):
|
||||||
yield element.getData()
|
yield element.getData()
|
||||||
|
|
||||||
|
class JidMultiField(ListMultiField):
|
||||||
|
"""
|
||||||
|
Covers jid-multi fields
|
||||||
|
"""
|
||||||
|
def is_valid(self):
|
||||||
|
if len(self.values):
|
||||||
|
for value in self.values:
|
||||||
|
try:
|
||||||
|
helpers.parse_jid(self.value)
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
if self.required:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
class TextMultiField(DataField):
|
class TextMultiField(DataField):
|
||||||
@nested_property
|
@nested_property
|
||||||
def value():
|
def value():
|
||||||
|
@ -530,6 +565,12 @@ class DataRecord(ExtendedNode):
|
||||||
|
|
||||||
def __getitem__(self, item):
|
def __getitem__(self, item):
|
||||||
return self.vars[item]
|
return self.vars[item]
|
||||||
|
|
||||||
|
def is_valid(self):
|
||||||
|
for f in self.iter_fields():
|
||||||
|
if not f.is_valid():
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
class DataForm(ExtendedNode):
|
class DataForm(ExtendedNode):
|
||||||
def __init__(self, type_=None, title=None, instructions=None, extend=None):
|
def __init__(self, type_=None, title=None, instructions=None, extend=None):
|
||||||
|
|
Loading…
Add table
Reference in a new issue