Skip to content

Commit 866865a

Browse files
authored
Merge pull request #24 from withlogicco/release-1.2.0
Release 1.2.0
2 parents 6bbb58b + 25b9890 commit 866865a

30 files changed

+358
-282
lines changed

.devcontainer/devcontainer.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Django Prose",
3+
"dockerComposeFile": [
4+
"../docker-compose.yml",
5+
"docker-compose.yml"
6+
],
7+
"service": "web",
8+
"workspaceFolder": "/usr/src/app",
9+
"settings": {
10+
"python.formatting.provider": "black",
11+
"editor.formatOnSave": true,
12+
"eslint.format.enable": true
13+
},
14+
"extensions": [
15+
"batisteo.vscode-django",
16+
"editorconfig.editorconfig",
17+
"ms-python.python"
18+
],
19+
"features": {
20+
"ghcr.io/devcontainers/features/common-utils:1": {},
21+
"ghcr.io/devcontainers/features/git:1": {}
22+
}
23+
}

.devcontainer/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: "3.8"
2+
3+
services:
4+
web:
5+
command: sleep infinity

.github/workflows/ci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ on: push
44

55
jobs:
66
deploy:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@v3
10-
- run: pipx install poetry==1.1.13
10+
- run: pipx install poetry==1.3.2
1111
- uses: actions/setup-python@v4
1212
with:
13-
python-version: '3.10'
13+
python-version: '3.11'
1414
cache: poetry
1515
- run: poetry install
1616
- run: poetry run black --check .

.github/workflows/release.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ on:
77

88
jobs:
99
deploy:
10-
runs-on: ubuntu-20.04
10+
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v3
13-
- run: pipx install poetry==1.1.13
13+
- run: pipx install poetry==1.3.2
1414
- uses: actions/setup-python@v4
1515
with:
16-
python-version: '3.10'
16+
python-version: '3.11'
1717
cache: poetry
1818
- run: poetry install
1919
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Django: Run server",
6+
"type": "python",
7+
"request": "launch",
8+
"program": "${workspaceFolder}/example/manage.py",
9+
"args": [
10+
"runserver",
11+
"0.0.0.0:8000"
12+
],
13+
"django": true,
14+
"justMyCode": true
15+
}
16+
]
17+
}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/withlogicco/poetry:1.1.13-python-3.10-slim
1+
FROM ghcr.io/withlogicco/poetry:1.3.2-python-3.11
22

33
COPY ./ ./
44
RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=/root/.cache/pypoetry poetry install

