Commit cbb6acc5 authored by Serge S. Koval's avatar Serge S. Koval

Merge pull request #1255 from Fraggle/master

Using sorted list field not handled (and crash) in process_ajax_references
parents 15a3d1df 5f797e71
...@@ -76,7 +76,7 @@ def create_ajax_loader(model, name, field_name, opts): ...@@ -76,7 +76,7 @@ def create_ajax_loader(model, name, field_name, opts):
ftype = type(prop).__name__ ftype = type(prop).__name__
if ftype == 'ListField': if ftype == 'ListField' or ftype == 'SortedListField':
prop = prop.field prop = prop.field
ftype = type(prop).__name__ ftype = type(prop).__name__
...@@ -97,7 +97,7 @@ def process_ajax_references(references, view): ...@@ -97,7 +97,7 @@ def process_ajax_references(references, view):
def handle_field(field, subdoc, base): def handle_field(field, subdoc, base):
ftype = type(field).__name__ ftype = type(field).__name__
if ftype == 'ListField': if ftype == 'ListField' or ftype == 'SortedListField':
child_doc = getattr(subdoc, '_form_subdocuments', {}).get(None) child_doc = getattr(subdoc, '_form_subdocuments', {}).get(None)
if child_doc: if child_doc:
......
...@@ -908,6 +908,63 @@ def test_nested_list_subdocument(): ...@@ -908,6 +908,63 @@ def test_nested_list_subdocument():
ok_('value' not in dir(inline_form)) ok_('value' not in dir(inline_form))
def test_nested_sortedlist_subdocument():
app, db, admin = setup()
class Comment(db.EmbeddedDocument):
name = db.StringField(max_length=20, required=True)
value = db.StringField(max_length=20)
class Model1(db.Document):
test1 = db.StringField(max_length=20)
subdoc = db.SortedListField(db.EmbeddedDocumentField(Comment))
# Check only
view1 = CustomModelView(
Model1,
form_subdocuments = {
'subdoc': {
'form_subdocuments': {
None: {
'form_columns': ('name',)
}
}
}
}
)
form = view1.create_form()
inline_form = form.subdoc.unbound_field.args[2]
ok_('name' in dir(inline_form))
ok_('value' not in dir(inline_form))
def test_sortedlist_subdocument_validation():
app, db, admin = setup()
class Comment(db.EmbeddedDocument):
name = db.StringField(max_length=20, required=True)
value = db.StringField(max_length=20)
class Model1(db.Document):
test1 = db.StringField(max_length=20)
subdoc = db.SortedListField(db.EmbeddedDocumentField(Comment))
view = CustomModelView(Model1)
admin.add_view(view)
client = app.test_client()
rv = client.post('/admin/model1/new/',
data={'test1': 'test1large', 'subdoc-0-name': 'comment', 'subdoc-0-value': 'test'})
eq_(rv.status_code, 302)
rv = client.post('/admin/model1/new/',
data={'test1': 'test1large', 'subdoc-0-name': '', 'subdoc-0-value': 'test'})
eq_(rv.status_code, 200)
ok_('This field is required' in rv.data)
def test_list_subdocument_validation(): def test_list_subdocument_validation():
app, db, admin = setup() app, db, admin = setup()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment