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

MongoEngine inline fields fixes

parent f6d0a10b
......@@ -55,6 +55,7 @@ class Post(db.Document):
name = db.StringField(max_length=20)
value = db.StringField(max_length=20)
inner = db.ListField(db.EmbeddedDocumentField(Comment))
lols = db.ListField(db.StringField(max_length=20))
# Customized admin views
......
......@@ -3,6 +3,11 @@ from wtforms.fields import FormField
class ModelFormField(FormField):
def __init__(self, model, *args, **kwargs):
# Small hack to get rid of separator if name is empty
name = kwargs.get('name')
if not name:
kwargs['separator'] = ''
super(ModelFormField, self).__init__(*args, **kwargs)
self.model = model
......
......@@ -12,7 +12,7 @@ class InlineFieldList(FieldList):
super(InlineFieldList, self).__init__(*args, **kwargs)
# Create template
self.template = self.unbound_field.bind(form=None, name='', prefix='', separator='')
self.template = self.unbound_field.bind(form=None, name='')
self.template.process(None)
def __call__(self, **kwargs):
......
......@@ -62,6 +62,10 @@ form.search-form a.clear i {
}
/* Inline forms */
.fa-inline-field {
padding-bottom: 0.5em;
}
.fa-inline-field-control {
float: right;
}
......@@ -41,12 +41,21 @@
$('[name]', $template).each(function(e) {
var me = $(this);
me.attr('id', prefix + '-' + me.attr('id'));
me.attr('name', prefix + '-' + me.attr('name'));
var id = me.attr('id');
var name = me.attr('name');
id = prefix + (id !== '' ? '-' + id : '');
name = prefix + (name !== '' ? '-' + name : '');
me.attr('id', id);
me.attr('name', name);
});
$template.appendTo($el);
// Select first field
$('input:first', $template).focus();
// Apply styles
this.applyGlobalStyles($template);
};
......
{% import 'admin/lib.html' as lib with context %}
{{ lib.render_form_fields(field, True) }}
<hr/>
......@@ -4,7 +4,6 @@
<a href="#" class="fa-remove-field"><i class="icon-remove"></i></a>
</div>
{{ render(template) }}
<hr/>
</div>
{%- endmacro %}
......@@ -21,7 +20,6 @@
{%- endif -%}
{{ render(subfield) }}
<hr/>
</div>
{% endfor %}
</div>
......
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