diff --git a/tabellio/searchform/form.py b/tabellio/searchform/form.py index caa175b..7697a11 100644 --- a/tabellio/searchform/form.py +++ b/tabellio/searchform/form.py @@ -348,6 +348,26 @@ def possible_topics(context): terms.append(SimpleVocabulary.createTerm(topic_id, topic_id, topic_str)) return SimpleVocabulary(terms) + +@grok.provider(IContextSourceBinder) +def possible_sort_options(context): + terms = [] + terms.append(SimpleVocabulary.createTerm('session', 'session', _('Session'))) + terms.append(SimpleVocabulary.createTerm('type', 'type', _('Type'))) + terms.append(SimpleVocabulary.createTerm('number', 'number', _('Number'))) + return SimpleVocabulary(terms) + + +@grok.provider(IContextSourceBinder) +def possible_sort_options_2(context): + terms = [] + terms.append(SimpleVocabulary.createTerm('session', 'session', _('Session'))) + terms.append(SimpleVocabulary.createTerm('type', 'type', _('Type'))) + return SimpleVocabulary(terms) + + + + class IDocumentSearch(interface.Interface): search_type_is_document = schema.TextLine(title=u'Search Type', default=u'1', required=False) nodoc = schema.TextLine(title=_(u'Dossier Number'), required=False) @@ -371,8 +391,7 @@ class IDocumentSearch(interface.Interface): end = schema.Date(title=_(u'Document End Date'), required=False) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type'), _(u'Number')]) + default='session', source=possible_sort_options) class DocumentSearchForm(form.Form): @@ -420,8 +439,7 @@ class IDossierSearch(interface.Interface): end = schema.Date(title=_(u'Dossier End Date'), required=False) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type'), _(u'Number')]) + default='session', source=possible_sort_options) class DossierSearchForm(form.Form): @@ -466,8 +484,7 @@ class IQuestionSearch(interface.Interface): end = schema.Date(title=_(u'Question End Date'), required=False) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type')]) + default='session', source=possible_sort_options_2) class QuestionSearchForm(form.Form): @@ -506,8 +523,7 @@ class IQuestionPfbSearch(interface.Interface): end = schema.Date(title=_(u'Question End Date'), required=False) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type')]) + default='session', source=possible_sort_options_2) class QuestionPfbSearchForm(form.Form): prefix = 'question' @@ -549,8 +565,7 @@ class IDocumentPfbSearch(interface.Interface): end = schema.Date(title=_(u'Document End Date'), required=False) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type'), _(u'Number')]) + default='session', source=possible_sort_options) class DocumentPfbSearchForm(form.Form): @@ -596,8 +611,7 @@ class IAdoptedDocumentPfbSearch(interface.Interface): adopted = schema.Bool(title=_(u'Limit to adopted'), required=False, default=True) sort_on = schema.Choice(title=_(u'Sort By'), required=True, - default=_(u'Session'), - values=[_(u'Session'), _(u'Type'), _(u'Number')]) + default='session', source=possible_sort_options) class AdoptedDocumentPfbSearchForm(form.Form): @@ -716,8 +730,7 @@ class IGlobalSearchForm(interface.Interface): source=possible_topics)); sort_on = schema.Choice(title=_(u'Sort By'), required=False, - default=_(u'Type'), - values=[_(u'Type'), _(u'Number'), _(u'Session')]) + default='type', source=possible_sort_options) class GlobalSearchForm(form.Form): @@ -874,8 +887,8 @@ class SearchView(BrowserView): elif data.get('search_type_is_question'): kw['portal_type'] = 'tabellio.documents.question' - cmp_function = None - if data.get('sort_on') == 'Type': + cmp_function = cmpfunctions.Cmp().cmp_session + if data.get('sort_on') == 'type': if data.get('search_type_is_document'): cmp_function = cmpfunctions.Cmp().cmp_doctype elif data.get('search_type_is_adopteddocument'): @@ -884,14 +897,14 @@ class SearchView(BrowserView): cmp_function = cmpfunctions.Cmp().cmp_dostype elif data.get('search_type_is_question'): cmp_function = cmpfunctions.Cmp().cmp_questype - elif data.get('sort_on') == 'Number': + elif data.get('sort_on') == 'number': cmp_function = cmpfunctions.Cmp().cmp_number - elif data.get('sort_on') == 'Session': + elif data.get('sort_on') == 'session': cmp_function = cmpfunctions.Cmp().cmp_session catalog = getToolByName(self.context, 'portal_catalog') print 'kw:', kw - log.info('Performing search (%r)' % kw) + log.info('Performing search (%r) (%r)' % (kw, cmp_function)) return sorted(catalog(**kw), cmp_function) def deputy_search_form(self):