diff --git a/.nojekyll b/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/404.html b/404.html new file mode 100644 index 00000000..efd21aca --- /dev/null +++ b/404.html @@ -0,0 +1,876 @@ + + + +
+ + + + + + + + + + + + + +ModHeader will break Google drive if Authentication Bearer token is set. The Google drive website pops up a dialog saying:
+ +The solution is to disable the Authentication header and Google drive will work as normal.
+Cognito is a single sign-on system from AWS. It allows multiple apps to accept authentication from the same set of user accounts. It separates the management of users and permissions from the applications that use them.
+We're invested in AWS, so we might as well use this too.
+We're following the implementation from the djangostar tutorial.
+These are the steps involved:
+The tutorial is 2 years old now (from 2020) and there's been some change made since then.
+These are the github actions used in the project.
+main
These are the directories and files in the project. Parts are summarized for clarity.
+/
+├── app/ # (1)!
+├── docs/ # (2)!
+├── scripts/ # (3)!
+├── docker-compose.yml # (4)!
+└── pyproject.toml # (5)!
+
./scripts/buildrun.sh
. See Django Project below for details.app/setup.cfg
in the future. We may move this file into app/
if it makes sense.app/
+├── core/ # (1)!
+├── data/ # (2)!
+├── peopledepot/ # (3)!
+│ ├── asgi.py
+│ ├── settings.py
+│ ├── urls.py
+│ └── wsgi.py
+├── scripts/ # (4)!
+│ └── convert.py
+├── Dockerfile # (5)!
+├── entrypoint.sh # (6)!
+├── manage.py # (7)!
+├── requirements.in # (8)!
+├── requirements.txt # (9)!
+└── setup.cfg # (10)!
+
convert.py
script, which converts csv files into django initial data code. It's used to generate code for the initial data migrations.uv pip compile
. See the uv tool for details.uv pip install
. Do not modify this file. Edit the requirements.in
file instead. See the uv tool for details.flake8
and pytest
. flake8
is the only tool that doesn't support pyproject.toml
yet, which is why we have this file.core/
+├── admin.py # (1)!
+├── api/
+│ ├── permissions.py # (2)!
+│ ├── serializers.py # (3)!
+│ ├── urls.py # (4)!
+│ └── views.py # (5)!
+├── apps.py # (6)!
+├── initial_data/
+│ ├── ...
+│ └── Initial data in json or csv format # (7)!
+├── migrations/
+│ ├── nnnn_migration_name.py # (8)!
+│ ├── ...
+│ └── max_migration.txt # (9)!
+├── models.py # (10)!
+├── scripts/ # (11)!
+├── tests/
+│ ├── conftest.py # (12)!
+│ ├── test_api.py # (13)!
+│ ├── test_models.py # (14)!
+│ └── test_permissions.py # (15)!
+└── utils/ # (16)!
+. └── jwt.py # (17)!
+
makemigrations
command.django-linear-migrations
. It stores the last migration name for the app for use in git merge conflicts.data/
+└── migrations/
+. ├── nnnn_migration_name.py # (1)!
+. ├── ...
+. └── max_migration.txt # (2)!
+
django-linear-migrations
. It stores the last migration name for the app for use in git merge conflicts./
+├── docs/
+│ ├── [topics]/ # (1)!
+│ ├── CONTRIBUTING.md # (2)!
+│ ├── index.md # (3)!
+│ ├── LICENSE # (4)!
+│ ├── license.md # (5)!
+│ └── _static/
+├── CONTRIBUTING.md # (6)!
+├── LICENSE # (7)!
+├── mkdocs.yml # (8)!
+└── README.md # (9)!
+
CONTRIBUTING.md
file in the project root. MkDocs requires all documentation files to be in the docs/
directory. This file uses a snippet to import the source content.README.md
file from the project root.LICENSE
file. This file uses a snippet to import the LICENSE
file from the project root. This is used for linking from the Documentation Homepage as well as the README.md
file in the Github web interface, which knows the file by this name only.license.md
file. This file uses a snippet to import the LICENSE
file from the project root. This is used for the MkDocs nav section, which requires the md
file extension.See here for creating a GitHub account. If you are not familiar with Git, this tutorial is recommended.
+Set up two-factor authentication on your account by following this guide.
+VS Code is recommended, but feel free to use a text editor of your choice.
+Before cloning your forked repository to your local machine, you must have Git installed. You can find instructions for installing Git for your operating system here.
+we recommend installing Windows Subsystem for Linux (WSL). WSL provides a Linux-compatible environment that can prevent common errors during script execution.
+After setting up WSL, install Git directly from the Linux terminal. This method can help avoid complications that sometimes arise when using Git Bash on Windows.
+If you prefer Git Bash or encounter errors related to line endings when running scripts, the problem might be due to file conversions in Windows. To address this, configure Git as follows:
+ +Feel free to reach out in the Hack for LA Slack channel if you encounter any errors while running scripts on Windows
+Please note that if you have a Mac the page offers several options (see other option, if you need to conserve hard drive space) including:
+$ brew install git
which in total only uses 300MB.Install or make sure docker and docker-compose are installed on your computer
+ +The recommended installation method for your operating system can be found here.
+Feel free to reach out in the Hack for LA Slack channel if you have trouble installing docker on your system
+More on using Docker and the concepts of containerization:
+ +You can fork the hackforla/peopledepot repository by clicking +. A fork is a copy of the repository that will be placed on your GitHub account.
+It should create a URL that looks like the following -> https://github.com/<your_GitHub_user_name>/peopledepot
For example -> https://github.com/octocat/peopledepot
What you have created is a forked copy in a remote version on GitHub. It is not on your local machine yet
+The following steps will clone (create) a local copy of the forked repository on your computer.
+Create a new folder in your computer that will contain hackforla
projects.
In your command line interface (Terminal, Git Bash, Powershell), move to where you want your new folder to be placed and create a new folder in your computer that will contain hackforla
projects. After that, navigate into the folder(directory) you just created.
For example:
+ +From the hackforla directory created in previous section:
+ +For example if your GitHub username was octocat
:
You can also clone using ssh which is more secure but requires more setup. Because of the additional setup, cloning using https as shown above is recommended
+You should now have a new folder in your hackforla
folder called peopledepot
. Verify this by changing into the new directory:
Verify that your local cloned repository is pointing to the correct origin
URL (that is, the forked repo on your own GitHub account):
You should see fetch
and push
URLs with links to your forked repository under your account (i.e. https://github.com/<your_GitHub_user_name>/peopledepot.git
). You are all set to make working changes to the project on your local machine.
However, we still need a way to keep our local repo up to date with the deployed project. To do so, you must add an upstream remote to incorporate changes made while you are working on your local repo. Run the following to add an upstream remote URL & update your local repo with recent changes to the hackforla
version:
After adding the upstream remote, you should now see it if you again run git remote -v
:
origin https://github.com/<your_GitHub_user_name>/peopledepot.git (fetch)
+origin https://github.com/<your_GitHub_user_name>/peopledepot.git (push)
+upstream https://github.com/hackforla/peopledepot.git (fetch)
+upstream https://github.com/hackforla/peopledepot.git (push)
+
Make sure the Docker service is running
+docker container ls
to verify Docker Desktop is running. If it is not running you will get the message: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Create an .env.docker file from .env.docker-example
+ +Build and run the project via the script (this includes running docker-compose up
)
Create a super user for logging into the web admin interface
+ +Browse to the web admin interface at http://localhost:8000/admin/
and confirm the admin site is running. Use DJANGO_SUPERUSER_USERNAME and DJANGO_SUPERUSER_PASSWORD from .env.docker for credentials.
See our documentation for Working with Docker for more useful Docker commands.
+This will check your changes for common problems.
+See the Pre-commit page for installation instructions.
+For consistency, an automated bot will perform the same checks on the repository side when you open a pull request.
+ + + + + + +We highly encourage contributors to add and update documentation in the same pull request as the code. This will ensure that the docs and features are synchronized.
+Please see the MkDocs page for how to view documentation changes locally using the mkdocs in docker.
+ + + + + + +Your fork of this repository on GitHub, and your local clone of that fork, will get out of sync with the (upstream) repository as others update the repository. (That's what has happened when you see something like "This branch is 1 commit behind peopledepot:main" on your forked repository.)
+One way to keep your fork up to date with this repository is to follow these instruction: Syncing your fork to the original repository via the browser
+You can also update your fork via the local clone of your fork, using these instructions. Assuming you have a local clone with remotes upstream
(this repo) and origin
(your GitHub fork of this repo):
Run the following two commands:
+ +If you have already created the branch upstream-main, the following commands will incorporate upstream changes:
+git checkout upstream-main # Move to the branch you want to merge with.
+git pull # This updates your tracking branch to match the main branch in this repository
+git checkout main # Move back to your main branch
+git merge upstream-main # Merge to bring your main current.
+
If you do all your work on topic branches (as suggested above) and keep main free of local modifications, this merge should apply cleanly.
+Then push the merge changes to your GitHub fork:
+ +If you go to your online GitHub repository this should remove the message "This branch is x commit behind peopledepot:main".
+ + + + + + +This guide aims to enable developers with little or no django experience to add django models and API endpoints to the project. Most code examples are followed by detailed explanations.
+This guide assumes the developer has followed the working with issues guide and have forked and created a local branch to work on this. The development server would be already running in the background and will automatically apply the changes when we save the files.
+We will choose the recurring_event issue as an example. Our goal is to create a database table and an API that a client can use to work with the data. The work is split into 3 testable components: the model, the admin site, and the API
+Let's start!
+Write the test
+We would like the model to store these data, and to return the name property in the str function.
+In app/core/tests/test_models.py
For testing many-to-many relationships, we can add
+See it fail
+ +Run it again after implementing the model to make sure the code satisfies the test
+Add the following to app/core/models.py
uuid
primary key, created_at
, and updated_at
timestamps. In the Github issue, these fields might be called id
, created
, and updated
. There's no need to add those.blank=True
, data fields should be null=True
.INTEGER
, VARCHAR
, but we need to convert them into Django field types when defining the model.VARCHAR
can be either CharField
or TextField
.CharField
has a max_length
, which makes it useful for finite length text data. We're going default to giving them max_length=255
unless there's a better value like max_length=2
for state abbreviation.TextField
doesn't have a maximum length, which makes it ideal for large text fields such as description
.__str__
function to output something more meaningful than the default. It lets us do a quick test of the model by calling str([model])
. It's also useful for the admin site model list view.For adding many-to-many relationships with additional fields, such as ended_on
, we can add
For adding many-to-many relationships without additional fields, we can just add
+app/core/models.py | |
---|---|
which leaves out the "through" field and the "join table" will be created implicitly.
+This generates the database migration files
+ +Since we overrode the __str__
function, we need to write a test for it.
Add a fixture for the model
+Fixtures are reusable code that can be used in multiple tests by declaring them as parameters of the test case. In this example, we show both defining a fixture (recurring_event) and using another fixture (project).
+Note: The conftest file is meant to hold shared test fixtures, among other things. The fixtures have directory scope.
+Add the following to app/core/tests/conftest.py
app/core/tests/conftest.py | |
---|---|
recurring_event
).project
model as a foreign key relation, so we pass in the project
fixture, which creates a project
model.__str__
method in a test.Add a test case
+When creating Django models, there's no need to test the CRUD functionality since Django itself is well-tested and we can expect it to generate the correct CRUD functionality. Feel free to write some tests for practice. What really needs testing are any custom code that's not part of Django. Sometimes we need to override the default Django behavior and that should be tested.
+Here's a basic test to see that the model stores its name.
+Add the following to app/core/tests/test_models.py
app/core/tests/test_models.py | |
---|---|
__str__
method should be tested since it's an override of the default Django method.__str__
method.Run the test script to show it passing
+ +This is a good place to pause, check, and commit progress.
+Run pre-commit checks
+ +Add and commit changes
+ +Django comes with an admin site interface that allows admin users to view and change the data in the models. It's essentially a database viewer.
+In app/core/admin.py
Import the new model
+app/core/admin.py | |
---|---|
Register the model with the admin site
+app/core/admin.py | |
---|---|
Check that everything's working and there are no issues, which should be the case unless there's custom input fields creating problems.
+See the development setup guide section on "Build and run using Docker locally" for how to view the admin interface.
+Example of a custom field (as opposed to the built-in ones)
+ +This is a good place to pause, check, and commit progress.
+Run pre-commit checks
+ +Add and commit changes
+ +There's several components to adding API endpoints: Model(already done), Serializer, View, and Route.
+This is code that serializes objects into strings for the API endpoints, and deserializes strings into object when we receive data from the client.
+In app/core/api/serializers.py
Following the many-to-many relationship between project and recurring event from above,
+Update the existing serializer classes
+Import the new model
+app/core/api/serializers.py | |
---|---|
Add a serializer class
+model
, the fields
we want to expose through the API, and any read_only_fields
.uuid
, created_at
, and updated_at
are managed by automations and are always read-only.Custom data fields may need extra code in the serializer
+ +Custom validators if we need them
+We will need to write custom validators here if we want custom behavior, such as validating URL strings and limit them to the github user profile pattern using regular expression, for example.
+ +Viewset defines the set of API endpoints for the model.
+In app/core/api/views.py
Import the model
+app/core/api/views.py | |
---|---|
Import the serializer
+app/core/api/views.py | |
---|---|
Add the viewset and CRUD API endpoint descriptions
+create
, retrieve
, partial_update
, update
, destroy
, list
.extend_schema_view
decorator to attach the API doc strings to the viewset. They are usually defined as docstrings of the corresponding function definitions inside the viewset. Since we use ModelViewSet
, there's nowhere to put the docstrings but above the viewset.ModelViewSet
are the queryset
, and the serializer_class
.permission_classes = [IsAuthenticated]
This example shows how to add a filter params. It's done for the user model as a requirement from VRMS.
+Here's a more complex API doc example (this example is using the User model's ViewSet)
+create
, retrieve
, partial_update
, update
, destroy
, list
.summary
string appears as an option in the dropdown.description
is displayed in the example.Add any query params according to the requirements (this example is using the User model's ViewSet)
+Notice the queryset
property is now the get_queryset(()
function which returns the queryset.
The get_queryset()
function overrides the default and lets us filter the objects returned to the client if they pass in a query param.
Start with all the model objects and filter them based on any available query params.
+In app/core/api/urls.py
Import the viewset.
+app/core/api/urls.py | |
---|---|
Register the viewset to the router
+app/core/api/urls.py | |
---|---|
http://localhost:8000/api/v1/recuring-events/
and http://localhost:8000/api/v1/recuring-events/<uuid>
basename
is the name used for generating the endpoint names, such as queryset
attribute, but it's required if the viewset overrides that with the get_queryset
functionreverse("recurring-event-list")
would return http://localhost:8000/api/v1/recuring-events/
For the CRUD operations, since we're using ModelViewSet
where all the actions are provided by rest_framework
and well-tested, it's not necessary to have test cases for them. But here's an example of one.
In app/core/tests/test_api.py
Import API URL
+app/core/tests/test_api.py | |
---|---|
Add test case
+Run the test script to show it passing
+ +In app/core/tests/test_api.py
Import API URL
+app/core/tests/test_api.py | |
---|---|
Add test case (following the example above)
+Run the test script to show it passing
+ +This is a good place to pause, check, and commit progress.
+Run pre-commit checks
+ +Add and commit changes
+ +Refer to the Issues page section on "Push to upstream origin" onward.
+The goal is to convert our initial data into scripts that can be loaded into the database when the backend is set up for the first time.
+These are the steps:
+You must have Docker installed
+The initial data exists in a Google spreadsheet, such as this one for People Depot. There should be individual sheets named after the model names the data correspond to, such as ProgramArea - Data
. The sheet name is useful for us to identify the model it corresponds to.
The sheet should be formatted like so:
+It is required that there be data in the first column of the sheet.
+Export the data from the Google spreadsheet
+ProgramArea - Data
data as our example.Start Docker
+From project root, run
+ +Go to the project root and run this command
+ +Check that there's a new file called app/core/scripts/programarea_seed.py
and that it looks correct
You can run it to verify, but will need to remove that data if you care about restoring the database state
+Run this command to run the script
+core_programarea
docker-compose exec web python manage.py dbshell
+
+# now we have a shell to the db
+
+# see if all the seed data got inserted
+select count(*) from core_programarea;
+# shows 9 rows
+
+delete from core_programarea;
+# DELETE 9
+
+select count(*) from core_programarea;
+# shows 0 rows
+
+# ctrl-d to exit dbshell
+
Look for name of the last migration file in core/data/migrations
directory
Create a script in the same directory named <number>_<modelname_in_lower_case>_seed.py
with the following contents and
+ replace <modelname_in_lower_case>
, ModelNameInPascalCase
, and <name of last script>
with appropriate values:
from django.db import migrations
+
+from core.models import ModelNameInPascalCase
+
+
+def forward(__code__, __reverse_code__):
+ # paste everything in seed script's run function here
+ # remove pass below
+ pass
+
+
+def reverse(__code__, __reverse_code__):
+ ModelNameInPascalCase.objects.all().delete()
+
+
+class Migration(migrations.Migration):
+ dependencies = [("data", "<name of last script, or contents of max_migration.txt>")]
+
+ operations = [migrations.RunPython(forward, reverse)]
+
For example:
+from django.db import migrations
+
+from core.models import BookType
+
+
+def forward(__code__, __reverse_code__):
+ items = [
+ (1, "Hard Cover"),
+ (2, "Soft Cover"),
+ ]
+ for uuid, name in items:
+ BookType.objects.create(uuid=uuid, name=name)
+
+
+def reverse(__code__, __reverse_code__):
+ BookType.objects.all().delete()
+
+
+class Migration(migrations.Migration):
+ dependencies = [("data", "0011_author_seed")]
+
+ operations = [migrations.RunPython(forward, reverse)]
+
In this example 011_author_seed
is the name of the last migration file in core/data/migrations
. You will also need to update this to the last python file in core/data/migrations
having the format xxxx_<modename_in_lower_case>_seed.py
.
If you have a requirement to run on your local machine or you are unable to get it to work on +Docker, do the following steps. WARNING: If you run into issues you will get limited support.
+Run these commands from the app
directory:
.env.docker-example
to .env.local
.env.local
and change values as appropriate. The file includes instructions on how to use local postgres
and sqlite
for the database. sqlite
has no set up. It uses a file db.sqlite3
. If it is not there, it automatically creates it.alias python="python3"
cd app
+
+# copy the env file
+cp .env.docker-example .env.local
+
+# create a virtual environment
+python -m venv venv
+
+# activate (enter) the virtual environment
+source venv/bin/activate
+# install dependencies
+pip install -r requirements.txt
+
+# start local server
+../scripts/start-local.sh
+# start server with alternate port
+# DJANGO_PORT=8001 ../scripts/start-local.sh
+
+# browse to http://localhost:8000 (or 8001) to see the app
+
+# Ctrl-C to stop the server
+
+# deactivate (exit) the virtual environment
+# to return to the system global environment
+deactivate
+
TIP: Look up direnv
for a useful method to automatically enter and exit virtual environments based on the current directory.
Thank you for volunteering your time! The following is a set of guidelines for contributing to the PeopleDepot repository, which is hosted on GitHub.
+Please make sure you have completed the onboarding process which includes joining the Hack for LA Slack, GitHub, and Google Drive. If you have not been onboarded, see the Getting Started Page. Workshop attendees are granted a temporary exception from this requirement.
+Find an issue in Prioritized Backlog here
+If you joined the PeopleDepot repository as described in a previous section:
+If you don't have privileges, add a comment that you are working on the issue.
+Once you have selected an issue to work on, create a branch for that issue.
+Verify you are on the main
branch.
You will see a list of all of your branches. There will be a star (*
) next to the branch that you are currently in. By default you should start on the main
branch.
If you are not currently in the main
branch, run the following command to return to it:
This ensures you have the most recent code, which is important if you previously cloned and it has been more than a day.
+Create a new branch where you will work on the issue. The branch name should include the issue number. For example, to create a new branch for issue 15 and change into it:
+ +Make changes to fix the issue.
+You can probably skip this if you fix the issue on the same day that you pulled the code.
+ +If you are using Visual studios code you can use the Git graphical user interface to stage your changes. For instructions check out the Git GUI page in the website Wiki
+Make sure you are on your issue branch (instead of main
)
You must add your files to the staging area before you can commit (save them to git).
+Run this command if you want to add changes from a specific file to your commit record:
+ +Run this command if you want to add all changes to all file(s) to your commit record:
+ +This command will list the files that have been staged with green text. These are the files that will be committed (saved) when you run the next command, git commit
. Please be sure all your staged changes are relevant to the issue you are working on. If you accidentally included unrelated changes, please unstage them before making this commit, and then make a new commit for the unrelated changes. (The commands for unstaging commits are provided in the output of your git status
command.)
This command will unstage a file that you don't want included in the commit. The specified file will not be committed (saved) when you run the next command, git commit
. This only works if the wrong files were added, but they were not yet committed. (See this tutorial for an in-depth discussion.) The file will be removed from the staging area, but not actually deleted:
This command saves your work, and prepares it to push to your repository. Use the -m
flag to quickly add a message to your commit. Your message should be a short description of the changes you made. It will be extremely helpful if other people can understand your message, so try to resist the temptation to be overly cryptic.
To commit your changes with a message, run:
+ +Ensure that your local repository is up-to-date with the main site:
+ +You can also sync your fork directly on GitHub by clicking "Sync Fork" at the right of the screen and then clicking "Update Branch"
+Push your local branch to your remote repository:
+ +Alternatively, you can run
+ +Once you are satisfied with your changes, push them to the feature branch you made within your remote repository.
+ +<issue-number>
with the issue you worked on:To create a new issue, please use the blank issue template (available when you click New Issue). If you want to create an issue for other projects to use, please create the issue in your own repository and send a slack message to one of your hack night hosts with the link.
+ + + + + + +This step is optional if this is your first time fixing an issue and you want to try fixing an issue without this step.
+In the People-depot Slack channel, send an introductory message with your GitHub handle/username
asking to be added to the Hack for LA peopledepot GitHub repository, have access to the Google Docs Drive, and Figma.
Please do the following once you have accepted the GitHub invite (comes via email or in your GitHub notifications)
+Make your own Hack for LA GitHub organization membership public by following this guide.
+To stop the service-container, but not destroy it (often sufficient for day-to-day work):
+ +To stop and destroy the service container:
+ +Add the -v
flag to destroy the data volumes as well:
To restore a database to its original state and remove any data manually added, delete the container and image. +From Docker:
+This helps speed up subsequent docker builds by caching intermediate files and reusing them across builds. It's available with docker buildkit. The key here is to disable anything that could delete the cache, because we want to preserve it. The cache mount is not going to end up in the docker image being built, so there's no concern about disk space usage.
+Put this flag between RUN
and the command
For pip, the files are by default stored in /root/.cache/pip
. Pip caching docs
For apk, the cache directory is /var/cache/apk/
. APK wiki on local cache
For apt, the cache directory is /var/cache/apt/
.
We're choosing to use an Alpine-based image for the smaller size and faster builds and downloads. However, a Debian-based image has the advantage of a large ecosystem of available packages, a limitation of Alpine that we may run up against in the future.
+Here is how we can switch to a Debian-based images if we need to:
+Edit Dockerfile
to look something like this
# pull official base image
+FROM python:3.10-alpine
+# (1)! define base image
+FROM python:3.10-bullseye
+
+# set work directory
+WORKDIR /usr/src/app
+
+# set environment variables
+ENV PYTHONDONTWRITEBYTECODE=1
+ENV PYTHONUNBUFFERED=1
+ENV PYTHONPYCACHEPREFIX=/root/.cache/pycache/
+ENV PIP_CACHE_DIR=/var/cache/buildkit/pip
+
+RUN mkdir -p $PIP_CACHE_DIR
+# (2)! prevent cache deletion
+RUN rm -f /etc/apt/apt.conf.d/docker-clean; \
+echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache
+
+# install system dependencies
+RUN \
+ --mount=type=cache,target=/var/cache/apk \
+ --mount=type=cache,target=/etc/apk/cache \
+ apk add \czjqqkd:19
+ 'graphviz=~9.0'
+
+# install font for graphviz
+COPY Roboto-Regular.ttf /root/.fonts/
+RUN fc-cache -f
+# (3)! define cache mounts and install dependencies
+ --mount=type=cache,target=/var/cache/apt,sharing=locked \
+ --mount=type=cache,target=/var/lib/apt,sharing=locked \
+ apt-get update \
+ && apt-get install --no-install-recommends -yqq \
+ netcat=1.10-46 \
+ gcc=4:10.2.1-1 \
+ postgresql=13+225+deb11u1 \
+ graphviz=2.42.2-5
+
+# install dependencies
+COPY ./requirements.txt .
+# hadolint ignore=DL3042
+# (4)! install uv for faster dependency resolution
+RUN \
+ --mount=type=cache,target=/root/.cache \
+ pip install uv==0.1.15 \
+ && uv pip install --system -r requirements.txt
+
+# copy entrypoint.sh
+COPY ./entrypoint.sh .
+RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh \
+ && chmod +x /usr/src/app/entrypoint.sh
+
+# copy project
+COPY . .
+
+# run entrypoint.sh
+ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
+
entrypoint.sh
dbshell
management commanderd.sh
Use the dive
tool to check the image layers for extra files that shouldn't be there.
These are the tools we use in the PeopleDepot project with notes on how we use them.
+We are using MkDocs to generate our documentation. See Docker-mkdocs repo for information about MkDocs and the image we're using.
+The first time starting the container may take longer due to downloading the ~40MB docker image
+Run the mkdocs container.
+ +-d
flag to run the container in the backgroundOpen a browser to http://localhost:8005/
to view the documentation locally.
Modify the files in the docs
directory. The site will auto-update when the files are saved.
Ctrl+C to quit the local server and stop the container
+We have a GitHub Action set up to generate and host the documentation on a GitHub Pages site
+We're using Material for MkDocs. Aside from standard markdown syntax, there are some MkDocs and Material-specific syntax which can help more effective documentation. See the Material reference docs for the complete set of syntax.
+Here's a list of commonly used MkDocs syntax for quick reference.
+@admin.register(RecurringEvent)
+class RecurringEventAdmin(admin.ModelAdmin):
+ list_display = (
+ "name",
+ "start_time",
+ "duration_in_min",
+ )
+
Numbered Lines | |
---|---|
```python title="Code Block"
+@admin.register(RecurringEvent)
+class RecurringEventAdmin(admin.ModelAdmin):
+ list_display = (
+ "name",
+ "start_time",
+ "duration_in_min",
+ )
+```
+
+```python title="Numbered Lines" linenums="1"
+@admin.register(RecurringEvent)
+class RecurringEventAdmin(admin.ModelAdmin):
+ list_display = (
+ "name",
+ "start_time",
+ "duration_in_min",
+ )
+```
+
+```python title="Highlighted Lines" hl_lines="1 3 5"
+@admin.register(RecurringEvent)
+class RecurringEventAdmin(admin.ModelAdmin):
+ list_display = (
+ "name",
+ "start_time",
+ "duration_in_min",
+ )
+```
+
The hooks will run when doing normal git commit
and git push
commands. It's recommended to do this in the command line to see the output. If performing these actions from a gui application, the interface may seem to hang for some time.
The pre-commit checks should be fast while the pre-push hooks will take longer since they'll do a full rebuild
+It's recommended to install "global" tools via pipx, which installs packages in an isolated environment rather than the global python environment.
+Install pre-commit
+ +Add the hook to git
+ +Pre-commit is now set up to check your files whenever you commit or push code.
+Test by adding an empty commit
+ +You should see a list of tests that are all skipped, because there's no changes in the commit to test.
+To skip the checks temporarily, you can do one of these
+ +Manually run the hooks (this runs it against all files rather than only changed files)
+ +More commands to run the hooks
+ +Update pre-commit and plugins to the latest version
+ +These are designed to make it easier to perform various everyday tasks in the project. They try to be transparent by exposing the underlying commands they execute so that users can have an idea of what's happening and try to learn the commands if they wish.
+scripts/
+├── buildrun.sh
+├── check-migrations.sh
+├── createsuperuser.sh
+├── db.sh
+├── erd.sh
+├── lint.sh
+├── loadenv.sh
+├── logs.sh
+├── migrate.sh
+├── precommit-check.sh
+├── run.sh
+├── start-local.sh
+├── test.sh
+└── update-dependencies.sh
+
These scripts assume you are using bash.
+buildrun.sh - clean, build, and run containers in background mode
+-v
to remove data volume, which resets the local database.check-migrations.sh - check if migrations are up to date
+createsuperuser.sh - create a default superuser
+DJANGO_SUPERUSER_USERNAME
and DJANGO_SUPERUSER_PASSWORD
are set in .env.dev
db.sh - connect to the database in the db
container
manage.py dbshell
, which requires the psql
executable in the web
containererd.sh - generate ER diagram
+app/erd.png
graphviz
packagelint.sh - lint and and auto-format code
+loadenv.sh - load environment variables from .env.dev
into shell environment
logs.sh - view/tail container logs
+migrate.sh - run database migrations inside container
+<app> <migration_number>
to migrate to that database state. Ex: migrate.sh core 0010
precommit-check.sh - sanity checks before committing code
+buildrun.sh
, lint.sh
, and test.sh
run.sh - start the development server in Docker, with some options
+-h
to show usagestart-local.sh - start the development server natively
+test.sh - run tests and generate test coverage report
+-k
flag to filter tests. For example test.sh -k program_area
will select only tests with "program_area" in the name.--no-cov
to disable the coverage report. The coverage report will show many missing lines of coverage as a result.update-dependencies.sh - update python dependencies to the latest versions
+We're using uv
as a faster replacement to pip
and pip-tools
. See the official documentation on getting started.
We're using uv
to compile and install python dependencies, which replaces the functionalities of pip
and pip-tools
. uv
can also create and maintain a virtual environment but we're not using it for now. In fact, we're suppressing it with the --system
option during uv pip install
.
uv
is already part of the docker
image, so there's no need to install it on the host. It does require prepending the docker-compose information to run, for example: docker-compose exec web uv pip compile requirements.in -o requirements.txt
. We'll omit the docker-compose exec web
portion from now on in this document.
requirements.in
is the requirements file and uv pip compile
generates requirement.txt
, with pinned versions, similar to lock files in other languages.
We shouldn't run this on every build, but we should do this manually every month/quarter or so.
+# docker-compose exec web
+uv pip compile requirements.in -o requirements.txt --no-header --upgrade
+
Or run the script
+ +--no-header
This solves the problem unnecessary code churn caused by changing headers--upgrade
--generate-hashes
Hashes improve security but are not verified by uv
at the moment. It is planned. Switch back to pip
for installation if we need to verify hashes.--no-annotate
This makes the generated file shorter but less informativeSee pip-compile docs for more options and explanation
+This is used in the Dockerfile
to install python dependencies.
--system
bypass the virtual environment requirementSee pip install docs for more options and explanation
+We're using the --system
option in the Dockerfile
to bypass the virtual environment requirement for uv
. This is because the docker image is already a virtual environment separate from the host.
We're leaving most dependencies unpinned in requirements.in
so that pip compile
will pin the newest compatible versions in requirements.txt
. The only manually pinned dependency is django~=4.2.0
. The x.2.x
versions have long term support, and we're using 4
, since 4.2
is the latest LTS available.
This is a temporary solution until we can deploy a dev environment for PeopleDepot.
+There's a few manual steps and the login is good for only an hour at a time.
+Prerequisites:
+Steps:
+Login (or register first then login) to a cognito account here. Do not worry if you see error messages - you will be using the url.
+ +Copy the URL when it redirects. Note: Instead of the screen below, the screen may display an error message. You can ignore any error messages.
+ +Extract the access_token
using the online tool.
access_token
Open ModHeader. If the icon is hidden, click on the Puzzle icon in the upper right of the browser to see it.
+Type the word Bearer and paste the token into ModHeader Authorization: Bearer \
Go to a page in api/v1/ to see that it allows access
+ +Explore APIs using Swagger
+ +Some fields have hints on how to retrieve the values.
+ +A redoc ui is also available
+ +PeopleDepot is a project of Hack for LA/Civic Tech Structure Inc. 501(c)(3). PeopleDepot aims to provide a single source of truth as the backend infrastructure and data store for Hack for LA projects, including data about people, program areas, and projects. PeopleDepot uses PostgreSQL for its database and Django as the backend data model framework with Django REST Framework for the API layer. PeopleDepot's goal is to serve as a repository of information for other infrastructure projects (e.g., VRMS, Hack for LA Website, Civic Tech Index, Tables, etc).
+The hardest part about running a large organization using only free or open source tools and technologies is how to manage the flow of information and provide relevant info to all the people and projects that need it. Managing multiple databases inefficiently can end up taking more time than the projects themselves. This project seeks to create a maintainable database infrastructure that is synchronized.
+In the process, it should allow for further automation and do away with manual storage of duplicate information across projects, which includes:
+Contact us in the #people-depot
channel on Slack.
This repository uses the GNU General Public License (v2.0).
+ + + + + + + + GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed.
+ Preamble
+
The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too.
+When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things.
+To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it.
+For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights.
+We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software.
+Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations.
+Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all.
+The precise terms and conditions for copying, distribution and +modification follow.
+ GNU GENERAL PUBLIC LICENSE
+
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does.
+You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee.
+You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions:
+a) You must cause the modified files to carry prominent notices +stating that you changed the files and the date of any change.
+b) You must cause any work that you distribute or publish, that in +whole or in part contains or is derived from the Program or any +part thereof, to be licensed as a whole at no charge to all third +parties under the terms of this License.
+c) If the modified program normally reads commands interactively +when run, you must cause it, when started running for such +interactive use in the most ordinary way, to print or display an +announcement including an appropriate copyright notice and a +notice that there is no warranty (or else, saying that you provide +a warranty) and that users may redistribute the program under +these conditions, and telling the user how to view a copy of this +License. (Exception: if the Program itself is interactive but +does not normally print such an announcement, your work based on +the Program is not required to print an announcement.)
+These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it.
+Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program.
+In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License.
+You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following:
+a) Accompany it with the complete corresponding machine-readable +source code, which must be distributed under the terms of Sections +1 and 2 above on a medium customarily used for software interchange; or,
+b) Accompany it with a written offer, valid for at least three +years, to give any third party, for a charge no more than your +cost of physically performing source distribution, a complete +machine-readable copy of the corresponding source code, to be +distributed under the terms of Sections 1 and 2 above on a medium +customarily used for software interchange; or,
+c) Accompany it with the information you received as to the offer +to distribute corresponding source code. (This alternative is +allowed only for noncommercial distribution and only if you +received the program in object code or executable form with such +an offer, in accord with Subsection b above.)
+The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable.
+If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code.
+You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance.
+You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it.
+Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License.
+If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program.
+If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances.
+It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice.
+This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License.
+If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License.
+The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns.
+Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation.
+If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally.
+ NO WARRANTY
+
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION.
+IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES.
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms.
+To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found.
+<one line to give the program's name and a brief idea of what it does.>
+Copyright (C) <year> <name of author>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
Also add information on how to contact you by electronic and paper mail.
+If the program is interactive, make it output a short notice like this +when it starts in an interactive mode:
+Gnomovision version 69, Copyright (C) year name of author
+Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+This is free software, and you are welcome to redistribute it
+under certain conditions; type `show c' for details.
+
The hypothetical commands show w' and
show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than show w' and
show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names:
+Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker.
+This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License.
+ + + + + + +We're using OpenAPI (swagger) for API documentation. We won't have a public URL for it until it's deployed. A ReDoc interface is also available.
+These are the URLs in the local dev environment
+PeopleDepot is a project of Hack for LA/Civic Tech Structure Inc. 501(c)(3). PeopleDepot aims to provide a single source of truth as the backend infrastructure and data store for Hack for LA projects, including data about people, program areas, and projects. PeopleDepot uses PostgreSQL for its database and Django as the backend data model framework with Django REST Framework for the API layer. PeopleDepot's goal is to serve as a repository of information for other infrastructure projects (e.g., VRMS, Hack for LA Website, Civic Tech Index, Tables, etc).
"},{"location":"#project-context","title":"Project context","text":"The hardest part about running a large organization using only free or open source tools and technologies is how to manage the flow of information and provide relevant info to all the people and projects that need it. Managing multiple databases inefficiently can end up taking more time than the projects themselves. This project seeks to create a maintainable database infrastructure that is synchronized.
In the process, it should allow for further automation and do away with manual storage of duplicate information across projects, which includes:
Contact us in the #people-depot
channel on Slack.
This repository uses the GNU General Public License (v2.0).
"},{"location":"license/","title":"License","text":" GNU GENERAL PUBLIC LICENSE\n Version 2, June 1991\n
Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble\n
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
GNU GENERAL PUBLIC LICENSE\n
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and \"any later version\", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY\n
BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS\n\n How to Apply These Terms to Your New Programs\n
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the \"copyright\" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>\nCopyright (C) <year> <name of author>\n\nThis program is free software; you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation; either version 2 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along\nwith this program; if not, write to the Free Software Foundation, Inc.,\n51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\n
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author\nGnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; type `show c' for details.\n
The hypothetical commands show w' and
show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than show w' and
show c'; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a \"copyright disclaimer\" for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
, 1 April 1989 Ty Coon, President of Vice
This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.
"},{"location":"architecture/Notes/","title":"Troubleshooting","text":""},{"location":"architecture/Notes/#modheader","title":"ModHeader","text":"ModHeader will break Google drive if Authentication Bearer token is set. The Google drive website pops up a dialog saying:
\"You are not signed in.\nYou are signed out. Sign back in, then click 'Retry'.\nRetry\"\n
The solution is to disable the Authentication header and Google drive will work as normal.
Cognito is a single sign-on system from AWS. It allows multiple apps to accept authentication from the same set of user accounts. It separates the management of users and permissions from the applications that use them.
"},{"location":"architecture/authentication/#why-we-use-cognito","title":"Why we use cognito","text":"We're invested in AWS, so we might as well use this too.
"},{"location":"architecture/authentication/#how-we-implement-it","title":"How we implement it","text":"We're following the implementation from the djangostar tutorial.
These are the steps involved:
The tutorial is 2 years old now (from 2020) and there's been some change made since then.
These are the github actions used in the project.
"},{"location":"architecture/github_actions/#files","title":"Files","text":".github/workflows/\n\u2514\u2500\u2500 deploy-docs.yml # (1)!\n
main
These are the directories and files in the project. Parts are summarized for clarity.
"},{"location":"architecture/project_structure/#top-level","title":"Top level","text":"/\n\u251c\u2500\u2500 app/ # (1)!\n\u251c\u2500\u2500 docs/ # (2)!\n\u251c\u2500\u2500 scripts/ # (3)!\n\u251c\u2500\u2500 docker-compose.yml # (4)!\n\u2514\u2500\u2500 pyproject.toml # (5)!\n
./scripts/buildrun.sh
. See Django Project below for details.app/setup.cfg
in the future. We may move this file into app/
if it makes sense.app/\n\u251c\u2500\u2500 core/ # (1)!\n\u251c\u2500\u2500 data/ # (2)!\n\u251c\u2500\u2500 peopledepot/ # (3)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 asgi.py\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 settings.py\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 urls.py\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 wsgi.py\n\u251c\u2500\u2500 scripts/ # (4)!\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 convert.py\n\u251c\u2500\u2500 Dockerfile # (5)!\n\u251c\u2500\u2500 entrypoint.sh # (6)!\n\u251c\u2500\u2500 manage.py # (7)!\n\u251c\u2500\u2500 requirements.in # (8)!\n\u251c\u2500\u2500 requirements.txt # (9)!\n\u2514\u2500\u2500 setup.cfg # (10)!\n
convert.py
script, which converts csv files into django initial data code. It's used to generate code for the initial data migrations.uv pip compile
. See the uv tool for details.uv pip install
. Do not modify this file. Edit the requirements.in
file instead. See the uv tool for details.flake8
and pytest
. flake8
is the only tool that doesn't support pyproject.toml
yet, which is why we have this file.core/\n\u251c\u2500\u2500 admin.py # (1)!\n\u251c\u2500\u2500 api/\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 permissions.py # (2)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 serializers.py # (3)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 urls.py # (4)!\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 views.py # (5)!\n\u251c\u2500\u2500 apps.py # (6)!\n\u251c\u2500\u2500 initial_data/\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 ...\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 Initial data in json or csv format # (7)!\n\u251c\u2500\u2500 migrations/\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 nnnn_migration_name.py # (8)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 ...\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 max_migration.txt # (9)!\n\u251c\u2500\u2500 models.py # (10)!\n\u251c\u2500\u2500 scripts/ # (11)!\n\u251c\u2500\u2500 tests/\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 conftest.py # (12)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 test_api.py # (13)!\n\u2502\u00a0\u00a0 \u251c\u2500\u2500 test_models.py # (14)!\n\u2502\u00a0\u00a0 \u2514\u2500\u2500 test_permissions.py # (15)!\n\u2514\u2500\u2500 utils/ # (16)!\n. \u2514\u2500\u2500 jwt.py # (17)!\n
makemigrations
command.django-linear-migrations
. It stores the last migration name for the app for use in git merge conflicts.data/\n\u2514\u2500\u2500 migrations/\n.\u00a0\u00a0 \u251c\u2500\u2500 nnnn_migration_name.py # (1)!\n.\u00a0\u00a0 \u251c\u2500\u2500 ...\n. \u2514\u2500\u2500 max_migration.txt # (2)!\n
django-linear-migrations
. It stores the last migration name for the app for use in git merge conflicts./\n\u251c\u2500\u2500 docs/\n\u2502 \u251c\u2500\u2500 [topics]/ # (1)!\n\u2502 \u251c\u2500\u2500 CONTRIBUTING.md # (2)!\n\u2502 \u251c\u2500\u2500 index.md # (3)!\n\u2502 \u251c\u2500\u2500 LICENSE # (4)!\n\u2502 \u251c\u2500\u2500 license.md # (5)!\n\u2502 \u2514\u2500\u2500 _static/\n\u251c\u2500\u2500 CONTRIBUTING.md # (6)!\n\u251c\u2500\u2500 LICENSE # (7)!\n\u251c\u2500\u2500 mkdocs.yml # (8)!\n\u2514\u2500\u2500 README.md # (9)!\n
CONTRIBUTING.md
file in the project root. MkDocs requires all documentation files to be in the docs/
directory. This file uses a snippet to import the source content.README.md
file from the project root.LICENSE
file. This file uses a snippet to import the LICENSE
file from the project root. This is used for linking from the Documentation Homepage as well as the README.md
file in the Github web interface, which knows the file by this name only.license.md
file. This file uses a snippet to import the LICENSE
file from the project root. This is used for the MkDocs nav section, which requires the md
file extension.Thank you for volunteering your time! The following is a set of guidelines for contributing to the PeopleDepot repository, which is hosted on GitHub.
Please make sure you have completed the onboarding process which includes joining the Hack for LA Slack, GitHub, and Google Drive. If you have not been onboarded, see the Getting Started Page. Workshop attendees are granted a temporary exception from this requirement.
Joining the team
Setting up the Development Environment
Working with Issues
Working with Git
Documentation
How-to Guides
Tools
See here for creating a GitHub account. If you are not familiar with Git, this tutorial is recommended.
"},{"location":"contributing/dev_environment/#two-factor-authentication","title":"Two-factor authentication","text":"Set up two-factor authentication on your account by following this guide.
"},{"location":"contributing/dev_environment/#text-editor","title":"Text editor","text":"VS Code is recommended, but feel free to use a text editor of your choice.
"},{"location":"contributing/dev_environment/#install-git","title":"Install Git","text":"Before cloning your forked repository to your local machine, you must have Git installed. You can find instructions for installing Git for your operating system here.
WindowsMacwe recommend installing Windows Subsystem for Linux (WSL). WSL provides a Linux-compatible environment that can prevent common errors during script execution.
After setting up WSL, install Git directly from the Linux terminal. This method can help avoid complications that sometimes arise when using Git Bash on Windows.
If you prefer Git Bash or encounter errors related to line endings when running scripts, the problem might be due to file conversions in Windows. To address this, configure Git as follows:
git config --system set autocrlf=false\n
Feel free to reach out in the Hack for LA Slack channel if you encounter any errors while running scripts on Windows
Please note that if you have a Mac the page offers several options (see other option, if you need to conserve hard drive space) including:
$ brew install git
which in total only uses 300MB.Install or make sure docker and docker-compose are installed on your computer
docker -v\ndocker-compose -v\n
The recommended installation method for your operating system can be found here.
Feel free to reach out in the Hack for LA Slack channel if you have trouble installing docker on your system
More on using Docker and the concepts of containerization:
You can fork the hackforla/peopledepot repository by clicking Fork . A fork is a copy of the repository that will be placed on your GitHub account.
It should create a URL that looks like the following -> https://github.com/<your_GitHub_user_name>/peopledepot
For example -> https://github.com/octocat/peopledepot
What you have created is a forked copy in a remote version on GitHub. It is not on your local machine yet
"},{"location":"contributing/dev_environment/#clone-a-copy-on-your-computer","title":"Clone a copy on your computer","text":"The following steps will clone (create) a local copy of the forked repository on your computer.
Create a new folder in your computer that will contain hackforla
projects.
In your command line interface (Terminal, Git Bash, Powershell), move to where you want your new folder to be placed and create a new folder in your computer that will contain hackforla
projects. After that, navigate into the folder(directory) you just created.
For example:
cd /projects\nmkdir hackforla\ncd hackforla\n
From the hackforla directory created in previous section:
git clone https://github.com/<your_GitHub_user_name>/peopledepot.git\n
For example if your GitHub username was octocat
:
git clone https://github.com/octocat/peopledepot.git\n
You can also clone using ssh which is more secure but requires more setup. Because of the additional setup, cloning using https as shown above is recommended
You should now have a new folder in your hackforla
folder called peopledepot
. Verify this by changing into the new directory:
cd peopledepot\n
"},{"location":"contributing/dev_environment/#verify-and-set-up-remote-references","title":"Verify and set up remote references","text":"Verify that your local cloned repository is pointing to the correct origin
URL (that is, the forked repo on your own GitHub account):
git remote -v\n
You should see fetch
and push
URLs with links to your forked repository under your account (i.e. https://github.com/<your_GitHub_user_name>/peopledepot.git
). You are all set to make working changes to the project on your local machine.
However, we still need a way to keep our local repo up to date with the deployed project. To do so, you must add an upstream remote to incorporate changes made while you are working on your local repo. Run the following to add an upstream remote URL & update your local repo with recent changes to the hackforla
version:
git remote add upstream https://github.com/hackforla/peopledepot.git\ngit fetch upstream\n
After adding the upstream remote, you should now see it if you again run git remote -v
:
origin https://github.com/<your_GitHub_user_name>/peopledepot.git (fetch)\norigin https://github.com/<your_GitHub_user_name>/peopledepot.git (push)\nupstream https://github.com/hackforla/peopledepot.git (fetch)\nupstream https://github.com/hackforla/peopledepot.git (push)\n
"},{"location":"contributing/dev_environment/#build-and-run-using-docker-locally","title":"Build and run using Docker locally","text":"Make sure the Docker service is running
Docker (Engine)Docker Desktopsudo systemctl status docker\n
It will show Active: active (running)
if it's running.
docker container ls
to verify Docker Desktop is running. If it is not running you will get the message: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Create an .env.docker file from .env.docker-example
cp ./app/.env.docker-example ./app/.env.docker\n
Build and run the project via the script (this includes running docker-compose up
)
./scripts/buildrun.sh\n
Create a super user for logging into the web admin interface
docker-compose exec web python manage.py createsuperuser --no-input\n
Browse to the web admin interface at http://localhost:8000/admin/
and confirm the admin site is running. Use DJANGO_SUPERUSER_USERNAME and DJANGO_SUPERUSER_PASSWORD from .env.docker for credentials.
See our documentation for Working with Docker for more useful Docker commands.
"},{"location":"contributing/dev_environment/#install-pre-commit","title":"Install pre-commit","text":"This will check your changes for common problems.
See the Pre-commit page for installation instructions.
For consistency, an automated bot will perform the same checks on the repository side when you open a pull request.
"},{"location":"contributing/documentation/","title":"Documentation","text":"We highly encourage contributors to add and update documentation in the same pull request as the code. This will ensure that the docs and features are synchronized.
Please see the MkDocs page for how to view documentation changes locally using the mkdocs in docker.
"},{"location":"contributing/git/","title":"Working with Git","text":""},{"location":"contributing/git/#sync-main-changes","title":"Sync Main Changes","text":"Your fork of this repository on GitHub, and your local clone of that fork, will get out of sync with the (upstream) repository as others update the repository. (That's what has happened when you see something like \"This branch is 1 commit behind peopledepot:main\" on your forked repository.)
One way to keep your fork up to date with this repository is to follow these instruction: Syncing your fork to the original repository via the browser
You can also update your fork via the local clone of your fork, using these instructions. Assuming you have a local clone with remotes upstream
(this repo) and origin
(your GitHub fork of this repo):
Run the following two commands:
git fetch upstream\ngit checkout -b upstream-main --track upstream/main\n
If you have already created the branch upstream-main, the following commands will incorporate upstream changes:
git checkout upstream-main # Move to the branch you want to merge with.\ngit pull # This updates your tracking branch to match the main branch in this repository\ngit checkout main # Move back to your main branch\ngit merge upstream-main # Merge to bring your main current.\n
If you do all your work on topic branches (as suggested above) and keep main free of local modifications, this merge should apply cleanly.
Then push the merge changes to your GitHub fork:
git push\n
If you go to your online GitHub repository this should remove the message \"This branch is x commit behind peopledepot:main\".
"},{"location":"contributing/issues/","title":"Working with Issues","text":""},{"location":"contributing/issues/#find-an-issue","title":"Find an issue","text":"Find an issue in Prioritized Backlog here
If you joined the PeopleDepot repository as described in a previous section:
If you don't have privileges, add a comment that you are working on the issue.
"},{"location":"contributing/issues/#create-a-new-branch","title":"Create a new branch","text":"Once you have selected an issue to work on, create a branch for that issue.
Verify you are on the main
branch.
git branch\n
You will see a list of all of your branches. There will be a star (*
) next to the branch that you are currently in. By default you should start on the main
branch.
If you are not currently in the main
branch, run the following command to return to it:
git checkout main\n
git pull origin main\n
This ensures you have the most recent code, which is important if you previously cloned and it has been more than a day.
Create a new branch where you will work on the issue. The branch name should include the issue number. For example, to create a new branch for issue 15 and change into it:
git checkout -b <new-branch-name>-15\n
"},{"location":"contributing/issues/#make-changes","title":"Make changes","text":"Make changes to fix the issue.
"},{"location":"contributing/issues/#pull-to-get-the-most-recent-code","title":"Pull to get the most recent code","text":"You can probably skip this if you fix the issue on the same day that you pulled the code.
git pull\n
If you are using Visual studios code you can use the Git graphical user interface to stage your changes. For instructions check out the Git GUI page in the website Wiki
"},{"location":"contributing/issues/#add-changed-files-to-staging","title":"Add changed files to staging","text":"Make sure you are on your issue branch (instead of main
)
git branch\n
You must add your files to the staging area before you can commit (save them to git).
Run this command if you want to add changes from a specific file to your commit record:
git add \u201cfilename.ext\u201d\n
Run this command if you want to add all changes to all file(s) to your commit record:
git add .\n
"},{"location":"contributing/issues/#check-git-status","title":"Check Git status","text":"This command will list the files that have been staged with green text. These are the files that will be committed (saved) when you run the next command, git commit
. Please be sure all your staged changes are relevant to the issue you are working on. If you accidentally included unrelated changes, please unstage them before making this commit, and then make a new commit for the unrelated changes. (The commands for unstaging commits are provided in the output of your git status
command.)
git status\n
"},{"location":"contributing/issues/#remove-files-that-you-dont-want-staged","title":"Remove files that you don't want staged","text":"This command will unstage a file that you don't want included in the commit. The specified file will not be committed (saved) when you run the next command, git commit
. This only works if the wrong files were added, but they were not yet committed. (See this tutorial for an in-depth discussion.) The file will be removed from the staging area, but not actually deleted:
git reset HEAD \u201cfilename.ext\u201d\n
"},{"location":"contributing/issues/#commit-staged-changes","title":"Commit staged changes","text":"This command saves your work, and prepares it to push to your repository. Use the -m
flag to quickly add a message to your commit. Your message should be a short description of the changes you made. It will be extremely helpful if other people can understand your message, so try to resist the temptation to be overly cryptic.
To commit your changes with a message, run:
git commit -m \u201cinsert message here\u201d\n
Ensure that your local repository is up-to-date with the main site:
git pull upstream\n
You can also sync your fork directly on GitHub by clicking \"Sync Fork\" at the right of the screen and then clicking \"Update Branch\"
"},{"location":"contributing/issues/#push-to-upstream-origin-aka-your-fork","title":"Push to upstream origin (aka, your fork)","text":"Push your local branch to your remote repository:
git push --set-upstream origin <your-branch-name>\n
Alternatively, you can run
git push\n
"},{"location":"contributing/issues/#create-a-pull-request","title":"Create a pull request","text":""},{"location":"contributing/issues/#push-all-changes-in-your-issue-branch","title":"Push all changes in your issue branch","text":"Once you are satisfied with your changes, push them to the feature branch you made within your remote repository.
git push --set-upstream origin <name-of-branch>\n
"},{"location":"contributing/issues/#complete-pull-request-from-github","title":"Complete pull request from GitHub","text":"<issue-number>
with the issue you worked on:fixes #<issue-number>\n
To create a new issue, please use the blank issue template (available when you click New Issue). If you want to create an issue for other projects to use, please create the issue in your own repository and send a slack message to one of your hack night hosts with the link.
"},{"location":"contributing/team/","title":"Joining Repository Team","text":"This step is optional if this is your first time fixing an issue and you want to try fixing an issue without this step.
In the People-depot Slack channel, send an introductory message with your GitHub handle/username
asking to be added to the Hack for LA peopledepot GitHub repository, have access to the Google Docs Drive, and Figma.
Please do the following once you have accepted the GitHub invite (comes via email or in your GitHub notifications)
Make your own Hack for LA GitHub organization membership public by following this guide.
"},{"location":"contributing/howto/","title":"How-to Guides","text":"These are the developer guides for how to do specific things with the project.
This guide aims to enable developers with little or no django experience to add django models and API endpoints to the project. Most code examples are followed by detailed explanations.
The developer will have exposure to the following in this documentThis guide assumes the developer has followed the working with issues guide and have forked and created a local branch to work on this. The development server would be already running in the background and will automatically apply the changes when we save the files.
We will choose the recurring_event issue as an example. Our goal is to create a database table and an API that a client can use to work with the data. The work is split into 3 testable components: the model, the admin site, and the API
Let's start!
"},{"location":"contributing/howto/add-model-and-api-endpoints/#data-model","title":"Data model","text":"TDD testWrite the test
We would like the model to store these data, and to return the name property in the str function.
In app/core/tests/test_models.py
def test_recurring_event_model(project):\nfrom datetime import datetime\npayload = {\n\"name\": \"test event\",\n\"start_time\": datetime(2023, 1, 1, 2, 34),\n\"duration_in_min\": 60,\n\"video_conference_url\": \"https://zoom.com/mtg/1234\",\n\"additional_info\": \"long description\",\n\"project\": project,\n}\nrecurring_event = RecurringEvent(**payload)\n# recurring_event.save()\nassert recurring_event.name == payload[\"name\"]\nassert recurring_event.start_time == payload[\"start_time\"]\nassert recurring_event.duration_in_min == payload[\"duration_in_min\"]\nassert recurring_event.video_conference_url == payload[\"video_conference_url\"]\nassert recurring_event.additional_info == payload[\"additional_info\"]\nassert recurring_event.project == payload[\"project\"]\nassert str(recurring_event) == payload[\"name\"]\n
For testing many-to-many relationships, we can add
app/core/tests/test_models.pydef test_project_recurring_event_relationship(project):\nrecurring_event = RecurringEvent.objects.get(name=\"{Name of Recurring Event}\")\nproject.recurring_events.add(recurring_event)\nassert project.recurring_events.count() == 1\nassert project.recurring_events.contains(recurring_event)\nassert recurring_event.projects.contains(project)\nproject.sdgs.remove(recurring_event)\nassert project.recurring_events.count() == 0\nassert not project.recurring_events.contains(recurring_event)\nassert not recurring_event.projects.contains(project)\n
See it fail
./scripts/test.sh\n
Run it again after implementing the model to make sure the code satisfies the test
Add the following to app/core/models.py
class RecurringEvent(AbstractBaseModel): # (1)!\n\"\"\"\n Recurring Events\n \"\"\"\nname = models.CharField(max_length=255)\nstart_time = models.TimeField(\"Start\", null=True, blank=True) # (2)!\nduration_in_min = models.IntegerField(null=True, blank=True) # (3)!\nvideo_conference_url = models.URLField(blank=True)\nadditional_info = models.TextField(blank=True) # (4)!\nproject = models.ForeignKey(Project, on_delete=models.CASCADE)\n# (5)!\n# location_id = models.ForeignKey(\"Location\", on_delete=models.DO_NOTHING)\n# event_type_id = models.ForeignKey(\"EventType\", on_delete=models.DO_NOTHING)\n# brigade_id = models.ForeignKey(\"Brigade\", on_delete=models.DO_NOTHING)\n# day_of_week = models.ForeignKey(\"DayOfWeek\", on_delete=models.DO_NOTHING)\n# must_roles = models.ManyToManyField(\"Role\")\n# should_roles = models.ManyToManyField(\"Role\")\n# could_roles = models.ManyToManyField(\"Role\")\n# frequency_id = models.ForeignKey(\"Frequency\", on_delete=models.DO_NOTHING)\ndef __str__(self): # (6)!\nreturn f\"{self.name}\"\n
uuid
primary key, created_at
, and updated_at
timestamps. In the Github issue, these fields might be called id
, created
, and updated
. There's no need to add those.blank=True
, data fields should be null=True
.INTEGER
, VARCHAR
, but we need to convert them into Django field types when defining the model.VARCHAR
can be either CharField
or TextField
.CharField
has a max_length
, which makes it useful for finite length text data. We're going default to giving them max_length=255
unless there's a better value like max_length=2
for state abbreviation.TextField
doesn't have a maximum length, which makes it ideal for large text fields such as description
.__str__
function to output something more meaningful than the default. It lets us do a quick test of the model by calling str([model])
. It's also useful for the admin site model list view.For adding many-to-many relationships with additional fields, such as ended_on
, we can add
class Project(AbstractBaseModel):\n...\nrecurring_events = models.ManyToManyField(\n\"RecurringEvent\",\nrelated_name=\"projects\",\nblank=True,\nthrough=\"ProjectRecurringEventXref\",\n)\n...\nclass ProjectRecurringEventXref(AbstractBaseModel):\n\"\"\"\n Joins a recurring event to a project\n \"\"\"\nrecurring_event_id = models.ForeignKey(RecurringEvent, on_delete=models.CASCADE)\nproject_id = models.ForeignKey(Project, on_delete=models.CASCADE)\nended_on = models.DateField(\"Ended on\", null=True, blank=True)\n
For adding many-to-many relationships without additional fields, we can just add
app/core/models.pyclass Project(AbstractBaseModel):\n...\nrecurring_events = models.ManyToManyField(\n\"RecurringEvent\",\nrelated_name=\"projects\",\nblank=True,\n)\n...\n
which leaves out the \"through\" field and the \"join table\" will be created implicitly.
"},{"location":"contributing/howto/add-model-and-api-endpoints/#run-migrations","title":"Run migrations","text":"This generates the database migration files
./scripts/migrate.sh\n
Test Since we overrode the __str__
function, we need to write a test for it.
Add a fixture for the model
Fixtures are reusable code that can be used in multiple tests by declaring them as parameters of the test case. In this example, we show both defining a fixture (recurring_event) and using another fixture (project).
Note: The conftest file is meant to hold shared test fixtures, among other things. The fixtures have directory scope.
Add the following to app/core/tests/conftest.py
@pytest.fixture\n# (1)!\ndef recurring_event(project): # (2)!\n# (3)!\nreturn RecurringEvent.objects.create(name=\"Test Recurring Event\", project=project)\n
recurring_event
).project
model as a foreign key relation, so we pass in the project
fixture, which creates a project
model.__str__
method in a test.Add a test case
When creating Django models, there's no need to test the CRUD functionality since Django itself is well-tested and we can expect it to generate the correct CRUD functionality. Feel free to write some tests for practice. What really needs testing are any custom code that's not part of Django. Sometimes we need to override the default Django behavior and that should be tested.
Here's a basic test to see that the model stores its name.
Add the following to app/core/tests/test_models.py
def test_recurring_event(recurring_event): # (1)!\n# (2)!\nassert str(recurring_event) == \"Test Recurring Event\" # (3)!\n
__str__
method should be tested since it's an override of the default Django method.__str__
method.Run the test script to show it passing
./scripts/test.sh\n
This is a good place to pause, check, and commit progress.
Run pre-commit checks
./scripts/precommit-check.sh\n
Add and commit changes
git add -A\ngit commit -m \"feat: add model: recurring_event\"\n
Django comes with an admin site interface that allows admin users to view and change the data in the models. It's essentially a database viewer.
"},{"location":"contributing/howto/add-model-and-api-endpoints/#register-the-model","title":"Register the model","text":"In app/core/admin.py
Import the new model
app/core/admin.pyfrom .models import RecurringEvent\n
Register the model with the admin site
app/core/admin.py@admin.register(RecurringEvent) # (2)!\nclass RecurringEventAdmin(admin.ModelAdmin): # (1)!\nlist_display = ( # (3)!\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n) # (4)!\n
Check that everything's working and there are no issues, which should be the case unless there's custom input fields creating problems.
See the development setup guide section on \"Build and run using Docker locally\" for how to view the admin interface.
Example of a custom field (as opposed to the built-in ones)
# (1)!\ntime_zone = TimeZoneField(blank=True, use_pytz=False, default=\"America/Los_Angeles\")\n
This is a good place to pause, check, and commit progress.
Run pre-commit checks
./scripts/precommit-check.sh\n
Add and commit changes
git add -A\ngit commit -m \"feat: register admin: recurring_event\"\n
There's several components to adding API endpoints: Model(already done), Serializer, View, and Route.
"},{"location":"contributing/howto/add-model-and-api-endpoints/#add-serializer","title":"Add serializer","text":"This is code that serializes objects into strings for the API endpoints, and deserializes strings into object when we receive data from the client.
In app/core/api/serializers.py
Following the many-to-many relationship between project and recurring event from above,
Update the existing serializer classes
app/core/api/serializers.pyclass ProjectSerializer(serializers.ModelSerializer):\n\"\"\"Used to retrieve project info\"\"\"\nrecurring_events = serializers.StringRelatedField(many=True)\nclass Meta:\nmodel = Project\nfields = (\n\"uuid\",\n\"name\",\n\"description\",\n\"created_at\",\n\"updated_at\",\n\"completed_at\",\n\"github_org_id\",\n\"github_primary_repo_id\",\n\"hide\",\n\"google_drive_id\",\n\"image_logo\",\n\"image_hero\",\n\"image_icon\",\n\"recurring_events\",\n)\nread_only_fields = (\n\"uuid\",\n\"created_at\",\n\"updated_at\",\n\"completed_at\",\n)\nclass RecurringEventSerializer(serializers.ModelSerializer):\n\"\"\"Used to retrieve recurring_event info\"\"\"\nprojects = serializers.StringRelatedField(many=True)\nclass Meta:\nmodel = RecurringEvent\nfields = (\n\"uuid\",\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n\"video_conference_url\",\n\"additional_info\",\n\"project\",\n\"projects\",\n)\nread_only_fields = (\n\"uuid\",\n\"created_at\",\n\"updated_at\",\n)\n
Import the new model
app/core/api/serializers.pyfrom core.models import RecurringEvent\n
Add a serializer class
app/core/api/serializers.pyclass RecurringEventSerializer(serializers.ModelSerializer): # (1)!\n\"\"\"Used to retrieve recurring_event info\"\"\"\nclass Meta:\nmodel = RecurringEvent # (2)!\nfields = (\n\"uuid\",\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n\"video_conference_url\",\n\"additional_info\",\n\"project\",\n)\nread_only_fields = (\n\"uuid\", # (3)!\n\"created_at\",\n\"updated_at\",\n)\n
model
, the fields
we want to expose through the API, and any read_only_fields
.uuid
, created_at
, and updated_at
are managed by automations and are always read-only.Custom data fields may need extra code in the serializer
time_zone = TimeZoneSerializerField(use_pytz=False) # (1)!\n
Custom validators if we need them
We will need to write custom validators here if we want custom behavior, such as validating URL strings and limit them to the github user profile pattern using regular expression, for example.
Example here when we have one\n
Viewset defines the set of API endpoints for the model.
In app/core/api/views.py
Import the model
app/core/api/views.pyfrom ..models import RecurringEvent\n
Import the serializer
app/core/api/views.pyfrom .serializers import RecurringEventSerializer\n
Add the viewset and CRUD API endpoint descriptions
app/core/api/views.py@extend_schema_view( # (2)!\nlist=extend_schema(description=\"Return a list of all the recurring events\"),\ncreate=extend_schema(description=\"Create a new recurring event\"),\nretrieve=extend_schema(description=\"Return the details of a recurring event\"),\ndestroy=extend_schema(description=\"Delete a recurring event\"),\nupdate=extend_schema(description=\"Update a recurring event\"),\npartial_update=extend_schema(description=\"Patch a recurring event\"),\n)\nclass RecurringEventViewSet(viewsets.ModelViewSet): # (1)!\npermission_classes = [IsAuthenticated] # (4)!\nqueryset = RecurringEvent.objects.all() # (3)!\nserializer_class = RecurringEventSerializer\n
create
, retrieve
, partial_update
, update
, destroy
, list
.extend_schema_view
decorator to attach the API doc strings to the viewset. They are usually defined as docstrings of the corresponding function definitions inside the viewset. Since we use ModelViewSet
, there's nowhere to put the docstrings but above the viewset.ModelViewSet
are the queryset
, and the serializer_class
.permission_classes = [IsAuthenticated]
This example shows how to add a filter params. It's done for the user model as a requirement from VRMS.
Here's a more complex API doc example (this example is using the User model's ViewSet)
app/core/api/views.py@extend_schema_view(\nlist=extend_schema( # (2)!\nsummary=\"Users List\",\ndescription=\"Return a list of all the existing users\",\nparameters=[\nOpenApiParameter(\nname=\"email\",\ntype=str,\ndescription=\"Filter by email address\",\nexamples=[\nOpenApiExample(\n\"Example 1\",\nsummary=\"Demo email\",\ndescription=\"get the demo user\",\nvalue=\"demo-email@email.com,\",\n),\n],\n),\nOpenApiParameter(\nname=\"username\",\ntype=OpenApiTypes.STR,\nlocation=OpenApiParameter.QUERY,\ndescription=\"Filter by username\",\nexamples=[\nOpenApiExample(\n\"Example 1\",\nsummary=\"Demo username\",\ndescription=\"get the demo user\",\nvalue=\"demo-user\",\n),\n],\n),\n],\n),\ncreate=extend_schema(description=\"Create a new user\"), # (1)!\nretrieve=extend_schema(description=\"Return the given user\"),\ndestroy=extend_schema(description=\"Delete the given user\"),\nupdate=extend_schema(description=\"Update the given user\"),\npartial_update=extend_schema(description=\"Partially update the given user\"),\n)\nclass UserViewSet(viewsets.ModelViewSet):\npass\n
create
, retrieve
, partial_update
, update
, destroy
, list
.summary
string appears as an option in the dropdown.description
is displayed in the example.Add any query params according to the requirements (this example is using the User model's ViewSet)
app/core/api/views.pyclass UserViewSet(viewsets.ModelViewSet):\n...\ndef get_queryset(self): # (1)!\n\"\"\"\n Optionally filter users by an 'email' and/or 'username' query paramerter in the URL\n \"\"\"\nqueryset = get_user_model().objects.all() # (2)!\nemail = self.request.query_params.get(\"email\")\nif email is not None:\nqueryset = queryset.filter(email=email)\nusername = self.request.query_params.get(\"username\")\nif username is not None:\nqueryset = queryset.filter(username=username)\nreturn queryset\n
Notice the queryset
property is now the get_queryset(()
function which returns the queryset.
The get_queryset()
function overrides the default and lets us filter the objects returned to the client if they pass in a query param.
Start with all the model objects and filter them based on any available query params.
In app/core/api/urls.py
Import the viewset.
app/core/api/urls.pyfrom .views import RecurringEventViewSet\n
Register the viewset to the router
app/core/api/urls.pyrouter.register(r\"recurring-events\", RecurringEventViewSet, basename=\"recurring-event\")\n# (1)!\n
http://localhost:8000/api/v1/recuring-events/
and http://localhost:8000/api/v1/recuring-events/<uuid>
basename
is the name used for generating the endpoint names, such as -list, -detail, etc. It's in the singular form. This is automatically generated if the viewset definition contains a queryset
attribute, but it's required if the viewset overrides that with the get_queryset
functionreverse(\"recurring-event-list\")
would return http://localhost:8000/api/v1/recuring-events/
For the CRUD operations, since we're using ModelViewSet
where all the actions are provided by rest_framework
and well-tested, it's not necessary to have test cases for them. But here's an example of one.
In app/core/tests/test_api.py
Import API URL
app/core/tests/test_api.pyRECURRING_EVENTS_URL = reverse(\"recurring-event-list\")\n
Add test case
app/core/tests/test_api.pydef test_create_recurring_event(auth_client, project):\n\"\"\"Test that we can create a recurring event\"\"\"\npayload = {\n\"name\": \"Test Weekly team meeting\",\n\"start_time\": \"18:00:00\",\n\"duration_in_min\": 60,\n\"video_conference_url\": \"https://zoom.com/link\",\n\"additional_info\": \"Test description\",\n\"project\": project.uuid,\n}\nres = auth_client.post(RECURRING_EVENTS_URL, payload)\nassert res.status_code == status.HTTP_201_CREATED\nassert res.data[\"name\"] == payload[\"name\"]\n
Run the test script to show it passing
./scripts/test.sh\n
In app/core/tests/test_api.py
Import API URL
app/core/tests/test_api.pyPROJECTS_URL = reverse(\"project-list\")\n
Add test case (following the example above)
app/core/tests/test_api.pydef test_project_sdg_xref(auth_client, project, recurring_event):\ndef get_object(objects, target_uuid):\nfor obj in objects:\nif str(obj[\"uuid\"]) == str(target_uuid):\nreturn obj\nreturn None\nproject.recurring_events.add(recurring_event)\nproj_res = auth_client.get(PROJECTS_URL)\ntest_proj = get_object(proj_res.data, project.uuid)\nassert test_proj is not None\nassert len(test_proj[\"recurring_events\"]) == 1\nassert recurring_event.name in test_proj[\"recurring_events\"]\nrecurring_event_res = auth_client.get(RECURRING_EVENT_URL)\ntest_recurring_event = get_object(recurring_event_res.data, recurring_event.uuid)\nassert test_recurring_event is not None\nassert len(test_recurring_event[\"projects\"]) == 1\nassert project.name in test_recurring_event[\"projects\"]\n
Run the test script to show it passing
./scripts/test.sh\n
This is a good place to pause, check, and commit progress.
Run pre-commit checks
./scripts/precommit-check.sh\n
Add and commit changes
git add -A\ngit commit -m \"feat: add endpoints: recurring_event\"\n
Refer to the Issues page section on \"Push to upstream origin\" onward.
"},{"location":"contributing/howto/create-initial-data-migrations/","title":"Create initial data scripts","text":""},{"location":"contributing/howto/create-initial-data-migrations/#overview","title":"Overview","text":"The goal is to convert our initial data into scripts that can be loaded into the database when the backend is set up for the first time.
These are the steps:
You must have Docker installed
The initial data exists in a Google spreadsheet, such as this one for People Depot. There should be individual sheets named after the model names the data correspond to, such as ProgramArea - Data
. The sheet name is useful for us to identify the model it corresponds to.
The sheet should be formatted like so:
It is required that there be data in the first column of the sheet.
"},{"location":"contributing/howto/create-initial-data-migrations/#gather-data-for-preparation","title":"Gather data for preparation","text":"Export the data from the Google spreadsheet
ProgramArea - Data
data as our example.Start Docker
From project root, run
./scripts/buildrun.sh\n
Go to the project root and run this command
docker-compose exec web python scripts/convert.py \"core/initial_data/PD_ Table and field explanations - ProgramArea - Data.csv\"\n
Check that there's a new file called app/core/scripts/programarea_seed.py
and that it looks correct
You can run it to verify, but will need to remove that data if you care about restoring the database state
Run this command to run the script
docker-compose exec web python manage.py runscript programarea_seed\n
core_programarea
docker-compose exec web python manage.py dbshell\n\n# now we have a shell to the db\n# see if all the seed data got inserted\nselect count(*) from core_programarea;\n# shows 9 rows\ndelete from core_programarea;\n# DELETE 9\nselect count(*) from core_programarea;\n# shows 0 rows\n# ctrl-d to exit dbshell\n
Look for name of the last migration file in core/data/migrations
directory
Create a script in the same directory named <number>_<modelname_in_lower_case>_seed.py
with the following contents and replace <modelname_in_lower_case>
, ModelNameInPascalCase
, and <name of last script>
with appropriate values:
from django.db import migrations\nfrom core.models import ModelNameInPascalCase\ndef forward(__code__, __reverse_code__):\n# paste everything in seed script's run function here\n# remove pass below\npass\ndef reverse(__code__, __reverse_code__):\nModelNameInPascalCase.objects.all().delete()\nclass Migration(migrations.Migration):\ndependencies = [(\"data\", \"<name of last script, or contents of max_migration.txt>\")]\noperations = [migrations.RunPython(forward, reverse)]\n
For example:
from django.db import migrations\nfrom core.models import BookType\ndef forward(__code__, __reverse_code__):\nitems = [\n(1, \"Hard Cover\"),\n(2, \"Soft Cover\"),\n]\nfor uuid, name in items:\nBookType.objects.create(uuid=uuid, name=name)\ndef reverse(__code__, __reverse_code__):\nBookType.objects.all().delete()\nclass Migration(migrations.Migration):\ndependencies = [(\"data\", \"0011_author_seed\")]\noperations = [migrations.RunPython(forward, reverse)]\n
In this example 011_author_seed
is the name of the last migration file in core/data/migrations
. You will also need to update this to the last python file in core/data/migrations
having the format xxxx_<modename_in_lower_case>_seed.py
.
If you have a requirement to run on your local machine or you are unable to get it to work on Docker, do the following steps. WARNING: If you run into issues you will get limited support.
Run these commands from the app
directory:
.env.docker-example
to .env.local
.env.local
and change values as appropriate. The file includes instructions on how to use local postgres
and sqlite
for the database. sqlite
has no set up. It uses a file db.sqlite3
. If it is not there, it automatically creates it.alias python=\"python3\"
cd app\n\n# copy the env file\ncp .env.docker-example .env.local\n\n# create a virtual environment\npython -m venv venv\n\n# activate (enter) the virtual environment\nsource venv/bin/activate\n# install dependencies\npip install -r requirements.txt\n\n# start local server\n../scripts/start-local.sh\n# start server with alternate port\n# DJANGO_PORT=8001 ../scripts/start-local.sh\n# browse to http://localhost:8000 (or 8001) to see the app\n# Ctrl-C to stop the server\n# deactivate (exit) the virtual environment\n# to return to the system global environment\ndeactivate\n
TIP: Look up direnv
for a useful method to automatically enter and exit virtual environments based on the current directory.
These are the tools we use in the PeopleDepot project with notes on how we use them.
To stop the service-container, but not destroy it (often sufficient for day-to-day work):
docker-compose stop\n
To stop and destroy the service container:
docker-compose down\n
Add the -v
flag to destroy the data volumes as well:
docker-compose down -v\n
"},{"location":"contributing/tools/docker/#recycling-refreshing-database","title":"Recycling / Refreshing Database","text":"To restore a database to its original state and remove any data manually added, delete the container and image. From Docker:
TerminalDocker Desktopdocker-compose down -v\n
This helps speed up subsequent docker builds by caching intermediate files and reusing them across builds. It's available with docker buildkit. The key here is to disable anything that could delete the cache, because we want to preserve it. The cache mount is not going to end up in the docker image being built, so there's no concern about disk space usage.
Put this flag between RUN
and the command
RUN \\\n--mount=type=cache,target=/root/.cache\n pip install -r requirements.txt\n
For pip, the files are by default stored in /root/.cache/pip
. Pip caching docs
For apk, the cache directory is /var/cache/apk/
. APK wiki on local cache
For apt, the cache directory is /var/cache/apt/
.
We're choosing to use an Alpine-based image for the smaller size and faster builds and downloads. However, a Debian-based image has the advantage of a large ecosystem of available packages, a limitation of Alpine that we may run up against in the future.
"},{"location":"contributing/tools/docker/#switching-to-debian","title":"Switching to Debian","text":"Here is how we can switch to a Debian-based images if we need to:
Edit Dockerfile
to look something like this
# pull official base image\nFROM python:3.10-alpine\n# (1)! define base image\nFROM python:3.10-bullseye\n# set work directory\nWORKDIR /usr/src/app\n# set environment variables\nENV PYTHONDONTWRITEBYTECODE=1\nENV PYTHONUNBUFFERED=1\nENV PYTHONPYCACHEPREFIX=/root/.cache/pycache/\nENV PIP_CACHE_DIR=/var/cache/buildkit/pip\nRUN mkdir -p $PIP_CACHE_DIR\n# (2)! prevent cache deletion\nRUN rm -f /etc/apt/apt.conf.d/docker-clean; \\ \necho 'Binary::apt::APT::Keep-Downloaded-Packages \"true\";' > /etc/apt/apt.conf.d/keep-cache\n# install system dependencies\nRUN \\\n--mount=type=cache,target=/var/cache/apk \\ \n--mount=type=cache,target=/etc/apk/cache \\ \napk add \\\u0002czjqqkd:19\u0003\n 'graphviz=~9.0'\n# install font for graphviz\nCOPY Roboto-Regular.ttf /root/.fonts/\nRUN fc-cache -f\n# (3)! define cache mounts and install dependencies\n--mount=type=cache,target=/var/cache/apt,sharing=locked \\ \n--mount=type=cache,target=/var/lib/apt,sharing=locked \\ \napt-get update \\ \n&& apt-get install --no-install-recommends -yqq \\ \nnetcat=1.10-46 \\ \ngcc=4:10.2.1-1 \\ \npostgresql=13+225+deb11u1 \\ \ngraphviz=2.42.2-5\n# install dependencies\nCOPY ./requirements.txt .\n# hadolint ignore=DL3042\n# (4)! install uv for faster dependency resolution\nRUN \\\n--mount=type=cache,target=/root/.cache \\\npip install uv==0.1.15 \\\n&& uv pip install --system -r requirements.txt\n\n# copy entrypoint.sh\nCOPY ./entrypoint.sh .\nRUN sed -i 's/\\r$//g' /usr/src/app/entrypoint.sh \\\n&& chmod +x /usr/src/app/entrypoint.sh\n\n# copy project\nCOPY . .\n\n# run entrypoint.sh\nENTRYPOINT [\"/usr/src/app/entrypoint.sh\"]\n\n- define base image
\n- prevent cache deletion
\n- install system dependencies
\n- define cache mounts for apt and lib
\n- install netcat for db wait script, which is used in
entrypoint.sh
\n- install gcc for python local compiling, which shouldn't be needed
\n- install postgresql for
dbshell
management command \n- install graphviz for generating ERD in
erd.sh
\n
\n \n- install uv for faster dependency resolution, which may or may not be wanted
\n
\n- \n
Use the dive
tool to check the image layers for extra files that shouldn't be there.
\n "},{"location":"contributing/tools/mkdocs/","title":"MkDocs","text":"We are using MkDocs to generate our documentation. See Docker-mkdocs repo for information about MkDocs and the image we're using.
"},{"location":"contributing/tools/mkdocs/#work-on-docs-locally","title":"Work on docs locally","text":"The first time starting the container may take longer due to downloading the ~40MB docker image
-
Run the mkdocs container.
docker-compose up mkdocs # (1)!\n
- Optionally use the
-d
flag to run the container in the background
-
Open a browser to http://localhost:8005/
to view the documentation locally.
-
Modify the files in the docs
directory. The site will auto-update when the files are saved.
-
Ctrl+C to quit the local server and stop the container
"},{"location":"contributing/tools/mkdocs/#auto-generated-docs","title":"Auto-generated docs","text":"We have a GitHub Action set up to generate and host the documentation on a GitHub Pages site
"},{"location":"contributing/tools/mkdocs/#mkdocs-syntax","title":"MkDocs syntax","text":"We're using Material for MkDocs. Aside from standard markdown syntax, there are some MkDocs and Material-specific syntax which can help more effective documentation. See the Material reference docs for the complete set of syntax.
Here's a list of commonly used MkDocs syntax for quick reference.
"},{"location":"contributing/tools/mkdocs/#code-blocks","title":"Code Blocks","text":"ExampleCode Code Block@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\nlist_display = (\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n)\n
Numbered Lines@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\nlist_display = (\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n)\n
Highlighted Lines@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\nlist_display = (\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n)\n
```python title=\"Code Block\"\n@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\n list_display = (\n \"name\",\n \"start_time\",\n \"duration_in_min\",\n )\n```\n\n```python title=\"Numbered Lines\" linenums=\"1\"\n@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\n list_display = (\n \"name\",\n \"start_time\",\n \"duration_in_min\",\n )\n```\n\n```python title=\"Highlighted Lines\" hl_lines=\"1 3 5\"\n@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\n list_display = (\n \"name\",\n \"start_time\",\n \"duration_in_min\",\n )\n```\n
"},{"location":"contributing/tools/mkdocs/#code-annotations","title":"Code Annotations","text":"ExampleCode Click the plus sign --> # (1)!\n
- This is an explanation text
``` bash\nClick the plus sign --> # (1)!\n```\n\n1. This is an explanation text\n
"},{"location":"contributing/tools/mkdocs/#text-blocks","title":"Text blocks","text":"ExampleCode Simple Block
Example
Content Block Text
Expandable Block Content
Opened Expandable Block Content
!!! example \"Simple Block\"\n\n!!! example\n Content Block Text\n\n??? example \"Expandable Block\"\n Content\n\n???+ example \"Opened Expandable Block\"\n Content\n
"},{"location":"contributing/tools/mkdocs/#tabbed-content","title":"Tabbed content","text":"ExampleCode LinuxMac linux-specific content
mac-specific content
=== \"Linux\"\n\n linux-specific content\n\n=== \"Mac\"\n\n mac-specific content\n
"},{"location":"contributing/tools/mkdocs/#buttons","title":"Buttons","text":"ExampleCode - Ctrl+C to quit the local server and stop the container
1. ++ctrl+c++ to quit the local server and stop the container\n
"},{"location":"contributing/tools/pre-commit/","title":"Pre-commit","text":"The hooks will run when doing normal git commit
and git push
commands. It's recommended to do this in the command line to see the output. If performing these actions from a gui application, the interface may seem to hang for some time.
The pre-commit checks should be fast while the pre-push hooks will take longer since they'll do a full rebuild
"},{"location":"contributing/tools/pre-commit/#installation","title":"Installation","text":"It's recommended to install \"global\" tools via pipx, which installs packages in an isolated environment rather than the global python environment.
-
Install pipx
-
Install pre-commit
pipx install pre-commit\n
-
Add the hook to git
pre-commit install\n
Pre-commit is now set up to check your files whenever you commit or push code.
-
Test by adding an empty commit
git commit --allow-empty -m \"Test\"\n
You should see a list of tests that are all skipped, because there's no changes in the commit to test.
"},{"location":"contributing/tools/pre-commit/#extra-information","title":"Extra information","text":" -
To skip the checks temporarily, you can do one of these
# skip all the hooks\ngit commit --no-verify\n\n# skip specific hooks\nSKIP=black,flake8 git commit\n
-
Manually run the hooks (this runs it against all files rather than only changed files)
pre-commit run --all-files\n
-
More commands to run the hooks
# run the hooks for the push staga\npre-commit run --all-files --hook-stage push\n\n# run the hooks for the commit stage\npre-commit run --all-files --hook-stage commit\n\n# run the hooks for\npre-commit run test --all-files --hook-stage push\n
-
Update pre-commit and plugins to the latest version
pre-commit autoupdate\n
"},{"location":"contributing/tools/scripts/","title":"Convenience Scripts","text":"These are designed to make it easier to perform various everyday tasks in the project. They try to be transparent by exposing the underlying commands they execute so that users can have an idea of what's happening and try to learn the commands if they wish.
scripts/\n\u251c\u2500\u2500 buildrun.sh\n\u251c\u2500\u2500 check-migrations.sh\n\u251c\u2500\u2500 createsuperuser.sh\n\u251c\u2500\u2500 db.sh\n\u251c\u2500\u2500 erd.sh\n\u251c\u2500\u2500 lint.sh\n\u251c\u2500\u2500 loadenv.sh\n\u251c\u2500\u2500 logs.sh\n\u251c\u2500\u2500 migrate.sh\n\u251c\u2500\u2500 precommit-check.sh\n\u251c\u2500\u2500 run.sh\n\u251c\u2500\u2500 start-local.sh\n\u251c\u2500\u2500 test.sh\n\u2514\u2500\u2500 update-dependencies.sh\n
These scripts assume you are using bash.
-
buildrun.sh - clean, build, and run containers in background mode
- Pass in
-v
to remove data volume, which resets the local database. - See the script file for more options.
-
check-migrations.sh - check if migrations are up to date
-
createsuperuser.sh - create a default superuser
- This assumes that
DJANGO_SUPERUSER_USERNAME
and DJANGO_SUPERUSER_PASSWORD
are set in .env.dev
-
db.sh - connect to the database in the db
container
- This is a different route than
manage.py dbshell
, which requires the psql
executable in the web
container
-
erd.sh - generate ER diagram
- The image is saved to
app/erd.png
- This script is dependent on the
graphviz
package
-
lint.sh - lint and and auto-format code
-
loadenv.sh - load environment variables from .env.dev
into shell environment
-
logs.sh - view/tail container logs
-
migrate.sh - run database migrations inside container
- Add
<app> <migration_number>
to migrate to that database state. Ex: migrate.sh core 0010
-
precommit-check.sh - sanity checks before committing code
- Call
buildrun.sh
, lint.sh
, and test.sh
-
run.sh - start the development server in Docker, with some options
- Pass in
-h
to show usage
-
start-local.sh - start the development server natively
-
test.sh - run tests and generate test coverage report
- Use the
-k
flag to filter tests. For example test.sh -k program_area
will select only tests with \"program_area\" in the name. - Pass in
--no-cov
to disable the coverage report. The coverage report will show many missing lines of coverage as a result.
-
update-dependencies.sh - update python dependencies to the latest versions
"},{"location":"contributing/tools/uv/","title":"uv","text":"We're using uv
as a faster replacement to pip
and pip-tools
. See the official documentation on getting started.
"},{"location":"contributing/tools/uv/#how-we-use-it","title":"How we use it","text":"We're using uv
to compile and install python dependencies, which replaces the functionalities of pip
and pip-tools
. uv
can also create and maintain a virtual environment but we're not using it for now. In fact, we're suppressing it with the --system
option during uv pip install
.
uv
is already part of the docker
image, so there's no need to install it on the host. It does require prepending the docker-compose information to run, for example: docker-compose exec web uv pip compile requirements.in -o requirements.txt
. We'll omit the docker-compose exec web
portion from now on in this document.
requirements.in
is the requirements file and uv pip compile
generates requirement.txt
, with pinned versions, similar to lock files in other languages.
"},{"location":"contributing/tools/uv/#usage","title":"Usage","text":""},{"location":"contributing/tools/uv/#upgrade-depencencies","title":"Upgrade depencencies","text":"We shouldn't run this on every build, but we should do this manually every month/quarter or so.
# docker-compose exec web\nuv pip compile requirements.in -o requirements.txt --no-header --upgrade\n
Or run the script
./scripts/update-dependencies.sh\n
"},{"location":"contributing/tools/uv/#pip-compile-options","title":"pip compile options","text":"Disable header in the generated file --no-header
This solves the problem unnecessary code churn caused by changing headers Upgrade all dependencies --upgrade
Generate pip-8 style hashes --generate-hashes
Hashes improve security but are not verified by uv
at the moment. It is planned. Switch back to pip
for installation if we need to verify hashes. Disable annotation of where dependencies come from --no-annotate
This makes the generated file shorter but less informative See pip-compile docs for more options and explanation
"},{"location":"contributing/tools/uv/#install-dependencies","title":"Install dependencies","text":"This is used in the Dockerfile
to install python dependencies.
uv pip install --system -r requirements.txt\n
"},{"location":"contributing/tools/uv/#pip-install-options","title":"pip install options","text":"Install to global --system
bypass the virtual environment requirement See pip install docs for more options and explanation
"},{"location":"contributing/tools/uv/#explanations","title":"Explanations","text":""},{"location":"contributing/tools/uv/#global-install","title":"Global install","text":"We're using the --system
option in the Dockerfile
to bypass the virtual environment requirement for uv
. This is because the docker image is already a virtual environment separate from the host.
"},{"location":"contributing/tools/uv/#version-pinning","title":"Version pinning","text":"We're leaving most dependencies unpinned in requirements.in
so that pip compile
will pin the newest compatible versions in requirements.txt
. The only manually pinned dependency is django~=4.2.0
. The x.2.x
versions have long term support, and we're using 4
, since 4.2
is the latest LTS available.
"},{"location":"howto/authenticate_cognito/","title":"Cognito authentication workflow (pre deployment)","text":"This is a temporary solution until we can deploy a dev environment for PeopleDepot.
There's a few manual steps and the login is good for only an hour at a time.
Prerequisites:
- ModHeader browser extension
Steps:
-
Login (or register first then login) to a cognito account here. Do not worry if you see error messages - you will be using the url.
-
Copy the URL when it redirects. Note: Instead of the screen below, the screen may display an error message. You can ignore any error messages.
.
-
Extract the access_token
using the online tool.
- Clear the top box and paste the URL text into it. The box should show there's 1 match
- The bottom box's content is the extracted
access_token
-
Open ModHeader. If the icon is hidden, click on the Puzzle icon in the upper right of the browser to see it.
-
Type the word Bearer and paste the token into ModHeader Authorization: Bearer \\
-
Go to a page in api/v1/ to see that it allows access
-
Explore APIs using Swagger
-
Some fields have hints on how to retrieve the values.
-
A redoc ui is also available
"},{"location":"ref/api_endpoints/","title":"Api endpoints","text":"We're using OpenAPI (swagger) for API documentation. We won't have a public URL for it until it's deployed. A ReDoc interface is also available.
These are the URLs in the local dev environment
- http://localhost:8000/api/schema/swagger-ui/
- http://localhost:8000/api/schema/redoc/
"}]}
\ No newline at end of file
diff --git a/sitemap.xml b/sitemap.xml
new file mode 100644
index 00000000..0f8724ef
--- /dev/null
+++ b/sitemap.xml
@@ -0,0 +1,3 @@
+
+
+
\ No newline at end of file
diff --git a/sitemap.xml.gz b/sitemap.xml.gz
new file mode 100644
index 00000000..18c6e921
Binary files /dev/null and b/sitemap.xml.gz differ