@@ -40,24 +40,8 @@ class MimeType: # noqa
4040
4141class EgsimView (View ):
4242 """Base View class for serving eGSIM HttpResponse. All views should inherits from
43- this class, implementing the abstract-like method `response`
44-
45- Example
46- =======
47-
48- 1. Implementation (note: any exception will be caught and returned as 500
49- HttpResponse, see `handle_exception`)
50- ```
51- class MyEgsimView(EgsimView):
52-
53- def response(self, request: HttpRequest, data: dict, files: Optional[dict] = None) -> HttpResponseBase:
54- content = ... # bytes or string sequence (serialized from a Python object)
55- return HttpResponse(content, content_type=MimeType.csv, ...)
56- # or, if content is a JSON dict:
57- return JsonResponse(content)
58- ```
59-
60- 2. URL mapping: given an endpoint (URL string or regex pattern), in `urls.py`:
43+ this class, implementing the abstract-like method `response` (**see docstring therein
44+ for details**). After that, you can map this view to a given URL as usual (in `urls.py`):
6145 ```
6246 urlpatterns = [
6347 ...
@@ -107,7 +91,10 @@ def response(self,
10791 need to be returned in try except clauses, as usual:
10892 ```
10993 try:
110- ... return response, e.g. JsonResponse, HttpResponse
94+ content = ... # bytes or string sequence (serialized from a Python object)
95+ return HttpResponse(content, content_type=MimeType.csv, ...)
96+ # or, if content is a JSON dict:
97+ return JsonResponse(content)
11198 except ValueError as exc:
11299 return self.error_response(exc, status=400)
113100 ```
@@ -184,17 +171,17 @@ def response(self,
184171
185172class APIFormView (EgsimView ):
186173 """:class:`EgsimView` subclass serving :class:`ApiForm.output()` objects and
187- expecting a 'format' request parameter (default if missing: 'json', see `MimeType`
188- class attributes) dictating the response type. Form validation errors will be
189- returned as 400 HttpResponse with the form error string as reponse message .
174+ expecting a 'format' request parameter (any attribute of :class: `MimeType`)
175+ dictating the response type. Form validation errors will be
176+ returned as 400 HttpResponse, any uncaught exception as 500 HttpResponse .
190177
191178 Usage
192179 =====
193180
194181 Given an `APiForm` subclass named `MyApiForm`:
195182
196183 1. If this view is supposed to return JSON data only, then `MyApiForm.output()`
197- must also return a JSON serializable dict. After that , you only need to
184+ must also return a JSON serializable dict. If this is the casse , you only need to
198185 implement a new endpoint in `urls.py`:
199186
200187 ```
@@ -205,10 +192,11 @@ class attributes) dictating the response type. Form validation errors will be
205192 ]
206193 ```
207194
208- 2. If this view is suppoosed to return several data formats, then
195+ 2. If this view is supposed to return several data formats, then
209196 `MyApiForm.output()` can be any Python object, but you must serialize it here
210- depending on the requested format. For instance, if you want to support users
211- request format to be 'hdf', this class expets the relative method `response_hdf`:
197+ depending on the requested format (including overriding the existing reponse_json,
198+ if needed). For instance, if you want to serve HDF data, you must implement
199+ the method `response_hdf`:
212200
213201 ```
214202 class MyApiFormView(APIFormView):
0 commit comments