def resource_dict_save(res_dict, context):
    model = context['model']
    session = context['session']
    id = res_dict.get('id')
    obj = None
    if id:
        obj = session.query(model.Resource).get(id)
    if (not obj):
        new = True
        obj = model.Resource()
    else:
        new = False
    table = class_mapper(model.Resource).mapped_table
    fields = [field.name for field in table.c]
    new_extras = {}
    for (key, value) in res_dict.iteritems():
        if isinstance(value, list):
            continue
        if (key in ('extras', 'revision_timestamp', 'tracking_summary')):
            continue
        if (key in fields):
            if isinstance(getattr(obj, key), datetime.datetime):
                if (getattr(obj, key).isoformat() == value):
                    continue
                if ((key == 'last_modified') and (not new)):
                    obj.url_changed = True
            if ((key == 'url') and (not new) and (obj.url != value)):
                obj.url_changed = True
            setattr(obj, key, value)
        else:
            new_extras[key] = value
    obj.state = u'active'
    obj.extras = new_extras
    session.add(obj)
    return obj
def resource_dict_save(res_dict, context):
    model = context['model']
    session = context['session']
    id = res_dict.get('id')
    obj = None
    if id:
        obj = session.query(model.Resource).get(id)
    if (not obj):
        new = True
        obj = model.Resource()
    else:
        new = False
    table = class_mapper(model.Resource).mapped_table
    fields = [field.name for field in table.c]
    new_extras = {}
    for (key, value) in res_dict.iteritems():
        if isinstance(value, list):
            continue
        if (key in ('extras', 'revision_timestamp', 'tracking_summary')):
            continue
        if (key in fields):
            if isinstance(getattr(obj, key), datetime.datetime):
                if (getattr(obj, key).isoformat() == value):
                    continue
                if ((key == 'last_modified') and (not new)):
                    obj.url_changed = True
            if ((key == 'url') and (not new) and (obj.url != value)):
                obj.url_changed = True
            setattr(obj, key, value)
        else:
            new_extras[key] = value
    obj.state = u'active'
    obj.extras = new_extras
    session.add(obj)
    return obj