コード例 #1
0
ファイル: views.py プロジェクト: lizardsystem/lizard-portal
def application(request, application_name, active_tab_name):
    """
        returns html page which loads specified (ext-js) application
    """
    context = '{}'
    user = request.user

    if user.is_authenticated():
        if user.iprangelogin_set.all().count() > 0:
            session_key = request.session.session_key
            try:
                context_store = user.sessioncontextstore_set.get(
                    session_key=session_key)
                context = context_store.context
            except SessionContextStore.DoesNotExist:
                pass
        else:
            try:
                context = user.usercontextstore.context
            except UserContextStore.DoesNotExist:
                pass

        perms_list = get_user_permissions_overall(user, 'user')

        perms = dict(get_user_permissions_overall(user, 'user', as_list=True))
    else:
        perms = {}
        perms_list = []

    try:
        extent_wgs = Area.objects.all().extent()
        wkt = 'LINESTRING(%f %f,%f %f)' % extent_wgs

        geom = GEOSGeometry(wkt, 4326)
        extent = geom.transform(900913, clone=True).extent
    except:
        #if getting extent failed (no areas or so) use default
        extent = (479517, 6799646, 584302, 7016613)

    t = get_template('application/' + application_name + '.js')
    c = RequestContext(request, {
            'application': application_name,
            'active_tab': active_tab_name,
            'context': context,
            'permission_list': perms_list,
            'perm': perms,
            'ftp_url': get_ftp_url(),
            'extent': ','.join(['%.0f' % value for value in  extent])
        })

    return HttpResponse(t.render(c),
        mimetype='text/javascript')
コード例 #2
0
ファイル: views.py プロジェクト: swinkels/lizard-portal
def application(request, application_name, active_tab_name):
    """
        returns html page which loads specified (ext-js) application
    """
    context = "{}"
    user = request.user

    if user.is_authenticated():
        if user.iprangelogin_set.all().count() > 0:
            session_key = request.session.session_key
            try:
                context_store = user.sessioncontextstore_set.get(session_key=session_key)
                context = context_store.context
            except SessionContextStore.DoesNotExist:
                pass
        else:
            try:
                context = user.usercontextstore.context
            except UserContextStore.DoesNotExist:
                pass

        perms_list = get_user_permissions_overall(user, "user")

        perms = dict(get_user_permissions_overall(user, "user", as_list=True))
    else:
        perms = {}
        perms_list = []

    try:
        extent_wgs = Area.objects.all().extent()
        wkt = "LINESTRING(%f %f,%f %f)" % extent_wgs

        geom = GEOSGeometry(wkt, 4326)
        extent = geom.transform(900913, clone=True).extent
    except:
        # if getting extent failed (no areas or so) use default
        extent = (479517, 6799646, 584302, 7016613)

    t = get_template("application/" + application_name + ".js")
    c = RequestContext(
        request,
        {
            "application": application_name,
            "active_tab": active_tab_name,
            "context": context,
            "permission_list": perms_list,
            "perms": perms,
            "extent": ",".join(["%.0f" % value for value in extent]),
        },
    )

    return HttpResponse(t.render(c), mimetype="text/javascript")
コード例 #3
0
ファイル: views.py プロジェクト: pombredanne/lizard-portal
def check_permission(user):
    """Return true is the user has permission
    is_analyst or superuser."""
    perms = dict(get_user_permissions_overall(user, 'user', as_list=True))
    if (('is_analyst' in perms) or user.is_superuser):
        return True
    return False
コード例 #4
0
ファイル: views.py プロジェクト: pombredanne/lizard-measure
def steerparameter_overview(request):
    """
    Return JSON for request.
    """
    c = RequestContext(request)

    areas = Area.objects.all()

    predefined_graphs = PredefinedGraphSelection.objects.all().values_list('name', flat=True)
    #predefined_graphs = ['testa', 'testb']

    parameters = SteeringParameterFree.objects.filter(area__in=areas).distinct().values_list('parameter_code', flat=True)

    parameters = [{'org': par, 'no_point': par.replace('.','_')} for par in parameters]

    perms = dict(get_user_permissions_overall(request.user, 'user', as_list=True))
    #parameters = ['test','test2']
    if request.user.is_authenticated():

        t = get_template('portals/stuurparameter-overzicht.js')
        c = RequestContext(request, {
            'predefined_graphs': predefined_graphs,
            'parameters': parameters,
            'perm': perms
            })

    else:
        t = get_template('portals/geen_toegang.js')

    return HttpResponse(t.render(c),  mimetype="text/plain")
