Kotti / deform_ext_autocomplete - Как я могу использовать ExtendedAutocompleteInputWidget в Kotti? - PullRequest
0 голосов
/ 08 апреля 2019

Я пытаюсь использовать ExtendedAutocompleteInputWidget из deform_ext_autocomplete, чтобы виджет имел автозаполнение. Причина, по которой я хочу использовать ExtendedAutocompleteInputWidget, заключается в том, что я могу получить пары ключ / отображаемое значение, где обычное автозаполнение имеет дело только с отображаемым значением.

Основываясь на документации для виджета , это то, что у меня до сих пор:

В my_project / resources.py:

class MyContent(Content):
    id = Column(Integer(), ForeignKey('contents.id'), primary_key=True)
    person = Column(Unicode())


    type_info = Content.type_info.copy(
        name=u'MyContent',
        title=u'MyContent',
        add_view=u'add_mycontent',
        addable_to=[u'Document'],
    )

В my_project / views / edit.py:

PERSONS = {'jhendrix': 'Jimi Hendrix',
           'jpage': 'Jimmy Page',
           'jbonham': 'John Bonham',
           'bcobham': 'Billy Cobham'}

def display_value(field, person_id):
    return PERSONS.get(person_id, '')

class MyContentSchema(ContentSchema):

    title = colander.SchemaNode(
        colander.String(),
        title=_(u'Title'),
    )

    person = colander.SchemaNode(
                 colander.String(),
                 widget=ExtendedAutocompleteInputWidget(
                     display_value = display_value,
                     delay=3,
                     values="/ajax_search"))


@view_config(name='edit',context=MyContent,permission='edit',
             renderer='kotti:templates/edit/node.pt')
class MyContentEditForm(EditFormView):
    schema_factory = MyContentSchema


@view_config(name=MyContent.type_info.add_view, permission='add',
             renderer='kotti:templates/edit/node.pt')
class MyContentAddForm(AddFormView):
    schema_factory=MyContentSchema
    add = MyContent
    item_type = u"MyContent"

@view_config(name='ajax_search',renderer='json')
def ajax_search(request):
    term = request.GET['term'].lower()
    res = []
    for person_id, name in PERSONS.items():
        if term not in name.lower():
            continue
        res.append({'displayed':name,
                    'stored':person_id,
                  })
    return res

К сожалению, я получаю ошибки:

pyramid.httpexceptions.HTTPNotFound: The resource could not be found.

During handling of the above exception, another exception occurred:

deform.exception.TemplateError: deform.exception.TemplateError: ext_autocomplete_input.pt

 - Expression: "field.serialize(cstruct).strip()"
 - Filename:   ... python3.5/site-packages/deform/templates/mapping_item.pt
 - Location:   (line 29: col 34)
 - Source:     ... place="structure field.serialize(cstruct).strip()"
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Expression: "child.render_template(item_template)"
 - Filename:   ... ite/lib/python3.5/site-packages/deform/templates/form.pt
 - Location:   (line 47: col 32)
 - Source:     ... ace="structure child.render_template(item_template)"/>
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  target_language: <NoneType - at 0xa40040>
               field: <Field - at 0x7f2fc9b234a8>
               category: default
               cstruct: <_null - at 0x7f2fcd643c50>
               repeat: {...} (0)
               error_class: error
               description: 
               input_append: <NoneType - at 0xa40040>
               structural: False
               input_prepend: <NoneType - at 0xa40040>
               hidden: False
               title: Person
               required: True
               oid: deformField4

Я пытаюсь использовать виджет неправильно?

Я использую Kotti 2.0.1.

...