Reddit clone for educational purposes. Developed by PyMasters
- Joining the project
- Rules of engagement
- How to Set up
- Ruff formatting and linting
- Usage with Docker 🐳
- In case of problems with starting the project
Want to join and work on it? https://pymasters.pl/spolecznosc and fill the form from this message: https://discord.com/channels/1035267230901997628/1221772410701873293/1247199896834936842
Good reading on working with code changes and pull request is https://google.github.io/eng-practices/. It contains both views - change author and reviewer.
- We use ClickUp to manage tasks: https://app.clickup.com/9012000285/v/l/8cjgdgx-412
- Kanban Board is used for ongoing work
- Kanban Backlog is used to store ideas in form of tasks, for reviewing and moving to Kanban Board.
- Tasks must follow precise life cycle
- when task is created in Kanban Backlog the status is "BACKLOG"
- when task is created in Kanban Board, or moved to Kanban Board from Kanban Backlog, status is set to "TO DO".
- when work is started, task is moved into "IN PROGRESS", and stays in this state until pull request is merged to dev
- after pull request is merged, status of the task is changed to "READY FOR QA"
- after QA is done, the person who is performing QA is setting the task as "DONE".
- if issues are found the task is moved back to "TO DO" with comments or new task is created to address those issues.
- Do not commit directly to
master
ordev
. Both branches are protected. - Check your code with
ruff check
prior to creating pull requests. The code is checked against PEP8 usingruff
. Violations will not allow merging.- fix can be applied by ruff automatically for some issues, check
ruff check --fix
.
- fix can be applied by ruff automatically for some issues, check
- Follow Git Flow approach while developing.
- video explaing git flow is available for Pymasters members at: https://discord.com/channels/1035267230901997628/1135149223306858536/1136744608555089990
- you can join Pymasters at https://pymasters.pl/spolecznosc
- Make changes and commit them. There should be only one reason to make a commit, eg. "Adding new fields to user model" should only contain changes related to those fields, nothing else. If there are other things - new commit is required.
- Use pull request to add your work. Make pull request to
dev
branch.- when pull request is created, and ready for review (branch up to date with
dev
, github actions passing) post a message on #reddit channel with link to pull request for review
- when pull request is created, and ready for review (branch up to date with
- When creating pull requests, "pymasters/reddit" team is added automatically as reviewers
- You can use "reviewers" option on far right of the screen to request review from certain team member directly by mentioning their name.
- One of the team members (or multiple) will perform code review and approve the pull request or request changes.
- If changes are requested, all comments have to be in constructive and friendly manner, as shown in https://google.github.io/eng-practices/review/reviewer/comments.html
- after all the requested changes are implemented and pull request is ready for another review, post a message with a link on #reddit
- It's a good thing to comment on the good parts of code with "Nice work" or something similar.
- video explaing git flow is available for Pymasters members at: https://discord.com/channels/1035267230901997628/1135149223306858536/1136744608555089990
- As this is a learning project, pair programming is most welcome. Jump on Zoom or google meet and work together: https://www.youtube.com/watch?v=wu6BOT-eMgc&t=105s&ab_channel=devmentor.pl
- Code quality and automated tests will be run and required to pass before pull request can be merged.
- At least one approval by other team member is required before pull request can be merged.
- After pull request is approved and code quality + tests are passed, pull request is merged by the author.
- It is author responsibility to watch over pull request, bump if there is no code review done, fix issues and merge pull request.
- Use excellent Bootstrap framework for handling HTML pages https://getbootstrap.com/
- Use class based views instead of function based views. A lot of examples and reading can be found on Jacek Blog: https://akademiait.com.pl/ and youtube: https://www.youtube.com/watch?v=2S9-pvFBlBc&ab_channel=AkademiaIT
- for testing use pytest. Tests using Django Unit Testing will not be accepted. A lot of tests are in our previous project: https://github.com/pymasterspl/Dshop. Also please watch https://www.youtube.com/watch?v=xn3wSM82fnA&ab_channel=AkademiaIT
- If you have questions, just ask on discord, reddit channel.
The project is using Pytest for automated testing. https://docs.pytest.org/
To run the tests first start project environment with:
poetry shell
Run tests in project directory with:
pytest -n auto -vv
This command runs tests in parallel, thus much faster.
Make sure all tests pass before creating PR. Automated tests are run on every PR and if tests fail, merge will not be possible.
This is most welcome. Test should be located in tests
directory of a module (remember to add __init__.py
file!).
Test filename should follow pattern test_{name}.py
where name is either functionality or, eg. "models", so test_models.py
.
Each test in the file must start with test_
prefix, otherwise Pytest will not find it.
Test driven development is most welcome, check https://www.youtube.com/watch?v=xn3wSM82fnA. It is understandable that TDD itself is cumbersome, so writing the tests after the code is also OK. Practice, practice, practice. Review other tests, experiment, and if questions, ask.
Clone repository to specific folder (ex. reddit):
git clone https://github.com/pymasterspl/reddit.git
You need to have installed Poetry package. If you don't have, please install using this command:
pip install poetry==1.7.1
Navigate to reddit folder by command:
cd reddit
Set poetry global option, to use project folder as place to hold Virtual environment (recommended):
poetry config virtualenvs.in-project true
Install virtual environment, using current dependencies:
poetry install
Copy file env-template to .env file using command:
# linux/mac
cp env-template .env
# windows
copy env-template .env
Start poetry virtual environment
poetry shell
Update local .env file as needed
Create admin account to access admin site:
# linux/mac
# to apply db changes
./manage.py migrate
./manage.py createsuperuser
# windows
# to apply db changes
python manage.py migrate
python manage.py createsuperuser
Run project:
# linux/mac
# to apply db changes
./manage.py migrate
# to start project
./manage.py runserver
# windows
# to apply db changes
python manage.py migrate
# to start project
python manage.py runserver
Load data from fixtures:
python manage.py loaddata {fixture_name}.json
Open web browser and navigate to localhost address: http://127.0.0.1:8000/
To enable registration on the site, you must provide your e-mail data. There are two ways.
In the env file you need to set these fields
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_USE_TLS = True
-
First possibility.
You enter your account password.
EMAIL_HOST_PASSWORD = 'your_password'
-
Second possibility.
You can generate a token for your account instead of entering your password.
* The first thing you need to do is go to https://myaccount.google.com/security
* Activate two-step verification via this link https://myaccount.google.com/signinoptions/twosv
* Then we return to the website https://myaccount.google.com in the input we enter app passwords or in Polish version "hasła do aplikacji" ( it depends on the language setting on your account )
* after entering a given view, you must enter the password from your Gmail, then enter the name of this code.
* Gmail returns you a code that you enter into the env file (EMAIL_HOST_PASSWORD).
This guide will help you set up Google OAuth login in a Django project using environment variables for client credentials.
- Navigate to Google Cloud Console.
- Make sure you're logged in with the Google account you want to use.
- In the top navigation bar, click on the project dropdown.
- Select New Project if you don't have an existing one.
- Give your project a name and click Create.
- In the left sidebar, go to API & Services > OAuth consent screen.
- Select External if you want users outside your organization to log in (e.g., for testing purposes).
- Fill in the required fields, such as App Name, User Support Email, and Developer Contact Information.
- Click Save and Continue.
-
In the left sidebar, go to API & Services > Credentials.
-
Click Create Credentials and select OAuth client ID.
-
Choose Web application as the Application type.
-
Enter a name for the client, like
Django Google Login
. -
In the Authorized JavaScript origins section, add:.
- If running locally, the URI should look like this:
http://127.0.0.1:8000
- If running locally, the URI should look like this:
-
Under Authorized redirect URIs, add the redirect URI for your Django app.
- If running locally, the URI should look like this:
http://127.0.0.1:8000/users/google/complete/google-oauth2/
- If running locally, the URI should look like this:
-
Click Create. Google will generate a Client ID and Client Secret.
-
Copy the Client ID and Client Secret. You will use these in your
.env
file.
After saving, changes can take from 5 minutes to a few hours to take effect.
- Open the
.env
file in the root of your Django project (create it if it doesn’t exist). - Add the following environment variables from Step 4.8, replacing default values in
GOOGLE_OAUTH2_KEY
andGOOGLE_OAUTH2_SECRET
.
This is how we use linter:
ruff check # Lint all files in the current directory.
ruff check --fix # Lint all files in the current directory, and fix any fixable errors.
ruff check --watch # Lint all files in the current directory, and re-lint on change.
ruff check path/to/code/ # Lint all files in `path/to/code` (and any subdirectories).
This is how to use formatter:
ruff format # Format all files in the current directory.
ruff format path/to/code/ # Format all files in `path/to/code` (and any subdirectories).
ruff format path/to/file.py # Format a single file.
ruff format --check # Checks if formatting is proper and reports violations. Does not change files.
More at: https://docs.astral.sh/ruff/linter/ https://docs.astral.sh/ruff/formatter/
To remove old, expired tokens that have been blacklisted, use the following management command:
python manage.py flushexpiredtokens
For setup and running with Docker, refer to the Docker configuration instructions.
- Check the env-template file and update the local .env file if necessary
- Run
poetry install