
views.py
About this file
The file is responsible to handle the API request URL endpoints for the
OpenRecords application.
The routes are defined to:
Edits the privacy privacy options of a request's title and agency request
summary,
Edits the title and agency request summary of a FOIL request through an API
PUT method,
Returns a set of events (id, type, and template), ordered by date descending,
and starting from a specific index,
Returns a set of responses (id, type, and template), ordered by date
descending, and starting from a specified index.
Code Issues
-
The function
get_request_events()
is almost 100 lines and theif
loop being long is difficult to follow since it is in afor
loop. -
Similary, function
get_request_responses()
is also too long with a lot of repetitive parameters in functions likefilter()
, andis_allowed()
.
Example: Functionis_allowed()
is called 6 times inget_request_responses()
with only one variant -permission_type
(called in another functionget_permission()
call).
A separate function can be made which is passed just thepermission_type
which will inturn callis_allowed
function which will fetch frompermission_utils.py
. This will reduce the number of lines ofget_request_responses()
.
edit_response_permission=is_allowed(user=current_user, request_id=response.request_id, permission=get_permission(permission_type='edit', response_type=type(response))), delete_response_permission=is_allowed(user=current_user, request_id=response.request_id, permission=get_permission(permission_type='delete', response_type=type(response))), edit_response_privacy_permission=is_allowed(user=current_user, request_id=response.request_id, permission=get_permission( permission_type='privacy', response_type=type( response))),
Code Check Report
app/request/api/views.py:221:31: E712 comparison to False should be 'if cond is False:' or 'if not cond:' app/request/api/views.py:232:31: E712 comparison to False should be 'if cond is False:' or 'if not cond:' app/request/api/views.py:245:31: E712 comparison to False should be 'if cond is False:' or 'if not cond:'
Documentation drawn from source code
.. module:: api.request.views.:synopsis: Handles the API request URL endpoints for the OpenRecords application
edit_privacy():
Edits the privacy privacy options of a request's title and agency request summary.Retrieves updated privacy options from AJAX call on view_request page and stores changes into database.:return: JSON Response with updated title and agency request summary privacy options
edit_request_info():
Edits the title and agency request summary of a FOIL request through an API PUT method.Retrieves updated edited content from AJAX call on view_request page and stores changes into database.:return: JSON Response with updated content: either request title or agency request summary)
get_request_events():
Returns a set of events (id, type, and template),ordered by date descending, and starting from a specific index.Request parameters:- start: (int) starting index- request_id: FOIL request id- with_template: (default: False) include html rows for each event
get_request_responses():
Returns a set of responses (id, type, and template),ordered by date descending, and starting from a specified index.Request parameters:- start: (int) starting index- request_id: FOIL request id- with_template: (default: False) include html (rows and modals) for each response