aa-structures 2.8.0__py3-none-any.whl → 2.9.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. {aa_structures-2.8.0.dist-info → aa_structures-2.9.1.dist-info}/METADATA +2 -2
  2. {aa_structures-2.8.0.dist-info → aa_structures-2.9.1.dist-info}/RECORD +62 -61
  3. structures/__init__.py +1 -1
  4. structures/admin.py +3 -3
  5. structures/app_settings.py +88 -69
  6. structures/core/notification_embeds/billing_embeds.py +40 -7
  7. structures/core/notification_embeds/{character_embeds.py → corporate_embeds.py} +23 -13
  8. structures/core/notification_embeds/main.py +76 -38
  9. structures/core/notification_embeds/moonmining_embeds.py +12 -17
  10. structures/core/notification_embeds/orbital_embeds.py +3 -8
  11. structures/core/notification_embeds/sov_embeds.py +21 -19
  12. structures/core/notification_embeds/structures_embeds.py +19 -26
  13. structures/core/notification_embeds/tower_embeds.py +2 -2
  14. structures/core/notification_embeds/war_embeds.py +298 -92
  15. structures/core/notification_types.py +63 -44
  16. structures/forms.py +0 -1
  17. structures/helpers.py +13 -0
  18. structures/locale/de/LC_MESSAGES/django.po +488 -302
  19. structures/locale/django.pot +494 -308
  20. structures/locale/en/LC_MESSAGES/django.po +494 -308
  21. structures/locale/es/LC_MESSAGES/django.po +488 -302
  22. structures/locale/fr_FR/LC_MESSAGES/django.po +494 -308
  23. structures/locale/it_IT/LC_MESSAGES/django.po +494 -308
  24. structures/locale/ja/LC_MESSAGES/django.po +494 -308
  25. structures/locale/ko_KR/LC_MESSAGES/django.po +488 -302
  26. structures/locale/ru/LC_MESSAGES/django.mo +0 -0
  27. structures/locale/ru/LC_MESSAGES/django.po +532 -349
  28. structures/locale/uk/LC_MESSAGES/django.po +488 -302
  29. structures/locale/zh_Hans/LC_MESSAGES/django.po +488 -302
  30. structures/migrations/0005_add_notification_types.py +135 -0
  31. structures/models/eveuniverse.py +0 -1
  32. structures/models/notifications.py +1 -1
  33. structures/models/owners.py +3 -1
  34. structures/tests/core/notification_embeds/test_main.py +29 -27
  35. structures/tests/core/test_notification_structuretimers.py +2 -1
  36. structures/tests/core/test_notifications_timerboard.py +2 -1
  37. structures/tests/core/test_serializers.py +4 -2
  38. structures/tests/core/test_starbases.py +4 -2
  39. structures/tests/integration/test_tasks.py +2 -1
  40. structures/tests/integration/test_views.py +6 -3
  41. structures/tests/models/test_eveuniverse.py +2 -1
  42. structures/tests/models/test_notifications_1.py +16 -21
  43. structures/tests/models/test_notifications_2.py +4 -2
  44. structures/tests/models/test_notifications_3.py +6 -3
  45. structures/tests/models/test_notifications_discord.py +2 -1
  46. structures/tests/models/test_owners_1.py +28 -4
  47. structures/tests/models/test_owners_2.py +2 -1
  48. structures/tests/models/test_owners_3.py +2 -1
  49. structures/tests/models/test_owners_4.py +2 -1
  50. structures/tests/models/test_owners_5.py +8 -4
  51. structures/tests/models/test_structures.py +16 -8
  52. structures/tests/test_helpers.py +23 -3
  53. structures/tests/test_managers_1.py +16 -8
  54. structures/tests/test_managers_2.py +2 -1
  55. structures/tests/test_tasks.py +12 -6
  56. structures/tests/testdata/entities.json +150 -0
  57. structures/tests/testdata/helpers.py +1 -0
  58. structures/tests/views/test_public.py +2 -1
  59. structures/tests/views/test_statistics.py +2 -1
  60. structures/tests/views/test_structures.py +20 -10
  61. {aa_structures-2.8.0.dist-info → aa_structures-2.9.1.dist-info}/LICENSE +0 -0
  62. {aa_structures-2.8.0.dist-info → aa_structures-2.9.1.dist-info}/WHEEL +0 -0
@@ -2,19 +2,19 @@
2
2
 
3
3
  # pylint: disable=missing-class-docstring
4
4
 
5
+ import re
5
6
  from typing import Optional
6
7
 
7
8
  import dhooks_lite
8
9
 
9
10
  from django.conf import settings
10
11
  from django.utils.translation import gettext as _
11
- from eveuniverse.models import EveEntity
12
12
 
13
13
  from app_utils.urls import reverse_absolute, static_file_absolute_url
14
14
 
15
15
  from structures import __title__
16
16
  from structures.core.notification_types import NotificationType
17
- from structures.helpers import get_or_create_esi_obj, is_absolute_url
17
+ from structures.helpers import get_or_create_eve_entity, is_absolute_url
18
18
  from structures.models.notifications import Notification, NotificationBase, Webhook