コード例 #5
0
ファイル: views.py プロジェクト: pombredanne/lizard-measure
def steering_parameter_form(request):
    """
        Return JSON with editor for steering parameters .
    """
    c = RequestContext(request)

    perms = dict(get_user_permissions_overall(request.user, 'user', as_list=True))

    object_id = request.GET.get('object_id', None)

    area = get_object_or_404(Area,ident=object_id)


    if request.user.is_authenticated():

        t = get_template('portals/stuurparameter_form.js')

        if area.area_class == Area.AREA_CLASS_KRW_WATERLICHAAM:
            predefined_graphs = PredefinedGraphSelection.objects.filter(
                Q(for_area_type=Area.AREA_CLASS_KRW_WATERLICHAAM)|Q(for_area_type=None)).distinct()

            related_areas = Area.objects.filter(Q(arealink_a__area_b=area)|Q(arealink_b__area_a=area)).distinct()
        elif  area.area_class == Area.AREA_CLASS_AAN_AFVOERGEBIED:
            predefined_graphs = PredefinedGraphSelection.objects.filter(
                Q(for_area_type=Area.AREA_CLASS_AAN_AFVOERGEBIED)|Q(for_area_type=None)).distinct()

            related_areas = Area.objects.filter(Q(arealink_a__area_b=area)|Q(arealink_b__area_a=area)|Q(id=area.id)).distinct()



        c = RequestContext(request, {
            'area': area,
            'predefined_graphs': json.dumps(
                [{'id': r.id, 'name': r.name, 'for_area_type': r.for_area_type}
                 for r in predefined_graphs]),
            'related_areas': json.dumps(
                [{'id': r.id, 'name': r.name}
                 for r in related_areas]),
            'perm': perms
        })

    else:
        t = get_template('portals/geen_toegang.js')

    return HttpResponse(t.render(c),  mimetype="text/plain")
コード例 #6
0
ファイル: views.py プロジェクト: pombredanne/lizard-measure
def organization_groupedit_portal(request):
    """
    Return JSON for request.
    """
    c = RequestContext(request)

    if request.user.is_authenticated():
        perms = dict(get_user_permissions_overall(request.user, 'user', as_list=True))

        t = get_template('portals/organisatie-beheer.js')
        c = RequestContext(request, {
            'perm': perms
        })

    else:
        t = get_template('portals/geen_toegang.js')

    return HttpResponse(t.render(c),  mimetype="text/plain")
コード例 #7
0
ファイル: views.py プロジェクト: pombredanne/lizard-measure
def krw_waterbody_measures(request, area_ident,
                           template='lizard_measure/waterbody_measures.html'):
    """
    Show list of measures for an area_ident.
    """
    area = get_object_or_404(Area, ident=area_ident)

    result_measures = _sorted_measures(area)

    perms = dict(get_user_permissions_overall(request.user, 'user', as_list=True))

    return render_to_response(
        template,
        {'waterbody': area,
         'main_measures': result_measures,
         'perm': perms
         },
        context_instance=RequestContext(request))
コード例 #8
0
ファイル: views.py プロジェクト: pombredanne/lizard-portal
def json_configuration(request):
    """
    Return JSON for request.
    """

    perms = dict(get_user_permissions_overall(
            request.user, 'user', as_list=True))
    c = RequestContext(request, {
        'perm': perms
    })

    portal_template = request.GET.get('portal_template', 'homepage')

    if request.user.is_authenticated():
        if portal_template == 'maatregelen-beheer':
            return redirect('lizard_measure.measure_groupedit_portal')
        elif portal_template == 'organisatie-beheer':
            return redirect('lizard_measure.organization_groupedit_portal')
        elif portal_template == 'stuurparameter-overzicht':
            return redirect('lizard_measure.steerparameter_overview')
        #elif portal_template == 'area_link':
            # We need the template that couples KRW water bodies and catchment
            # areas which is only allowed if the user is an analyst. We cannot
            # easily detect that in the template itself so we do that here.
            #is_funct_beheerder = request.user.user_group_memberships.filter(
            #permission_mappers__permission_group__permissions__codename=
            #'is_funct_beheerder').exists()
            #if not is_funct_beheerder:
            #    t = get_template('portals/geen_toegang.js')
            #    return HttpResponse(t.render(c),  mimetype="text/plain")
        try:
            t = get_template('portals/' + portal_template + '.js')
        except TemplateDoesNotExist:
            pc = PortalConfiguration.objects.filter(slug=portal_template)[0]
            t = Template(pc.configuration)

    else:
        t = get_template('portals/geen_toegang.js')

    return HttpResponse(t.render(c),  mimetype="text/plain")
コード例 #9
0
ファイル: views.py プロジェクト: pombredanne/lizard-measure
def measure_groupedit_portal(request):
    """
    Return JSON for request.
    """
    c = RequestContext(request)

    perms = dict(get_user_permissions_overall(request.user, 'user', as_list=True))


    if request.user.is_authenticated():

        t = get_template('portals/maatregelen-beheer.js')
        c = RequestContext(request, {
            'measure_types': json.dumps(
                [{'id': r.id, 'name': str(r)}
                 for r in MeasureType.objects.all()],
            ),
            'periods': json.dumps(
                [{'id': r.id, 'name': str(r)}
                 for r in MeasurePeriod.objects.all()],
            ),
            'aggregations': json.dumps(
                [{'id': r[0], 'name': r[1]}
                 for r in Measure.AGGREGATION_TYPE_CHOICES],
            ),
            'categories': json.dumps(
                [{'id': r.id, 'name': str(r)}
                 for r in MeasureCategory.objects.all()],
            ),
            'units': json.dumps(
                [{'id': r.id, 'name': str(r)}
                 for r in Unit.objects.all()],
            ),
            'perm': perms
        })

    else:
        t = get_template('portals/geen_toegang.js')

    return HttpResponse(t.render(c),  mimetype="text/plain")