Esempio n. 1
0
File: form.py Progetto: skshetry/app
    def conv_List(self, model, field, kwargs):
        if field.field is None:
            raise ValueError('ListField "%s" must have field specified for model %s' % (field.name, model))

        if isinstance(field.field, ReferenceField):
            loader = getattr(self.view, '_form_ajax_refs', {}).get(field.name)
            if loader:
                return AjaxSelectMultipleField(loader, **kwargs)

            kwargs['widget'] = form.Select2Widget(multiple=True)
            kwargs.setdefault('validators', []).append(validators.Optional())

            # TODO: Support AJAX multi-select
            doc_type = field.field.document_type
            return mongo_fields.ModelSelectMultipleField(model=doc_type, **kwargs)

        # Create converter
        view = self._get_subdocument_config(field.name)
        converter = self.clone_converter(view)

        if field.field.choices:
            kwargs['multiple'] = True
            return converter.convert(model, field.field, kwargs)

        unbound_field = converter.convert(model, field.field, {})
        return InlineFieldList(unbound_field, min_entries=0, **kwargs)
Esempio n. 2
0
class RoleView(ModelView):
    """Admin view for roles."""

    can_view_details = True

    list_all = ('id', 'name', 'description')

    column_list = \
        column_searchable_list = \
        column_filters = \
        column_details_list = \
        columns_sortable_list = \
        list_all

    form_columns = ('name', 'description', 'users')

    user_loader = QueryAjaxModelLoader(
        'user',
        LocalProxy(lambda: _datastore.db.session),
        User,
        fields=['email'],
        page_size=10
    )

    form_extra_fields = {
        'users': AjaxSelectMultipleField(user_loader)
    }

    form_ajax_refs = {
        'user': user_loader
    }
Esempio n. 3
0
    def _model_select_field(self, prop, multiple, remote_model, **kwargs):
        loader = getattr(self.view, '_form_ajax_refs', {}).get(prop.key)

        if loader:
            if multiple:
                return AjaxSelectMultipleField(loader, **kwargs)
            else:
                return AjaxSelectField(loader, **kwargs)

        if 'query_factory' not in kwargs:
            kwargs['query_factory'] = lambda: self.session.query(remote_model)

        if multiple:
            return QuerySelectMultipleField(**kwargs)
        else:
            return QuerySelectField(**kwargs)
Esempio n. 4
0
class RoleView(ModelView):
    """Admin view for roles."""

    can_view_details = True

    list_all = ("id", "name", "description")

    column_list = (
        column_searchable_list
    ) = column_filters = column_details_list = columns_sortable_list = list_all

    form_columns = ("name", "description", "users")

    user_loader = QueryAjaxModelLoader(
        "user",
        LocalProxy(lambda: _datastore.db.session),
        User,
        fields=["email"],
        page_size=10,
    )

    form_extra_fields = {"users": AjaxSelectMultipleField(user_loader)}

    form_ajax_refs = {"user": user_loader}
Esempio n. 5
0
 class FileAssignForm(Form):
     assign_events = AjaxSelectMultipleField(loader=None)
     comment = StringField('File Comment')