19
19
 
20
20
  from .helpers import target_datetime_formatted
@@ -33,7 +33,7 @@ class NotificationBaseEmbed:
33
33
  if not isinstance(notification, NotificationBase):
34
34
  raise TypeError("notification must be of type Notification")
35
35
  self._notification = notification
36
- self._parsed_text = notification.parsed_text()
36
+ self._data = notification.parsed_text()
37
37
  self._title = ""
38
38
  self._description = ""
39
39
  self._color = None
@@ -66,24 +66,24 @@ class NotificationBaseEmbed:
66
66
  damage_parts = []
67
67
  for prop in damage_labels:
68
68
  field_name = f"{prop[0]}{field_postfix}"
69
- if field_name in self._parsed_text:
69
+ if field_name in self._data:
70
70
  label = prop[1]
71
- value = self._parsed_text[field_name] * factor
71
+ value = self._data[field_name] * factor
72
72
  damage_parts.append(f"{label}: {value:.1f}%")
73
73
  damage_text = " | ".join(damage_parts)
74
74
  return damage_text
75
75
 
76
76
  def get_aggressor_link(self) -> str:
77
77
  """Returns the aggressor link from a parsed_text for POS and POCOs only."""
78
- if self._parsed_text.get("aggressorAllianceID"):
78
+ if self._data.get("aggressorAllianceID"):
79
79
  key = "aggressorAllianceID"
80
- elif self._parsed_text.get("aggressorCorpID"):
80
+ elif self._data.get("aggressorCorpID"):
81
81
  key = "aggressorCorpID"
82
- elif self._parsed_text.get("aggressorID"):
82
+ elif self._data.get("aggressorID"):
83
83
  key = "aggressorID"
84
84
  else:
85
85
  return "(Unknown aggressor)"
86
- entity = get_or_create_esi_obj(EveEntity, id=self._parsed_text[key])
86
+ entity = get_or_create_eve_entity(id=self._data[key])
87
87
  return Webhook.create_link(entity.name, entity.profile_url)
88
88
 
89
89
  def fuel_expires_target_date(self) -> str:
@@ -153,16 +153,18 @@ class NotificationBaseEmbed:
153
153
 
154
154
  # pylint: disable = too-many-locals
155
155
  @staticmethod
156
- def create(notification: "NotificationBase") -> "NotificationBaseEmbed":
156
+ def create(notif: "NotificationBase") -> "NotificationBaseEmbed":
157
157
  """Creates a new instance of the respective subclass for given Notification."""
158
158
 
159
159
  from .billing_embeds import (
160
160
  NotificationBillingBillOutOfMoneyMsg,
161
161
  NotificationBillingIHubBillAboutToExpire,
162
162
  NotificationBillingIHubDestroyedByBillFailure,
163
+ NotificationCorpAllBillMsg,
163
164
  )
