mezzanine_events/event_import.py
def create_event(self, data, data_url, user):
        """
        Create an Event instance based on serialized data.
        The featured image will be retrieved from the original server
        and the EventDateTime instances will be attached.
        """
        converted = convert(data)
        items = deserialize("json", json.dumps([converted]), ignorenonexistent=True)
        event = list(items)[0].object
        event.id = None  # Ensure new event ID
        event.slug = event.generate_unique_slug()
        event.site_id = current_site_id()
        event.user = user

        if not event.location:
            event.location = data["fields"].get("location_title", "")

        # Get the original featured image and save it locally
        img_path = data["fields"].get("featured_image")
        if img_path:
            parts = urlparse(data_url)
            img_url = urljoin(parts.scheme + "://" + parts.hostname, "static/media/" + img_path)
            img_response = requests.get(img_url)
            if img_response.status_code == requests.codes.ok:
                _, filename = os.path.split(img_path)
                filepath = os.path.join("uploads", "events", unquote(filename))
                filepath = default_storage.save(filepath, ContentFile(img_response.content))
                event.featured_image = filepath

        # Discard all M2M data as it may cause integrity issues when saving
        event.m2m_data = {}
        # Commit the new event to the database (required before saving EventDateTimes)
        event.save()

        # Add EventDateTimes instances (for old Mezzanine Calendar objects)
        for dt in data.get("dateandtimes", []):
            dt = convert(dt)
            occ = deserialize("json", json.dumps([dt]), ignorenonexistent=True)
            occ = list(occ)[0].object
            occ.event = event
            occ.save()

        # Import occurrences (if available)
        for occ_data in data.get("occurrences", []):
            occ = occ_data["fields"].copy()
            occ.pop("event")
            event.occurrences.create(**occ)

        return event

        Create an Event instance based on serialized data.
        The featured image will be retrieved from the original server
        and the EventDateTime instances will be attached.
        
Create an Event instance based on serialized data.
The featured image will be retrieved from the original server
and the EventDateTime instances will be attached.
Create an Event instance based on serialized data . The featured image will be retrieved from the original server and the EventDateTime instances will be attached .
def create_event(self, data, data_url, user):
        converted = convert(data)
        items = deserialize("json", json.dumps([converted]), ignorenonexistent=True)
        event = list(items)[0].object
        event.id = None  
        event.slug = event.generate_unique_slug()
        event.site_id = current_site_id()
        event.user = user
        if not event.location:
            event.location = data["fields"].get("location_title", "")
        img_path = data["fields"].get("featured_image")
        if img_path:
            parts = urlparse(data_url)
            img_url = urljoin(parts.scheme + "://" + parts.hostname, "static/media/" + img_path)
            img_response = requests.get(img_url)
            if img_response.status_code == requests.codes.ok:
                _, filename = os.path.split(img_path)
                filepath = os.path.join("uploads", "events", unquote(filename))
                filepath = default_storage.save(filepath, ContentFile(img_response.content))
                event.featured_image = filepath
        event.m2m_data = {}
        event.save()
        for dt in data.get("dateandtimes", []):
            dt = convert(dt)
            occ = deserialize("json", json.dumps([dt]), ignorenonexistent=True)
            occ = list(occ)[0].object
            occ.event = event
            occ.save()
        for occ_data in data.get("occurrences", []):
            occ = occ_data["fields"].copy()
            occ.pop("event")
            event.occurrences.create(**occ)
        return event
def create_event ( self , data , data_url , user ) : converted = convert ( data ) items = deserialize ( "json" , json . dumps ( [ converted ] ) , ignorenonexistent = True ) event = list ( items ) [ 0 ] . object event . id = None event . slug = event . generate_unique_slug ( ) event . site_id = current_site_id ( ) event . user = user if not event . location : event . location = data [ "fields" ] . get ( "location_title" , "" ) img_path = data [ "fields" ] . get ( "featured_image" ) if img_path : parts = urlparse ( data_url ) img_url = urljoin ( parts . scheme + "://" + parts . hostname , "static/media/" + img_path ) img_response = requests . get ( img_url ) if img_response . status_code == requests . codes . ok : _ , filename = os . path . split ( img_path ) filepath = os . path . join ( "uploads" , "events" , unquote ( filename ) ) filepath = default_storage . save ( filepath , ContentFile ( img_response . content ) ) event . featured_image = filepath event . m2m_data = { } event . save ( ) for dt in data . get ( "dateandtimes" , [ ] ) : dt = convert ( dt ) occ = deserialize ( "json" , json . dumps ( [ dt ] ) , ignorenonexistent = True ) occ = list ( occ ) [ 0 ] . object occ . event = event occ . save ( ) for occ_data in data . get ( "occurrences" , [ ] ) : occ = occ_data [ "fields" ] . copy ( ) occ . pop ( "event" ) event . occurrences . create ( ** occ ) return event
Create an Event instance based on serialized data.
Create an Event instance based on serialized data .
"""
        Create an Event instance based on serialized data.
        The featured image will be retrieved from the original server
        and the EventDateTime instances will be attached.
        """ # Ensure new event ID # Get the original featured image and save it locally # Discard all M2M data as it may cause integrity issues when saving # Commit the new event to the database (required before saving EventDateTimes) # Add EventDateTimes instances (for old Mezzanine Calendar objects) # Import occurrences (if available)
self
data
data_url
user