views.py

About this file

This module handles the request URL endpoints for the OpenRecords application.

There are routes defined for the following:

  • Create a new FOIL request sends a confirmation email after the Requests object is created.
  • Testing purposes of the view a request back until backend functionality is implemented.
  • Handle messaging to the requester if they submitted a request to a non-portal agency.
  • Get selected category value from the request body and generate a list of sorted agencies from the category.
  • Handle contacting the agency about a request as a requester.

Code Issues

  • The request route decorator should be explained so that someone coming to this code for the first time knows what it is doing. (One comment for first decorator is enough.)
  • Function new() is very long (over 100 lines). Should be broken up into smaller units for readability and unit testing.
  • view_all() has no docstring. Also, why does it need a holiday list? Not saying it doesn't, just saying it is not explained.
  • This if is hard to follow because huge:
    			
    		if current_user in current_request.agency_users \
                or current_request.agency_request_summary \
                and (current_request.requester == current_user
                     and current_request.status == request_status.CLOSED
                     and not current_request.privacy['agency_request_summary']
                     or current_request.status == request_status.CLOSED
                     and current_request.agency_request_summary_release_date
                     and current_request.agency_request_summary_release_date
                     < datetime.utcnow()
                     and not current_request.privacy['agency_request_summary']):
    			
    			
    Recommend writing a predicate like show_agency_req() and placing all conditions in there.
  • Lines 308-329 should be replaced by an attempt to get the value from the dictionary with a default of False. (See here.)
  • Also, use of assert detected on line 225. The use of assert is also considered as general bad practice in OpenStack codebases.

    Instead, a simple if condition can be used.

    	  
    	  if not condition:
    	      raise AssertionError()
    	  
    	  

Code Check Report


app/request/views.py:261:16: E713 test for membership should be 'not in'
app/request/views.py:481:80: W291 trailing whitespace
app/request/views.py:482:13: W291 trailing whitespace
                        

Documentation drawn from source code


.. module:: request.views.

:synopsis: Handles the request URL endpoints for the OpenRecords application


new():

Create a new FOIL request
sends a confirmation email after the Requests object is created.

title: request title
description: request description
agency: agency selected for the request
submission: submission method for the request

:return: redirect to homepage on successful form validation
if form fields are missing or has improper values, backend error messages (WTForms) will appear

view_all():

view(request_id):

This function is for testing purposes of the view a request back until backend functionality is implemented.

:return: redirect to view request page

non_portal_agency(agency_name):

This function handles messaging to the requester if they submitted a request to a non-portal agency.

:return: redirect to non_portal_agency page.

get_agencies_as_choices():

Get selected category value from the request body and generate a list of sorted agencies from the category.

:return: list of agency choices

contact_agency(request_id):

This function handles contacting the agency about a request as a requester.
:return:

Source code