Skip to content

Commit

Permalink
Upgrade to Django 5
Browse files Browse the repository at this point in the history
  • Loading branch information
FinalAngel committed Feb 23, 2024
1 parent 105200c commit 9206543
Show file tree
Hide file tree
Showing 24 changed files with 152 additions and 238 deletions.
26 changes: 9 additions & 17 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
# Code of Conduct

In this open-source project, our aim is to foster a welcoming and inclusive environment. We expect all contributors
and participants interact with each other with courtesy, respect and kindness.
## Welcome to Our Open-Source Community

We will not tolerate abuse or harassment of any kind.
This collaborative project strives to create an inclusive and welcoming environment. We value all contributors' and participants' interactions that reflect courtesy, respect, and kindness.

In the event of a concern about behaviour, please contact the maintainers of the project:
We have a zero-tolerance policy for any form of abuse or harassment.

* Dennis Schwertel <dennis.swchwertel@divio.com>
If you have concerns about behaviour, please reach out to Divio at info@divio.com.

Reports will be taken seriously and treated in confidence. If necessary, the maintainers will act to exclude
individuals from participating in this and other projects.
Reports will be treated confidentially and taken seriously. The project maintainers may take appropriate action, including exclusion from participation in this and other projects, if necessary.

## Guidelines for Code Review

## Code review
Code review is a crucial but sometimes challenging process for contributors and reviewers. It involves constructive critique, and improvements are often needed before accepting contributions.

Code review can be a frustrating process for both contributors and reviewers, with many opportunities for mutual
misunderstanding.
We expect contributors to recognize that all aspects of their submissions, including code and underlying ideas, will be carefully reviewed.

We expect participants who submit contributions for review to understand and accept that all contributions to the
project, including code and the ideas behind it, will be reviewed carefully. Often review will include critique and
criticism, and will almost always require improvements or other changes before contributions can be accepted.

We also expect reviewers to communicate sensitively and respectfully.

This is in line with a shared aim for the success of the project.
Reviewers are encouraged to provide feedback sensitively and respectfully, aligning with our shared goal for the project's success.
34 changes: 14 additions & 20 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
# How to contribute to the project
# Contributing to the Project

Thanks for contributing, welcome aboard.
Thank you for contributing! We appreciate your involvement in making this project better. Before you start, please familiarize yourself with our [Code of Conduct](./CODE_OF_CONDUCT.md).

Please see our [CODE OF CONDUCT](./CODE_OF_CONDUCT.md) for our code of conduct.
## Submitting Proposals

Proposals can be submitted through:

