human
Complete the below
def group_dictize(group, context, include_groups=True, include_tags=True, include_users=True, include_extras=True, packages_field='datasets', **kw):

    ''''Turns a Group object and related into a dictionary. The related objects
    like tags are included unless you specify it in the params.
    :param packages_field: determines the format of the `packages` field - can
    be `datasets`, `dataset_count` or None.'
    '''
assistant
#Here is the Python program you requested.
    assert (packages_field in ('datasets', 'dataset_count', None))
    if (packages_field == 'dataset_count'):
        dataset_counts = context.get('dataset_counts', None)
    result_dict = d.table_dictize(group, context)
    result_dict.update(kw)
    result_dict['display_name'] = (group.title or group.name)
    if include_extras:
        result_dict['extras'] = extras_dict_dictize(group._extras, context)
    context['with_capacity'] = True
    if packages_field:
        def get_packages_for_this_group(group_, just_the_count=False):
            q = {'facet': 'false', 'rows': 0}
            if group_.is_organization:
                q['fq'] = 'owner_org:"{0}"'.format(group_.id)
            else:
                q['fq'] = 'groups:"{0}"'.format(group_.name)
            if group_.is_organization:
                is_group_member = (context.get('user') and authz.has_user_permission_for_group_or_org(group_.id, context.get('user'), 'read'))
                if is_group_member:
                    q['include_private'] = True
            if (not just_the_count):
                try:
                    packages_limit = context['limits']['packages']
                except KeyError:
                    q['rows'] = 1000
                else:
                    q['rows'] = packages_limit
            search_context = dict(((k, v) for (k, v) in context.items() if (k != 'schema')))
            search_results = logic.get_action('package_search')(search_context, q)
            return (search_results['count'], search_results['results'])
        if (packages_field == 'datasets'):
            (package_count, packages) = get_packages_for_this_group(group)
            result_dict['packages'] = packages
        elif (dataset_counts is None):
            (package_count, packages) = get_packages_for_this_group(group, just_the_count=True)
        else:
            facets = dataset_counts
            if group.is_organization:
                package_count = facets['owner_org'].get(group.id, 0)
            else:
               ...