Package madrona :: Package features :: Module views
[hide private]

Module views

source code

Functions [hide private]
 
get_object_for_editing(request, uid, target_klass=None)
Return the specified instance by uid for editing.
source code
 
get_object_for_viewing(request, uid, target_klass=None)
Return the specified instance by uid for viewing.
source code
 
handle_link(request, uids, link=None)
Handles all requests to views setup via features.register using Link objects.
source code
 
delete(request, model=None, uid=None)
When calling, provide the request object, reference to the resource class, and the primary key of the object to delete.
source code
 
multi_delete(request, instances)
Generic view to delete multiple instances
source code
 
create(request, model, action)
When calling, provide the request object and a ModelForm class
source code
 
create_form(request, model, action=None)
Serves a form for creating new objects
source code
 
update_form(request, model, uid)
Returns a form for editing features
source code
 
update(request, model, uid)
When calling, provide the request object, a model class, and the primary key of the instance to be updated.
source code
 
resource(request, model=None, uid=None)
Provides a resource for a django model that can be utilized by the madrona.features client module.
source code
 
form_resources(request, model=None, uid=None) source code
 
decorate_with_manipulators(extra_context, form_class) source code
 
copy(request, instances)
Generic view that can be used to copy any feature classes.
source code
 
kml(request, instances) source code
 
kmz(request, instances) source code
 
kml_core(request, instances, kmz)
Generic view for KML representation of feature classes.
source code
 
share_form(request, model=None, uid=None)
Generic view for showing the sharing form for an object
source code
 
manage_collection(request, action, uids, collection_model, collection_uid) source code
 
workspace(request, username, is_owner) source code
 
feature_tree_css(request) source code
 
to_response(status=200, select=None, show=None, parent=None, untoggle=None, location=None)
Will return an appropriately structured response that the client can interpret to carry out the following actions:
source code
 
to_csv(features) source code
 
has_features(user)
Util function to determine if a user owns any features
source code
 
geojson_link(request, instances)
Generic view for GeoJSON representation of feature classes.
source code
Variables [hide private]
  logger = get_logger()
Function Details [hide private]

get_object_for_editing(request, uid, target_klass=None)

source code 

Return the specified instance by uid for editing.
If a target_klass is provided, uid will be checked for consistency.
If the request has no logged-in user, a 401 Response will be returned. If 
the item is not found, a 404 Response will be returned. If the user is 
not authorized to edit the item (not the owner or a staff user), a 403 Not
Authorized Response will be returned.

usage:

instance = get_object_for_editing(request, 'mlpa_mpa_12', target_klass=Mpa)
if isinstance(instance, HttpResponse):
    return instance

get_object_for_viewing(request, uid, target_klass=None)

source code 

Return the specified instance by uid for viewing.
If a target_klass is provided, uid will be checked for consistency.
If the request has no authenticated user, a 401 Response will be returned.
If the item is not found, a 404 Response will be returned. If the user is 
not authorized to view the item (not the owner or part of a group the item
is shared with), a 403 Not Authorized Response will be returned.

usage:

instance = get_object_for_viewing(request, 'mlpa_mpa_12', target_klass=Mpa)
if isinstance(instance, HttpResponse):
    return instance

handle_link(request, uids, link=None)

source code 

Handles all requests to views setup via features.register using Link 
objects.

Assuming a valid request, this generic view will call the view specified 
by the link including an instance or instances argument containing the 
relavent Feature(s).

If the incoming request is invalid, any one of the following errors may be
returned:

401: login required
403: user does not have permission (not admin user or doesn't own object 
     to be edited)
404: feature(s) could not be found
400: requested for feature classes not supported by this view
5xx: server error

delete(request, model=None, uid=None)

source code 

When calling, provide the request object, reference to the resource class, and the primary key of the object to delete.

Possible response codes:

