Ejemplo n.º 1
0
def get_data_for_feature(user, uid):
    try:
        f = get_feature_by_uid(uid)
    except:
        return False , HttpResponse("Feature %s does not exist" % uid, status=404)

    viewable, response = f.is_viewable(user)
    if not viewable:
        return viewable, response

    features = []
    collections = []


    if isinstance(f, FeatureCollection):
        obj_id = f.pk
        ct = ContentType.objects.get_for_model(f.__class__)
        for fmodel in get_feature_models():
            unattached = list(fmodel.objects.filter(content_type=ct,object_id=obj_id))
            features.extend(unattached)
            
        for cmodel in get_collection_models():
            collections_top = list(cmodel.objects.filter(content_type=ct,object_id=obj_id))
            collections.extend(collections_top)
    elif isinstance(f, Feature):
        features.append(f)

    return features, collections
Ejemplo n.º 2
0
def get_shared_data(shareuser, sharegroup, user):
    sg = Group.objects.get(pk=sharegroup)
    su = User.objects.get(pk=shareuser)

    features = []
    collections = []

    for fmodel in get_feature_models():
        # Find top level features shared with user
        # top-level == not belonging to any collections
        # have to use content_type and object_id fields to determine
        unattached = list(
                fmodel.objects.shared_with_user(user,filter_groups=[sg])
                 .filter(user=su, content_type=None,object_id=None)
        )
        features.extend(unattached)
        
    for cmodel in get_collection_models():
        collections_top = list(
                cmodel.objects.shared_with_user(user,filter_groups=[sg])
                 .filter(user=su, content_type=None,object_id=None)
        )
        collections.extend(collections_top)

    return features, collections
Ejemplo n.º 3
0
def get_public_data():
    """
    No login necessary, everyone sees these
    Public groups defined in settings.SHARING_TO_PUBLIC_GROUPS
    """
    from django.conf import settings
    public_groups = Group.objects.filter(name__in=settings.SHARING_TO_PUBLIC_GROUPS)
    features = []
    collections = []

    for fmodel in get_feature_models():
        unattached = list(fmodel.objects.filter(sharing_groups__in=public_groups))
        features.extend(unattached)
        
    for cmodel in get_collection_models():
        collections_top = list(cmodel.objects.filter(sharing_groups__in=public_groups))
        collections.extend(collections_top)

    return features, collections
Ejemplo n.º 4
0
def get_features(uids, user):
    """ 
    Returns list of tuples representing mapnik layers
    Tuple => (model_class, [pks])
    Note: currently just a single pk per 'layer' which is
    incredibly inefficient but the only way to ensure 
    proper layer ordering (??).
        features = [ (Mpa, [49, 50]),
                    (Pipeline, [32, 31]),
                    (Shipwreck, [32, 31])
                ]
    """
    feature_models = get_feature_models()
    collection_models = get_collection_models()
    features = []  # list of tuples => (model, [pks])
    for uid in uids:
        log.debug("processing uid %s" % uid)
        applabel, modelname, pk = uid.split('_')
        model = get_model_by_uid("%s_%s" % (applabel, modelname))
        feature = get_feature_by_uid(uid)

        if user:
            viewable, response = feature.is_viewable(user)
            if not viewable:
                continue

        if model in collection_models:
            collection = get_feature_by_uid(uid)
            if user:
                viewable, response = collection.is_viewable(user)
                if not viewable:
                    continue
            all_children = collection.feature_set(recurse=True)
            children = [
                x for x in all_children if x.__class__ in feature_models
            ]
            for child in children:
                features.append((child.__class__, [child.pk]))
        else:
            features.append((model, [int(pk)]))

    return features
Ejemplo n.º 5
0
def get_user_data(user):
    """
    Organizes user's Features and FeatureCollections.
    Only returns objects owned by user, not shared
    Returns only the features/collections at the top level,
    nested child features will be handled later through
    recursive calls to feature_set.
    """
    toplevel_features = []
    toplevel_collections = []

    for fmodel in get_feature_models():
        unattached = list(fmodel.objects.filter(user=user, content_type=None, object_id=None))
        toplevel_features.extend(unattached)
        
    for cmodel in get_collection_models():
        collections_top = list(cmodel.objects.filter(user=user, content_type=None, object_id=None))
        toplevel_collections.extend(collections_top)

    return toplevel_features, toplevel_collections
