diff --git a/CHANGELOG.md b/CHANGELOG.md index a5e50a6e..62142c74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,14 @@ Section Order: - Optional doctrine field to FAT link creation forms - Integrity hashes to CSS and JavaScript +### Changed + +- Settings from `local.py` moved to DB + +### Removed + +- `AFAT_APP_NAME` setting to ensure the app name can be properly localized + ## \[3.3.0\] - 2024-11-06 ### Added diff --git a/README.md b/README.md index 6a358463..c06fa6bf 100644 --- a/README.md +++ b/README.md @@ -189,15 +189,15 @@ python myauth/manage.py afat_import_from_allianceauth_fat ## Settings -To customize the module, the following settings are available. - -| Name | Description | Default Value | Value Type | -| :------------------------------------- | :--------------------------------------------------------------- | :---------------------- | :--------- | -| AFAT_APP_NAME | Custom application name, in case you'd like a different name | Fleet Activity Tracking | string | -| AFAT_DEFAULT_FATLINK_EXPIRY_TIME | Default expiry time for clickable FAT links in Minutes | 60 | int | -| AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME | Time in minutes a FAT link can be re-opened after it has expired | 60 | int | -| AFAT_DEFAULT_FATLINK_REOPEN_DURATION | Time in minutes a FAT link is re-opened | 60 | int | -| AFAT_DEFAULT_LOG_DURATION | Time in days before log entries are being removed from the DB | 60 | int | +To customize the module, the following settings can be managed in your admin backend: + +| Setting | Description | Default Value | +| :--------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :------------ | +| Use doctrines from fittings module | Whether to use the doctrines from the Fittings modules in the doctrine dropdown or from AFATs own doctrine list. (Note: The [fittings module](https://gitlab.com/colcrunch/fittings) needs to be installed for this.) | No | +| Default FAT link expiry time | Default expiry time for clickable FAT links in Minutes | 60 | +| Default FAT link reopen grace time | Time in minutes a FAT link can be re-opened after it has expired | 60 | +| Default FAT link reopen duration | Time in minutes a FAT link is re-opened | 60 | +| Default log duration | Time in days before log entries are being removed from the DB | 60 | ## Permissions diff --git a/afat/app_settings.py b/afat/app_settings.py index a6a2e997..d07e9a29 100644 --- a/afat/app_settings.py +++ b/afat/app_settings.py @@ -2,42 +2,14 @@ Our app setting """ -# Third Party -import unidecode - # Django from django.apps import apps from django.utils.text import slugify -from django.utils.translation import gettext_lazy as _ - -# Alliance Auth (External Libs) -from app_utils.app_settings import clean_setting - -# Set default expiry time in minutes -AFAT_DEFAULT_FATLINK_EXPIRY_TIME = clean_setting( - name="AFAT_DEFAULT_FATLINK_EXPIRY_TIME", default_value=60 -) - -# Set the default time in minutes a FAT lnk can be re-opened after it is expired -AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME = clean_setting( - name="AFAT_DEFAULT_FATLINK_REOPEN_GRACE_TIME", default_value=60 -) - -# Set the default time in minutes a FAT link is re-opened for -AFAT_DEFAULT_FATLINK_REOPEN_DURATION = clean_setting( - name="AFAT_DEFAULT_FATLINK_REOPEN_DURATION", default_value=60 -) - -AFAT_DEFAULT_LOG_DURATION = clean_setting( - name="AFAT_DEFAULT_LOG_DURATION", default_value=60 -) -# Name of this app, as shown in the Auth sidebar and page titles -AFAT_APP_NAME = clean_setting( - name="AFAT_APP_NAME", default_value=_("Fleet Activity Tracking"), required_type=str -) +# Alliance Auth AFAT +from afat import __title__ -AFAT_BASE_URL = slugify(unidecode.unidecode(AFAT_APP_NAME), allow_unicode=True) +AFAT_BASE_URL = slugify(value=__title__, allow_unicode=True) def fittings_installed() -> bool: diff --git a/afat/auth_hooks.py b/afat/auth_hooks.py index b525315e..cebe3fdc 100644 --- a/afat/auth_hooks.py +++ b/afat/auth_hooks.py @@ -7,8 +7,8 @@ from allianceauth.services.hooks import MenuItemHook, UrlHook # Alliance Auth AFAT -from afat import urls -from afat.app_settings import AFAT_APP_NAME, AFAT_BASE_URL +from afat import __title__, urls +from afat.app_settings import AFAT_BASE_URL class AaAfatMenuItem(MenuItemHook): # pylint: disable=too-few-public-methods @@ -20,7 +20,7 @@ def __init__(self): # Setup menu entry for sidebar MenuItemHook.__init__( self, - text=AFAT_APP_NAME, + text=__title__, classes="fa-solid fa-space-shuttle", url_name="afat:dashboard", navactive=["afat:"], diff --git a/afat/forms.py b/afat/forms.py index 4c68d21b..a0eb3015 100644 --- a/afat/forms.py +++ b/afat/forms.py @@ -8,7 +8,6 @@ from django.utils.translation import gettext_lazy as _ # Alliance Auth AFAT -from afat.app_settings import AFAT_DEFAULT_FATLINK_EXPIRY_TIME from afat.models import Doctrine, FleetType, Setting @@ -35,7 +34,7 @@ def get_mandatory_form_label_text(text): class AFatEsiFatForm(forms.Form): """ Fat link form - Used to create ESI fatlinks + Used to create ESI FAT links """ name_esi = forms.CharField( @@ -63,7 +62,7 @@ class AFatEsiFatForm(forms.Form): class AFatManualFatForm(forms.Form): """ - Manual fat form + Manual FAT form """ character = forms.CharField( @@ -86,7 +85,7 @@ class AFatManualFatForm(forms.Form): class AFatClickFatForm(forms.Form): """ Fat link form - Used to create clickable fatlinks + Used to create clickable FAT links """ name = forms.CharField( @@ -114,10 +113,20 @@ class AFatClickFatForm(forms.Form): required=True, label=get_mandatory_form_label_text(text=_("FAT link expiry time in minutes")), min_value=1, - initial=AFAT_DEFAULT_FATLINK_EXPIRY_TIME, + initial=0, widget=forms.TextInput(attrs={"placeholder": _("Expiry time in minutes")}), ) + def __init__(self, *args, **kwargs): + self.request = kwargs.pop("request", None) + super().__init__(*args, **kwargs) + + # This is a hack to set the initial value of the duration field, + # which comes from the settings in the database. + self.fields["duration"].initial = Setting.get_setting( + Setting.Field.DEFAULT_FATLINK_EXPIRY_TIME + ) + class FatLinkEditForm(forms.Form): """ diff --git a/afat/migrations/0025_setting_default_fatlink_expiry_time_and_more.py b/afat/migrations/0025_setting_default_fatlink_expiry_time_and_more.py new file mode 100644 index 00000000..922ac07e --- /dev/null +++ b/afat/migrations/0025_setting_default_fatlink_expiry_time_and_more.py @@ -0,0 +1,60 @@ +# Generated by Django 4.2.16 on 2024-11-08 19:45 + +# Django +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("afat", "0024_doctrines_and_settings"), + ] + + operations = [ + migrations.AddField( + model_name="setting", + name="default_fatlink_expiry_time", + field=models.PositiveIntegerField( + default=60, + help_text="Default expiry time for clickable FAT links in minutes. (Default: 60 minutes)", + verbose_name="Default FAT link expiry time", + ), + ), + migrations.AddField( + model_name="setting", + name="default_fatlink_reopen_duration", + field=models.PositiveIntegerField( + default=60, + help_text="Default time in minutes a FAT link is re-opened for. (Default: 60 minutes)", + verbose_name="Default FAT link reopen duration", + ), + ), + migrations.AddField( + model_name="setting", + name="default_fatlink_reopen_grace_time", + field=models.PositiveIntegerField( + default=60, + help_text="Default time in minutes a FAT link can be re-opened after it is expired. (Default: 60 minutes)", + verbose_name="Default FAT link reopen grace time", + ), + ), + migrations.AddField( + model_name="setting", + name="default_log_duration", + field=models.PositiveIntegerField( + default=60, + help_text="Default time in days a log entry is kept. (Default: 60 days)", + verbose_name="Default log duration", + ), + ), + migrations.AlterField( + model_name="setting", + name="use_doctrines_from_fittings_module", + field=models.BooleanField( + db_index=True, + default=False, + help_text="Whether to use the doctrines from the Fittings modules in the doctrine dropdown. Note: The fittings module needs to be installed for this.", + verbose_name="Use doctrines from fittings module", + ), + ), + ] diff --git a/afat/models.py b/afat/models.py index a960c6fd..1c1e7c62 100644 --- a/afat/models.py +++ b/afat/models.py @@ -440,10 +440,53 @@ class Field(models.TextChoices): Choices for Setting.Field """ + DEFAULT_FATLINK_EXPIRY_TIME = "default_fatlink_expiry_time", _( + "Default FAT link expiry time" + ) + DEFAULT_FATLINK_REOPEN_DURATION = "default_fatlink_reopen_duration", _( + "Default FAT link reopen duration" + ) + DEFAULT_FATLINK_REOPEN_GRACE_TIME = "default_fatlink_reopen_grace_time", _( + "Default FAT link reopen grace time" + ) + DEFAULT_LOG_DURATION = "default_log_duration", _("Default log duration") USE_DOCTRINES_FROM_FITTINGS_MODULE = "use_doctrines_from_fittings_module", _( - "Use Doctrines from Fittings module" + "Use doctrines from fittings module" ) + default_fatlink_expiry_time = models.PositiveIntegerField( + default=60, + help_text=_( + "Default expiry time for clickable FAT links in minutes. " + "(Default: 60 minutes)" + ), + verbose_name=Field.DEFAULT_FATLINK_EXPIRY_TIME.label, # pylint: disable=no-member + ) + + default_fatlink_reopen_grace_time = models.PositiveIntegerField( + default=60, + help_text=_( + "Default time in minutes a FAT link can be re-opened after it is expired. " + "(Default: 60 minutes)" + ), + verbose_name=Field.DEFAULT_FATLINK_REOPEN_GRACE_TIME.label, # pylint: disable=no-member + ) + + default_fatlink_reopen_duration = models.PositiveIntegerField( + default=60, + help_text=_( + "Default time in minutes a FAT link is re-opened for. " + "(Default: 60 minutes)" + ), + verbose_name=Field.DEFAULT_FATLINK_REOPEN_DURATION.label, # pylint: disable=no-member + ) + + default_log_duration = models.PositiveIntegerField( + default=60, + help_text=_("Default time in days a log entry is kept. (Default: 60 days)"), + verbose_name=Field.DEFAULT_LOG_DURATION.label, # pylint: disable=no-member + ) + use_doctrines_from_fittings_module = models.BooleanField( default=False, db_index=True, diff --git a/afat/tasks.py b/afat/tasks.py index 2c1f0b89..366c9b8d 100644 --- a/afat/tasks.py +++ b/afat/tasks.py @@ -23,8 +23,7 @@ # Alliance Auth AFAT from afat import __title__ -from afat.app_settings import AFAT_DEFAULT_LOG_DURATION -from afat.models import Fat, FatLink, Log +from afat.models import Fat, FatLink, Log, Setting from afat.providers import esi from afat.utils import get_or_create_character @@ -308,8 +307,11 @@ def logrotate(): :rtype: """ - logger.info(msg=f"Cleaning up logs older than {AFAT_DEFAULT_LOG_DURATION} days") + logger.info( + msg=f"Cleaning up logs older than {Setting.get_setting(Setting.Field.DEFAULT_LOG_DURATION)} days" + ) Log.objects.filter( - log_time__lte=timezone.now() - timedelta(days=AFAT_DEFAULT_LOG_DURATION) + log_time__lte=timezone.now() + - timedelta(days=Setting.get_setting(Setting.Field.DEFAULT_LOG_DURATION)) ).delete() diff --git a/afat/templates/afat/partials/fatlinks/details/fatlink-info.html b/afat/templates/afat/partials/fatlinks/details/fatlink-info.html index 23316ecf..e4e51eee 100644 --- a/afat/templates/afat/partials/fatlinks/details/fatlink-info.html +++ b/afat/templates/afat/partials/fatlinks/details/fatlink-info.html @@ -53,7 +53,7 @@
-