200: delete operation successful 401: login required 403: user does not have permission (not admin user or doesn't own object) 404: resource for deletion could not be found 5xx: server error

create(request, model, action)

source code 

When calling, provide the request object and a ModelForm class

    POST:   Create a new instance from filled out ModelForm

        201: Created. Response body includes representation of resource
        400: Validation error. Response body includes form. Form should
            be displayed back to the user for correction.
        401: Not logged in.
        5xx: Server error.

create_form(request, model, action=None)

source code 

Serves a form for creating new objects

GET only

update(request, model, uid)

source code 

When calling, provide the request object, a model class, and the
primary key of the instance to be updated.

    POST: Update instance.

        possible response codes:

        200: OK. Object updated and in response body.
        400: Form validation error. Present form back to user.
        401: Not logged in.
        403: Forbidden. User is not staff or does not own object.
        404: Instance for uid not found.
        5xx: Server error.

resource(request, model=None, uid=None)

source code 

Provides a resource for a django model that can be utilized by the 
madrona.features client module.

Implements actions for the following http actions:

    POST:   Update an object
    DELETE: Delete it
    GET:    Provide a page representing the model. For MPAs, this is the 
            MPA attributes screen. The madrona client will display this
            page in the sidebar whenever the object is brought into focus. 

            To implement GET, this view needs to be passed a view function
            that returns an HttpResponse or a template can be specified
            that will be passed the instance and an optional extra_context

Uses madrona.features.views.update and madrona.feature.views.delete

copy(request, instances)

source code 

Generic view that can be used to copy any feature classes. Supports requests referencing multiple instances.

To copy, this view will call the copy() method with the request's user as it's sole argument. The Feature base class has a generic copy method, but developers can override it. A poorly implemented copy method that does not return the copied instance will raise an exception here.

This view returns a space-delimited list of the Feature uid's for selection in the user-interface after this operation via the X-Madrona-Select response header.

kml_core(request, instances, kmz)

source code 

Generic view for KML representation of feature classes. Can be overridden in options but this provided a default.

share_form(request, model=None, uid=None)

source code 

Generic view for showing the sharing form for an object

    POST:   Update the sharing status of an object
    GET:    Provide an html form for selecting groups
            to which the feature will be shared.

workspace(request, username, is_owner)

source code 
Decorators:
  • @cache_page(60* 60)

feature_tree_css(request)

source code 
Decorators:
  • @cache_page(60* 60)

to_response(status=200, select=None, show=None, parent=None, untoggle=None, location=None)

source code 
Will return an appropriately structured response that the client can 
interpret to carry out the following actions:

    select
        Accepts a list of features. Tells the client to select these 
        features in the user interface after an editing operation

    show
        Accepts a single feature. Client will show that feature's 
        attribute window in the sidebar

    untoggle
        Accepts a list of features. Useful for toggling the visibility of
        original features that are being copied so there are not multiple
        overlapping copies on the map

    parent
        Gives a hint to the client that the edited feature falls within a
        particular FeatureCollection. Without this hint the client may not
        in all cases be able to perform select and show behaviors.

These behaviors are intended to be specified to the client using 
X-Madrona- style headers in the response. Unfortunately, we have to post
some forms via an iframe in order to upload files. This makes it 
impossible to get the response headers on the client end. This function
therefor currently also returns all headers in a json structure in the 
response body.

geojson_link(request, instances)

source code 

Generic view for GeoJSON representation of feature classes. 
Can be overridden but this is provided a default.

To override, feature class needs a geojson object that returns 
   a geojson feature string (no trailing comma)::

  { "type": "Feature",
    "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
    "properties": {"prop0": "value0"}
  }

GeoJSON Feature collections *cannot* be nested within other feature collections
http://lists.geojson.org/pipermail/geojson-geojson.org/2008-October/000464.html
Thus collections can be treated using one of the following strategies: 

  ``flat``: (DEFAULT) The collection is "flattened" to contain all the  
      features in a single featurecollection (lossy)

  ``nest_feature_set``: the collection is represented as an empty geometry with a special
      feature_set property; a list of UIDs to fetch 
      (requires a client with knowledge of this convention)

Pass by URL GET parameter like ?strategy=nest_feature_set