mezzanine_events/utils.py
def convert(obj):
    """
    Convert a single Mezzanine Calendar object into Mezzanine Events
    """

    def map_fields(fields, new_fields):
        for new_field in new_fields:
            old_field = new_field

            # Handle renamed fields
            if isinstance(new_field, tuple):
                new_field, old_field = new_field

            try:
                yield (new_field, fields[old_field])
            except KeyError:
                continue

    def combine_dt(d, t):
        """
        Combine naive date and time into an aware datetime
        """
        if not isinstance(d, date):
            d = datetime.strptime(d, "%Y-%m-%d").date()
        if not isinstance(t, time):
            t = datetime.strptime(t, "%H:%M:%S").time()
        return make_aware(datetime.combine(d, t))

    # Event
    if obj["model"] == "mezzanine_calendar.event":
        return {
            "model": "mezzanine_events.event",
            "pk": obj["pk"],
            "fields": dict(map_fields(obj["fields"], EVENT_FIELDS)),
        }

    # EventDateTime (renamed to Occurrence)
    elif obj["model"] == "mezzanine_calendar.eventdatetime":
        f = obj["fields"]
        fields = dict(map_fields(f, OCCURRENCE_FIELDS))

        start = combine_dt(f["day"], f["start_time"] or datetime.min.time())
        fields["start"] = start.isoformat()

        fields["end"] = None
        if f["end_time"] is not None:
            end = combine_dt(f["day"], f["end_time"])
            fields["end"] = end.isoformat()

        return {"model": "mezzanine_events.occurrence", "pk": obj["pk"], "fields": fields}

    # EventCategory
    elif obj["model"] == "mezzanine_calendar.eventcategory":
        fields = dict(map_fields(obj["fields"], CATEGORY_FIELDS))
        fields["order"] = None
        return {"model": "mezzanine_events.eventcategory", "pk": obj["pk"], "fields": fields}

    # Let everything else go through unchanged
    return obj

    Convert a single Mezzanine Calendar object into Mezzanine Events
    
Convert a single Mezzanine Calendar object into Mezzanine Events
Convert a single Mezzanine Calendar object into Mezzanine Events
def convert(obj):
    def map_fields(fields, new_fields):
        for new_field in new_fields:
            old_field = new_field
            if isinstance(new_field, tuple):
                new_field, old_field = new_field
            try:
                yield (new_field, fields[old_field])
            except KeyError:
                continue
    def combine_dt(d, t):
        if not isinstance(d, date):
            d = datetime.strptime(d, "%Y-%m-%d").date()
        if not isinstance(t, time):
            t = datetime.strptime(t, "%H:%M:%S").time()
        return make_aware(datetime.combine(d, t))
    if obj["model"] == "mezzanine_calendar.event":
        return {
            "model": "mezzanine_events.event",
            "pk": obj["pk"],
            "fields": dict(map_fields(obj["fields"], EVENT_FIELDS)),
        }
    DateTime (renamed to Occurrence)
    elif obj["model"] == "mezzanine_calendar.eventdatetime":
        f = obj["fields"]
        fields = dict(map_fields(f, OCCURRENCE_FIELDS))
        start = combine_dt(f["day"], f["start_time"] or datetime.min.time())
        fields["start"] = start.isoformat()
        fields["end"] = None
        if f["end_time"] is not None:
            end = combine_dt(f["day"], f["end_time"])
            fields["end"] = end.isoformat()
        return {"model": "mezzanine_events.occurrence", "pk": obj["pk"], "fields": fields}
    Category
    elif obj["model"] == "mezzanine_calendar.eventcategory":
        fields = dict(map_fields(obj["fields"], CATEGORY_FIELDS))
        fields["order"] = None
        return {"model": "mezzanine_events.eventcategory", "pk": obj["pk"], "fields": fields}
    return obj
def convert ( obj ) : def map_fields ( fields , new_fields ) : for new_field in new_fields : old_field = new_field if isinstance ( new_field , tuple ) : new_field , old_field = new_field try : yield ( new_field , fields [ old_field ] ) except KeyError : continue def combine_dt ( d , t ) : """
        Combine naive date and time into an aware datetime
        """ if not isinstance ( d , date ) : d = datetime . strptime ( d , "%Y-%m-%d" ) . date ( ) if not isinstance ( t , time ) : t = datetime . strptime ( t , "%H:%M:%S" ) . time ( ) return make_aware ( datetime . combine ( d , t ) ) if obj [ "model" ] == "mezzanine_calendar.event" : return { "model" : "mezzanine_events.event" , "pk" : obj [ "pk" ] , "fields" : dict ( map_fields ( obj [ "fields" ] , EVENT_FIELDS ) ) , } elif obj [ "model" ] == "mezzanine_calendar.eventdatetime" : f = obj [ "fields" ] fields = dict ( map_fields ( f , OCCURRENCE_FIELDS ) ) start = combine_dt ( f [ "day" ] , f [ "start_time" ] or datetime . min . time ( ) ) fields [ "start" ] = start . isoformat ( ) fields [ "end" ] = None if f [ "end_time" ] is not None : end = combine_dt ( f [ "day" ] , f [ "end_time" ] ) fields [ "end" ] = end . isoformat ( ) return { "model" : "mezzanine_events.occurrence" , "pk" : obj [ "pk" ] , "fields" : fields } elif obj [ "model" ] == "mezzanine_calendar.eventcategory" : fields = dict ( map_fields ( obj [ "fields" ] , CATEGORY_FIELDS ) ) fields [ "order" ] = None return { "model" : "mezzanine_events.eventcategory" , "pk" : obj [ "pk" ] , "fields" : fields } return obj
Convert a single Mezzanine Calendar object into Mezzanine Events
Convert a single Mezzanine Calendar object into Mezzanine Events
"""
    Convert a single Mezzanine Calendar object into Mezzanine Events
    """ # Handle renamed fields """
        Combine naive date and time into an aware datetime
        """ # Event # EventDateTime (renamed to Occurrence) # EventCategory # Let everything else go through unchanged
obj