164
- from .character_embeds import (
165
+ from .corporate_embeds import (
165
166
  NotificationCharAppAcceptMsg,
167
+ NotificationCharAppRejectMsg,
166
168
  NotificationCharAppWithdrawMsg,
167
169
  NotificationCharLeftCorpMsg,
168
170
  NotificationCorpAppInvitedMsg,
@@ -213,26 +215,42 @@ class NotificationBaseEmbed:
213
215
  NotificationTowerResourceAlertMsg,
214
216
  )
215
217
  from .war_embeds import (
218
+ NotificationAcceptedAlly,
219
+ NotificationAllWarCorpJoinedAllianceMsg,
220
+ NotificationAllWarSurrenderMsg,
216
221
  NotificationAllyJoinedWarMsg,
217
222
  NotificationCorpWarSurrenderMsg,
223
+ NotificationDeclareWar,
224
+ NotificationMercOfferedNegotiationMsg,
225
+ NotificationMercOfferRetractedMsg,
226
+ NotificationOfferedSurrender,
227
+ NotificationOfferedToAlly,
218
228
  NotificationWarAdopted,
219
229
  NotificationWarCorporationBecameEligible,
220
230
  NotificationWarCorporationNoLongerEligible,
221
231
  NotificationWarDeclared,
232
+ NotificationWarHQRemovedFromSpace,
222
233
  NotificationWarInherited,
234
+ NotificationWarInvalid,
223
235
  NotificationWarRetractedByConcord,
224
236
  NotificationWarSurrenderOfferMsg,
225
237
  )
226
238
 
227
- if not isinstance(notification, NotificationBase):
239
+ if not isinstance(notif, NotificationBase):
228
240
  raise TypeError("notification must be of type NotificationBase")
229
241
 
230
242
  NT = NotificationType
231
243
  notif_type_2_class = {
244
+ # Billing
245
+ NT.BILLING_CORP_ALL_BILL_MSG: NotificationCorpAllBillMsg,
246
+ NT.BILLING_BILL_OUT_OF_MONEY_MSG: NotificationBillingBillOutOfMoneyMsg,
247
+ NT.BILLING_I_HUB_BILL_ABOUT_TO_EXPIRE: NotificationBillingIHubBillAboutToExpire,
248
+ NT.BILLING_I_HUB_DESTROYED_BY_BILL_FAILURE: NotificationBillingIHubDestroyedByBillFailure,
232
249
  # character
233
250
  NT.CORP_APP_NEW_MSG: NotificationCorpAppNewMsg,
234
251
  NT.CORP_APP_INVITED_MSG: NotificationCorpAppInvitedMsg,
235
252
  NT.CORP_APP_REJECT_CUSTOM_MSG: NotificationCorpAppRejectCustomMsg,
253
+ NT.CORP_APP_REJECT_MSG: NotificationCharAppRejectMsg,
236
254
  NT.CHAR_APP_WITHDRAW_MSG: NotificationCharAppWithdrawMsg,
237
255
  NT.CHAR_APP_ACCEPT_MSG: NotificationCharAppAcceptMsg,
238
256
  NT.CHAR_LEFT_CORP_MSG: NotificationCharLeftCorpMsg,
@@ -242,7 +260,23 @@ class NotificationBaseEmbed:
242
260
  NT.MOONMINING_AUTOMATIC_FRACTURE: NotificationMoonminningAutomaticFracture,
243
261
  NT.MOONMINING_EXTRACTION_CANCELLED: NotificationMoonminningExtractionCanceled,
244
262
  NT.MOONMINING_LASER_FIRED: NotificationMoonminningLaserFired,
245
- # upwell structures
263
+ # Orbitals
264
+ NT.ORBITAL_ATTACKED: NotificationOrbitalAttacked,
265
+ NT.ORBITAL_REINFORCED: NotificationOrbitalReinforced,
266
+ # Sov
267
+ NT.SOV_ENTOSIS_CAPTURE_STARTED: NotificationSovEntosisCaptureStarted,
268
+ NT.SOV_COMMAND_NODE_EVENT_STARTED: NotificationSovCommandNodeEventStarted,
269
+ NT.SOV_ALL_CLAIM_ACQUIRED_MSG: NotificationSovAllClaimAcquiredMsg,
270
+ NT.SOV_ALL_CLAIM_LOST_MSG: NotificationSovAllClaimLostMsg,
271
+ NT.SOV_STRUCTURE_REINFORCED: NotificationSovStructureReinforced,
272
+ NT.SOV_STRUCTURE_DESTROYED: NotificationSovStructureDestroyed,
273
+ NT.SOV_ALL_ANCHORING_MSG: NotificationSovAllAnchoringMsg,
274
+ # Towers
275
+ NT.TOWER_ALERT_MSG: NotificationTowerAlertMsg,
276
+ NT.TOWER_RESOURCE_ALERT_MSG: NotificationTowerResourceAlertMsg,
277
+ NT.TOWER_REFUELED_EXTRA: NotificationTowerRefueledExtra,
278
+ NT.TOWER_REINFORCED_EXTRA: NotificationTowerReinforcedExtra,
279
+ # Upwell structures
246
280
  NT.STRUCTURE_ONLINE: NotificationStructureOnline,
247
281
  NT.STRUCTURE_FUEL_ALERT: NotificationStructureFuelAlert,
248
282
  NT.STRUCTURE_JUMP_FUEL_ALERT: NotificationStructureJumpFuelAlert,
@@ -258,42 +292,46 @@ class NotificationBaseEmbed:
258
292
  NT.OWNERSHIP_TRANSFERRED: NotificationStructureOwnershipTransferred,
259
293
  NT.STRUCTURE_ANCHORING: NotificationStructureAnchoring,
260
294
  NT.STRUCTURE_REINFORCEMENT_CHANGED: NotificationStructureReinforceChange,
261
- # Orbitals
262
- NT.ORBITAL_ATTACKED: NotificationOrbitalAttacked,
263
- NT.ORBITAL_REINFORCED: NotificationOrbitalReinforced,
264
- # Towers
265
- NT.TOWER_ALERT_MSG: NotificationTowerAlertMsg,
266
- NT.TOWER_RESOURCE_ALERT_MSG: NotificationTowerResourceAlertMsg,
267
- NT.TOWER_REFUELED_EXTRA: NotificationTowerRefueledExtra,
268
- NT.TOWER_REINFORCED_EXTRA: NotificationTowerReinforcedExtra,
269
- # Sov
270
- NT.SOV_ENTOSIS_CAPTURE_STARTED: NotificationSovEntosisCaptureStarted,
271
- NT.SOV_COMMAND_NODE_EVENT_STARTED: NotificationSovCommandNodeEventStarted,
272
- NT.SOV_ALL_CLAIM_ACQUIRED_MSG: NotificationSovAllClaimAcquiredMsg,
273
- NT.SOV_ALL_CLAIM_LOST_MSG: NotificationSovAllClaimLostMsg,
274
- NT.SOV_STRUCTURE_REINFORCED: NotificationSovStructureReinforced,
275
- NT.SOV_STRUCTURE_DESTROYED: NotificationSovStructureDestroyed,
276
- NT.SOV_ALL_ANCHORING_MSG: NotificationSovAllAnchoringMsg,
277
295
  # War
296
+ NT.WAR_ACCEPTED_ALLY: NotificationAcceptedAlly,
278
297
  NT.WAR_ALLY_JOINED_WAR_AGGRESSOR_MSG: NotificationAllyJoinedWarMsg,
279
298
  NT.WAR_ALLY_JOINED_WAR_ALLY_MSG: NotificationAllyJoinedWarMsg,
280
299
  NT.WAR_ALLY_JOINED_WAR_DEFENDER_MSG: NotificationAllyJoinedWarMsg,
300
+ NT.WAR_ALL_WAR_CORP_JOINED_ALLIANCE_MSG: NotificationAllWarCorpJoinedAllianceMsg,
301
+ NT.WAR_ALL_WAR_SURRENDER_MSG: NotificationAllWarSurrenderMsg,
302
+ NT.WAR_CORPORATION_BECAME_ELIGIBLE: NotificationWarCorporationBecameEligible,
303
+ NT.WAR_CORPORATION_NO_LONGER_ELIGIBLE: NotificationWarCorporationNoLongerEligible,
304
+ NT.WAR_DECLARE_WAR: NotificationDeclareWar,
305
+ NT.WAR_MERC_OFFERED_NEGOTIATION_MSG: NotificationMercOfferedNegotiationMsg,
306
+ NT.WAR_MERC_OFFER_RETRACTED_MSG: NotificationMercOfferRetractedMsg,
281
307
  NT.WAR_CORP_WAR_SURRENDER_MSG: NotificationCorpWarSurrenderMsg,
308
+ NT.WAR_HQ_REMOVED_FROM_SPACE: NotificationWarHQRemovedFromSpace,
309
+ NT.WAR_OFFERED_TO_ALLY: NotificationOfferedToAlly,
310
+ NT.WAR_OFFERED_SURRENDER: NotificationOfferedSurrender,
282
311
  NT.WAR_WAR_ADOPTED: NotificationWarAdopted,
283
312
  NT.WAR_WAR_DECLARED: NotificationWarDeclared,
284
313
  NT.WAR_WAR_INHERITED: NotificationWarInherited,
314
+ NT.WAR_INVALID: NotificationWarInvalid,
285
315
  NT.WAR_WAR_RETRACTED_BY_CONCORD: NotificationWarRetractedByConcord,
286
- NT.WAR_CORPORATION_BECAME_ELIGIBLE: NotificationWarCorporationBecameEligible,
287
- NT.WAR_CORPORATION_NO_LONGER_ELIGIBLE: NotificationWarCorporationNoLongerEligible,
288
316
  NT.WAR_WAR_SURRENDER_OFFER_MSG: NotificationWarSurrenderOfferMsg,
289
- # Billing
290
- NT.BILLING_BILL_OUT_OF_MONEY_MSG: NotificationBillingBillOutOfMoneyMsg,
291
- NT.BILLING_I_HUB_BILL_ABOUT_TO_EXPIRE: NotificationBillingIHubBillAboutToExpire,
292
- NT.BILLING_I_HUB_DESTROYED_BY_BILL_FAILURE: NotificationBillingIHubDestroyedByBillFailure,
293
317
  }
294
318
  try:
295
- notif_class = notif_type_2_class[notification.notif_type]
319
+ notif_class = notif_type_2_class[notif.notif_type]
296
320
  except KeyError:
297
- raise NotImplementedError(repr(notification.notif_type)) from None
321
+ return NotificationGenericEmbed(notif)
322
+
323
+ return notif_class(notif)
324
+
298
325
 
299
- return notif_class(notification)
326
+ class NotificationGenericEmbed(NotificationBaseEmbed):
327
+ """A generic embed for undefined notifs."""
328
+
329
+ def __init__(self, notif: Notification) -> None:
330
+ super().__init__(notif)
331
+ self._title = re.sub(
332
+ r"((?<=[a-z])[A-Z]|(?<!\A)[A-Z](?=[a-z]))", r" \1", notif.notif_type
333
+ )
334
+ self._color = Webhook.Color.INFO
335
+ self._thumbnail = dhooks_lite.Thumbnail(
336
+ notif.sender.icon_url(size=self.ICON_DEFAULT_SIZE)
337
+ )
@@ -6,12 +6,11 @@
6
6
  import dhooks_lite
7
7
 
8
8
  from django.utils.translation import gettext as _
9
- from eveuniverse.models import EveEntity, EveType
10
9
 
11
10
  from app_utils.datetime import ldap_time_2_datetime
12
11
 
13
12
  from structures.app_settings import STRUCTURES_NOTIFICATION_SHOW_MOON_ORE
14
- from structures.helpers import get_or_create_esi_obj
13
+ from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type
15
14
  from structures.models import Notification, Webhook
16
15
 
17
16
  from .helpers import (
@@ -31,7 +30,7 @@ class NotificationMoonminingEmbed(NotificationBaseEmbed):
31
30
  self._solar_system_link = gen_solar_system_text(
32
31
  self._notification.eve_solar_system()
33
32
  )
34
- self._structure_name = self._parsed_text["structureName"]
33
+ self._structure_name = self._data["structureName"]
35
34
  self._owner_link = gen_corporation_link(str(notification.owner))
36
35
  structure_type = self._notification.eve_structure_type()
37
36
  self._thumbnail = dhooks_lite.Thumbnail(
@@ -44,12 +43,12 @@ class NotificationMoonminingEmbed(NotificationBaseEmbed):
44
43
  )
45
44
 
46
45
  def _ore_composition_text(self) -> str:
47
- if "oreVolumeByType" not in self._parsed_text:
46
+ if "oreVolumeByType" not in self._data:
48
47
  return ""
49
48
 
50
49
  ore_list = []
51
- for ore_type_id, volume in self._parsed_text["oreVolumeByType"].items():
52
- ore_type = get_or_create_esi_obj(EveType, id=ore_type_id)
50
+ for ore_type_id, volume in self._data["oreVolumeByType"].items():
51
+ ore_type = get_or_create_eve_type(id=ore_type_id)
53
52
  if ore_type:
54
53
  ore_list.append(
55
54
  {"id": ore_type_id, "name": ore_type.name, "volume": volume}
@@ -64,9 +63,9 @@ class NotificationMoonminingEmbed(NotificationBaseEmbed):
64
63
  class NotificationMoonminningExtractionStarted(NotificationMoonminingEmbed):
65
64
  def __init__(self, notification: Notification) -> None:
66
65
  super().__init__(notification)
67
- started_by = get_or_create_esi_obj(EveEntity, id=self._parsed_text["startedBy"])
68
- ready_time = ldap_time_2_datetime(self._parsed_text["readyTime"])
69
- auto_time = ldap_time_2_datetime(self._parsed_text["autoTime"])
66
+ started_by = get_or_create_eve_entity(id=self._data["startedBy"])
67
+ ready_time = ldap_time_2_datetime(self._data["readyTime"])
68
+ auto_time = ldap_time_2_datetime(self._data["autoTime"])
70
69
  self._title = _("Moon mining extraction started")
71
70
  self._description = _(
72
71
  "A moon mining extraction has been started "
@@ -92,7 +91,7 @@ class NotificationMoonminningExtractionStarted(NotificationMoonminingEmbed):
92
91
  class NotificationMoonminningExtractionFinished(NotificationMoonminingEmbed):
93
92
  def __init__(self, notification: Notification) -> None:
94
93
  super().__init__(notification)
95
- auto_time = ldap_time_2_datetime(self._parsed_text["autoTime"])
94
+ auto_time = ldap_time_2_datetime(self._data["autoTime"])
96
95
  self._title = _("Extraction finished")
97
96
  self._description = _(
98
97
  "The extraction for %(structure_name)s at %(moon)s "
@@ -135,10 +134,8 @@ class NotificationMoonminningAutomaticFracture(NotificationMoonminingEmbed):
135
134
  class NotificationMoonminningExtractionCanceled(NotificationMoonminingEmbed):
136
135
  def __init__(self, notification: Notification) -> None:
137
136
  super().__init__(notification)
138
- if self._parsed_text["cancelledBy"]:
139
- cancelled_by = get_or_create_esi_obj(
140
- EveEntity, id=self._parsed_text["cancelledBy"]
141
- )
137
+ if self._data["cancelledBy"]:
138
+ cancelled_by = get_or_create_eve_entity(id=self._data["cancelledBy"])
142
139
  else:
143
140
  cancelled_by = _("(unknown)")
144
141
  self._title = _("Extraction cancelled")
@@ -159,9 +156,7 @@ class NotificationMoonminningExtractionCanceled(NotificationMoonminingEmbed):
159
156
  class NotificationMoonminningLaserFired(NotificationMoonminingEmbed):
160
157
  def __init__(self, notification: Notification) -> None:
161
158
  super().__init__(notification)
162
- fired_by = EveEntity.objects.get_or_create_esi(id=self._parsed_text["firedBy"])[
163
- 0
164
- ]
159
+ fired_by = get_or_create_eve_entity(id=self._data["firedBy"])
165
160
  self._title = _("Moon drill fired")
166
161
  self._description = _(
167
162
  "The moon drill fitted to %(structure_name)s at %(moon)s "
@@ -5,12 +5,11 @@
5
5
  import dhooks_lite
6
6
 
7
7
  from django.utils.translation import gettext as _
8
- from eveuniverse.models import EveType
9
8
 
10
9
  from app_utils.datetime import ldap_time_2_datetime
11
10
 
12
11
  from structures.constants import EveTypeId
13
- from structures.helpers import get_or_create_esi_obj
12
+ from structures.helpers import get_or_create_eve_type
14
13
  from structures.models import Notification, Webhook
15
14
 
16
15
  from .helpers import (
@@ -27,9 +26,7 @@ class NotificationOrbitalEmbed(NotificationBaseEmbed):
27
26
  def __init__(self, notification: Notification) -> None:
28
27
  super().__init__(notification)
29
28
  self._planet = self._notification.eve_planet()
30
- self._structure_type = get_or_create_esi_obj(
31
- EveType, id=EveTypeId.CUSTOMS_OFFICE
32
- )
29
+ self._structure_type = get_or_create_eve_type(id=EveTypeId.CUSTOMS_OFFICE)
33
30
  self._solar_system_link = gen_solar_system_text(
34
31
  self._notification.eve_solar_system()
35
32
  )
@@ -61,9 +58,7 @@ class NotificationOrbitalAttacked(NotificationOrbitalEmbed):
61
58
  class NotificationOrbitalReinforced(NotificationOrbitalEmbed):
62
59
  def __init__(self, notification: Notification) -> None:
63
60
  super().__init__(notification)
64
- reinforce_exit_time = ldap_time_2_datetime(
65
- self._parsed_text["reinforceExitTime"]
66
- )
61
+ reinforce_exit_time = ldap_time_2_datetime(self._data["reinforceExitTime"])
67
62
  self._title = _("Orbital reinforced")
68
63
  self._description = _(
69
64
  "The %(structure_type)s at %(planet)s in %(solar_system)s "
@@ -5,13 +5,17 @@
5
5
  import dhooks_lite
6
6
 
7
7
  from django.utils.translation import gettext as _
8
- from eveuniverse.models import EveEntity, EveMoon, EveType
8
+ from eveuniverse.models import EveMoon
9
9
 
10
10
  from app_utils.datetime import ldap_time_2_datetime
11
11
 
12
12
  from structures.constants import EveTypeId
13
13
  from structures.core import sovereignty
14
- from structures.helpers import get_or_create_esi_obj
14
+ from structures.helpers import (
15
+ get_or_create_esi_obj,
16
+ get_or_create_eve_entity,
17
+ get_or_create_eve_type,
18
+ )
15
19
  from structures.models import Notification, Webhook
16
20
 
17
21
  from .helpers import (
@@ -31,15 +35,15 @@ class NotificationSovEmbed(NotificationBaseEmbed):
31
35
  super().__init__(notification)
32
36
  self._solar_system = self._notification.eve_solar_system()
33
37
  self._solar_system_link = gen_solar_system_text(self._solar_system)
34
- if "structureTypeID" in self._parsed_text:
35
- structure_type_id = self._parsed_text["structureTypeID"]
36
- elif "campaignEventType" in self._parsed_text:
38
+ if "structureTypeID" in self._data:
39
+ structure_type_id = self._data["structureTypeID"]
40
+ elif "campaignEventType" in self._data:
37
41
  structure_type_id = sovereignty.event_type_to_type_id(
38
- self._parsed_text["campaignEventType"]
42
+ self._data["campaignEventType"]
39
43
  )
40
44
  else:
41
45
  structure_type_id = EveTypeId.TCU
42
- structure_type = get_or_create_esi_obj(EveType, id=structure_type_id)
46
+ structure_type = get_or_create_eve_type(id=structure_type_id)
43
47
  self._structure_type_name = structure_type.name
44
48
  try:
45
49
  self._sov_owner_link = gen_alliance_link(notification.sender.name)
@@ -95,8 +99,8 @@ class NotificationSovCommandNodeEventStarted(NotificationSovEmbed):
95
99
  class NotificationSovAllClaimAcquiredMsg(NotificationSovEmbed):
96
100
  def __init__(self, notification: Notification) -> None:
97
101
  super().__init__(notification)
98
- alliance = get_or_create_esi_obj(EveEntity, id=self._parsed_text["allianceID"])
99
- corporation = get_or_create_esi_obj(EveEntity, id=self._parsed_text["corpID"])
102
+ alliance = get_or_create_eve_entity(id=self._data["allianceID"])
103
+ corporation = get_or_create_eve_entity(id=self._data["corpID"])
100
104
  self._title = (
101
105
  _("DED Sovereignty claim acknowledgment: %s") % self._solar_system.name
102
106
  )
@@ -115,8 +119,8 @@ class NotificationSovAllClaimAcquiredMsg(NotificationSovEmbed):
115
119
  class NotificationSovAllClaimLostMsg(NotificationSovEmbed):
116
120
  def __init__(self, notification: Notification) -> None:
117
121
  super().__init__(notification)
118
- alliance = get_or_create_esi_obj(EveEntity, id=self._parsed_text["allianceID"])
119
- corporation = get_or_create_esi_obj(EveEntity, id=self._parsed_text["corpID"])
122
+ alliance = get_or_create_eve_entity(id=self._data["allianceID"])
123
+ corporation = get_or_create_eve_entity(id=self._data["corpID"])
120
124
  self._title = _("Lost sovereignty in: %s") % self._solar_system.name
121
125
  self._description = _(
122
126
  "DED acknowledges that member corporation %(corporation)s has lost its "
@@ -132,7 +136,7 @@ class NotificationSovAllClaimLostMsg(NotificationSovEmbed):
132
136
  class NotificationSovStructureReinforced(NotificationSovEmbed):
133
137
  def __init__(self, notification: Notification) -> None:
134
138
  super().__init__(notification)
135
- timer_starts = ldap_time_2_datetime(self._parsed_text["decloakTime"])
139
+ timer_starts = ldap_time_2_datetime(self._data["decloakTime"])
136
140
  self._title = _(
137
141
  "%(structure_type)s in %(solar_system)s has entered reinforced mode"
138
142
  ) % {
@@ -175,21 +179,19 @@ class NotificationSovStructureDestroyed(NotificationSovEmbed):
175
179
  class NotificationSovAllAnchoringMsg(NotificationBaseEmbed):
176
180
  def __init__(self, notification: Notification) -> None:
177
181
  super().__init__(notification)
178
- corporation = get_or_create_esi_obj(
179
- EveEntity, id=self._parsed_text.get("corpID")
180
- )
182
+ corporation = get_or_create_eve_entity(id=self._data.get("corpID"))
181
183
  corp_link = gen_eve_entity_link(corporation)
182
- alliance_id = self._parsed_text.get("allianceID")
184
+ alliance_id = self._data.get("allianceID")
183
185
  if alliance_id:
184
- alliance = get_or_create_esi_obj(EveEntity, id=alliance_id)
186
+ alliance = get_or_create_eve_entity(id=alliance_id)
185
187
  structure_owner = f"{corp_link} ({alliance.name})"
186
188
  else:
187
189
  structure_owner = corp_link
188
190
  eve_solar_system = self._notification.eve_solar_system()
189
191
  structure_type = self._notification.eve_structure_type("typeID")
190
- moon_id = self._parsed_text.get("moonID")
192
+ moon_id = self._data.get("moonID")
191
193
  if moon_id:
192
- eve_moon = get_or_create_esi_obj(EveMoon, id=moon_id)
194
+ eve_moon: EveMoon = get_or_create_esi_obj(EveMoon, id=moon_id)
193
195
  location_text = _(" near **%s**") % eve_moon.name
194
196
  else:
195
197
  location_text = ""
@@ -7,11 +7,10 @@ from collections import namedtuple
7
7
  import dhooks_lite
8
8
 
9
9
  from django.utils.translation import gettext as _
10
- from eveuniverse.models import EveEntity, EveType
11
10
 
12
11
  from app_utils.datetime import ldap_time_2_datetime, ldap_timedelta_2_timedelta
13
12
 
14
- from structures.helpers import get_or_create_esi_obj
13
+ from structures.helpers import get_or_create_eve_entity, get_or_create_eve_type
15
14
  from structures.models import Notification, Structure, Webhook
16
15
 
17
16
  from .helpers import (
@@ -31,7 +30,7 @@ class NotificationStructureEmbed(NotificationBaseEmbed):
31
30
  super().__init__(notification)
32
31
  try:
33
32
  structure = Structure.objects.select_related_defaults().get(
34
- id=self._parsed_text["structureID"]
33
+ id=self._data["structureID"]
35
34
  )
36
35
  except Structure.DoesNotExist:
37
36
  structure = None
@@ -97,7 +96,7 @@ class NotificationStructureJumpFuelAlert(NotificationStructureEmbed):
97
96
  def __init__(self, notification: Notification) -> None:
98
97
  super().__init__(notification)
99
98
  self._title = _("Jump gate low on Liquid Ozone")
100
- threshold_str = f"{self._parsed_text['threshold']:,}"
99
+ threshold_str = f"{self._data['threshold']:,}"
101
100
  quantity_str = f"{self._structure.jump_fuel_quantity():,}"
102
101
  self._description += _(
103
102
  "is below %(threshold)s units on Liquid Ozone.\n"
@@ -153,7 +152,7 @@ class NotificationStructureUnanchoring(NotificationStructureEmbed):
153
152
  super().__init__(notification)
154
153
  self._title = _("Structure un-anchoring")
155
154
  unanchored_at = notification.timestamp + ldap_timedelta_2_timedelta(
156
- self._parsed_text["timeLeft"]
155
+ self._data["timeLeft"]
157
156
  )
158
157
  self._description += _(
159
158
  "has started un-anchoring. It will be fully un-anchored at: %s"
@@ -173,11 +172,11 @@ class NotificationStructureUnderAttack(NotificationStructureEmbed):
173
172
 
174
173
  def _get_attacker_link(self) -> str:
175
174
  """Returns the attacker link from a parsed_text for Upwell structures only."""
176
- if self._parsed_text.get("allianceName"):
177
- return gen_alliance_link(self._parsed_text["allianceName"])
175
+ if self._data.get("allianceName"):
176
+ return gen_alliance_link(self._data["allianceName"])
178
177
 
179
- if self._parsed_text.get("corpName"):
180
- return gen_corporation_link(self._parsed_text["corpName"])
178
+ if self._data.get("corpName"):
179
+ return gen_corporation_link(self._data["corpName"])
181
180
 
182
181
  return _("(unknown)")
183
182
 
@@ -187,7 +186,7 @@ class NotificationStructureLostShield(NotificationStructureEmbed):
187
186
  super().__init__(notification)
188
187
  self._title = _("Structure lost shield")
189
188
  timer_ends_at = notification.timestamp + ldap_timedelta_2_timedelta(
190
- self._parsed_text["timeLeft"]
189
+ self._data["timeLeft"]
191
190
  )
192
191
  self._description += _(
193
192
  "has lost its shields. Armor timer end at: %s"
@@ -200,7 +199,7 @@ class NotificationStructureLostArmor(NotificationStructureEmbed):
200
199
  super().__init__(notification)
201
200
  self._title = _("Structure lost armor")
202
201
  timer_ends_at = notification.timestamp + ldap_timedelta_2_timedelta(
203
- self._parsed_text["timeLeft"]
202
+ self._data["timeLeft"]
204
203
  )
205
204
  self._description += _(
206
205
  "has lost its armor. Hull timer end at: %s"
@@ -224,18 +223,14 @@ class NotificationStructureOwnershipTransferred(NotificationBaseEmbed):
224
223
  "The %(structure_type)s %(structure_name)s in %(solar_system)s "
225
224
  ) % {
226
225
  "structure_type": structure_type.name,
227
- "structure_name": Webhook.text_bold(self._parsed_text["structureName"]),
226
+ "structure_name": Webhook.text_bold(self._data["structureName"]),
228
227
  "solar_system": gen_solar_system_text(
229
228
  self._notification.eve_solar_system()
230
229
  ),
231
230
  }
232
- from_corporation = get_or_create_esi_obj(
233
- EveEntity, id=self._parsed_text["oldOwnerCorpID"]
234
- )
235
- to_corporation = get_or_create_esi_obj(
236
- EveEntity, id=self._parsed_text["newOwnerCorpID"]
237
- )
238
- character = get_or_create_esi_obj(EveEntity, id=self._parsed_text["charID"])
231
+ from_corporation = get_or_create_eve_entity(id=self._data["oldOwnerCorpID"])
232
+ to_corporation = get_or_create_eve_entity(id=self._data["newOwnerCorpID"])
233
+ character = get_or_create_eve_entity(id=self._data["charID"])
239
234
  self._description += _(
240
235
  "has been transferred from %(from_corporation)s "
241
236
  "to %(to_corporation)s by %(character)s."
@@ -256,9 +251,7 @@ class NotificationStructureAnchoring(NotificationBaseEmbed):
256
251
  super().__init__(notification)
257
252
  structure_type = self._notification.eve_structure_type()
258
253
  solar_system = self._notification.eve_solar_system("solarsystemID")
259
- owner_link = gen_corporation_link(
260
- self._parsed_text.get("ownerCorpName", "(unknown)")
261
- )
254
+ owner_link = gen_corporation_link(self._data.get("ownerCorpName", "(unknown)"))
262
255
  self._description = _(
263
256
  "A %(structure_type)s belonging to %(owner_link)s "
264
257
  "has started anchoring in %(solar_system)s. "
@@ -282,7 +275,7 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
282
275
  def __init__(self, notification: Notification) -> None:
283
276
  super().__init__(notification)
284
277
  all_structure_info = []
285
- for structure_info in self._parsed_text["allStructureInfo"]:
278
+ for structure_info in self._data["allStructureInfo"]:
286
279
  try:
287
280
  structure = Structure.objects.select_related_defaults().get(
288
281
  id=structure_info[0]
@@ -291,7 +284,7 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
291
284
  all_structure_info.append(
292
285
  self.StructureInfo(
293
286
  name=structure_info[1],
294
- eve_type=get_or_create_esi_obj(EveType, id=structure_info[2]),
287
+ eve_type=get_or_create_eve_type(id=structure_info[2]),
295
288
  eve_solar_system=None,
296
289
  owner_link=_("(unknown)"),
297
290
  )
@@ -307,11 +300,11 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
307
300
  )
308
301
 
309
302
  self._title = _("Structure reinforcement time changed")
310
- change_effective = ldap_time_2_datetime(self._parsed_text["timestamp"])
303
+ change_effective = ldap_time_2_datetime(self._data["timestamp"])
311
304
  self._description = _(
312
305
  "Reinforcement hour has been changed to %s "
313
306
  "for the following structures:\n"
314
- ) % Webhook.text_bold(self._parsed_text["hour"])
307
+ ) % Webhook.text_bold(self._data["hour"])
315
308
  for structure_info in all_structure_info:
316
309
  if eve_solar_system := structure_info.eve_solar_system:
317
310
  solar_system_text = gen_solar_system_text(eve_solar_system)
@@ -69,8 +69,8 @@ class NotificationTowerAlertMsg(NotificationTowerEmbed):
69
69
  class NotificationTowerResourceAlertMsg(NotificationTowerEmbed):
70
70
  def __init__(self, notification: Notification) -> None:
71
71
  super().__init__(notification)
72
- if "wants" in self._parsed_text and self._parsed_text["wants"]:
73
- fuel_quantity = self._parsed_text["wants"][0]["quantity"]
72
+ if "wants" in self._data and self._data["wants"]:
73
+ fuel_quantity = self._data["wants"][0]["quantity"]
74
74
  starbase_type = self._notification.eve_structure_type("typeID")
75
75
  seconds = starbases.fuel_duration(
76
76
  starbase_type=starbase_type,