Ejemplo n.º 6
0
def get_features(uids,user):
    """ 
    Returns list of tuples representing mapnik layers
    Tuple => (model_class, [pks])
    Note: currently just a single pk per 'layer' which is
    incredibly inefficient but the only way to ensure 
    proper layer ordering (??).
        features = [ (Mpa, [49, 50]),
                    (Pipeline, [32, 31]),
                    (Shipwreck, [32, 31])
                ]
    """
    feature_models = get_feature_models()
    collection_models = get_collection_models()
    features = [] # list of tuples => (model, [pks])
    for uid in uids:
        log.debug("processing uid %s" % uid)
        applabel, modelname, pk = uid.split('_')
        model = get_model_by_uid("%s_%s" % (applabel,modelname))
        feature = get_feature_by_uid(uid)

        if user:
            viewable, response = feature.is_viewable(user)
            if not viewable:
                continue

        if model in collection_models:
            collection = get_feature_by_uid(uid)
            if user:
                viewable, response = collection.is_viewable(user)
                if not viewable:
                    continue
            all_children = collection.feature_set(recurse=True)
            children = [x for x in all_children if x.__class__ in feature_models]
            for child in children:
                features.append((child.__class__,[child.pk]))
        else:
            features.append((model,[int(pk)]))

    return features
Ejemplo n.º 7
0
def overlap_geotiff(collection_uids, user=None):
    collections = [get_feature_by_uid(x) for x in collection_uids.split(',')]
    collections = [x for x in collections if x.__class__ in get_collection_models()]
    if len(collections) < 1:
        raise Http404

    filenames = []
    for collection in collections:
        viewable, response = collection.is_viewable(user)
        if user and not viewable:
            return response

        fs = collection.feature_set(recurse=True)
        poly_fs = [x for x in fs if isinstance(x,PolygonFeature)]
        unique_types = list(set([x.__class__ for x in poly_fs]))
        for model in unique_types:
            responder = ShpResponder(model.objects.filter(pk__in=[x.pk for x in poly_fs if x.__class__ == model]))
            responder.geo_field = 'geometry_final'
            fn = responder('return_file_not_response')
            filenames.append(fn)

    temp_geotiff = create_heatmap(filenames)
    return temp_geotiff
Ejemplo n.º 8
0
            name="%s_create_form" % (options.slug, )),
            
        url(r'^%s/(?P<uid>[\w_]+)/$' % (options.slug, ), 'resource', 
            kwargs={'model': model}, 
            name='%s_resource' % (options.slug, )),
            
        url(r'^%s/(?P<uid>[\w_]+)/form/$' % (options.slug, ), 
            'form_resources', kwargs={'model': model}, 
            name='%s_update_form' % (options.slug,)),

        url(r'^%s/(?P<uid>[\w_]+)/share/$' % (options.slug, ), 
            'share_form', kwargs={'model': model}, 
            name='%s_share_form' % (options.slug,)),
    )

for model in get_collection_models():
    options = model.get_options()
    urlpatterns += patterns('lingcod.features.views',
        url(r'^%s/(?P<collection_uid>[\w_]+)/remove/(?P<uids>[\w_,]+)$' % (options.slug, ), 
            'manage_collection', kwargs={'collection_model': model, 'action': 'remove'}, 
            name='%s_remove_features' % (options.slug,)),

        url(r'^%s/(?P<collection_uid>[\w_]+)/add/(?P<uids>[\w_,]+)$' % (options.slug, ), 
            'manage_collection', kwargs={'collection_model': model, 'action': 'add'}, 
            name='%s_add_features' % (options.slug,)),
    )

for link in registered_links:
    path = r'^%s/links/%s/(?P<uids>[\w_,]+)/$' % (link.parent_slug, link.slug)
    urlpatterns += patterns('lingcod.features.views',
        url(path, 'handle_link', kwargs={'link': link}, 
Ejemplo n.º 9
0
            name="%s_create_form" % (options.slug, )),
        url(r'^%s/(?P<uid>[\w_]+)/$' % (options.slug, ),
            'resource',
            kwargs={'model': model},
            name='%s_resource' % (options.slug, )),
        url(r'^%s/(?P<uid>[\w_]+)/form/$' % (options.slug, ),
            'form_resources',
            kwargs={'model': model},
            name='%s_update_form' % (options.slug, )),
        url(r'^%s/(?P<uid>[\w_]+)/share/$' % (options.slug, ),
            'share_form',
            kwargs={'model': model},
            name='%s_share_form' % (options.slug, )),
    )

for model in get_collection_models():
    options = model.get_options()
    urlpatterns += patterns(
        'lingcod.features.views',
        url(r'^%s/(?P<collection_uid>[\w_]+)/remove/(?P<uids>[\w_,]+)$' %
            (options.slug, ),
            'manage_collection',
            kwargs={
                'collection_model': model,
                'action': 'remove'
            },
            name='%s_remove_features' % (options.slug, )),
        url(r'^%s/(?P<collection_uid>[\w_]+)/add/(?P<uids>[\w_,]+)$' %
            (options.slug, ),
            'manage_collection',
            kwargs={