def more_occurrences_text(self): msgid = _( u"msg_num_more_occurrences", default=u"There are ${results} more occurrences.", mapping={u"results": self.num_more_occurrences}, ) return self.context.translate(msgid)
def validate_start_end(data): # data_postprocessing sets end=start if open_end if data.start > data.end and not data.open_end: raise StartBeforeEnd( _("error_end_must_be_after_start_date", default=u"End date must be after start date.") )
def handleSaveImport(self, action): data, errors = self.extractData() if errors: return False self.save_data(data) ical_file = data["ical_file"] ical_url = data["ical_url"] event_type = data["event_type"] sync_strategy = data["sync_strategy"] if ical_file or ical_url: if ical_file: # File upload is not saved in settings ical_resource = ical_file.data ical_import_from = ical_file.filename else: ical_resource = urllib2.urlopen(ical_url).read() ical_import_from = ical_url import_metadata = ical_import( self.context, ics_resource=ical_resource, event_type=event_type, sync_strategy=sync_strategy ) count = import_metadata["count"] IStatusMessage(self.request).addStatusMessage( _( "ical_import_imported", default=u"${num} events imported from ${filename}", mapping={"num": count, "filename": ical_import_from}, ), "info", ) else: IStatusMessage(self.request).addStatusMessage( _("ical_import_no_ics", default=u"Please provide either a icalendar ics file or a " u"URL to a file."), "error", ) self.request.response.redirect(self.context.absolute_url())
def handleSaveImport(self, action): data, errors = self.extractData() if errors: return False self.save_data(data) ical_file = data['ical_file'] ical_url = data['ical_url'] event_type = data['event_type'] sync_strategy = data['sync_strategy'] if ical_file or ical_url: if ical_file: # File upload is not saved in settings ical_resource = ical_file.data ical_import_from = ical_file.filename else: ical_resource = urllib2.urlopen(ical_url).read() ical_import_from = ical_url import_metadata = ical_import( self.context, ics_resource=ical_resource, event_type=event_type, sync_strategy=sync_strategy, ) count = import_metadata['count'] IStatusMessage(self.request).addStatusMessage( _('ical_import_imported', default=u"${num} events imported from ${filename}", mapping={'num': count, 'filename': ical_import_from}), 'info') else: IStatusMessage(self.request).addStatusMessage( _('ical_import_no_ics', default=u"Please provide either a icalendar ics file or a " u"URL to a file."), 'error') self.request.response.redirect(self.context.absolute_url())
def validate_start_end(data): if ( data.start and data.end and data.start > data.end and not data.open_end ): raise StartBeforeEnd( _("error_end_must_be_after_start_date", default=u"End date must be after start date.") )
def SynchronizationStrategies(context): """Vocabulary for icalendar synchronization strategies. SYNC_KEEP_NEWER: Import, if the imported event is modified after the existing one. SYNC_KEEP_MINE: On conflicts, just do nothing. SYNC_KEEP_THEIRS: On conflicts, update the existing event with the external one. SYNC_NONE: Don't synchronize but import events and create new ones, even if they already exist. For each one, create a new sync_uid. """ items = [ (_('sync_keep_newer', default="Keep newer"), base.SYNC_KEEP_NEWER), (_('sync_keep_mine', default="Keep mine"), base.SYNC_KEEP_MINE), (_('sync_keep_theirs', default="Keep theirs"), base.SYNC_KEEP_THEIRS), (_('sync_none', default="No Syncing"), base.SYNC_NONE), ] items = [SimpleTerm(title=i[0], value=i[1]) for i in items] return SimpleVocabulary(items)
def handleSave(self, action): data, errors = self.extractData() if errors: return False self.save_data(data) IStatusMessage(self.request).addStatusMessage( _("msg_ical_import_settings_saved", default=u"Ical import settings saved."), "info" ) self.request.response.redirect(self.context.absolute_url())
def __call__(self): cal = IICalendar(self.context) if not cal: return _(u'ical_view_no_events', default=u'No events found.') name = '%s.ics' % self.context.getId() self.request.RESPONSE.setHeader('Content-Type', 'text/calendar') self.request.RESPONSE.setHeader('Content-Disposition', 'attachment; filename="%s"' % name) # get iCal self.request.RESPONSE.write(cal.as_string().encode('utf-8'))
def __call__(self, request): rstartDate = request.form.get('startDate', None) rendDate = request.form.get('endDate', None) errors = {} if rstartDate: try: start = DateTime(rstartDate) except: errors['startDate'] = _(u'error_invalid_start_date', default=u'Start date is not valid.') else: start = self.context.start() openEnd = request.form.get('openEnd', False) if openEnd: # In case the event has an open end, enddate is set automatically # later and we need not check it return errors if rendDate: try: end = DateTime(rendDate) except: errors['endDate'] = _(u'error_invalid_end_date', default=u'End date is not valid.') else: end = self.context.end() if 'startDate' in errors or 'endDate' in errors: # No point in validating bad input return errors if start > end: errors['endDate'] = _( u'error_end_must_be_after_start_date', default=u'End date must be after start date.' ) return errors and errors or None
def Weekdays(context): """ Vocabulary for Weekdays. """ items =[(_(u"weekday-0", default=u"Monday"),'0'), (_(u"weekday-1", default=u"Tuesday"),'1'), (_(u"weekday-2", default=u"Wednesday"),'2'), (_(u"weekday-3", default=u"Thursday"),'3'), (_(u"weekday-4", default=u"Friday"),'4'), (_(u"weekday-5", default=u"Saturday"),'5'), (_(u"weekday-6", default=u"Sunday"),'6'), ] return SimpleVocabulary.fromItems(items)
def header_string(self): start, end = self._start_end start_dict = date_speller(self.context, start) if start else None end_dict = date_speller(self.context, end) if end else None mode = self.mode main_msgid = None sub_msgid = None if mode == 'all': main_msgid = _(u"all_events", default=u"All events") elif mode == 'past': main_msgid = _(u"past_events", default=u"Past events") elif mode == 'future': main_msgid = _(u"future_events", default=u"Future events") elif mode == 'now': main_msgid = _(u"todays_upcoming_events", default=u"Todays upcoming events") elif mode == 'today': main_msgid = _(u"todays_events", default=u"Todays events") elif mode == '7days': main_msgid = _(u"7days_events", default=u"Events in next 7 days.") sub_msgid = _( u"events_from_until", default=u"${from} until ${until}.", mapping={ 'from': "%s, %s. %s %s" % (start_dict['wkday'], start.day, start_dict['month'], start.year), 'until': "%s, %s. %s %s" % (end_dict['wkday'], end.day, end_dict['month'], end.year), }) elif mode == 'day': main_msgid = _(u"events_on_day", default=u"Events on ${day}", mapping={ 'day': "%s, %s. %s %s" % (start_dict['wkday'], start.day, start_dict['month'], start.year), }) elif mode == 'week': main_msgid = _(u"events_in_week", default=u"Events in week ${weeknumber}", mapping={'weeknumber': start.isocalendar()[1]}) sub_msgid = _( u"events_from_until", default=u"${from} until ${until}.", mapping={ 'from': "%s, %s. %s %s" % (start_dict['wkday'], start.day, start_dict['month'], start.year), 'until': "%s, %s. %s %s" % (end_dict['wkday'], end.day, end_dict['month'], end.year), }) elif mode == 'month': main_msgid = _(u"events_in_month", default=u"Events in ${month} ${year}", mapping={ 'month': start_dict['month'], 'year': start.year, }) trans = self.context.translate return { 'main': trans(main_msgid) if main_msgid else '', 'sub': trans(sub_msgid) if sub_msgid else '' }
def first_weekday_sun0(): return wkday_to_mon1(first_weekday()) ATEventSchema = ATContentTypeSchema.copy() + atapi.Schema(( atapi.DateTimeField('startDate', required=True, searchable=False, accessor='start', write_permission=ModifyPortalContent, default_method=default_start, languageIndependent=True, widget=DatetimeWidget( label=_( u'label_event_start', default=u'Event Starts' ), description=_( u'help_event_start', default=u"Date and Time, when the event begins." ), with_time=1, first_day=first_weekday_sun0, ), ), atapi.DateTimeField('endDate', required=True, searchable=False, accessor='end', write_permission=ModifyPortalContent,
def more_occurrences_text(self): msgid = _(u"msg_num_more_occurrences", default=u"There are ${results} more occurrences.", mapping={u"results": self.num_more_occurrences}) return self.context.translate(msgid)
class StartBeforeEnd(Invalid): __doc__ = _("error_invalid_date", default=u"Invalid start or end date")
def validate_start_end(data): # data_postprocessing sets end=start if open_end if data.start > data.end and not data.open_end: raise StartBeforeEnd( _("error_end_must_be_after_start_date", default=u"End date must be after start date."))
class IEventContact(model.Schema): """ Event Contact Schema. """ contact_name = schema.TextLine( title=_( u'label_event_contact_name', default=u'Contact Name' ), description=_( u'help_event_contact_name', default=u'Name of a person to contact about this event.' ), required=False, default=None ) directives.widget( 'contact_name', TextFieldWidget, klass=u'event_contact_name' ) contact_email = schema.TextLine( title=_( u'label_event_contact_email', default=u'Contact E-mail' ), description=_( u'help_event_contact_email', default=u'Email address to contact about this event.' ), required=False, default=None ) directives.widget( 'contact_email', TextFieldWidget, klass=u'event_contact_email' ) contact_phone = schema.TextLine( title=_( u'label_event_contact_phone', default=u'Contact Phone' ), description=_( u'help_event_contact_phone', default=u'Phone number to contact about this event.' ), required=False, default=None ) directives.widget( 'contact_phone', TextFieldWidget, klass=u'event_contact_phone' ) event_url = schema.URI( title=_( u'label_event_url', default=u'Event URL' ), description=_( u'help_event_url', default=u'Web address with more info about the event. ' u'Add http:// for external links.' ), required=False, default=None ) directives.widget( 'event_url', TextFieldWidget, klass=u'event_url' )
def validate_start_end(data): if data.start > data.end: raise StartBeforeEnd(_("exception_start_before_end_text", default=u"The start date must be before the\ end date."))
class IEventBasic(model.Schema, IDXEvent): """ Basic event schema. """ start = schema.Datetime( title=_( u'label_event_start', default=u'Event Starts' ), description=_( u'help_event_start', default=u'Date and Time, when the event begins.' ), required=True, defaultFactory=default_start ) directives.widget( 'start', DatetimeFieldWidget, default_timezone=default_timezone, klass=u'event_start' ) end = schema.Datetime( title=_( u'label_event_end', default=u'Event Ends' ), description=_( u'help_event_end', default=u'Date and Time, when the event ends.' ), required=True, defaultFactory=default_end ) directives.widget( 'end', DatetimeFieldWidget, default_timezone=default_timezone, klass=u'event_end' ) whole_day = schema.Bool( title=_( u'label_event_whole_day', default=u'Whole Day' ), description=_( u'help_event_whole_day', default=u'Event lasts whole day.' ), required=False, default=False ) directives.widget( 'whole_day', SingleCheckBoxFieldWidget, klass=u'event_whole_day' ) open_end = schema.Bool( title=_( u'label_event_open_end', default=u'Open End' ), description=_( u'help_event_open_end', default=u"This event is open ended." ), required=False, default=False ) directives.widget( 'open_end', SingleCheckBoxFieldWidget, klass=u'event_open_end' ) # icalendar event uid sync_uid = schema.TextLine(required=False) directives.mode(sync_uid='hidden') @invariant def validate_start_end(data): if ( data.start and data.end and data.start > data.end and not data.open_end ): raise StartBeforeEnd( _("error_end_must_be_after_start_date", default=u"End date must be after start date.") )
def title(self): return _(u"Events")
class EditForm(base.EditForm): schema = IEventsPortlet label = _(u"Edit Events Portlet") description = _(u"This portlet lists upcoming Events.")
def header_string(self): start, end = self._start_end start_dict = start and date_speller(self.context, start) or None end_dict = end and date_speller(self.context, end) or None mode = self.mode main_msgid = None sub_msgid = None if mode == 'all': main_msgid = _(u"all_events", default=u"All events") elif mode == 'past': main_msgid = _(u"past_events", default=u"Past events") elif mode == 'future': main_msgid = _(u"future_events", default=u"Future events") elif mode == 'now': main_msgid = _(u"todays_upcoming_events", default=u"Todays upcoming events") elif mode == 'today': main_msgid = _(u"todays_events", default=u"Todays events") elif mode == '7days': main_msgid = _(u"7days_events", default=u"Events in next 7 days.") sub_msgid = _(u"events_from_until", default=u"${from} until ${until}.", mapping={ 'from': "%s, %s. %s %s" % ( start_dict['wkday'], start.day, start_dict['month'], start.year), 'until': "%s, %s. %s %s" % ( end_dict['wkday'], end.day, end_dict['month'], end.year), } ) elif mode == 'day': main_msgid = _(u"events_on_day", default=u"Events on ${day}", mapping={ 'day': "%s, %s. %s %s" % ( start_dict['wkday'], start.day, start_dict['month'], start.year), } ) elif mode == 'week': main_msgid = _(u"events_in_week", default=u"Events in week ${weeknumber}", mapping={'weeknumber': start.isocalendar()[1]}) sub_msgid = _(u"events_from_until", default=u"${from} until ${until}.", mapping={ 'from': "%s, %s. %s %s" % ( start_dict['wkday'], start.day, start_dict['month'], start.year), 'until': "%s, %s. %s %s" % ( end_dict['wkday'], end.day, end_dict['month'], end.year), } ) elif mode == 'month': main_msgid = _(u"events_in_month", default=u"Events in ${month} ${year}", mapping={ 'month': start_dict['month'], 'year': start.year, } ) trans = self.context.translate return {'main': main_msgid and trans(main_msgid) or '', 'sub': sub_msgid and trans(sub_msgid) or ''}
class EditForm(base.EditForm): schema = ICalendarPortlet label = _(u"Edit Calendar Portlet") description = _(u"This portlet displays events in a calendar.")
def first_weekday_sun0(): return wkday_to_mon1(first_weekday()) ATEventSchema = ATContentTypeSchema.copy() + atapi.Schema( ( atapi.DateTimeField( "startDate", required=True, searchable=False, accessor="start", write_permission=ModifyPortalContent, default_method=default_start, languageIndependent=True, widget=DatetimeWidget( label=_(u"label_event_start", default=u"Event Starts"), description=_(u"help_event_start", default=u"Date and Time, when the event begins."), with_time=1, first_day=first_weekday_sun0, ), ), atapi.DateTimeField( "endDate", required=True, searchable=False, accessor="end", write_permission=ModifyPortalContent, default_method=default_end, languageIndependent=True, widget=DatetimeWidget( label=_(u"label_event_end", default=u"Event Ends"),
def first_weekday_sun0(): return wkday_to_mon1(first_weekday()) ATEventSchema = ATContentTypeSchema.copy() + atapi.Schema(( atapi.DateTimeField('startDate', required=True, searchable=False, accessor='start', write_permission=ModifyPortalContent, default_method=default_start, languageIndependent=True, widget=DatetimeWidget( label=_(u'label_event_start', default=u'Event Starts'), description=_(u'help_start', default=u"Date and Time, when the event begins."), with_time=1, first_day=first_weekday_sun0, ), ), atapi.DateTimeField('endDate', required=True, searchable=False, accessor='end', write_permission=ModifyPortalContent, default_method=default_end, languageIndependent=True, widget=DatetimeWidget(
def first_weekday_sun0(): return wkday_to_mon1(first_weekday()) ATEventSchema = ATContentTypeSchema.copy() + atapi.Schema(( atapi.DateTimeField( 'startDate', required=True, searchable=False, accessor='start', write_permission=ModifyPortalContent, default_method=default_start, languageIndependent=True, widget=DatetimeWidget( label=_(u'label_event_start', default=u'Event Starts'), description=_(u'help_event_start', default=u"Date and Time, when the event begins."), with_time=1, first_day=first_weekday_sun0, ), ), atapi.DateTimeField( 'endDate', required=True, searchable=False, accessor='end', write_permission=ModifyPortalContent, default_method=default_end, languageIndependent=True, widget=DatetimeWidget(
def validate_start_end(data): if data.start > data.end: raise StartBeforeEnd( _("error_end_must_be_after_start_date", default=u"End date must be after start date."))