-
Notifications
You must be signed in to change notification settings - Fork 19
Code Flows
griffincj edited this page Dec 7, 2021
·
4 revisions
There are several "flows" through the code that are particularly common and will likely be relevant in future code changes.
The most common flow is: SomeReact.jsx -> api.js -> urls.py -> some_function() in views.py
-
Resesearchers.jsx
provides the front-end code for the search page. Like all React pages, the front-end components are rendered in therender()
method. ThehandleSearch()
method takes the string from the textbox input and passes it toapi.js
in a promise (.then()) -
api.js
contains endpoints which point to URLs in urls.py. Essentially, this file acts as the bridge between React and Python (or front-end and back-end). For search querying, we refer to thegetResearcherSearchResults
endpoint, which routes to "/researcher" in urls.py. -
urls.py
is a standard file used by web frameworks like Django to define the routing of URLs within the web application. In this case, the "/researchers" URL is referred to, which retrieves theResearcherSearchList
class fromviews.py
using the query that was passed from api.js -
views.py
contains the main python function definitions for the application, including forResearcherSearchList
. ResearchSearchList returns a queryset all the way back to Researchers.jsx, from which it is displayed.
-
Citizens.jsx
contains the front-end code andapi.js
references to get the appropriate database objects.
Note: Much of the Citizens.jsx code should be deprecated, as it refers to database columns (i.e. Location ID) that have no use for this specific application.
-
api.js
is called for bothApi.getLocationQuestions(0)
andApi.getLocationStages(0)
. These refer tourls.py
, specifically "/location/0/questions" and "location/0/stages" respectively -
urls.py
refers toLocationQuestionList
andLocationStageList
for Locations and Stages respectively -
views.py
contains LocationQuestionList, which gets a queryset of questions from the database (queries Question.objects.all()). LocationStageList returns a JSON response containing the hard-coded "stages of a police complaint", which serve as rough categories for the questions.