Skip to content

Commit ca7ce18

Browse files
authored
Merge pull request #6 from withlogicco/release-1.0
Django Prose 1.0
2 parents c89676b + efa4c0e commit ca7ce18

File tree

23 files changed

+601
-255
lines changed

23 files changed

+601
-255
lines changed

.github/workflows/ci.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
deploy:
7+
runs-on: ubuntu-20.04
8+
steps:
9+
- uses: actions/checkout@v3
10+
- run: pipx install poetry==1.1.13
11+
- uses: actions/setup-python@v3
12+
with:
13+
python-version: '3.10'
14+
cache: poetry
15+
- run: poetry install
16+
- run: poetry run black --check .

.github/workflows/pypi.yml

Lines changed: 0 additions & 24 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-20.04
11+
steps:
12+
- uses: actions/checkout@v3
13+
- run: pipx install poetry==1.1.13
14+
- uses: actions/setup-python@v3
15+
with:
16+
python-version: '3.10'
17+
cache: poetry
18+
- run: poetry install
19+
- run: poetry config pypi-token.pypi ${{ secrets.PYPI_TOKEN }}
20+
- run: poetry publish --build

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM ghcr.io/withlogicco/poetry:1.1.13-python-3.10-slim
2+
3+
COPY ./ ./
4+
RUN --mount=type=cache,target=/root/.cache/pip --mount=type=cache,target=/root/.cache/pypoetry poetry install
5+
6+
COPY ./ ./

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2020 Paris Kasidiaris <paris@sourcelair.com>
3+
Copyright (c) 2022 LOGIC SMPC <paris@withlogic.co>
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Procfile

Lines changed: 0 additions & 1 deletion
This file was deleted.

README.md

Lines changed: 112 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,124 @@
11
# Django Prose
22

3-
Wonderful rich-text editing in Django.
3+
![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-
## Install
5+
Django Prose provides your Django applications with wonderful rich-text editing.
6+
7+
## Requirements
8+
9+
- Python 3.6.2 or later
10+
- Django 3.0 or later
11+
- Bleach 4.0 or later
12+
13+
## Getting started
14+
15+
To get started with Django Prose, first make sure to install it. We use and suggest using Poetry, although Pipenv and pip will work seamlessly as well
616

717
```console
8-
pip install django-prose
18+
poetry add django-prose
19+
```
20+
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)):
22+
23+
```python
24+
INSTALLED_APPS = [
25+
# Django stock apps (e.g. 'django.contrib.admin')
26+
27+
'prose',
28+
29+
# your application's apps
30+
]
31+
```
32+
33+
Last, run migrations so you can use Django Prose's Document model:
34+
35+
```
36+
python manage.py migrate prose
37+
```
38+
39+
Now, you are ready to go 🚀.
40+
41+
## Usage
42+
43+
There are different ways to use Django prose according to your needs. We will examine all of them here.
44+
45+
### Small rich-text information
46+
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:
48+
49+
```py
50+
from django.db import models
51+
from prose.fields import RichTextField
52+
53+
class Article(models.Model):
54+
excerpt = RichTextField()
55+
```
56+
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)
58+
59+
```django
60+
<div class="article-excerpt">{{ article.excerpt | safe}}</div>
961
```
1062

63+
### Large rich-text information
64+
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:
66+
67+
```py
68+
from django.db import models
69+
from prose.fields import RichTextField
70+
from prose.models import AbstractDocument
71+
72+
class ArticleContent(AbstractDocument):
73+
pass
74+
75+
class Article(models.Model):
76+
excerpt = RichTextField()
77+
body = models.OneToOneField(ArticleContent, on_delete=models.CASCADE)
78+
```
79+
80+
Similarly here you can display the article's body by marking it as `safe`
81+
82+
```django
83+
<div class="article-body">{{ article.body.content | safe}}</div>
84+
```
85+
86+
### Attachments
87+
88+
Django Prose can also handle uploading attachments with drag and drop. To set this up, first you need to:
89+
90+
- [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)))
91+
- [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))
92+
- [x] (Optional) Set up a different Django storage to store your files (e.g. S3)
93+
94+
## 🔒 A note on security
95+
96+
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.
97+
98+
For this reason Django Prose is using [Bleach](https://bleach.readthedocs.io/en/latest/) to only allow the following tags and attributes:
99+
100+
- **Allowed tags**: `p`, `ul`, `ol`, `li`, `strong`, `em`, `div`, `span`, `a`, `blockquote`, `pre`, `figure`, `figcaption`, `br`, `code`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `picture`, `source`, `img`
101+
- **Allowed attributes**: `alt`, `class`, `id`, `src`, `srcset`, `href`, `media`
102+
103+
## Screenshots
104+
105+
### Django Prose Documents in Django Admin
106+
107+
108+
![Django Prose Document in Django Admin](./docs/django-admin-prose-document.png)
109+
110+
## Development for Django Prose
111+
112+
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:
113+
114+
```console
115+
docker compose run --rm migrate
116+
docker compose run --rm createsuperuser
117+
docker compose up
118+
```
11119

12120
---
13121

14122
<p align="center">
15-
<i>Built with ❤️ in Athens, Greece.</i>
123+
<i>🦄 Built with ❤️ by <a href="https://withlogic.co/">LOGIC</a>. 🦄</i>
16124
</p>

docker-compose.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: "3.8"
2+
3+
x-base:
4+
&base
5+
build: .
6+
image: django-prose
7+
volumes:
8+
- .:/usr/src/app
9+
- media:/mnt/media
10+
- static:/mnt/static
11+
working_dir: /usr/src/app/prose_example
12+
13+
services:
14+
web:
15+
<<: *base
16+
ports:
17+
- ${PROSE_EXAMPLE_EXTERNAL_PORT:-8000}:8000
18+
command: python manage.py runserver 0.0.0.0:8000
19+
20+
shell:
21+
<<: *base
22+
command: python manage.py shell
23+
profiles:
24+
- tools
25+
26+
makemigrations:
27+
<<: *base
28+
command: python manage.py makemigrations
29+
profiles:
30+
- tools
31+
32+
migrate:
33+
<<: *base
34+
command: python manage.py migrate
35+
profiles:
36+
- tools
37+
38+
createsuperuser:
39+
<<: *base
40+
command: python manage.py createsuperuser
41+
profiles:
42+
- tools
43+
44+
black:
45+
<<: *base
46+
command: black /usr/src/app
47+
profiles:
48+
- tools
49+
50+
volumes:
51+
media:
52+
static:
100 KB
Loading

0 commit comments

Comments
 (0)