README.md

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
![PyPI - Downloads](https://img.shields.io/pypi/dw/django-prose?color=purple) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-prose)
44

5-
Django Prose provides your Django applications with wonderful rich-text editing.
5+
Django Prose provides your Django applications with wonderful rich-text editing capabilities.
66

77
## Requirements
88

9-
- Python 3.6.2 or later
10-
- Django 2.2 or later
9+
- Python 3.8 or later
10+
- Django 3.2 or later
1111
- Bleach 4.0 or later
1212

1313
## Getting started
@@ -18,7 +18,7 @@ To get started with Django Prose, first make sure to install it. We use and sugg
1818
poetry add django-prose
1919
```
2020

21-
Then, add `prose` in Django's installed apps (example: [`prose_example/prose_example/settings.py`](https://github.com/withlogicco/django-prose/blob/55fb9319e55d873afe43968817a2f5ea3f055d11/prose_example/prose_example/settings.py#L46)):
21+
Then, add `prose` in Django's installed apps (example: [`example/example/settings.py`](https://github.com/withlogicco/django-prose/blob/9e24cc794eae6db48818dd15a483d106d6a99da0/example/example/settings.py#L46)):
2222

2323
```python
2424
INSTALLED_APPS = [
@@ -42,9 +42,17 @@ Now, you are ready to go 🚀.
4242

4343
There are different ways to use Django prose according to your needs. We will examine all of them here.
4444

45-
### Small rich-text information
45+
### Rendering rich-text in templates
4646

47-
You might want to add rich-text information in a model that is just a few characters (e.g. 140), like an excerpt from an article. In that case we suggest using the `RichTextField`. Example:
47+
Rich text content essentially is HTML. For this reason it needs to be manually marked as [`safe`](https://docs.djangoproject.com/en/4.2/ref/templates/builtins/#safe), when rendered in Django templates. Example:
48+
49+
```django
50+
{{ document.content | safe}}
51+
```
52+
53+
### Small rich-text content
54+
55+
You might want to add rich-text content in a model that is just a few characters (e.g. 140), like an excerpt from an article. In that case we suggest using the `RichTextField`. Example:
4856

4957
```py
5058
from django.db import models
@@ -54,15 +62,15 @@ class Article(models.Model):
5462
excerpt = RichTextField()
5563
```
5664

57-
Then you can display the article excerpt in your HTML templates by marking it as [`safe`](https://docs.djangoproject.com/en/4.0/ref/templates/builtins/#safe)
65+
As mentioned above, you need to mark the article excerpt as `safe`, in order to render it:
5866

5967
```django
6068
<div class="article-excerpt">{{ article.excerpt | safe}}</div>
6169
```
6270

63-
### Large rich-text information
71+
### Large rich-text content
6472

65-
In case you want to store large rich-text information, like the content of an article, which can span to quite a few thousand characters, we suggest you use the `AbstractDocument` model. This will save large rich-text information in a separate database table, which is better for performance. Example:
73+
In case you want to store large rich-text content, like the body of an article, which can span to quite a few thousand characters, we suggest you use the `AbstractDocument` model. This will save large rich-text content in a separate database table, which is better for performance. Example:
6674

6775
```py
6876
from django.db import models
@@ -77,7 +85,7 @@ class Article(models.Model):
7785
body = models.OneToOneField(ArticleContent, on_delete=models.CASCADE)
7886
```
7987

80-
Similarly here you can display the article's body by marking it as `safe`
88+
Similarly here as well, you need to mark the article's body as `safe`, in order to render it:
8189

8290
```django
8391
<div class="article-body">{{ article.body.content | safe}}</div>
@@ -104,10 +112,14 @@ The same is true also, if you are rendering the forms field manually.
104112

105113
Django Prose can also handle uploading attachments with drag and drop. To set this up, first you need to:
106114

107-
- [x] Set up the `MEDIA_ROOT` of your Django project (example in [`prose_example/prose_example/settings.py`](https://github.com/withlogicco/django-prose/blob/55fb9319e55d873afe43968817a2f5ea3f055d11/prose_example/prose_example/settings.py#L132)))
108-
- [x] Include the Django Prose URLs (example in [`prose_example/prose_example/urls.py`](https://github.com/withlogicco/django-prose/blob/9073d713f8d3febe5c50705976dbb31063270886/prose_example/prose_example/urls.py#L9-L10))
115+
- [x] Set up the `MEDIA_ROOT` and `MEDIA_URL` of your Django project (example in [`example/example/settings.py`](https://github.com/withlogicco/django-prose/blob/9e24cc794eae6db48818dd15a483d106d6a99da0/example/example/settings.py#L130-L131)))
116+
- [x] Include the Django Prose URLs (example in [`example/example/urls.py`](https://github.com/withlogicco/django-prose/blob/9e24cc794eae6db48818dd15a483d106d6a99da0/example/example/urls.py#L13-L14))
109117
- [x] (Optional) Set up a different Django storage to store your files (e.g. S3)
110118

119+
### Full example
120+
121+
You can find a full example of a blog, built with Django Prose in the [`example`](./example/) directory.
122+
111123
## 🔒 A note on security
112124

113125
As you can see in the examples above, what Django Prose does is provide you with a user friendly editor ([Trix](https://trix-editor.org/)) for your rich text content and then store it as HTML in your database. Since you will mark this HTML as safe in order to use it in your templates, it needs to be **sanitised**, before it gets stored in the database.
@@ -121,21 +133,30 @@ For this reason Django Prose is using [Bleach](https://bleach.readthedocs.io/en/
121133

122134
### Django Prose Documents in Django Admin
123135

124-
125136
![Django Prose Document in Django Admin](./docs/django-admin-prose-document.png)
126137

138+
## Real world use cases
139+
- **Remote Work Café**: Used to edit location pagess, like [Amsterdam | Remote Work Café](https://remotework.cafe/locations/amsterdam/)
140+
- In production by multiple clients of [LOGIC](https://withlogic.co), from small companies to the public sector.
141+
142+
If you are using Django Prose in your application too, feek free to open a [Pull Request](https://github.com/withlogicco/django-prose/pulls) to include it here. We would love to have it.
143+
127144
## Development for Django Prose
128145

129-
If you plan to contribute code to Django Prose, this section is for you. All development tooling for Django Prose has been set up with Docker. To get started run these commands in the provided order:
146+
If you plan to contribute code to Django Prose, this section is for you. All development tooling for Django Prose has been set up with Docker and Development Containers.
147+
148+
To get started run these commands in the provided order:
130149

131150
```console
132151
docker compose run --rm migrate
133152
docker compose run --rm createsuperuser
134153
docker compose up
135154
```
136155

156+
If you are using Visual Studio code, just open this repository in a container using the [`Dev Containers: Open Folder in Container`](https://code.visualstudio.com/docs/devcontainers/containers#_quick-start-open-an-existing-folder-in-a-container).
157+
137158
---
138159

139160
<p align="center">
140-
<i>🦄 Built with ❤️ by <a href="https://withlogic.co/">LOGIC</a>. 🦄</i>
161+
<i>🦄 Built with <a href="https://withlogic.co/">LOGIC</a>. 🦄</i>
141162
</p>

bin/server

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33
set -e
44

5-
python prose_example/manage.py migrate
6-
python prose_example/manage.py runserver 0.0.0.0:${PORT:-8000}
5+
python example/manage.py migrate
6+
python example/manage.py runserver 0.0.0.0:${PORT:-8000}
77

docker-compose.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,42 @@ x-base:
88
- .:/usr/src/app
99
- media:/mnt/media
1010
- static:/mnt/static
11-
working_dir: /usr/src/app/prose_example
11+
working_dir: /usr/src/app/
1212

1313
services:
1414
web:
1515
<<: *base
1616
ports:
1717
- ${PROSE_EXAMPLE_EXTERNAL_PORT:-8000}:8000
18-
command: python manage.py runserver 0.0.0.0:8000
18+
command: ./bin/server
1919

2020
shell:
2121
<<: *base
22-
command: python manage.py shell
22+
command: python example/manage.py shell
2323
profiles:
2424
- tools
2525

2626
makemigrations:
2727
<<: *base
28-
command: python manage.py makemigrations
28+
command: python example/manage.py makemigrations
2929
profiles:
3030
- tools
3131

3232
migrate:
3333
<<: *base
34-
command: python manage.py migrate
34+
command: python example/manage.py migrate
3535
profiles:
3636
- tools
3737

3838
createsuperuser:
3939
<<: *base
40-
command: python manage.py createsuperuser
40+
command: python example/manage.py createsuperuser
4141
profiles:
4242
- tools
4343

4444
black:
4545
<<: *base
46-
command: black /usr/src/app
46+
command: black .
4747
profiles:
4848
- tools
4949

0 commit comments

Comments
 (0)