## Submitting proposals
- [Pull Requests](https://github.com/divio/getting-started-with-django/pulls)
- [Issues](https://github.com/divio/getting-started-with-django/issues)

Please provide proposals as
[pull requests](https://github.com/divio/getting-started-with-django/pulls)
or
[issues](https://github.com/divio/getting-started-with-django/issues) as appropriate.
## Pull Requests and Branches

When making pull requests, adhere to the following:

## Pull requests and branches
- Submit from a properly named new branch.
- Target the `main` branch.

Please make pull requests:

* from an appropriately-named new branch
* to the ``main`` branch

See:

* [how to make pull requests](https://help.github.com/articles/using-pull-requests/)
* [how to manage branches](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/)
Learn more:

- [How to make pull requests](https://help.github.com/articles/using-pull-requests/)
- [Managing branches](https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/)

### Whitespace

Do not use trailing whitespace (spaces or tabs at the end of a line). They are often not visible, and can cause silent
problems and misleading unexpected changes. For example, some editors quietly delete them by default.
Avoid trailing whitespace (spaces or tabs at the end of a line). They might be invisible and lead to silent issues or unexpected changes. Some editors may silently delete them by default.
11 changes: 5 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM python:3.12

# Set environment variables for Python
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

# Set the working directory to /app
WORKDIR /app
Expand All @@ -24,13 +24,12 @@ RUN pip-compile requirements.in && \

# Copy the rest of the project files into the container
COPY . /app/
RUN chmod +x manage.py

# Run collectstatic to gather static files
RUN python manage.py collectstatic --noinput

# Make port 8000 available to the world outside this container
EXPOSE 8000
# Make port 80 available to the world outside this container
EXPOSE 80

# Define the command to run your application
CMD ["gunicorn", "wsgi:application", "--bind", "0.0.0.0:8000"]
CMD ["gunicorn", "mysite.wsgi:application", "--bind", "0.0.0.0:80"]
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2024, Divio AG
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Divio AG nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL DIVIO AG BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
84 changes: 18 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,28 @@
# Getting started with Django
# Getting Started with Django

[![Deploy at Divio
badge](https://img.shields.io/badge/deploy%20at%20divio-DFFF67)](https://control.divio.com/app/new/?template_url=https://github.com/divio/getting-started-with-django/archive/refs/heads/main.zip)
[![Deploy to Divio](https://img.shields.io/badge/DEPLOY-TO%20DIVIO-DFFF67?logo=docker&logoColor=white&labelColor=333333)](https://control.divio.com/app/new/?template_url=https://github.com/divio/getting-started-with-django/archive/refs/heads/main.zip)

Welcome to our QuickStart template – your portal to swift application development and seamless local testing. Whether you're delving into Django for the first time or optimizing your workflow, our template, based on Djangos' [Getting started](https://docs.djangoproject.com/en/5.0/intro/) guide, has got you covered.

This is a template project to bootstrap a Django application.
## Cloud Setup

Use the app creation wizard with a free [Divio Account](https://control.divio.com/) and choose **Django** from the template selection. Alternatively, click the `Deploy to Divio` button above and follow the app creation wizard. Finally, deploy your app to the `test` or `live` environment.

## Quick Start with Divio Cloud
Beware that the **admin** user is not created automatically.
You can do so by connecting via SSH and manually run `python manage.py createsuperuser`.

### Create a free Divio account
Create a free [Divio account](https://control.divio.com/).
For in-depth details about Divio Cloud, refer to the [Divio documentation](https://docs.divio.com/introduction/).

### Deploy your app in Divio Cloud
- Click the `Deploy at Divio` button above and provide the information requested by the app creation wizard (eg. app name and app settings)
## Local Setup

- In Divio Control Panel dashboard, Add `PostgreSQL` database under Services section.
Install the [Divio CLI](https://github.com/divio/divio-cli) to set up your app locally.

- Under settings, add the `Release Command` for database migration:
- `python manage.py migrate`
(`Release Commands` are the commands executed at the start of app container).
Alternatively, build this app locally using Docker:


- Deploy an environment; test or live. Open the Env URL in your browser.

For more details about Divio system, read [Divio documentation](https://docs.divio.com/introduction/)


## Setup your local development environment with Divio CLI

Please follow our simple guidelines for [Divio CLI installation](https://docs.divio.com/introduction/01-installation/) and [setup local development](https://docs.divio.com/introduction/01-installation/#tutorial-installation&gsc.tab=0)


## Setup your local development environment without Divio CLI

### Install Docker

This project uses Docker and docker-compose which you can install from the [offical Docker website](https://docs.docker.com/get-docker/).

### Clone the repository

```
git clone https://github.com/divio/getting-started-with-django.git
```

### Build the project

Let's build the docker image of the project.
```
cd getting-started-with-django
docker-compose build
```

### Run the project

```
docker-compose up
```

This command will start the `web` and `database_default` services. You can reach the web application at [http://localhost:8000]() and Admin panel at [http://localhost:8000/admin]()


To access admin, create a super user.
```
docker-compose run web python manage.py createsuperuser
```

## How to develop

Follow the official [Django development guides](https://docs.djangoproject.com/en/4.2/intro/tutorial01/)


## Contribute to the project

See the [contribution guide](./CONTRIBUTING.md).
1. Ensure [Docker](https://docs.docker.com/get-docker/) is installed and running.
2. Clone this repository locally.
3. Build the app with `docker compose build`.
4. Run the migrations with `docker compose run --rm web python manage.py migrate`
5. Create a superuser with `docker compose run --rm web python manage.py createsuperuser`
6. Run the app using `docker compose up`.
7. Open [http://localhost:8000]() to view your app.
17 changes: 5 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
version: '3'
version: "3"

services:

web:
# the application's web service (container) will use an image based on our Dockerfile
build: "."
# Map the internal port 80 to port 8000 on the host
build: .
ports:
- "8000:80"
# Map the host directory to app (which allows us to see and edit files inside the container)
volumes:
- ".:/app:rw"
# The default command to run when launching the container
command: python manage.py runserver 0.0.0.0:80
# a link to database_default, the application's local database service
environment:
DATABASE_URL: postgres://postgres@database_default:5432/db
links:
- "database_default"
# load environment variables from env file
env_file: ./localdev/.env.local
command: python manage.py runserver 0.0.0.0:80

database_default:
# the application's web service will use an off-the-shelf image
image: postgres:13.5-alpine
environment:
POSTGRES_DB: "db"
Expand Down
4 changes: 0 additions & 4 deletions localdev/.env.local

This file was deleted.

2 changes: 1 addition & 1 deletion manage.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions asgi.py → mysite/asgi.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""
ASGI config for project.
ASGI config.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

application = get_asgi_application()
Loading

0 comments on commit 9206543

Please sign in to comment.