Esempio n. 1
0
    def updateObject(self, context, v):

        # Get the accessor object
        acc = IEventAccessor(context)

        # Establish the input arguments
        kwargs = self.getRequestDataAsArguments(v)

        # Pass the arguments into the object
        acc.edit(**kwargs)

        # Update any arguments that are not part of the default event schema
        acc.update(**kwargs)

        # Update complex fields (text, event agenda)
        self.updateComplexFields(acc.context, v)

        # Reindex the object
        acc.context.reindexObject()

        # Ref: http://docs.plone.org/external/plone.app.event/docs/development.html#accessing-event-objects-via-an-unified-accessor-object
        # Throw ObjectModifiedEvent after setting properties to call an event subscriber which does some timezone related post calculations
        notify(ObjectModifiedEvent(acc.context))

        # Return object that was updated
        return acc.context
Esempio n. 2
0
    def importContent(self):

        # Create new content importer object
        v = AtlasProductImporter(uid=self.uid, domain=self.domain)

        # Additional fields
        kwargs = {}

        # Add a Webinar Group
        webinar_group = self.addWebinarGroup(self.import_path, v, **kwargs)

        # Add the Webinar
        webinar = self.addWebinar(webinar_group, v,
                                  **kwargs)

        # Set the webinar start/end dates to publish date of imported object
        webinar_date_start = v.data.start
        webinar_date_start = DateTime(webinar_date_start).asdatetime()

        webinar_date_end = v.data.end
        webinar_date_end = DateTime(webinar_date_end).asdatetime()

        acc = IEventAccessor(webinar)
        acc.edit(start=webinar_date_start, end=webinar_date_end)
        acc.update(start=webinar_date_start, end=webinar_date_end)

        # Initialize webinar_url variable
        webinar_url = v.data.event_url

        # If we have a 'webinar_url', set that on the Webinar Product
        if webinar_url:
            acc.edit(webinar_url=webinar_url)
            acc.update(webinar_url=webinar_url)

        # Finalize items
        self.finalize(webinar)
        self.finalize(webinar_group)

        # Return JSON output
        return self.getJSON(webinar_group)
Esempio n. 3
0
    def importContent(self):

        # Create new content importer object
        v = AtlasProductImporter(uid=self.uid, domain=self.domain)

        # Additional fields
        kwargs = {}

        # Add a Webinar Group
        webinar_group = self.addWebinarGroup(self.import_path, v, **kwargs)

        # Add the Webinar
        webinar = self.addWebinar(webinar_group, v,
                                  **kwargs)

        # Set the webinar start/end dates to publish date of imported object
        webinar_date = v.data.effective
        webinar_date = DateTime(webinar_date).asdatetime()

        acc = IEventAccessor(webinar)
        acc.edit(start=webinar_date, end=webinar_date)
        acc.update(start=webinar_date, end=webinar_date)

        # Initialize webinar_url variable
        webinar_url = None

        # Add the Webinar Recording.  If we're a simple link, add the recording
        # with the link.  Otherwise, if it's a folder, cycle through the contents
        # and find links and files
        if v.data.type in ['Link',]:
            webinar_url = v.data.get_remote_url
            webinar_recording = self.addWebinarRecording(webinar, v,
                                                            webinar_recorded_url=webinar_url,
                                                            **kwargs)

        elif v.data.type in ['Folder',]:

            # Get contents data importer objects
            contents = [AtlasProductImporter(uid=x, domain=self.domain) for x in v.data.contents]

            # Get the link objects from the contents that have the webinar host in the URL
            webinar_links = [x for x in contents if x.data.type in ['Link',]]

            if webinar_links:

                # Only the first link matters
                _v = webinar_links[0]

                webinar_url = _v.data.get_remote_url

                webinar_recording = self.addWebinarRecording(webinar, v,
                                                             webinar_recorded_url=webinar_url,
                                                             **kwargs)

                # Get the files in the folder.  Assumption is that the first file is
                # the presentation, and the rest are handouts.
                webinar_files = [x for x in contents if x.data.type in ['File',]]

                webinar_presentations = webinar_files[0:1]
                webinar_handouts = webinar_files[1:]

                for _v in webinar_presentations:
                     item = self.addWebinarPresentation(webinar_recording, _v, **kwargs)

                for _v in webinar_handouts:
                     item = self.addWebinarHandout(webinar_recording, _v, **kwargs)

        # If we have a 'webinar_url', set that on the Webinar Product
        if webinar_url:
            acc.edit(webinar_url=webinar_url)
            acc.update(webinar_url=webinar_url)

        # Finalize items
        self.finalize(webinar)
        self.finalize(webinar_group)

        # Return JSON output
        return self.getJSON(webinar_group)
Esempio n. 4
0
    def importContent(self):

        # Create new content importer object
        v = AtlasProductImporter(uid=self.uid, domain=self.domain)

        # Additional fields
        kwargs = {}

        # Check for existing Workshop Group
        workshop_group = self.getWorkshopGroup(v.data.title)

        # If we found a Workshop Group, append this workshop's original Plone id
        # to it.
        if workshop_group:

            original_plone_ids = list(getattr(workshop_group, 'original_plone_ids', []))

            if v.data.uid not in original_plone_ids:
                original_plone_ids.append(v.data.uid)
                workshop_group.original_plone_ids = original_plone_ids
                workshop_group.reindexObject()

        # Add a Workshop Group if there isn't one
        else:
            workshop_group = self.addWorkshopGroup(self.import_path, v, **kwargs)

        # Get the location data from Google Maps integration
        location = v.data.location

        # Only attempt to look up location data if a location is provided.
        if location:

            # Use the LocationAdapter directly rather than ILocationMarker,
            # since the workshop is not created yet.
            adapted = LocationAdapter(None)
            geocode_data = adapted.geocode(location)

            # If the address lookup succeeded
            if geocode_data:

                # Get the venue, street_address, city, state, zip_code
                kwargs.update(adapted.get_address_fields(geocode_data))

                # Lat/LNG coordinates if they exist
                (lat, lng) = adapted.lookup_coords(geocode_data)

                if lat and lng:
                    kwargs['latitude'] = lat
                    kwargs['longitude'] = lng

            # Otherwise, push the provided location into the street_address field
            else:
                kwargs['street_address'] = location

        # Workshop Contact Info
        for (_old, _new) in [
            ('contact_name', 'registration_help_name'),
            ('contact_email', 'registration_help_email'),
            ('contact_phone', 'registration_help_phone'),
        ]:
            kwargs[_new] = getattr(v.data, _old)

        # Map Link
        kwargs['map_link'] = v.data.map_link

        # Add the Workshop
        workshop = self.addWorkshop(workshop_group, v,
                                  **kwargs)

        # Get the workshop start/end dates
        workshop_start_date = v.data.start
        workshop_start_date = DateTime(workshop_start_date).asdatetime()

        workshop_end_date = v.data.end
        workshop_end_date = DateTime(workshop_end_date).asdatetime()

        acc = IEventAccessor(workshop)
        acc.edit(start=workshop_start_date, end=workshop_end_date)
        acc.update(start=workshop_start_date, end=workshop_end_date)

        # Finalize items
        self.finalize(workshop)
        self.finalize(workshop_group)

        # Return JSON output
        return self.getJSON(workshop_group)