From 720e6c20e8977530b734c192e14de32e7189d247 Mon Sep 17 00:00:00 2001 From: <> Date: Wed, 6 Dec 2023 21:39:20 +0000 Subject: [PATCH] Deployed cee8c8b with MkDocs version: 1.5.3 --- .nojekyll | 0 404.html | 599 ++ CONTRIBUTING/index.html | 1430 ++++ LICENSE/index.html | 954 +++ architecture/Notes/index.html | 695 ++ architecture/authentication/index.html | 789 ++ assets/images/favicon.png | Bin 0 -> 1870 bytes assets/javascripts/bundle.b425cdc4.min.js | 29 + assets/javascripts/bundle.b425cdc4.min.js.map | 8 + assets/javascripts/lunr/min/lunr.ar.min.js | 1 + assets/javascripts/lunr/min/lunr.da.min.js | 18 + assets/javascripts/lunr/min/lunr.de.min.js | 18 + assets/javascripts/lunr/min/lunr.du.min.js | 18 + assets/javascripts/lunr/min/lunr.es.min.js | 18 + assets/javascripts/lunr/min/lunr.fi.min.js | 18 + assets/javascripts/lunr/min/lunr.fr.min.js | 18 + assets/javascripts/lunr/min/lunr.hi.min.js | 1 + assets/javascripts/lunr/min/lunr.hu.min.js | 18 + assets/javascripts/lunr/min/lunr.hy.min.js | 1 + assets/javascripts/lunr/min/lunr.it.min.js | 18 + assets/javascripts/lunr/min/lunr.ja.min.js | 1 + assets/javascripts/lunr/min/lunr.jp.min.js | 1 + assets/javascripts/lunr/min/lunr.kn.min.js | 1 + assets/javascripts/lunr/min/lunr.ko.min.js | 1 + assets/javascripts/lunr/min/lunr.multi.min.js | 1 + assets/javascripts/lunr/min/lunr.nl.min.js | 18 + assets/javascripts/lunr/min/lunr.no.min.js | 18 + assets/javascripts/lunr/min/lunr.pt.min.js | 18 + assets/javascripts/lunr/min/lunr.ro.min.js | 18 + assets/javascripts/lunr/min/lunr.ru.min.js | 18 + assets/javascripts/lunr/min/lunr.sa.min.js | 1 + .../lunr/min/lunr.stemmer.support.min.js | 1 + assets/javascripts/lunr/min/lunr.sv.min.js | 18 + assets/javascripts/lunr/min/lunr.ta.min.js | 1 + assets/javascripts/lunr/min/lunr.te.min.js | 1 + assets/javascripts/lunr/min/lunr.th.min.js | 1 + assets/javascripts/lunr/min/lunr.tr.min.js | 18 + assets/javascripts/lunr/min/lunr.vi.min.js | 1 + assets/javascripts/lunr/min/lunr.zh.min.js | 1 + assets/javascripts/lunr/tinyseg.js | 206 + assets/javascripts/lunr/wordcut.js | 6708 +++++++++++++++++ .../workers/search.208ed371.min.js | 42 + .../workers/search.208ed371.min.js.map | 8 + assets/stylesheets/main.26e3688c.min.css | 1 + assets/stylesheets/main.26e3688c.min.css.map | 1 + assets/stylesheets/palette.ecc896b0.min.css | 1 + .../stylesheets/palette.ecc896b0.min.css.map | 1 + how-to/add-model-and-api-endpoints/index.html | 1402 ++++ index.html | 765 ++ search/search_index.json | 1 + sitemap.xml | 3 + sitemap.xml.gz | Bin 0 -> 127 bytes tools/code-quality/pre-commit/index.html | 676 ++ tools/mkdocs/index.html | 795 ++ tools/scripts/index.html | 678 ++ 55 files changed, 16077 insertions(+) create mode 100644 .nojekyll create mode 100644 404.html create mode 100644 CONTRIBUTING/index.html create mode 100644 LICENSE/index.html create mode 100644 architecture/Notes/index.html create mode 100644 architecture/authentication/index.html create mode 100644 assets/images/favicon.png create mode 100644 assets/javascripts/bundle.b425cdc4.min.js create mode 100644 assets/javascripts/bundle.b425cdc4.min.js.map create mode 100644 assets/javascripts/lunr/min/lunr.ar.min.js create mode 100644 assets/javascripts/lunr/min/lunr.da.min.js create mode 100644 assets/javascripts/lunr/min/lunr.de.min.js create mode 100644 assets/javascripts/lunr/min/lunr.du.min.js create mode 100644 assets/javascripts/lunr/min/lunr.es.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.fr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hu.min.js create mode 100644 assets/javascripts/lunr/min/lunr.hy.min.js create mode 100644 assets/javascripts/lunr/min/lunr.it.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ja.min.js create mode 100644 assets/javascripts/lunr/min/lunr.jp.min.js create mode 100644 assets/javascripts/lunr/min/lunr.kn.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ko.min.js create mode 100644 assets/javascripts/lunr/min/lunr.multi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.nl.min.js create mode 100644 assets/javascripts/lunr/min/lunr.no.min.js create mode 100644 assets/javascripts/lunr/min/lunr.pt.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ro.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ru.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sa.min.js create mode 100644 assets/javascripts/lunr/min/lunr.stemmer.support.min.js create mode 100644 assets/javascripts/lunr/min/lunr.sv.min.js create mode 100644 assets/javascripts/lunr/min/lunr.ta.min.js create mode 100644 assets/javascripts/lunr/min/lunr.te.min.js create mode 100644 assets/javascripts/lunr/min/lunr.th.min.js create mode 100644 assets/javascripts/lunr/min/lunr.tr.min.js create mode 100644 assets/javascripts/lunr/min/lunr.vi.min.js create mode 100644 assets/javascripts/lunr/min/lunr.zh.min.js create mode 100644 assets/javascripts/lunr/tinyseg.js create mode 100644 assets/javascripts/lunr/wordcut.js create mode 100644 assets/javascripts/workers/search.208ed371.min.js create mode 100644 assets/javascripts/workers/search.208ed371.min.js.map create mode 100644 assets/stylesheets/main.26e3688c.min.css create mode 100644 assets/stylesheets/main.26e3688c.min.css.map create mode 100644 assets/stylesheets/palette.ecc896b0.min.css create mode 100644 assets/stylesheets/palette.ecc896b0.min.css.map create mode 100644 how-to/add-model-and-api-endpoints/index.html create mode 100644 index.html create mode 100644 search/search_index.json create mode 100644 sitemap.xml create mode 100644 sitemap.xml.gz create mode 100644 tools/code-quality/pre-commit/index.html create mode 100644 tools/mkdocs/index.html create mode 100644 tools/scripts/index.html 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..34c6d423 --- /dev/null +++ b/404.html @@ -0,0 +1,599 @@ + + + +
+ + + + + + + + + + + + + +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.
+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 hfla-site
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.
NOTE: Once you have accepted the GitHub invite (comes via email or in your GitHub notifications), please do the following:
+Make your own Hack for LA GitHub organization membership public by following this guide.
+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.
+Installation Guide for Windows Users +- 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.
+Note: 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
.
Be Aware: What you have created is a forked copy in a remote version on GitHub. It is not yet on your local machine yet.
+The following steps will clone (create) a local copy of the forked repository on your computer.
+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:
+ +For example if your GitHub username was octocat
:
**Note: 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 website on your local machine.
However, we still need a way to keep our local repo up to date with the deployed website. 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)
+
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?
docker-compose up
)http://localhost:8000/admin/
and confirm the admin site is running. Use DJANGO_SUPERUSER_USERNAME and DJANGO_SUPERUSER_PASSWORD from .env.dev for credentials.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:
+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.
+ +Note: 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 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:
Important: before committing each file, make sure to run the pre-commit script:*
+ +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: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".
+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.
+You can go to these links and submit an issue:
+ + + + + + + + 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.
+ + + + + + +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.
+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 document:
+This guide assumes the developer has followed the contributing doc 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!
+Add the following to app/core/models.py
+class RecurringEvent(AbstractBaseModel):
+ """
+ Recurring Events
+ """
+
+ name = models.CharField(max_length=255)
+ start_time = models.TimeField("Start", null=True, blank=True)
+ duration_in_min = models.IntegerField(null=True, blank=True)
+ video_conference_url = models.URLField(blank=True)
+ additional_info = models.TextField(blank=True)
+
+ project = models.ForeignKey(Project, on_delete=models.CASCADE)
+ # location_id = models.ForeignKey("Location", on_delete=models.DO_NOTHING)
+ # event_type_id = models.ForeignKey("EventType", on_delete=models.DO_NOTHING)
+ # brigade_id = models.ForeignKey("Brigade", on_delete=models.DO_NOTHING)
+ # day_of_week = models.ForeignKey("DayOfWeek", on_delete=models.DO_NOTHING)
+ # must_roles = models.ManyToManyField("Role")
+ # should_roles = models.ManyToManyField("Role")
+ # could_roles = models.ManyToManyField("Role")
+ # frequency_id = models.ForeignKey("Frequency", on_delete=models.DO_NOTHING)
+
+ def __str__(self):
+ return f"{self.name}"
+
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.Since we overrode the __str__
function, we need to write a test for it.
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
+def recurring_event(project):
+ return RecurringEvent.objects.create(name="Test Recurring Event", project=project)
+
recurring_event
).project
model as a foreign key relation, so we pass in the project
fixture, which creates a project
model.We create an object of the new model, passing in at least the required fields. In this case, we passed in enough arguments to use the __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):
+ assert str(recurring_event) == "Test Recurring Event"
+
__str__
method should be tested since it's an override of the default Django method.Write assertion(s) to check that what's passed into the model is what it contains. The simplest thing to check is the __str__
method.
Run the test script to show it passing
+This is a good place to pause, check, and commit progress.
+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.
+@admin.register(RecurringEvent)
+class RecurringEventAdmin(admin.ModelAdmin):
+ list_display = (
+ "name",
+ "start_time",
+ "duration_in_min",
+ )
+
See the contributing doc 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.
+There's several components to adding API endpoints: Model(already done), Serializer, View, and Router.
+This is code that serializes objects into strings for the API endpoints, and deserializes strings into object when we receive data from the client.
+class RecurringEventSerializer(serializers.ModelSerializer):
+ """Used to retrieve recurring_event info"""
+
+ class Meta:
+ model = RecurringEvent
+ fields = (
+ "uuid",
+ "name",
+ "start_time",
+ "duration_in_min",
+ "video_conference_url",
+ "additional_info",
+ "project",
+ )
+ read_only_fields = (
+ "uuid",
+ "created_at",
+ "updated_at",
+ )
+
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
+This non-built-in model field provides a serializer so we just point to it.
+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.
+@extend_schema_view(
+ list=extend_schema(description="Return a list of all the recurring events"),
+ create=extend_schema(description="Create a new recurring event"),
+ retrieve=extend_schema(description="Return the details of a recurring event"),
+ destroy=extend_schema(description="Delete a recurring event"),
+ update=extend_schema(description="Update a recurring event"),
+ partial_update=extend_schema(description="Patch a recurring event"),
+)
+class RecurringEventViewSet(viewsets.ModelViewSet):
+ permission_classes = [IsAuthenticated]
+ queryset = RecurringEvent.objects.all()
+ serializer_class = RecurringEventSerializer
+
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.
+@extend_schema_view(
+ list=extend_schema(
+ summary="Users List",
+ description="Return a list of all the existing users",
+ parameters=[
+ OpenApiParameter(
+ name="email",
+ type=str,
+ description="Filter by email address",
+ examples=[
+ OpenApiExample(
+ "Example 1",
+ summary="Demo email",
+ description="get the demo user",
+ value="demo-email@email.com,",
+ ),
+ ],
+ ),
+ OpenApiParameter(
+ name="username",
+ type=OpenApiTypes.STR,
+ location=OpenApiParameter.QUERY,
+ description="Filter by username",
+ examples=[
+ OpenApiExample(
+ "Example 1",
+ summary="Demo username",
+ description="get the demo user",
+ value="demo-user",
+ ),
+ ],
+ ),
+ ],
+ ),
+ create=extend_schema(description="Create a new user"),
+ retrieve=extend_schema(description="Return the given user"),
+ destroy=extend_schema(description="Delete the given user"),
+ update=extend_schema(description="Update the given user"),
+ partial_update=extend_schema(description="Partially update the given user"),
+)
+class UserViewSet(viewsets.ModelViewSet):
+
create
, retrieve
, partial_update
, update
, destroy
, list
.This one is fancy and provides examples of data to pass into the query params. It's probably more than we need right now.
+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)
+class UserViewSet(viewsets.ModelViewSet):
+ ...
+
+ def get_queryset(self):
+ """
+ Optionally filter users by an 'email' and/or 'username' query paramerter in the URL
+ """
+ queryset = get_user_model().objects.all()
+ email = self.request.query_params.get("email")
+ if email is not None:
+ queryset = queryset.filter(email=email)
+ username = self.request.query_params.get("username")
+ if username is not None:
+ queryset = queryset.filter(username=username)
+ return queryset
+
queryset
property is now the get_queryset(()
function which returns the queryset.get_queryset()
function overrides the default and lets us filter the objects returned to the client if they pass in a query param.http://localhost/api/v1/recuring-events/
and http://localhost/api/v1/recuring-events/<uuid>
basename
is the name used for generating the endpoint names, such as [basename]-list, [basename]-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/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.
def test_create_recurring_event(auth_client, project):
+ """Test that we can create a recurring event"""
+
+ payload = {
+ "name": "Test Weekly team meeting",
+ "start_time": "18:00:00",
+ "duration_in_min": 60,
+ "video_conference_url": "https://zoom.com/link",
+ "additional_info": "Test description",
+ "project": project.uuid,
+ }
+ res = auth_client.post(RECURRING_EVENTS_URL, payload)
+ assert res.status_code == status.HTTP_201_CREATED
+ assert res.data["name"] == payload["name"]
+
Then
+Run the test script to show it passing
+This is a good place to pause, check, and commit progress.
+Refer to the contributing doc section on "Push to upstream origin" onward.
+ + + + + + +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: +- Recruiting members (Website: Project info and meeting times) +- Onboarding members to resources (e.g., GitHub, Google Calendar, Google Drive, Google Docs, Google Sheets, etc.) +- Helping members find roles (Civic Tech Jobs: roles and project info) +- Managing team permissions (VRMS: GitHub, Google Calendar, Google Drives, etc.)
+Contact us in the #people-depot
channel on Slack.
This repository uses the GNU General Public License (v2.0).
+ + + + + + + +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: - Recruiting members (Website: Project info and meeting times) - Onboarding members to resources (e.g., GitHub, Google Calendar, Google Drive, Google Docs, Google Sheets, etc.) - Helping members find roles (Civic Tech Jobs: roles and project info) - Managing team permissions (VRMS: GitHub, Google Calendar, Google Drives, etc.)
"},{"location":"#technology-used","title":"Technology used","text":"Contact us in the #people-depot
channel on Slack.
This repository uses the GNU General Public License (v2.0).
"},{"location":"CONTRIBUTING/","title":"Contributing","text":"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.
"},{"location":"CONTRIBUTING/#1-joining-repository-team","title":"1. 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 hfla-site
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.
NOTE: Once you have accepted the GitHub invite (comes via email or in your GitHub notifications), please do the following:
Make your own Hack for LA GitHub organization membership public by following this guide.
"},{"location":"CONTRIBUTING/#2-setting-up-development-environment","title":"2. Setting Up Development Environment","text":""},{"location":"CONTRIBUTING/#21-pre-requisites","title":"2.1 Pre-requisites","text":""},{"location":"CONTRIBUTING/#211-github-account","title":"2.1.1 GitHub account","text":"See here for creating a GitHub account. If you are not familiar with Git, this tutorial is recommended.
"},{"location":"CONTRIBUTING/#212-two-factor-authentication","title":"2.1.2 Two-factor authentication","text":"Set up two-factor authentication on your account by following this guide.
"},{"location":"CONTRIBUTING/#213-text-editor","title":"2.1.3 Text editor","text":"VS Code is recommended, but feel free to use a text editor of your choice.
"},{"location":"CONTRIBUTING/#214-install-git","title":"2.1.4 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.
Installation Guide for Windows Users - 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:
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\n docker-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.
Note: 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
.
Be Aware: What you have created is a forked copy in a remote version on GitHub. It is not yet on your local machine yet.
"},{"location":"CONTRIBUTING/#221-clone-a-copy-on-your-computer","title":"2.2.1 Clone a copy on your computer","text":"The following steps will clone (create) a local copy of the forked repository on your computer.
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
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
**Note: 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/#222-verify-and-set-up-remote-references","title":"2.2.2 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 website on your local machine.
However, we still need a way to keep our local repo up to date with the deployed website. 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/#23-build-and-run-using-docker-locally","title":"2.3 Build and run using Docker locally","text":"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?
cp .env.dev-sample .env.dev\n
docker-compose up
)./scripts/buildrun.sh\n
docker-compose exec web python manage.py createsuperuser --no-input\n
http://localhost:8000/admin/
and confirm the admin site is running. Use DJANGO_SUPERUSER_USERNAME and DJANGO_SUPERUSER_PASSWORD from .env.dev for credentials.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/#32-recycling-refreshing-database","title":"3.2 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:
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/#42-create-a-new-branch","title":"4.2 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/#43-make-changes","title":"4.3 Make changes","text":"Make changes to fix the issue.
"},{"location":"CONTRIBUTING/#44-pull-to-get-the-most-recent-code","title":"4.4 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
Note: 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 Wiki.
"},{"location":"CONTRIBUTING/#45-add-changed-files-to-staging","title":"4.5 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/#46-check-git-status","title":"4.6 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/#47-remove-files-that-you-dont-want-staged","title":"4.7 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/#48-run-pre-commit-checks","title":"4.8 Run pre-commit checks","text":"Important: before committing each file, make sure to run the pre-commit script:*
./scripts/precommit-check.sh\n
"},{"location":"CONTRIBUTING/#49-commit-staged-changes","title":"4.9 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\"
Click here to see how to sync the fork on GitHub"},{"location":"CONTRIBUTING/#410-push-to-upstream-origin-aka-your-fork","title":"4.10 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/#411-create-a-pull-request","title":"4.11 Create a pull request","text":""},{"location":"CONTRIBUTING/#4111-push-all-changes-in-your-issue-branch","title":"4.11.1 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/#4112-complete-pull-request-from-github","title":"4.11.2 Complete pull request from GitHub","text":"<issue-number>
with the issue you worked on:fixes #<issue-number>\n
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/#5-creating-issues","title":"5. Creating Issues","text":"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/#appendix","title":"Appendix","text":""},{"location":"CONTRIBUTING/#a-submitting-bugs-for-third-party-packages-apps","title":"A. Submitting Bugs for Third Party Packages / Apps","text":"You can go to these links and submit an issue:
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":"\"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.
"},{"location":"architecture/authentication/","title":"Cognito authentication","text":""},{"location":"architecture/authentication/#what-is-it","title":"What is it","text":"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.
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 document:
This guide assumes the developer has followed the contributing doc 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":"how-to/add-model-and-api-endpoints/#the-model","title":"The model","text":""},{"location":"how-to/add-model-and-api-endpoints/#add-the-model-in-django","title":"Add the model in django","text":"Add the following to app/core/models.py
class RecurringEvent(AbstractBaseModel):\n\"\"\"\n Recurring Events\n \"\"\"\nname = models.CharField(max_length=255)\nstart_time = models.TimeField(\"Start\", null=True, blank=True)\nduration_in_min = models.IntegerField(null=True, blank=True)\nvideo_conference_url = models.URLField(blank=True)\nadditional_info = models.TextField(blank=True)\nproject = models.ForeignKey(Project, on_delete=models.CASCADE)\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):\nreturn f\"{self.name}\"\n
link to code
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../scripts/migrate.sh\n
"},{"location":"how-to/add-model-and-api-endpoints/#write-a-simple-test","title":"Write a simple test","text":"Since we overrode the __str__
function, we need to write a test for it.
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\ndef recurring_event(project):\nreturn RecurringEvent.objects.create(name=\"Test Recurring Event\", project=project)\n
link to code
recurring_event
).project
model as a foreign key relation, so we pass in the project
fixture, which creates a project
model.We create an object of the new model, passing in at least the required fields. In this case, we passed in enough arguments to use the __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):\nassert str(recurring_event) == \"Test Recurring Event\"\n
link to code
__str__
method should be tested since it's an override of the default Django method.Write assertion(s) to check that what's passed into the model is what it contains. The simplest thing to check is the __str__
method.
Run the test script to show it passing
./scripts/test.sh\n
"},{"location":"how-to/add-model-and-api-endpoints/#check-point-1","title":"Check point 1","text":"This is a good place to pause, check, and commit progress.
./scripts/precommit-check.sh\n
git add -A\ngit commit -m \"feat: add model: recurring_event\"\n
"},{"location":"how-to/add-model-and-api-endpoints/#the-admin-site","title":"The admin site","text":"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":"how-to/add-model-and-api-endpoints/#register-the-model-with-the-admin-site","title":"Register the model with the admin site","text":"from .models import RecurringEvent\n
link to code
@admin.register(RecurringEvent)\nclass RecurringEventAdmin(admin.ModelAdmin):\nlist_display = (\n\"name\",\n\"start_time\",\n\"duration_in_min\",\n)\n
link to code
See the contributing doc 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)
time_zone = TimeZoneField(blank=True, use_pytz=False, default=\"America/Los_Angeles\")\n
link to code
This is a good place to pause, check, and commit progress.
./scripts/precommit-check.sh\n
git add -A\ngit commit -m \"feat: register admin: recurring_event\"\n
"},{"location":"how-to/add-model-and-api-endpoints/#the-api","title":"The API","text":"There's several components to adding API endpoints: Model(already done), Serializer, View, and Router.
"},{"location":"how-to/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.
from core.models import RecurringEvent\n
link to code
class RecurringEventSerializer(serializers.ModelSerializer):\n\"\"\"Used to retrieve recurring_event info\"\"\"\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)\nread_only_fields = (\n\"uuid\",\n\"created_at\",\n\"updated_at\",\n)\n
link to code
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)\n
link to code
This non-built-in model field provides a serializer so we just point to it.
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
"},{"location":"how-to/add-model-and-api-endpoints/#add-viewset","title":"Add viewset","text":"Viewset defines the set of API endpoints for the model.
from .serializers import RecurringEventSerializer\n
link to code
@extend_schema_view(\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):\npermission_classes = [IsAuthenticated]\nqueryset = RecurringEvent.objects.all()\nserializer_class = RecurringEventSerializer\n
link to code
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.
@extend_schema_view(\nlist=extend_schema(\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\"),\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):\n
link to code
create
, retrieve
, partial_update
, update
, destroy
, list
.This one is fancy and provides examples of data to pass into the query params. It's probably more than we need right now.
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)
class UserViewSet(viewsets.ModelViewSet):\n...\ndef get_queryset(self):\n\"\"\"\n Optionally filter users by an 'email' and/or 'username' query paramerter in the URL\n \"\"\"\nqueryset = get_user_model().objects.all()\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
link to code
queryset
property is now the get_queryset(()
function which returns the queryset.get_queryset()
function overrides the default and lets us filter the objects returned to the client if they pass in a query param.from .views import RecurringEventViewSet\n
link to code
router.register(r\"recurring-events\", RecurringEventViewSet, basename=\"recurring-event\")\n
link to code
http://localhost/api/v1/recuring-events/
and http://localhost/api/v1/recuring-events/<uuid>
basename
is the name used for generating the endpoint names, such as [basename]-list, [basename]-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/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.
RECURRING_EVENTS_URL = reverse(\"recurring-event-list\")\n
link to code
def 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
link to code
Then
Run the test script to show it passing
./scripts/test.sh\n
"},{"location":"how-to/add-model-and-api-endpoints/#check-point-3","title":"Check point 3","text":"This is a good place to pause, check, and commit progress.
./scripts/precommit-check.sh\n
git add -A\ngit commit -m \"feat: add endpoints: recurring_event\"\n
"},{"location":"how-to/add-model-and-api-endpoints/#push-the-code-and-start-a-pr","title":"Push the code and start a PR","text":"Refer to the contributing doc section on \"Push to upstream origin\" onward.
"},{"location":"tools/mkdocs/","title":"MkDocs","text":""},{"location":"tools/mkdocs/#introduction","title":"Introduction","text":"We are using MkDocs to generate our documentation. See Docker-mkdocs repo for information about MkDocs and the image we're using.
"},{"location":"tools/mkdocs/#mkdocs-docker-image","title":"MkDocs docker image","text":""},{"location":"tools/mkdocs/#how-it-works","title":"How it works","text":""},{"location":"tools/mkdocs/#work-on-docs-locally","title":"Work on docs locally","text":"It should already be running with the peopledepot django server. If not, run the mkdocs container.
docker-compose up mkdocs # (1)!\n
-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.
Quit
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
"},{"location":"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.
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.lint.sh - lint and and auto-format code
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. The coverage report will show many missing lines of coverage as a result. We recommend adding --no-cov
in this case to disable the coverage report.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
createsuperuser.sh - creates a default superuser.
DJANGO_SUPERUSER_USERNAME
and DJANGO_SUPERUSER_PASSWORD
are set in .env.dev
The pre-commit hook in git will run before each commit and will abort the commit on failure. The advantage of this over GitHub Actions is that GitHub Actions work on code that's already committed, so it needs to allow code to be committed first.
We're setting a set of fast checks to run on each commit and longer checks such as a full rebuild to run when trying to push the code.
The hooks run when doing normal git commit
and git push
commands. It's recommended to do this in the command line. If performing these actions from a gui application, the interface may seem to hang for some time.
Installing the pre-commit hooks to git
Install pre-commit (virtual environment or at least per-user install is recommended)
pip install pre-commit --local\n
Add the hook to your local git repo
cd $(git rev-parse --show-toplevel) # go to the repo's root dir\npre-commit install\n
Update pre-commit and plugins to the latest version
pre-commit autoupdate\n
Test run the hooks (this runs it against all files rather than only staged files)
pre-commit run --all-files\n
(Extra info) More commands to test run the hooks
pre-commit run --all-files --hook-stage push\npre-commit run --all-files --hook-stage commit\npre-commit run test --all-files --hook-stage push\n
The pre-commit hook in git will run before each commit and will abort the commit on failure. The advantage of this over GitHub Actions is that GitHub Actions work on code that's already committed, so it needs to allow code to be committed first.
+We're setting a set of fast checks to run on each commit and longer checks such as a full rebuild to run when trying to push the code.
+The hooks run when doing normal git commit
and git push
commands. It's recommended to do this in the command line. If performing these actions from a gui application, the interface may seem to hang for some time.
Installing the pre-commit hooks to git
+Install pre-commit (virtual environment or at least per-user install is recommended)
+ +Add the hook to your local git repo
+ +Update pre-commit and plugins to the latest version
+ +Test run the hooks (this runs it against all files rather than only staged files)
+ +(Extra info) More commands to test run the hooks
+ +We are using MkDocs to generate our documentation. See Docker-mkdocs repo for information about MkDocs and the image we're using.
+It should already be running with the peopledepot django server. If not, 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.
Quit
+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
+ + + + + + +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.
+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.lint.sh - lint and and auto-format code
+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. The coverage report will show many missing lines of coverage as a result. We recommend adding --no-cov
in this case to disable the coverage report.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
+createsuperuser.sh - creates a default superuser.
+DJANGO_SUPERUSER_USERNAME
and DJANGO_SUPERUSER_PASSWORD
are set in .env.dev