Esempio n. 1
0
def map_view(request, mapid, snapshot=None, layer_name=None,
             template='maps/map_view.html'):
    """
    The view that returns the map composer opened to
    the map with the given map ID.
    """
    map_obj = _resolve_map(
        request,
        mapid,
        'base.view_resourcebase',
        _PERMISSION_MSG_VIEW)

    if request.user != map_obj.owner and not request.user.is_superuser:
        savematrix(request=request, action='Map View Geoexplorer', resource=map_obj)

    if snapshot is None:
        config = map_obj.viewer_json(request)
    else:
        config = snapshot_config(snapshot, map_obj, request)

    if layer_name:
        config = add_layers_to_map_config(
            request, map_obj, (layer_name, ), False)

    return render(request, template, context={
        'config': json.dumps(config),
        'map': map_obj,
        'preview': getattr(
            settings,
            'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
            'geoext')
    })
Esempio n. 2
0
def map_detail(request, mapid, snapshot=None, template='maps/map_detail.html'):
    '''
    The view that show details of each map
    '''
    map_obj = _resolve_map(
        request,
        mapid,
        'base.view_resourcebase',
        _PERMISSION_MSG_VIEW)

    # Update count for popularity ranking,
    # but do not includes admins or resource owners
    if request.user != map_obj.owner and not request.user.is_superuser:
        Map.objects.filter(
            id=map_obj.id).update(
            popular_count=F('popular_count') + 1)
        savematrix(request=request, action='Map View Detail', resource=map_obj)

    if snapshot is None:
        config = map_obj.viewer_json(request)
    else:
        config = snapshot_config(snapshot, map_obj, request)

    config = json.dumps(config)
    layers = MapLayer.objects.filter(map=map_obj.id)
    links = map_obj.link_set.download()

    group = None
    if map_obj.group:
        try:
            group = GroupProfile.objects.get(slug=map_obj.group.name)
        except GroupProfile.DoesNotExist:
            group = None
    context_dict = {
        'config': config,
        'resource': map_obj,
        'group': group,
        'layers': layers,
        'perms_list': get_perms(request.user, map_obj.get_self_resource()),
        'permissions_json': _perms_info_json(map_obj),
        "documents": get_related_documents(map_obj),
        'links': links,
        'preview': getattr(
            settings,
            'GEONODE_CLIENT_LAYER_PREVIEW_LIBRARY',
            'geoext'),
        'crs': getattr(
            settings,
            'DEFAULT_MAP_CRS',
            'EPSG:3857')
    }

    if settings.SOCIAL_ORIGINS:
        context_dict["social_links"] = build_social_links(request, map_obj)

    return render(request, template, context=context_dict)
Esempio n. 3
0
def document_download(request, docid, basemodel=Document):
    document = get_object_or_404(basemodel, pk=docid)

    if request.user != document.owner and not request.user.is_superuser:
        savematrix(request=request,
                   action='Document Download',
                   resource=document)

    if settings.MONITORING_ENABLED and document:
        if hasattr(document, 'alternate'):
            request.add_resource('document', document.alternate)

    if not request.user.has_perm('base.download_resourcebase',
                                 obj=document.get_self_resource()):
        return HttpResponse(loader.render_to_string(
            '401.html',
            context={
                'error_message':
                _("You are not allowed to view this document.")
            },
            request=request),
                            status=401)
    return DownloadResponse(document.doc_file)
