diff --git a/structures/admin.py b/structures/admin.py index ea173a7..2bf1b32 100644 --- a/structures/admin.py +++ b/structures/admin.py @@ -19,9 +19,9 @@ from allianceauth.services.hooks import get_extension_logger from app_utils.django import admin_boolean_icon_html -from . import app_settings, tasks -from .core.notification_types import NotificationType -from .models import ( +from structures import app_settings, tasks +from structures.core.notification_types import NotificationType +from structures.models import ( FuelAlert, FuelAlertConfig, GeneratedNotification, diff --git a/structures/app_settings.py b/structures/app_settings.py index 05d094c..7844374 100644 --- a/structures/app_settings.py +++ b/structures/app_settings.py @@ -3,10 +3,22 @@ from app_utils.app_settings import clean_setting STRUCTURES_ADD_TIMERS = clean_setting("STRUCTURES_ADD_TIMERS", True) -"""Whether to automatically add timers for certain notifications on the timerboard -(will have no effect if aa-timerboard app is not installed). - -Will create timers from anchoring, lost shield and lost armor notifications. +"""Whether to automatically add timers for supported notification types +to Alliance Auth's Structure Timers or Erik's Structure Timers +(apps have to be installed for this setting to work). + +Supported notification types are: + +- moon mining extraction canceled +- moon mining extraction started +- orbital reinforced +- skyhook lost shield +- sov structure reinforced +- structure lost armor +- structure lost shield +- tower reinforced + +Moon mining notifications can be disabled with `STRUCTURES_MOON_EXTRACTION_TIMERS_ENABLED`. """ STRUCTURES_ADMIN_NOTIFICATIONS_ENABLED = clean_setting( @@ -77,7 +89,10 @@ STRUCTURES_MOON_EXTRACTION_TIMERS_ENABLED = clean_setting( "STRUCTURES_MOON_EXTRACTION_TIMERS_ENABLED", True ) -"""Whether to create / remove timers from moon extraction notifications.""" +"""Whether to include moon mining extraction notifications when adding timers. + +Requires the "add timers" feature to be enabled with `STRUCTURES_ADD_TIMERS` +""" STRUCTURES_NOTIFICATION_MAX_RETRIES = clean_setting( "STRUCTURES_NOTIFICATION_MAX_RETRIES", 3 @@ -89,14 +104,14 @@ STRUCTURES_NOTIFICATION_SET_AVATAR = clean_setting( "STRUCTURES_NOTIFICATION_SET_AVATAR", True ) -"""Wether structures sets the name and avatar icon of a webhook. +"""Whether structures sets the name and avatar icon of a webhook. When ``False`` the webhook will use it's own values as set on the platform. """ STRUCTURES_NOTIFICATION_SHOW_MOON_ORE = clean_setting( "STRUCTURES_NOTIFICATION_SHOW_MOON_ORE", True ) -"""Wether ore details are shown on moon timers.""" +"""Whether ore details are shown on moon timers.""" STRUCTURES_NOTIFICATION_SYNC_GRACE_MINUTES = clean_setting( @@ -131,7 +146,9 @@ STRUCTURES_SHOW_FUEL_EXPIRES_RELATIVE = clean_setting( "STRUCTURES_SHOW_FUEL_EXPIRES_RELATIVE", True ) -"""Whether fuel expires in structures browser is shown as absolute value.""" +"""Whether fuel expiration in the structures browser is shown as a relative value +(e.g., time remaining) instead of an absolute date. +""" STRUCTURES_SHOW_JUMP_GATES = clean_setting("STRUCTURES_SHOW_JUMP_GATES", True) """Whether to show the jump gates tab.""" @@ -175,7 +192,7 @@ "STRUCTURES_NOTIFICATION_TURNAROUND_LONG", 50 ) -# Turnaround duration with more than x seconds are regarded as outliers +# Turnaround durations of more than x seconds are regarded as outliers # and will be ignored when calculating the averages STRUCTURES_NOTIFICATION_TURNAROUND_MAX_VALID = clean_setting( "STRUCTURES_NOTIFICATION_TURNAROUND_MAX_VALID", 3600 diff --git a/structures/apps.py b/structures/apps.py index 1f54b40..5b27057 100644 --- a/structures/apps.py +++ b/structures/apps.py @@ -1,6 +1,6 @@ from django.apps import AppConfig -from . import __version__ +from structures import __version__ class StructuresConfig(AppConfig): @@ -9,4 +9,4 @@ class StructuresConfig(AppConfig): verbose_name = f"Structures v{__version__}" def ready(self) -> None: - from . import checks # noqa: F401 pylint: disable=unused-import + from structures import checks # noqa: F401 pylint: disable=unused-import diff --git a/structures/auth_hooks.py b/structures/auth_hooks.py index 62d636d..c21393e 100644 --- a/structures/auth_hooks.py +++ b/structures/auth_hooks.py @@ -3,7 +3,7 @@ from allianceauth import hooks from allianceauth.services.hooks import MenuItemHook, UrlHook -from . import __title__, urls +from structures import __title__, urls class StructuresMenuItem(MenuItemHook): diff --git a/structures/core/notification_embeds/__init__.py b/structures/core/notification_embeds/__init__.py index 3f8af6c..fc1a77f 100644 --- a/structures/core/notification_embeds/__init__.py +++ b/structures/core/notification_embeds/__init__.py @@ -1,5 +1,5 @@ """Generating notification embeds for Structures.""" -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed __all__ = ["NotificationBaseEmbed"] diff --git a/structures/core/notification_embeds/billing_embeds.py b/structures/core/notification_embeds/billing_embeds.py index 2796407..7d38c5e 100644 --- a/structures/core/notification_embeds/billing_embeds.py +++ b/structures/core/notification_embeds/billing_embeds.py @@ -12,15 +12,14 @@ from app_utils.helpers import humanize_number from structures.constants import EveTypeId -from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_eve_entity_link, gen_solar_system_text, target_datetime_formatted, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type +from structures.models import Notification, Webhook class BillType(models.IntegerChoices): diff --git a/structures/core/notification_embeds/corporate_embeds.py b/structures/core/notification_embeds/corporate_embeds.py index 21dbc43..cf06da7 100644 --- a/structures/core/notification_embeds/corporate_embeds.py +++ b/structures/core/notification_embeds/corporate_embeds.py @@ -6,15 +6,14 @@ from django.utils.translation import gettext as _ -from structures.helpers import get_or_create_eve_entity -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_eve_entity_link, gen_eve_entity_link_from_id, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import get_or_create_eve_entity +from structures.models import Notification, Webhook class NotificationCorpCharEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/main.py b/structures/core/notification_embeds/main.py index f8bda90..480fe19 100644 --- a/structures/core/notification_embeds/main.py +++ b/structures/core/notification_embeds/main.py @@ -14,12 +14,15 @@ from app_utils.urls import reverse_absolute, static_file_absolute_url from structures import __title__ +from structures.core.notification_embeds.helpers import ( + gen_alliance_link, + gen_corporation_link, + target_datetime_formatted, +) from structures.core.notification_types import NotificationType from structures.helpers import get_or_create_eve_entity, is_absolute_url from structures.models.notifications import Notification, NotificationBase, Webhook -from .helpers import gen_alliance_link, gen_corporation_link, target_datetime_formatted - logger = get_extension_logger(__name__) @@ -183,13 +186,13 @@ def generate_embed(self) -> dhooks_lite.Embed: def create(notif: "NotificationBase") -> "NotificationBaseEmbed": """Creates a new instance of the respective subclass for given Notification.""" - from .billing_embeds import ( + from structures.core.notification_embeds.billing_embeds import ( NotificationBillingBillOutOfMoneyMsg, NotificationBillingIHubBillAboutToExpire, NotificationBillingIHubDestroyedByBillFailure, NotificationCorpAllBillMsg, ) - from .corporate_embeds import ( + from structures.core.notification_embeds.corporate_embeds import ( NotificationCharAppAcceptMsg, NotificationCharAppRejectMsg, NotificationCharAppWithdrawMsg, @@ -201,25 +204,25 @@ def create(notif: "NotificationBase") -> "NotificationBaseEmbed": NotificationCorpGoalCompleted, NotificationCorpGoalCreated, ) - from .moonmining_embeds import ( + from structures.core.notification_embeds.moonmining_embeds import ( NotificationMoonminningAutomaticFracture, NotificationMoonminningExtractionCanceled, NotificationMoonminningExtractionFinished, NotificationMoonminningExtractionStarted, NotificationMoonminningLaserFired, ) - from .orbital_embeds import ( + from structures.core.notification_embeds.orbital_embeds import ( NotificationOrbitalAttacked, NotificationOrbitalReinforced, ) - from .skyhook_embeds import ( + from structures.core.notification_embeds.skyhook_embeds import ( NotificationSkyhookDeployed, NotificationSkyhookDestroyed, NotificationSkyhookLostShield, NotificationSkyhookOnline, NotificationSkyhookUnderAttack, ) - from .sov_embeds import ( + from structures.core.notification_embeds.sov_embeds import ( NotificationSovAllAnchoringMsg, NotificationSovAllClaimAcquiredMsg, NotificationSovAllClaimLostMsg, @@ -228,7 +231,7 @@ def create(notif: "NotificationBase") -> "NotificationBaseEmbed": NotificationSovStructureDestroyed, NotificationSovStructureReinforced, ) - from .structures_embeds import ( + from structures.core.notification_embeds.structures_embeds import ( NotificationStructureAnchoring, NotificationStructureDestroyed, NotificationStructureFuelAlert, @@ -247,13 +250,13 @@ def create(notif: "NotificationBase") -> "NotificationBaseEmbed": NotificationStructureWentHighPower, NotificationStructureWentLowPower, ) - from .tower_embeds import ( + from structures.core.notification_embeds.tower_embeds import ( NotificationTowerAlertMsg, NotificationTowerRefueledExtra, NotificationTowerReinforcedExtra, NotificationTowerResourceAlertMsg, ) - from .war_embeds import ( + from structures.core.notification_embeds.war_embeds import ( NotificationAcceptedAlly, NotificationAllWarCorpJoinedAllianceMsg, NotificationAllWarSurrenderMsg, diff --git a/structures/core/notification_embeds/moonmining_embeds.py b/structures/core/notification_embeds/moonmining_embeds.py index 91c7cd4..b0a31f2 100644 --- a/structures/core/notification_embeds/moonmining_embeds.py +++ b/structures/core/notification_embeds/moonmining_embeds.py @@ -10,15 +10,14 @@ from app_utils.datetime import ldap_time_2_datetime from structures.app_settings import STRUCTURES_NOTIFICATION_SHOW_MOON_ORE -from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_solar_system_text, target_datetime_formatted, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type +from structures.models import Notification, Webhook class NotificationMoonminingEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/orbital_embeds.py b/structures/core/notification_embeds/orbital_embeds.py index 305c96c..c09ba6d 100644 --- a/structures/core/notification_embeds/orbital_embeds.py +++ b/structures/core/notification_embeds/orbital_embeds.py @@ -9,15 +9,14 @@ from app_utils.datetime import ldap_time_2_datetime from structures.constants import EveTypeId -from structures.helpers import get_or_create_eve_type -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_solar_system_text, target_datetime_formatted, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import get_or_create_eve_type +from structures.models import Notification, Webhook class NotificationOrbitalEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/skyhook_embeds.py b/structures/core/notification_embeds/skyhook_embeds.py index 6fbd42e..1785f29 100644 --- a/structures/core/notification_embeds/skyhook_embeds.py +++ b/structures/core/notification_embeds/skyhook_embeds.py @@ -8,14 +8,13 @@ from app_utils.datetime import ldap_time_2_datetime -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_solar_system_text, target_datetime_formatted, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.models import Notification, Webhook class NotificationSkyhookEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/sov_embeds.py b/structures/core/notification_embeds/sov_embeds.py index bea528e..0ec1643 100644 --- a/structures/core/notification_embeds/sov_embeds.py +++ b/structures/core/notification_embeds/sov_embeds.py @@ -11,21 +11,20 @@ from structures.constants import EveTypeId from structures.core import sovereignty -from structures.helpers import ( - get_or_create_esi_obj, - get_or_create_eve_entity, - get_or_create_eve_type, -) -from structures.models import Notification, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_alliance_link, gen_corporation_link, gen_eve_entity_link, gen_solar_system_text, target_datetime_formatted, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import ( + get_or_create_esi_obj, + get_or_create_eve_entity, + get_or_create_eve_type, +) +from structures.models import Notification, Webhook class NotificationSovEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/structures_embeds.py b/structures/core/notification_embeds/structures_embeds.py index 60cf978..df241cf 100644 --- a/structures/core/notification_embeds/structures_embeds.py +++ b/structures/core/notification_embeds/structures_embeds.py @@ -10,16 +10,15 @@ from app_utils.datetime import ldap_time_2_datetime, ldap_timedelta_2_timedelta -from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type -from structures.models import Notification, Structure, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_solar_system_text, target_datetime_formatted, timeuntil, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type +from structures.models import Notification, Structure, Webhook class NotificationStructureEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/tower_embeds.py b/structures/core/notification_embeds/tower_embeds.py index 4a94f98..a074d1d 100644 --- a/structures/core/notification_embeds/tower_embeds.py +++ b/structures/core/notification_embeds/tower_embeds.py @@ -9,15 +9,14 @@ from django.utils.translation import gettext as _ from structures.core import starbases -from structures.models import GeneratedNotification, Notification, Structure, Webhook - -from .helpers import ( +from structures.core.notification_embeds.helpers import ( gen_corporation_link, gen_solar_system_text, target_datetime_formatted, timeuntil, ) -from .main import NotificationBaseEmbed +from structures.core.notification_embeds.main import NotificationBaseEmbed +from structures.models import GeneratedNotification, Notification, Structure, Webhook class NotificationTowerEmbed(NotificationBaseEmbed): diff --git a/structures/core/notification_embeds/war_embeds.py b/structures/core/notification_embeds/war_embeds.py index f5e5da2..c2d778c 100644 --- a/structures/core/notification_embeds/war_embeds.py +++ b/structures/core/notification_embeds/war_embeds.py @@ -11,12 +11,14 @@ from app_utils.datetime import ldap_time_2_datetime from app_utils.helpers import humanize_number +from structures.core.notification_embeds.helpers import ( + gen_eve_entity_link, + target_datetime_formatted, +) +from structures.core.notification_embeds.main import NotificationBaseEmbed from structures.helpers import get_or_create_eve_entity from structures.models import Notification, Webhook -from .helpers import gen_eve_entity_link, target_datetime_formatted -from .main import NotificationBaseEmbed - class NotificationAcceptedAlly(NotificationBaseEmbed): def __init__(self, notification: Notification) -> None: diff --git a/structures/core/notification_timers.py b/structures/core/notification_timers.py index d498493..19d0b88 100644 --- a/structures/core/notification_timers.py +++ b/structures/core/notification_timers.py @@ -20,20 +20,19 @@ STRUCTURES_TIMERS_ARE_CORP_RESTRICTED, ) from structures.constants import EveTypeId +from structures.core import sovereignty, starbases +from structures.core.notification_types import NotificationType from structures.models import Notification, Structure -from . import sovereignty, starbases -from .notification_types import NotificationType - if "timerboard" in app_labels(): from allianceauth.timerboard.models import Timer as AuthTimer else: AuthTimer = None # pylint: disable = invalid-name if "structuretimers" in app_labels(): - from structuretimers.models import Timer + from structuretimers.models import Timer as StructureTimer else: - Timer = None # pylint: disable = invalid-name + StructureTimer = None # pylint: disable = invalid-name logger = get_extension_logger(__name__) @@ -102,21 +101,21 @@ def _gen_timer_structure_reinforcement(notif: Notification) -> bool: ) timer_processed = True - if Timer: + if StructureTimer: timer_map = { - NotificationType.STRUCTURE_LOST_SHIELD: Timer.Type.ARMOR, - NotificationType.STRUCTURE_LOST_ARMOR: Timer.Type.HULL, + NotificationType.STRUCTURE_LOST_SHIELD: StructureTimer.Type.ARMOR, + NotificationType.STRUCTURE_LOST_ARMOR: StructureTimer.Type.HULL, } visibility = ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) - Timer.objects.create( + StructureTimer.objects.create( eve_solar_system=structure_obj.eve_solar_system, structure_type=structure_obj.eve_type, timer_type=timer_map.get(notif.notif_type), - objective=Timer.Objective.FRIENDLY, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, eve_corporation=notif.owner.corporation, eve_alliance=notif.owner.corporation.alliance, @@ -156,20 +155,20 @@ def _gen_timer_sov_reinforcements(notif: Notification) -> bool: ) timer_processed = True - if Timer: + if StructureTimer: structure_type, _ = EveType.objects.get_or_create_esi( id=sovereignty.event_type_to_type_id(parsed_text["campaignEventType"]) ) visibility = ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) - Timer.objects.create( + StructureTimer.objects.create( eve_solar_system=solar_system, structure_type=structure_type, - timer_type=Timer.Type.FINAL, - objective=Timer.Objective.FRIENDLY, + timer_type=StructureTimer.Type.FINAL, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, eve_corporation=notif.owner.corporation, eve_alliance=notif.owner.corporation.alliance, @@ -204,20 +203,20 @@ def _gen_timer_customs_office_reinforcements(notif: Notification) -> bool: ) timer_processed = True - if Timer: + if StructureTimer: structure_type, _ = EveType.objects.get_or_create_esi( id=EveTypeId.CUSTOMS_OFFICE ) visibility = ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) - Timer.objects.create( + StructureTimer.objects.create( eve_solar_system=solar_system, structure_type=structure_type, - timer_type=Timer.Type.FINAL, - objective=Timer.Objective.FRIENDLY, + timer_type=StructureTimer.Type.FINAL, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, location_details=planet.name, eve_corporation=notif.owner.corporation, @@ -254,17 +253,17 @@ def _gen_timer_skyhook_reinforcements(notif: Notification) -> bool: ) timer_processed = True - if Timer: + if StructureTimer: visibility = ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) - Timer.objects.create( + StructureTimer.objects.create( eve_solar_system=solar_system, structure_type=structure_type, - timer_type=Timer.Type.FINAL, - objective=Timer.Objective.FRIENDLY, + timer_type=StructureTimer.Type.FINAL, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, location_details=planet.name, eve_corporation=notif.owner.corporation, @@ -306,12 +305,12 @@ def _gen_timer_moon_extraction(notif: Notification) -> bool: ) timer_processed = True - if Timer: - Timer.objects.create( + if StructureTimer: + StructureTimer.objects.create( eve_solar_system=solar_system, structure_type=structure_type, - timer_type=Timer.Type.MOONMINING, - objective=Timer.Objective.FRIENDLY, + timer_type=StructureTimer.Type.MOONMINING, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, location_details=moon.name, eve_corporation=notif.owner.corporation, @@ -353,14 +352,14 @@ def _gen_timer_moon_extraction(notif: Notification) -> bool: deleted_count, ) - if Timer: - timer_query = Timer.objects.filter( + if StructureTimer: + timer_query = StructureTimer.objects.filter( eve_solar_system=solar_system, structure_type=structure_type, - timer_type=Timer.Type.MOONMINING, + timer_type=StructureTimer.Type.MOONMINING, location_details=moon.name, date=eve_time_2, - objective=Timer.Objective.FRIENDLY, + objective=StructureTimer.Objective.FRIENDLY, eve_corporation=notif.owner.corporation, eve_alliance=notif.owner.corporation.alliance, visibility=_calc_visibility(), @@ -379,11 +378,11 @@ def _gen_timer_moon_extraction(notif: Notification) -> bool: def _calc_visibility(): - if Timer: + if StructureTimer: return ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) return None @@ -423,17 +422,17 @@ def _gen_timer_tower_reinforcements(notif: Notification) -> bool: ) timer_processed = True - if Timer: + if StructureTimer: visibility = ( - Timer.Visibility.CORPORATION + StructureTimer.Visibility.CORPORATION if STRUCTURES_TIMERS_ARE_CORP_RESTRICTED - else Timer.Visibility.UNRESTRICTED + else StructureTimer.Visibility.UNRESTRICTED ) - Timer.objects.create( + StructureTimer.objects.create( eve_solar_system=structure.eve_solar_system, structure_type=structure.eve_type, - timer_type=Timer.Type.FINAL, - objective=Timer.Objective.FRIENDLY, + timer_type=StructureTimer.Type.FINAL, + objective=StructureTimer.Objective.FRIENDLY, date=eve_time, location_details=structure.eve_moon.name, eve_corporation=notif.owner.corporation, diff --git a/structures/forms.py b/structures/forms.py index 7f3415c..b286770 100644 --- a/structures/forms.py +++ b/structures/forms.py @@ -2,7 +2,7 @@ from django import forms -from .models import StructureTag +from structures.models import StructureTag class TagsFilterForm(forms.Form): diff --git a/structures/managers.py b/structures/managers.py index 16484c9..c1c476f 100644 --- a/structures/managers.py +++ b/structures/managers.py @@ -19,14 +19,14 @@ from allianceauth.eveonline.models import EveCorporationInfo from allianceauth.services.hooks import get_extension_logger -from .app_settings import STRUCTURES_HOURS_UNTIL_STALE_NOTIFICATION -from .constants import EveCategoryId, EveTypeId -from .core.notification_types import NotificationType -from .providers import esi -from .webhooks.managers import WebhookBaseManager +from structures.app_settings import STRUCTURES_HOURS_UNTIL_STALE_NOTIFICATION +from structures.constants import EveCategoryId, EveTypeId +from structures.core.notification_types import NotificationType +from structures.providers import esi +from structures.webhooks.managers import WebhookBaseManager if TYPE_CHECKING: - from .models import Owner, Structure + from structures.models import Owner, Structure logger = get_extension_logger(__name__) @@ -302,8 +302,8 @@ def filter_tags(self, tag_names: Iterable[str]) -> models.QuerySet: return query def annotate_has_poco_details(self) -> models.QuerySet: - """Add annotation wether the structure has poco details.""" - from .models import PocoDetails + """Add annotation that reports whether the structure has poco details.""" + from structures.models import PocoDetails return self.annotate( has_poco_details=Exists( @@ -313,7 +313,7 @@ def annotate_has_poco_details(self) -> models.QuerySet: def annotate_has_starbase_detail(self) -> models.QuerySet: """Add annotation whether the structure has starbase details.""" - from .models import StarbaseDetail + from structures.models import StarbaseDetail return self.annotate( has_starbase_detail=Exists( @@ -323,7 +323,7 @@ def annotate_has_starbase_detail(self) -> models.QuerySet: def annotate_jump_fuel_quantity(self) -> models.QuerySet: """Add annotation with quantity of jump fuel.""" - from .models import StructureItem + from structures.models import StructureItem return self.annotate( jump_fuel_quantity_2=Sum( @@ -366,7 +366,7 @@ def update_or_create_esi(self, *, id: int, token: Token) -> Tuple[Any, bool]: Returns: object, created """ - from .models import Owner + from structures.models import Owner id = int(id) logger.info("Trying to fetch structure from ESI with ID %s", id) @@ -464,7 +464,7 @@ def _extract_position(self, structure): @staticmethod def _save_related_structure_services(structure, obj): - from .models import StructureService + from structures.models import StructureService StructureService.objects.filter(structure=obj).delete() if "services" in structure and structure["services"]: @@ -514,7 +514,7 @@ def update_or_create_for_space_type( ) def _obj_params_from_solar_system(self, solar_system): - from .models import EveSpaceType + from structures.models import EveSpaceType space_type = EveSpaceType.from_solar_system(solar_system) params = self.model.SPACE_TYPE_MAP.get(space_type) diff --git a/structures/models/__init__.py b/structures/models/__init__.py index 48b8fc6..66c04ac 100644 --- a/structures/models/__init__.py +++ b/structures/models/__init__.py @@ -1,5 +1,5 @@ -from .eveuniverse import EveSovereigntyMap, EveSpaceType -from .notifications import ( +from structures.models.eveuniverse import EveSovereigntyMap, EveSpaceType +from structures.models.notifications import ( FuelAlert, FuelAlertConfig, GeneratedNotification, @@ -9,9 +9,9 @@ Webhook, get_default_notification_types, ) -from .owners import Owner, OwnerCharacter -from .structures_1 import Structure, StructureItem, StructureTag -from .structures_2 import ( +from structures.models.owners import Owner, OwnerCharacter +from structures.models.structures_1 import Structure, StructureItem, StructureTag +from structures.models.structures_2 import ( PocoDetails, StarbaseDetail, StarbaseDetailFuel, diff --git a/structures/models/notifications.py b/structures/models/notifications.py index ec4bc0c..1626c16 100644 --- a/structures/models/notifications.py +++ b/structures/models/notifications.py @@ -39,10 +39,9 @@ NotificationManager, WebhookManager, ) +from structures.models.structures_1 import Structure from structures.webhooks.models import WebhookBase -from .structures_1 import Structure - logger = get_extension_logger(__name__) # Supported languages diff --git a/structures/models/owners.py b/structures/models/owners.py index b7e1ce4..f20ea45 100644 --- a/structures/models/owners.py +++ b/structures/models/owners.py @@ -45,18 +45,21 @@ ) from structures.constants import EveGroupId, EveTypeId from structures.managers import OwnerManager -from structures.providers import esi - -from .eveuniverse import EveSovereigntyMap -from .notifications import ( +from structures.models.eveuniverse import EveSovereigntyMap +from structures.models.notifications import ( EveEntity, GeneratedNotification, Notification, NotificationType, Webhook, ) -from .structures_1 import Structure, StructureItem -from .structures_2 import PocoDetails, StarbaseDetail, StarbaseDetailFuel +from structures.models.structures_1 import Structure, StructureItem +from structures.models.structures_2 import ( + PocoDetails, + StarbaseDetail, + StarbaseDetailFuel, +) +from structures.providers import esi logger = get_extension_logger(__name__) diff --git a/structures/models/structures_1.py b/structures/models/structures_1.py index c680552..35bee54 100644 --- a/structures/models/structures_1.py +++ b/structures/models/structures_1.py @@ -26,8 +26,7 @@ hours_until_deadline, ) from structures.managers import StructureManager, StructureTagManager - -from .eveuniverse import EveSpaceType +from structures.models.eveuniverse import EveSpaceType logger = get_extension_logger(__name__) @@ -719,7 +718,7 @@ def handle_fuel_notifications(self, old_instance: "Structure"): def _send_refueled_notification(self): """Send a refueled notifications for this structure.""" - from .notifications import Notification, NotificationType + from structures.models.notifications import Notification, NotificationType notif_type = ( NotificationType.TOWER_REFUELED_EXTRA diff --git a/structures/models/structures_2.py b/structures/models/structures_2.py index 7f95f9f..367cf11 100644 --- a/structures/models/structures_2.py +++ b/structures/models/structures_2.py @@ -12,8 +12,7 @@ from structures.constants import EveGroupId from structures.core import starbases - -from .structures_1 import Structure +from structures.models.structures_1 import Structure logger = get_extension_logger(__name__) diff --git a/structures/providers.py b/structures/providers.py index fb3df8e..9372055 100644 --- a/structures/providers.py +++ b/structures/providers.py @@ -4,7 +4,7 @@ from esi.openapi_clients import ESIClientProvider -from . import __version__ +from structures import __version__ spec_file = Path(__file__).parent / "openapi_2025-12-16.json" esi = ESIClientProvider( diff --git a/structures/tasks.py b/structures/tasks.py index 8127715..c63ef5b 100644 --- a/structures/tasks.py +++ b/structures/tasks.py @@ -12,10 +12,10 @@ from allianceauth.services.hooks import get_extension_logger from allianceauth.services.tasks import QueueOnce -from . import __title__ -from .app_settings import STRUCTURES_TASKS_TIME_LIMIT -from .core.notification_types import NotificationType -from .models import ( +from structures import __title__ +from structures.app_settings import STRUCTURES_TASKS_TIME_LIMIT +from structures.core.notification_types import NotificationType +from structures.models import ( EveSovereigntyMap, FuelAlertConfig, JumpFuelAlertConfig, diff --git a/structures/tests/__init__.py b/structures/tests/__init__.py index e06b6cf..e69de29 100644 --- a/structures/tests/__init__.py +++ b/structures/tests/__init__.py @@ -1,5 +0,0 @@ -import json - - -def to_json(obj): - return json.dumps(obj, sort_keys=True) diff --git a/structures/tests/helpers.py b/structures/tests/helpers.py index 684737c..445c057 100644 --- a/structures/tests/helpers.py +++ b/structures/tests/helpers.py @@ -7,6 +7,13 @@ from django.core.cache import cache from django.test import TestCase +from app_utils.testing import json_response_to_python + + +def json_response_to_dict(response, key="id") -> dict: + """Convert JSON response into dict by given key.""" + return {obj[key]: obj for obj in json_response_to_python(response)["data"]} + def datetime_to_ldap(my_dt: dt.datetime) -> int: """Return a standard datetime as ldap datetime.""" diff --git a/structures/tests/test_admin.py b/structures/tests/test_admin.py index c2bcd4d..562f0e6 100644 --- a/structures/tests/test_admin.py +++ b/structures/tests/test_admin.py @@ -27,8 +27,7 @@ StructureTag, Webhook, ) - -from .testdata.factories import ( +from structures.tests.testdata.factories import ( CustomsOfficeFactory, EveAllianceInfoFactory, EveCorporationInfoFactory, diff --git a/structures/tests/test_managers_2.py b/structures/tests/test_managers_2.py index 1febd0e..98bf4a8 100644 --- a/structures/tests/test_managers_2.py +++ b/structures/tests/test_managers_2.py @@ -7,8 +7,7 @@ from structures.core.notification_types import NotificationType from structures.models import GeneratedNotification, Notification, Owner - -from .testdata.factories import ( +from structures.tests.testdata.factories import ( GeneratedNotificationFactory, NotificationFactory, OwnerCharacterFactory, diff --git a/structures/tests/test_tasks.py b/structures/tests/test_tasks.py index b63763b..49b44f1 100644 --- a/structures/tests/test_tasks.py +++ b/structures/tests/test_tasks.py @@ -13,8 +13,7 @@ from structures import tasks from structures.core.notification_types import NotificationType from structures.models import Owner, Webhook - -from .testdata.factories import ( +from structures.tests.testdata.factories import ( FuelAlertConfigFactory, JumpFuelAlertConfigFactory, NotificationFactory, diff --git a/structures/tests/testdata/factories.py b/structures/tests/testdata/factories.py index 316d7e7..137f8e0 100644 --- a/structures/tests/testdata/factories.py +++ b/structures/tests/testdata/factories.py @@ -46,7 +46,7 @@ Webhook, ) -# from .helpers import datetime_to_ldap # TODO: Use for notifications +# from structures.tests.helpers import datetime_to_ldap # TODO: Use for notifications T = TypeVar("T") diff --git a/structures/tests/testdata/helpers.py b/structures/tests/testdata/helpers.py index a0999eb..27990a2 100644 --- a/structures/tests/testdata/helpers.py +++ b/structures/tests/testdata/helpers.py @@ -23,6 +23,7 @@ EveSolarSystemNullSecFactory, IHUBTypeFactory, MoonOreTypeFactory, + NotificationFactory, RefineryFactory, SkyhookFactory, StarbaseFactory, @@ -30,8 +31,6 @@ TCUTypeFactory, ) -from .factories import NotificationFactory - _current_folder = Path(__file__).parent _FILENAME_EVEUNIVERSE_TESTDATA = "eveuniverse.json" diff --git a/structures/tests/views/test_public.py b/structures/tests/views/test_public.py index 3f70ea8..efd79f7 100644 --- a/structures/tests/views/test_public.py +++ b/structures/tests/views/test_public.py @@ -2,6 +2,7 @@ from app_utils.testing import NoSocketsTestCase +from structures.tests.helpers import json_response_to_dict from structures.tests.testdata.factories import ( CustomsOfficeFactory, OwnerFactory, @@ -9,8 +10,6 @@ ) from structures.views import public -from .utils import json_response_to_dict - class TestPocoListDataView(NoSocketsTestCase): @classmethod diff --git a/structures/tests/views/test_statistics.py b/structures/tests/views/test_statistics.py index 68381a0..9467875 100644 --- a/structures/tests/views/test_statistics.py +++ b/structures/tests/views/test_statistics.py @@ -1,5 +1,6 @@ from django.test import RequestFactory, TestCase +from structures.tests.helpers import json_response_to_dict from structures.tests.testdata.factories import ( CustomsOfficeFactory, EveAllianceInfoFactory, @@ -14,8 +15,6 @@ ) from structures.views import statistics -from .utils import json_response_to_dict - class TestStatistics(TestCase): @classmethod diff --git a/structures/tests/views/test_structures.py b/structures/tests/views/test_structures.py index d78dc59..4fd13da 100644 --- a/structures/tests/views/test_structures.py +++ b/structures/tests/views/test_structures.py @@ -12,8 +12,8 @@ from app_utils.testdata_factories import UserMainFactory from app_utils.testing import json_response_to_python -import structures.views.status from structures.models import Owner, Structure +from structures.tests.helpers import json_response_to_dict from structures.tests.testdata.factories import ( CustomsOfficeFactory, EveCharacterFactory, @@ -29,8 +29,6 @@ ) from structures.views import structures -from .utils import json_response_to_dict - VIEWS_PATH = "structures.views.structures" OWNERS_PATH = "structures.models.owners" diff --git a/structures/tests/views/utils.py b/structures/tests/views/utils.py deleted file mode 100644 index e25c75d..0000000 --- a/structures/tests/views/utils.py +++ /dev/null @@ -1,6 +0,0 @@ -from app_utils.testing import json_response_to_python - - -def json_response_to_dict(response, key="id") -> dict: - """Convert JSON response into dict by given key.""" - return {obj[key]: obj for obj in json_response_to_python(response)["data"]} diff --git a/structures/urls.py b/structures/urls.py index c10e032..8bb004f 100644 --- a/structures/urls.py +++ b/structures/urls.py @@ -3,7 +3,7 @@ from django.urls import path from django.views.decorators.cache import never_cache -from .views import public, statistics, status, structures +from structures.views import public, statistics, status, structures app_name = "structures" diff --git a/structures/views/public.py b/structures/views/public.py index 546383c..5759811 100644 --- a/structures/views/public.py +++ b/structures/views/public.py @@ -12,8 +12,7 @@ from structures.constants import EveCategoryId from structures.core.serializers import PocoListSerializer from structures.models import Structure - -from .common import add_common_context, add_common_data_export +from structures.views.common import add_common_context, add_common_data_export logger = get_extension_logger(__name__) diff --git a/structures/views/statistics.py b/structures/views/statistics.py index be22770..00d2726 100644 --- a/structures/views/statistics.py +++ b/structures/views/statistics.py @@ -14,8 +14,7 @@ from structures.constants import EveCategoryId, EveGroupId, EveTypeId from structures.helpers import floating_icon_with_text_html from structures.models import Structure - -from .common import add_common_context, add_common_data_export +from structures.views.common import add_common_context, add_common_data_export logger = get_extension_logger(__name__) diff --git a/structures/views/structures.py b/structures/views/structures.py index 36e4bce..5b6df18 100644 --- a/structures/views/structures.py +++ b/structures/views/structures.py @@ -44,8 +44,7 @@ StructureTag, Webhook, ) - -from .common import add_common_context, add_common_data_export +from structures.views.common import add_common_context, add_common_data_export logger = get_extension_logger(__name__) diff --git a/structures/webhooks/models.py b/structures/webhooks/models.py index ee1e371..50b8b79 100644 --- a/structures/webhooks/models.py +++ b/structures/webhooks/models.py @@ -3,8 +3,8 @@ from django.db import models from django.utils.translation import gettext_lazy as _ -from .core import DiscordWebhookMixin -from .managers import WebhookBaseManager +from structures.webhooks.core import DiscordWebhookMixin +from structures.webhooks.managers import WebhookBaseManager # TODO: Investigate if this can be changed to a dependency injection to use fakes