示例#1
0
文件: views.py 项目: point97/madrona
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
示例#2
0
文件: views.py 项目: Ecotrust/madrona
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
示例#3
0
文件: views.py 项目: Ecotrust/madrona
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
示例#4
0
文件: views.py 项目: Ecotrust/madrona
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
示例#5
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
示例#6
0
文件: views.py 项目: Ecotrust/madrona
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
示例#7
0
文件: views.py 项目: Ecotrust/madrona
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
示例#8
0
文件: views.py 项目: point97/madrona
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
示例#9
0
文件: views.py 项目: point97/madrona
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
示例#10
0
文件: views.py 项目: point97/madrona
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