Esempio n. 4
0
def common(request):
	response = {}
	code = None
	flag = 'entireAfg'
	filterLock = None
	rawFilterLock = None
	kwarg = {}

	if 'page' not in request.GET:
		mutable = request.GET._mutable
		request.GET._mutable = True
		request.GET['page'] = 'baseline'
		request.GET._mutable = mutable

	if 'code' in request.GET:
		kwarg['areacode'] = code = request.GET['code'].strip()
		# kwarg['areatype'] = flag = 'currentProvince'

	if 'flag' in request.GET:
		filterLock = request.GET['filter']
		rawFilterLock = filterLock
		kwarg['areageom'] = filterLock = 'ST_GeomFromText(\''+filterLock+'\',4326)'
		# kwarg['areatype'] = flag = request.GET['flag']

	if 'pdf' in request.GET:
		# # mapCode = '700'
		# mapCode = settings.MATRIX_DEFAULT_MAP_CODE
		# try:
		# 	map_obj = _resolve_map(request, mapCode, 'base.view_resourcebase', _PERMISSION_MSG_VIEW)
		# except Exception as identifier:
		# 	print 'Warning: _resolve_map() failed using settings.MATRIX_DEFAULT_MAP_CODE'
		# else:
		# 	px = get_object_or_404(Profile, id=request.GET['user'])
		# 	queryset = matrix(user=px,resourceid=map_obj,action='Dashboard PDF '+request.GET['page'])
		# 	queryset.save()
		savematrix(request=request, action='Dashboard PDF %s'%(request.GET['page']))
	else:
		# # mapCode = '700'
		# mapCode = settings.MATRIX_DEFAULT_MAP_CODE
		# try:
		# 	map_obj = _resolve_map(request, mapCode, 'base.view_resourcebase', _PERMISSION_MSG_VIEW)
		# except Exception as identifier:
		# 	print 'Warning: _resolve_map() failed using settings.MATRIX_DEFAULT_MAP_CODE.'
		# else:
		# 	queryset = matrix(user=request.user,resourceid=map_obj,action='Dashboard '+request.GET['page'])
		# 	queryset.save()
		savematrix(request=request, action='Dashboard %s'%(request.GET['page']))

	page_name = request.GET['page']
	arg = [request]
	if page_name in ['accessibility', 'security']:
		arg = [request]
	page_name = 'avalancheforecast' if page_name == 'avalcheforecast' else page_name
	if page_name in ['drought']:
		if 'date' in request.GET:
			kwarg['date'] = request.GET.get('date')

	# get response data by importing module dynamically and run its dashboard functiion
	if page_name in DASHBOARD_META.get('DASHBOARD_TO_APP', {}).keys() \
	and DASHBOARD_META.get('DASHBOARD_TO_APP', {})[page_name] in DASHBOARD_META.get('DASHBOARD_APPS', []):

		# import module
		module = importlib.import_module('%s.views'%(DASHBOARD_META.get('DASHBOARD_TO_APP', {})[page_name]))
		# page_meta = dict_ext(module.get_dashboard_meta()).pathget('pagenames', page_name)

		# get dashboard meta info
		dashboard_meta = dict_ext(module.get_dashboard_meta())

		# get dashboard page meta info from dashboard meta
		page_meta = list_ext([v for v in dashboard_meta.pathget('pages') if v.get('name') == page_name]).get(0,dict_ext)

		# call dashboard page data retrieval function
		function_name = page_meta.get('function')
		response = dict_ext(getattr(module, function_name)(*arg, **kwarg) if function_name else {})

		response['dashboard_template'] = page_meta.get('template')
	# elif page_name == 'baseline':
	# 	response = dashboard_baseline(*arg, **kwarg)
	# 	response['dashboard_template'] = 'dash_baseline.html'
	# elif page_name == 'main':
	# 	response = getAllQuickOverview(*arg, **kwarg)
	# 	response['dashboard_template'] = 'dash_main.html'
	else:
		raise Http404("Dashboard page '%s' not found"%(request.GET['page']))

	# if request.GET['page'] == 'baseline':
	# 	response = getBaseline(request, filterLock, flag, code)
	# elif request.GET['page'] == 'floodforecast':
	# 	response = getFloodForecast(request, filterLock, flag, code)
	# elif request.GET['page'] == 'floodrisk':
	# 	response = getFloodRisk(request, filterLock, flag, code)
	# elif request.GET['page'] == 'avalancherisk':
	# 	response = getAvalancheRisk(request, filterLock, flag, code)
	# elif request.GET['page'] == 'avalcheforecast':
	# 	response = getAvalancheForecast(request, filterLock, flag, code)
	# elif request.GET['page'] == 'accessibility':
	# 	response = getAccessibility(request, rawFilterLock, flag, code)
	# elif request.GET['page'] == 'earthquake':
	# 	response = getEarthquake(request, filterLock, flag, code)
	# elif request.GET['page'] == 'security':
	# 	response = getSecurity(request, rawFilterLock, flag, code)
	# elif request.GET['page'] == 'landslide':
	# 	response = getLandslideRisk(request, filterLock, flag, code)
	# elif request.GET['page'] == 'main':
	# 	response = getQuickOverview(request, filterLock, flag, code)
	
	try:
		int(code)
		response['add_link_reporthub'] = '&code='+str(code) if 'code' in request.GET else ''
		response['add_link'] = ''
	except:
		response['add_link'] = '&code='+str(code) if 'code' in request.GET else ''	
		response['add_link_reporthub'] = ''
	
	# if 'code' in request.GET:
	# 	response['add_link'] = '&code='+str(code)

	response['checked'] = request.GET['_checked'].split(",") if '_checked' in request.GET else []
	# response['checked'] = []
	# if '_checked' in request.GET:
	# 	response['checked'] = request.GET['_checked'].split(",") 

	response['jsondata'] = json.dumps(response, cls=JSONEncoderCustom)

	return response
Esempio n. 5
0
def document_detail(request, docid, basemodel=Document):
    """
    The view that show details of each document
    """
    document = None
    try:
        document = _resolve_document(request,
                                     docid,
                                     'base.view_resourcebase',
                                     _PERMISSION_MSG_VIEW,
                                     basemodel=basemodel)

    except Http404:
        return HttpResponse(loader.render_to_string('404.html',
                                                    context={},
                                                    request=request),
                            status=404)

    except PermissionDenied:
        return HttpResponse(loader.render_to_string(
            '401.html',
            context={
                'error_message':
                _("You are not allowed to view this document.")
            },
            request=request),
                            status=403)

    if document is None:
        return HttpResponse('An unknown error has occured.',
                            content_type="text/plain",
                            status=401)

    else:
        related = get_related_resources(document)

        # Update count for popularity ranking,
        # but do not includes admins or resource owners
        if request.user != document.owner and not request.user.is_superuser:
            Document.objects.filter(id=document.id).update(
                popular_count=F('popular_count') + 1)
            savematrix(request=request,
                       action='Document View',
                       resource=document)

        metadata = document.link_set.metadata().filter(
            name__in=settings.DOWNLOAD_FORMATS_METADATA)

        group = None
        if document.group:
            try:
                group = GroupProfile.objects.get(slug=document.group.name)
            except GroupProfile.DoesNotExist:
                group = None
        preview_url = document.thumbnail_url.replace("-thumb", "-preview")
        context_dict = {
            'perms_list': get_perms(request.user,
                                    document.get_self_resource()),
            'permissions_json': _perms_info_json(document),
            'resource': document,
            'group': group,
            'metadata': metadata,
            'imgtypes': IMGTYPES,
            'preview_url': preview_url,
            'related': related
        }

        if settings.SOCIAL_ORIGINS:
            context_dict["social_links"] = build_social_links(
                request, document)

        if getattr(settings, 'EXIF_ENABLED', False):
            try:
                from geonode.contrib.exif.utils import exif_extract_dict
                exif = exif_extract_dict(document)
                if exif:
                    context_dict['exif_data'] = exif
            except BaseException:
                print "Exif extraction failed."

        return render(request,
                      "documents/document_detail.html",
                      context=context_dict)