def package_dict_save(pkg_dict, context):
    model = context['model']
    package = context.get('package')
    allow_partial_update = context.get('allow_partial_update', False)
    if package:
        pkg_dict['id'] = package.id
    Package = model.Package
    if ('metadata_created' in pkg_dict):
        del pkg_dict['metadata_created']
    if ('metadata_modified' in pkg_dict):
        del pkg_dict['metadata_modified']
    pkg = d.table_dict_save(pkg_dict, Package, context)
    if (not pkg.id):
        pkg.id = str(uuid.uuid4())
    package_resource_list_save(pkg_dict.get('resources'), pkg, context)
    package_tag_list_save(pkg_dict.get('tags'), pkg, context)
    package_membership_list_save(pkg_dict.get('groups'), pkg, context)
    if ('relationships_as_subject' in pkg_dict):
        subjects = pkg_dict.get('relationships_as_subject')
        relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
    if ('relationships_as_object' in pkg_dict):
        objects = pkg_dict.get('relationships_as_object')
        relationship_list_save(objects, pkg, 'relationships_as_object', context)
    extras = package_extras_save(pkg_dict.get('extras'), pkg, context)
    return pkg
def package_dict_save(pkg_dict, context):
    model = context['model']
    package = context.get('package')
    allow_partial_update = context.get('allow_partial_update', False)
    if package:
        pkg_dict['id'] = package.id
    Package = model.Package
    if ('metadata_created' in pkg_dict):
        del pkg_dict['metadata_created']
    if ('metadata_modified' in pkg_dict):
        del pkg_dict['metadata_modified']
    pkg = d.table_dict_save(pkg_dict, Package, context)
    if (not pkg.id):
        pkg.id = str(uuid.uuid4())
    package_resource_list_save(pkg_dict.get('resources'), pkg, context)
    package_tag_list_save(pkg_dict.get('tags'), pkg, context)
    package_membership_list_save(pkg_dict.get('groups'), pkg, context)
    if ('relationships_as_subject' in pkg_dict):
        subjects = pkg_dict.get('relationships_as_subject')
        relationship_list_save(subjects, pkg, 'relationships_as_subject', context)
    if ('relationships_as_object' in pkg_dict):
        objects = pkg_dict.get('relationships_as_object')
        relationship_list_save(objects, pkg, 'relationships_as_object', context)
    extras = package_extras_save(pkg_dict.get('extras'), pkg, context)
    return pkg