work around differences in handling of document types

This commit is contained in:
Frédéric Péters 2011-11-21 18:43:45 +01:00
parent dc2d148d3a
commit ee9030f5fc
1 changed files with 18 additions and 3 deletions

View File

@ -201,6 +201,21 @@ def possible_document_types(context):
terms.append(SimpleVocabulary.createTerm(doctype_id, doctype_id, doctype_str))
return SimpleVocabulary(terms)
def get_docdos_type_id(context, type_id):
if type_id in MAPPING.keys():
return type_id
catalog = getToolByName(context, 'portal_catalog')
possible_doctypes = catalog.uniqueValuesFor('doctype')
possible_dostypes = catalog.uniqueValuesFor('dostype')
for iter_type_id in (possible_dostypes + possible_doctypes):
if iter_type_id is None:
continue
rep_id = iter_type_id.encode('ascii', 'replace')
if type_id in (iter_type_id, rep_id):
return iter_type_id
return None
@grok.provider(IContextSourceBinder)
def possible_dossier_types(context):
catalog = getToolByName(context, 'portal_catalog')
@ -624,11 +639,11 @@ class SearchView(BrowserView):
kw['no'] = data.get('nodos')
if data.get('doctype'):
kw['doctype'] = possible_document_types(self.context).getTermByToken(data.get('doctype')).title
kw['doctype'] = get_docdos_type_id(self.context, data.get('doctype'))
if data.get('dostype'):
kw['dostype'] = possible_dossier_types(self.context).getTermByToken(data.get('dostype')).title
kw['dostype'] = get_docdos_type_id(self.context, data.get('dostype'))
if data.get('l_doctypes'):
kw['doctype'] = [possible_document_types(self.context).getTermByToken(x).title for x in data.get('l_doctypes')]
kw['doctype'] = [get_docdos_type_id(self.context, x) for x in data.get('l_doctypes')]
if data.get('start') and data.get('end'):
kw['dateDoc'] = {'query': [data.get('start'), data.get('end')], 'range': 'minmax'}