forked from torchbox/wagtaildraftsharing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from mozmeao/5-customisable-max-age
Support custom max age + multiple links per Revision
- Loading branch information
Showing
10 changed files
with
237 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
wagtaildraftsharing/migrations/0003_alter_wagtaildraftsharinglink_revision.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by Django 5.1.1 on 2024-12-04 10:56 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("wagtaildraftsharing", "0002_alter_wagtaildraftsharinglink_created_by"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="wagtaildraftsharinglink", | ||
name="revision", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="+", | ||
to="wagtailcore.revision", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
from django.conf import settings | ||
|
||
WAGTAILDRAFTSHARING_ADMIN_MENU_POSITION = getattr( | ||
settings, | ||
"WAGTAILDRAFTSHARING_ADMIN_MENU_POSITION", | ||
200, | ||
) | ||
|
||
WAGTAILDRAFTSHARING_VERBOSE_NAME = getattr( | ||
settings, | ||
"WAGTAILDRAFTSHARING_VERBOSE_NAME", | ||
"Draftsharing Link", | ||
) | ||
|
||
WAGTAILDRAFTSHARING_VERBOSE_NAME_PLURAL = getattr( | ||
settings, | ||
"WAGTAILDRAFTSHARING_VERBOSE_NAME_PLURAL", | ||
"Draftsharing Links", | ||
) | ||
|
||
WAGTAILDRAFTSHARING_MENU_ITEM_LABEL = getattr( | ||
settings, | ||
"WAGTAILDRAFTSHARING_MENU_ITEM_LABEL", | ||
"Create draft sharing link", | ||
) | ||
|
||
DEFAULT_MAX_AGE = 7 * 24 * 60 * 60 # 7 days | ||
WAGTAILDRAFTSHARING_MAX_AGE = getattr( | ||
settings, | ||
"WAGTAILDRAFTSHARING_MAX_AGE", | ||
DEFAULT_MAX_AGE, | ||
) | ||
import dataclasses | ||
from typing import cast | ||
|
||
from django.conf import settings as django_settings | ||
from django.utils.functional import SimpleLazyObject | ||
|
||
_DEFAULT_MAX_TTL = 28 * 24 * 60 * 60 # 28 days | ||
|
||
|
||
@dataclasses.dataclass | ||
class WagtaildraftsharingSettings: | ||
ADMIN_MENU_POSITION: int = 200 | ||
VERBOSE_NAME: str = "Draftsharing Link" | ||
VERBOSE_NAME_PLURAL: str = "Draftsharing Links" | ||
MENU_ITEM_LABEL: str = "Create draft sharing link" | ||
MAX_TTL: int = _DEFAULT_MAX_TTL | ||
|
||
|
||
def _init_settings(): | ||
""" | ||
Get and validate Wagtaildraftsharing settings from the Django settings. | ||
""" | ||
|
||
setting_name = "WAGTAILDRAFTSHARING" | ||
django_settings_dict = getattr(django_settings, setting_name, {}) | ||
|
||
overriden_defaults = {} | ||
|
||
for optional_setting_name in [ | ||
"ADMIN_MENU_POSITION", | ||
"VERBOSE_NAME", | ||
"VERBOSE_NAME_PLURAL", | ||
"MENU_ITEM_LABEL", | ||
"MAX_TTL", | ||
]: | ||
if optional_setting_name in django_settings_dict: | ||
overriden_defaults[optional_setting_name] = django_settings_dict[ | ||
optional_setting_name | ||
] | ||
|
||
return WagtaildraftsharingSettings(**overriden_defaults) | ||
|
||
|
||
settings = cast(WagtaildraftsharingSettings, SimpleLazyObject(_init_settings)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.