Skip to content

Commit

Permalink
Drop django 3.1 support (#438)
Browse files Browse the repository at this point in the history
* Move badge from Travis-CI to GH actions

and prepare a GH action to automatically publish new releases upon tagging

* attempt to fix failing test_email_change_view

* add missing import to documentation

* Replace 3rd party jsonfield against builtin

Since Django-3.1 a JSONField has been added for all supported databases.

This also drops support for Django-3.1 and below, since these versions reached their EOL.

* use internal JSONField

* exclude Django>=4 with Python-3.7

* Add pytz as external dependency
  • Loading branch information
jrief authored Feb 16, 2023
1 parent 1d833db commit 52b2900
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 26 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish django-post_office

on:
push:
tags:
- '*'

jobs:
publish:
name: "Publish release"
runs-on: "ubuntu-latest"

environment:
name: deploy

strategy:
matrix:
python-version: ["3.9"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install build --user
- name: Build 🐍 Python 📦 Package
run: python -m build --sdist --wheel --outdir dist/
- name: Publish 🐍 Python 📦 Package to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN_POST_OFFICE }}
15 changes: 10 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ jobs:
name: Python${{ matrix.python-version }}/Django${{ matrix.django-version }}
strategy:
matrix:
python-version: ["3.9"]
django-version: ["3.2.16", "4.0.8", "4.1.3"]
python-version: ["3.7", "3.10"]
django-version: ["3.2", "4.0", "4.1"]
exclude:
- python-version: 3.7
django-version: 4.0
- python-version: 3.7
django-version: 4.1

steps:
- uses: actions/checkout@v3
Expand All @@ -30,9 +35,9 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install django==${{ matrix.django-version }}
pip install jsonfield pytz
pip install pytz
pip install "Django==${{ matrix.django-version }}.*"
- name: Run Test
run: |
`which django-admin` test post_office --settings=post_office.test_settings --pythonpath=.
`which django-admin` test post_office --settings=post_office.test_settings --pythonpath=.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ will otherwise be stripped for security reasons.

## Installation

