def add_and_refresh(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = _("Please correct the following errors before saving the form")
            return

        if data.has_key("calendar_urls"):
            urls = [v for v in data["calendar_urls"].split()]
            utils.fetch_calendars(self.context, self.request, urls)
        else:
            urls = []

        annotations = IAnnotations(self.context)
        annotations["slc.calendarfetcher-urls"] = urls
        addStatusMessage(self.request, "URLs Saved", type="info")
        self.request.response.redirect(self.context.REQUEST.get("URL"))
    def fetch_remote_calendars(self):
        """ Fetch all the calendars as specified in the current context.
        """
        messages = {}
        if not self.is_calendar_enhanced():
            return "Not an ICalendarEnhanced object"

        calendar = Acquisition.aq_inner(self.context)
        annotations = IAnnotations(calendar)
        urls = annotations.get("slc.calendarfetcher-urls", [])
        messages["/".join(calendar.getPhysicalPath())] = utils.fetch_calendars(calendar, self.request, urls)

        return messages
    def fetch_all_remote_calendars(self):
        """ Fetch all the calendars for every ICalendarEnhanced folder in the
            entire website.
        """
        messages = {}
        catalog = getToolByName(self.context, "portal_catalog")
        brains = catalog(object_provides="p4a.calendar.interfaces.ICalendarEnhanced")
        for brain in brains:
            calendar = brain.getObject()
            annotations = IAnnotations(calendar)
            urls = annotations.get("slc.calendarfetcher-urls", [])
            messages[brain.getURL()] = utils.fetch_calendars(calendar, self.request, urls)

        return messages