Beispiel #1
0
 def get(self, request):
     """Returns json representation of all resources in the collection."""
     items_list = [item.attributes_dict() for item in self.collection.all()]
     return http.HttpResponseOKJson({
             'self' : full_url(request.path),
             self.collection.collection_name: items_list
             })
Beispiel #2
0
    def put(self, request, location_uuid):
        """Creates a resource that enables open access to a given location."""
        location = self.locations_collection.find_item(location_uuid)
        if location is None:
            return http.HttpResponseNotFound('Location not found.')
        if location.open_access:
            return http.HttpResponseOKJson(self._attributes_dict(request))

        location.grant_open_access()
        response =  http.HttpResponseCreated(self._attributes_dict(request))
        response['Location'] = full_url(request.path)
        return response
Beispiel #3
0
 def _attributes_dict(request):
     """Attributes representing a resource to which a request is related."""
     return {'self' : full_url(request.path)}