[![Build
Status](https://travis-ci.org/ui/django-post_office.png?branch=master)](https://travis-ci.org/ui/django-post_office) [![PyPI version](https://img.shields.io/pypi/v/django-post_office.svg)](https://pypi.org/project/django-post_office/) ![Software license](https://img.shields.io/pypi/l/django-post_office.svg)
[![Build Status](https://github.com/ui/django-post_office/actions/workflows/test.yml/badge.svg)](https://github.com/ui/django-post_office/actions)
[![PyPI](https://img.shields.io/pypi/pyversions/django-post_office.svg)]()
[![PyPI version](https://img.shields.io/pypi/v/django-post_office.svg)](https://pypi.python.org/pypi/django-post_office)
[![PyPI](https://img.shields.io/pypi/l/django-post_office.svg)]()

Install from PyPI (or [manually download from PyPI](http://pypi.python.org/pypi/django-post_office)):

```sh
pip install django-post_office
Expand Down Expand Up @@ -311,6 +312,7 @@ inlined images, use the following code snippet:

```python
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template

subject, body = "Hello", "Plain text body"
from_email, to_email = "[email protected]", "[email protected]"
Expand All @@ -328,6 +330,7 @@ plain text body, use this code snippet:

```python
from django.core.mail import EmailMultiAlternatives
from django.template.loader import get_template

subject, from_email, to_email = "Hello", "[email protected]", "[email protected]"
template = get_template('email-template-name.html', using='post_office')
Expand Down Expand Up @@ -550,7 +553,7 @@ POST_OFFICE = {
}
```

`CONTEXT_FIELD_CLASS` defaults to `jsonfield.JSONField`.
`CONTEXT_FIELD_CLASS` defaults to `django.db.models.JSONField`.

### Logging

Expand Down
6 changes: 3 additions & 3 deletions post_office/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models, migrations
import jsonfield.fields

import post_office.fields
import post_office.validators
import post_office.models
Expand Down Expand Up @@ -38,8 +38,8 @@ class Migration(migrations.Migration):
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
('last_updated', models.DateTimeField(auto_now=True, db_index=True)),
('scheduled_time', models.DateTimeField(db_index=True, null=True, blank=True)),
('headers', jsonfield.fields.JSONField(null=True, blank=True)),
('context', jsonfield.fields.JSONField(null=True, blank=True)),
('headers', models.JSONField(null=True, blank=True)),
('context', models.JSONField(null=True, blank=True)),
],
options={
},
Expand Down
6 changes: 3 additions & 3 deletions post_office/migrations/0004_auto_20160607_0901.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 1.9.6 on 2016-06-07 07:01
from django.db import migrations, models
import django.db.models.deletion
import jsonfield.fields

import post_office.models


Expand Down Expand Up @@ -47,12 +47,12 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='email',
name='context',
field=jsonfield.fields.JSONField(blank=True, null=True, verbose_name='Context'),
field=models.JSONField(blank=True, null=True, verbose_name='Context'),
),
migrations.AlterField(
model_name='email',
name='headers',
field=jsonfield.fields.JSONField(blank=True, null=True, verbose_name='Headers'),
field=models.JSONField(blank=True, null=True, verbose_name='Headers'),
),
migrations.AlterField(
model_name='email',
Expand Down
5 changes: 2 additions & 3 deletions post_office/migrations/0008_attachment_headers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by Django 1.11.16 on 2018-11-30 08:54
from django.db import migrations
import jsonfield.fields
from django.db import migrations, models


class Migration(migrations.Migration):
Expand All @@ -13,6 +12,6 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name='attachment',
name='headers',
field=jsonfield.fields.JSONField(blank=True, null=True, verbose_name='Headers'),
field=models.JSONField(blank=True, null=True, verbose_name='Headers'),
),
]
5 changes: 2 additions & 3 deletions post_office/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from django.utils.encoding import smart_str
from django.utils.translation import pgettext_lazy, gettext_lazy as _
from django.utils import timezone
from jsonfield import JSONField

from post_office import cache
from post_office.fields import CommaSeparatedEmailField
Expand Down Expand Up @@ -68,7 +67,7 @@ class Email(models.Model):
help_text=_("Email won't be sent after this timestamp"))
message_id = models.CharField("Message-ID", null=True, max_length=255, editable=False)
number_of_retries = models.PositiveIntegerField(null=True, blank=True)
headers = JSONField(_('Headers'), blank=True, null=True)
headers = models.JSONField(_('Headers'), blank=True, null=True)
template = models.ForeignKey('post_office.EmailTemplate', blank=True,
null=True, verbose_name=_("Email template"),
on_delete=models.CASCADE)
Expand Down Expand Up @@ -316,7 +315,7 @@ class Attachment(models.Model):
emails = models.ManyToManyField(Email, related_name='attachments',
verbose_name=_('Emails'))
mimetype = models.CharField(max_length=255, default='', blank=True)
headers = JSONField(_('Headers'), blank=True, null=True)
headers = models.JSONField(_('Headers'), blank=True, null=True)

class Meta:
app_label = 'post_office'
Expand Down
2 changes: 1 addition & 1 deletion post_office/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ def get_message_id_fqdn():


CONTEXT_FIELD_CLASS = get_config().get('CONTEXT_FIELD_CLASS',
'jsonfield.JSONField')
'django.db.models.JSONField')
context_field_class = import_string(CONTEXT_FIELD_CLASS)
5 changes: 3 additions & 2 deletions post_office/tests/test_html_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,13 @@ def test_email_change_view(self):
msg.send()

# check that in the Email's detail view, the message is rendered
self.assertEqual(Email.objects.count(), 1) # TODO: remove this
email = Email.objects.latest('id')
parts = email.email_message().message().walk()
part = next(parts)
self.assertEqual(part.get_content_type(), 'multipart/mixed')
self.assertIsInstance(part, SafeMIMEMultipart)
part = next(parts)
self.assertEqual(part.get_content_type(), 'text/html')
self.assertIsInstance(part, SafeMIMEText)
part = next(parts)
self.assertEqual(part.get_content_type(), 'image/png')
content_id = part['Content-Id'][1:33]
Expand Down
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def run_tests(self):
package_data={'': ['README.rst']},
install_requires=[
'bleach[css]',
'django>=2.2',
'jsonfield>=3.0',
'django>=3.2',
'pytz',
],
classifiers=[
Expand All @@ -66,6 +65,10 @@ def run_tests(self):
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Framework:: Django:: 3.2'
'Framework:: Django:: 4.0',
'Framework:: Django:: 4.1',
'Topic :: Communications :: Email',
'Topic :: Internet :: WWW/HTTP',
'Topic :: Software Development :: Libraries :: Python Modules',
Expand Down

0 comments on commit 52b2900

Please sign in to comment.