Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove and replace pkg_resources and distutils with modern equivalents #389

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions newsletter/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pkg_resources import get_distribution, DistributionNotFound
from importlib.metadata import version, PackageNotFoundError

try:
__version__ = get_distribution("django-newsletter").version
except DistributionNotFound:
__version__ = version("django-newsletter")
except PackageNotFoundError:
# package is not installed
__version__ = None
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 5.0.6 on 2024-05-08 15:28

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("newsletter", "0008_longer_subscription_name"),
]

operations = [
migrations.AlterField(
model_name="article",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="attachment",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="message",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="newsletter",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="submission",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
migrations.AlterField(
model_name="subscription",
name="id",
field=models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
]
10 changes: 7 additions & 3 deletions newsletter/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import sys
import os
import time
from datetime import datetime
Expand All @@ -17,7 +18,7 @@
from django.utils.timezone import now
from django.urls import reverse

from distutils.version import LooseVersion
# from distutils.version import LooseVersion

from .fields import DynamicImageField
from .utils import (
Expand Down Expand Up @@ -740,8 +741,11 @@ def get_absolute_url(self):
def get_address(name, email):
# Converting name to ascii for compatibility with django < 1.9.
# Remove this when django 1.8 is no longer supported.
if LooseVersion(django.get_version()) < LooseVersion('1.9'):
name = name.encode('ascii', 'ignore').decode('ascii').strip()
# if LooseVersion(django.get_version()) < LooseVersion('1.9'):
# name = name.encode('ascii', 'ignore').decode('ascii').strip()
# Assuming django.get_version() returns a string like '1.8.18'
django_version = tuple(map(int, django.get_version().split('.')))
name = name.encode('ascii', 'ignore').decode('ascii').strip() if django_version < (1, 9) else name
if name:
return f'{name} <{email}>'
else:
Expand Down
Loading