def __call__(self, context): """Build a vocabulary of event types. """ items = [ SimpleTerm(0, 0, _(u'All Events')), SimpleTerm(1, 1, _(u'Seminar')), SimpleTerm(2, 2, _(u'Distance Learning')), SimpleTerm(3, 3, _(u'CBT/WBT/E-Learning')), ] return SimpleVocabulary(items)
def __call__(self, context): """Build a vocabulary of sort options. """ items = [ SimpleTerm('Treffergenauigkeit', 'Treffergenauigkeit', _(u'Treffergenauigkeit')), SimpleTerm('city', 'city', _(u'Ort')), SimpleTerm('zip', 'zip', _(u'PLZ')), SimpleTerm('startTime', 'startTime', _(u'Datum')), ] return SimpleVocabulary(items)
def __call__(self, context): """Build a vocabulary of sort options. """ items = [ SimpleTerm( 'Treffergenauigkeit', 'Treffergenauigkeit', _(u'Treffergenauigkeit') ), SimpleTerm('city', 'city', _(u'Ort')), SimpleTerm('zip', 'zip', _(u'PLZ')), SimpleTerm('startTime', 'startTime', _(u'Datum')), ] return SimpleVocabulary(items)
def events(self): """Get the events for the provided parameters using the IIWWBSearcher utility. """ if self.form_instance.status: return [] # don't do anything if there were validation errors querydict = self._construct_query() results = [] try: searcher = getUtility(IIWWBSearcher) if querydict: results = searcher.get_results(querydict) except: IStatusMessage(self.request).addStatusMessage( u"An error occured while fetching results. Please try again " "later.", type="error") logger.exception('Error fetching results') if not results: IStatusMessage(self.request).addStatusMessage( _('No events found.'), type="info") return results
def check_enough_data_provided(obj): """Check that the user has provided enough data to perform the query. """ if not (obj.query or obj.zipcity or obj.startDate or obj.county): raise Invalid( _( "You have to fill out at least one of required " "fields: Keywords, Zip code or city, Event Start, County" ) )
class ListEventsForm(form.Form): """The List Events search form based on z3c.form.""" fields = field.Fields(IListEventsForm) fields['startDate'].widgetFactory = DateFieldWidget label = _(u"List Events") # don't try to read Plone root for form fields data, this is only mostly # usable for edit forms, where you have an actual context ignoreContext = True def updateWidgets(self): """Move fields' descriptions to title attrs of HTML form elements. This way fields' descriptions are displayed as tooltip text, making the UI a bit more classy. Also, set a custom widget template for the zipcity field that displays a link to the zip code picker. And set the default date of startDate to today. Necessary, since the setting done in the schema will stay on the day Zope was started. """ self.fields['startDate'].field.default = date.today() super(ListEventsForm, self).updateWidgets() for name, widget in self.widgets.items(): widget.title = widget.field.description self.widgets['zipcity'].template = ViewPageTemplateFile("zipcode.pt") @button.buttonAndHandler(_(u"List Events")) def list_events(self, action): """Submit button handler.""" data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return @button.buttonAndHandler(_(u"Reset")) def reset_form(self, action): """Cancel button handler.""" url = self.request['URL'] self.request.response.redirect(url)
# -*- coding: utf-8 -*- """Definitions of vocabularies.""" from iwwb.eventlist import _ from zope.interface import implements from zope.schema.interfaces import IVocabularyFactory from zope.schema.vocabulary import SimpleTerm from zope.schema.vocabulary import SimpleVocabulary COUNTIES = dict( alle=_(u'no_selection', default=u'No selection'), baw=u'Baden-Württemberg', bay=u'Bayern', bln=u'Berlin', bra=u'Brandenburg', bre=u'Bremen', hh=u'Hamburg', hes=u'Hessen', mvp=u'Mecklenburg-Vorpommern', nds=u'Niedersachsen', nrw=u'Nordrhein-Westfalen', rpf=u'Rheinland-Pfalz', saa=u'Saarland', sac=u'Sachsen', san=u'Sachsen-Anhalt', slh=u'Schleswig-Holstein', thu=u'Thüringen', ) class CountiesVocabulary(object):
def check_enough_data_provided(obj): """Check that the user has provided enough data to perform the query. """ if not (obj.query or obj.zipcity or obj.startDate or obj.county): raise Invalid(_("You have to fill out at least one of required " \ "fields: Keywords, Zip code or city, Event Start, County"))
class IListEventsForm(Interface): """Field definition for List Events form.""" query = schema.TextLine( title=_(u'Keywords'), description=_(u'Enter the search keywords. Examples: Seminar, Excel, ' 'Berlin, etc.'), required=False, ) allwords = schema.Bool( title=_(u'All words'), description=_(u'If you tick this checkbox, only courses that match ' 'all keywords you enter will be displayed.'), required=False, default=True, ) startDate = schema.Date( title=_(u'Course Start'), description=_(u'Select the date when the course should start'), required=False, default=date.today(), constraint=check_year_constraint, ) county = schema.Choice( title=_(u'County'), description=_(u'By selecting a county you can limit the courses found ' 'to those that take place in that county.'), vocabulary='iwwb.eventlist.vocabularies.Counties', required=False, default='alle', ) zipcity = schema.TextLine( title=_(u'Zip or City'), description=_(u'Enter the zip code or city.'), required=False, ) type = schema.Choice( title=_(u'Event type'), description=_(u'Select the event type.'), vocabulary='iwwb.eventlist.vocabularies.EventTypes', required=False, default=0, ) startTimeRequired = schema.Bool( title=_(u'Exclude events without dates'), description=_(u'If the event does not have the date information it ' 'will not be listed.'), required=False, default=True, ) @invariant def check_enough_data_provided(obj): """Check that the user has provided enough data to perform the query. """ if not (obj.query or obj.zipcity or obj.startDate or obj.county): raise Invalid(_("You have to fill out at least one of required " \ "fields: Keywords, Zip code or city, Event Start, County"))