def group_dict_save(group_dict, context, prevent_packages_update=False):
    from ckan.lib.search import rebuild
    model = context['model']
    session = context['session']
    group = context.get('group')
    allow_partial_update = context.get('allow_partial_update', False)
    Group = model.Group
    if group:
        group_dict['id'] = group.id
    group = d.table_dict_save(group_dict, Group, context)
    if (not group.id):
        group.id = str(uuid.uuid4())
    context['group'] = group
    if (not prevent_packages_update):
        pkgs_edited = group_member_save(context, group_dict, 'packages')
    else:
        pkgs_edited = {'added': [], 'removed': []}
    group_users_changed = group_member_save(context, group_dict, 'users')
    group_groups_changed = group_member_save(context, group_dict, 'groups')
    group_tags_changed = group_member_save(context, group_dict, 'tags')
    log.debug('Group save membership changes - Packages: %r  Users: %r  Groups: %r  Tags: %r', pkgs_edited, group_users_changed, group_groups_changed, group_tags_changed)
    extras = group_extras_save(group_dict.get('extras', {}), context)
    if (extras or (not allow_partial_update)):
        old_extras = set(group.extras.keys())
        new_extras = set(extras.keys())
        for key in (old_extras - new_extras):
            del group.extras[key]
        for key in new_extras:
            group.extras[key] = extras[key]
    package_ids = pkgs_edited['removed']
    package_ids.extend(pkgs_edited['added'])
    if package_ids:
        session.commit()
        map(rebuild, package_ids)
    return group
def group_dict_save(group_dict, context, prevent_packages_update=False):
    from ckan.lib.search import rebuild
    model = context['model']
    session = context['session']
    group = context.get('group')
    allow_partial_update = context.get('allow_partial_update', False)
    Group = model.Group
    if group:
        group_dict['id'] = group.id
    group = d.table_dict_save(group_dict, Group, context)
    if (not group.id):
        group.id = str(uuid.uuid4())
    context['group'] = group
    if (not prevent_packages_update):
        pkgs_edited = group_member_save(context, group_dict, 'packages')
    else:
        pkgs_edited = {'added': [], 'removed': []}
    group_users_changed = group_member_save(context, group_dict, 'users')
    group_groups_changed = group_member_save(context, group_dict, 'groups')
    group_tags_changed = group_member_save(context, group_dict, 'tags')
    log.debug('Group save membership changes - Packages: %r  Users: %r  Groups: %r  Tags: %r', pkgs_edited, group_users_changed, group_groups_changed, group_tags_changed)
    extras = group_extras_save(group_dict.get('extras', {}), context)
    if (extras or (not allow_partial_update)):
        old_extras = set(group.extras.keys())
        new_extras = set(extras.keys())
        for key in (old_extras - new_extras):
            del group.extras[key]
        for key in new_extras:
            group.extras[key] = extras[key]
    package_ids = pkgs_edited['removed']
    package_ids.extend(pkgs_edited['added'])
    if package_ids:
        session.commit()
        map(rebuild, package_ids)
    return group