0

I'm trying to use ExtendedAutocompleteInputWidget from deform_ext_autocomplete so a widget will have autocomplete. The reason I want to use ExtendedAutocompleteInputWidget is so I can get key/display value pairs, where as the normal autocomplete only deals with the Display value.

Based on documentation for the widget, this is what I have so far:

In 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'],
    )

In 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

Unfortunately, I am getting errors:

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

Am I approaching trying to use the widget the wrong way?

I'm using Kotti 2.0.1.

Patrick Downey
  • 965
  • 8
  • 13
  • I can't find any examples/usage outside of the documentation. Also, I noticed something interesting. The 'delay' parameter isn't shown in the examples, but in __init__.py of deform.ext.autocomplete, it tests to see if delay is None. In this case, it assumes delay was passed in/exists in some form. – Patrick Downey Apr 12 '19 at 13:27
  • I think I identified the problem. I used pdb and found out in genericpath.py, its attempting to get the template from the wrong location. Its pointing to the templates folder in deform. So I have to figure out how I could correct that in my copy of the extended autocomplete. Also, reading up on the dates of the version numbers of deform vs the date of deform_ext_autocomplete, I don't believe this is entirely compatible with the version of Kotti I'm using. – Patrick Downey Apr 17 '19 at 10:27

0 Answers0