human
Complete this python program:
def map_download(request, mapid, template='maps/map_download.html'):
assistant
#Here is the Python code you requested.

    """Download all the layers of a map as a batch
    XXX To do, remove layer status once progress id done
    This should be fix because
    """
    map_obj = _resolve_map(request, mapid, 'base.download_resourcebase', _PERMISSION_MSG_VIEW)
    map_status = dict()
    if (request.method == 'POST'):
        url = ('%srest/process/batchDownload/launch/' % ogc_server_settings.LOCATION)
        def perm_filter(layer):
            return request.user.has_perm('base.view_resourcebase', obj=layer.get_self_resource())
        mapJson = map_obj.json(perm_filter)
        j_map = json.loads(mapJson)
        j_layers = j_map['layers']
        for j_layer in j_layers:
            if (j_layer['service'] is None):
                j_layers.remove(j_layer)
                continue
            if (len([l for l in j_layers if (l == j_layer)]) > 1):
                j_layers.remove(j_layer)
        mapJson = json.dumps(j_map)
        (resp, content) = http_client.request(url, 'POST', body=mapJson)
        status = int(resp.status)
        if (status == 200):
            map_status = json.loads(content)
            request.session['map_status'] = map_status
        else:
            raise Exception(('Could    not    start    the    download    of    %s.    Error    was:    %s' % (map_obj.title, content)))
    locked_layers = []
    remote_layers = []
    downloadable_layers = []
    for lyr in map_obj.layer_set.all():
        if (lyr.group != 'background'):
            if (not lyr.local):
                remote_layers.append(lyr)
            else:
                ownable_layer = Layer.objects.get(alternate=lyr.name)
                if (not request.user.has_perm('download_resourcebase', obj=ownable_layer.get_self_resource())):
                    locked_layers.append(lyr)
                elif (len([l for l in downloadable_layers if (l.name == lyr.name)]) == 0):
                    downloadable_layers.append(lyr)
    return render_to_response(template, RequestContext(request, {'geoserver': ogc_server_settings.PUBLIC_LOCATION, 'map_status': map_status, 'map': map_obj, 'locked_layers': locked_layers, 'remote_layers': remote_layers, 'downloadable_layers': downloadable_layers,...