aa-structures 2.6.0__py3-none-any.whl → 2.6.2__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 (39) hide show
  1. {aa_structures-2.6.0.dist-info → aa_structures-2.6.2.dist-info}/METADATA +1 -1
  2. {aa_structures-2.6.0.dist-info → aa_structures-2.6.2.dist-info}/RECORD +37 -38
  3. structures/__init__.py +1 -1
  4. structures/admin.py +208 -206
  5. structures/core/notification_embeds/billing_embeds.py +11 -10
  6. structures/core/notification_embeds/character_embeds.py +18 -17
  7. structures/core/notification_embeds/main.py +6 -6
  8. structures/core/notification_embeds/moonmining_embeds.py +25 -26
  9. structures/core/notification_embeds/orbital_embeds.py +8 -7
  10. structures/core/notification_embeds/sov_embeds.py +26 -35
  11. structures/core/notification_embeds/structures_embeds.py +67 -64
  12. structures/core/notification_embeds/tower_embeds.py +29 -22
  13. structures/core/notification_embeds/war_embeds.py +33 -44
  14. structures/core/serializers.py +1 -1
  15. structures/helpers.py +7 -1
  16. structures/locale/de/LC_MESSAGES/django.po +1036 -185
  17. structures/locale/django.pot +1054 -184
  18. structures/locale/en/LC_MESSAGES/django.po +1054 -184
  19. structures/locale/es/LC_MESSAGES/django.po +1035 -184
  20. structures/locale/fr_FR/LC_MESSAGES/django.po +1054 -184
  21. structures/locale/it_IT/LC_MESSAGES/django.po +1054 -184
  22. structures/locale/ja/LC_MESSAGES/django.po +1054 -184
  23. structures/locale/ko_KR/LC_MESSAGES/django.po +1035 -184
  24. structures/locale/ru/LC_MESSAGES/django.mo +0 -0
  25. structures/locale/ru/LC_MESSAGES/django.po +1144 -199
  26. structures/locale/uk/LC_MESSAGES/django.po +1035 -184
  27. structures/locale/zh_Hans/LC_MESSAGES/django.po +1036 -185
  28. structures/migrations/0004_improve_localization.py +401 -0
  29. structures/models/notifications.py +3 -3
  30. structures/models/owners.py +11 -11
  31. structures/models/structures_1.py +16 -16
  32. structures/templates/structures/base.html +1 -1
  33. structures/tests/test_helpers.py +13 -0
  34. structures/views.py +1 -2
  35. structures/webhooks/models.py +14 -5
  36. structures/locale/ko/LC_MESSAGES/django.mo +0 -0
  37. structures/locale/ko/LC_MESSAGES/django.po +0 -2221
  38. {aa_structures-2.6.0.dist-info → aa_structures-2.6.2.dist-info}/LICENSE +0 -0
  39. {aa_structures-2.6.0.dist-info → aa_structures-2.6.2.dist-info}/WHEEL +0 -0
@@ -6,11 +6,12 @@ from collections import namedtuple
6
6
 
7
7
  import dhooks_lite
8
8
 
9
- from django.utils.translation import gettext as __
9
+ from django.utils.translation import gettext as _
10
10
  from eveuniverse.models import EveEntity, EveType
11
11
 
12
12
  from app_utils.datetime import ldap_time_2_datetime, ldap_timedelta_2_timedelta
13
13
 
14
+ from structures.helpers import get_or_create_esi_obj
14
15
  from structures.models import Notification, Structure, Webhook
15
16
 
16
17
  from .helpers import (
@@ -34,7 +35,7 @@ class NotificationStructureEmbed(NotificationBaseEmbed):
34
35
  )
35
36
  except Structure.DoesNotExist:
36
37
  structure = None
37
- structure_name = __("(unknown)")
38
+ structure_name = _("(unknown)")
38
39
  structure_type = self._notification.eve_structure_type()
39
40
  structure_solar_system = self._notification.eve_solar_system(
40
41
  "solarsystemID"
@@ -46,19 +47,24 @@ class NotificationStructureEmbed(NotificationBaseEmbed):
46
47
  structure_type = structure.eve_type
47
48
  structure_solar_system = structure.eve_solar_system
48
49
  owner_link = gen_corporation_link(str(structure.owner))
49
- location = f" at {structure.eve_moon} " if structure.eve_moon else ""
50
+ # Translators: Context is a location, e.g. a moon
51
+ location = _(" at %s ") % structure.eve_moon if structure.eve_moon else ""
50
52
 
51
53
  self._structure = structure
52
- self._description = __(
53
- "The %(structure_type)s %(structure_name)s%(location)s in %(solar_system)s "
54
- "belonging to %(owner_link)s "
55
- ) % {
56
- "structure_type": structure_type.name,
57
- "structure_name": Webhook.text_bold(structure_name),
58
- "location": location,
59
- "solar_system": gen_solar_system_text(structure_solar_system),
60
- "owner_link": owner_link,
61
- }
54
+ self._description = (
55
+ _(
56
+ "The %(structure_type)s %(structure_name)s%(location)s "
57
+ "in %(solar_system)s belonging to %(owner_link)s"
58
+ )
59
+ % {
60
+ "structure_type": structure_type.name,
61
+ "structure_name": Webhook.text_bold(structure_name),
62
+ "location": location,
63
+ "solar_system": gen_solar_system_text(structure_solar_system),
64
+ "owner_link": owner_link,
65
+ }
66
+ + " "
67
+ )
62
68
  self._thumbnail = dhooks_lite.Thumbnail(
63
69
  structure_type.icon_url(size=self.ICON_DEFAULT_SIZE)
64
70
  )
@@ -67,8 +73,8 @@ class NotificationStructureEmbed(NotificationBaseEmbed):
67
73
  class NotificationStructureOnline(NotificationStructureEmbed):
68
74
  def __init__(self, notification: Notification) -> None:
69
75
  super().__init__(notification)
70
- self._title = __("Structure online")
71
- self._description += __("is now online.")
76
+ self._title = _("Structure online")
77
+ self._description += _("is now online.")
72
78
  self._color = Webhook.Color.SUCCESS
73
79
 
74
80
 
@@ -79,8 +85,8 @@ class NotificationStructureFuelAlert(NotificationStructureEmbed):
79
85
  hours_left = timeuntil(self._structure.fuel_expires_at)
80
86
  else:
81
87
  hours_left = "?"
82
- self._title = __("Structure fuel alert")
83
- self._description += __("is running out of fuel in %s.") % Webhook.text_bold(
88
+ self._title = _("Structure fuel alert")
89
+ self._description += _("is running out of fuel in %s.") % Webhook.text_bold(
84
90
  hours_left
85
91
  )
86
92
 
@@ -90,17 +96,16 @@ class NotificationStructureFuelAlert(NotificationStructureEmbed):
90
96
  class NotificationStructureJumpFuelAlert(NotificationStructureEmbed):
91
97
  def __init__(self, notification: Notification) -> None:
92
98
  super().__init__(notification)
93
- self._title = __("Jump gate low on Liquid Ozone")
99
+ self._title = _("Jump gate low on Liquid Ozone")
94
100
  threshold_str = f"{self._parsed_text['threshold']:,}"
95
101
  quantity_str = f"{self._structure.jump_fuel_quantity():,}"
96
- self._description += __(
102
+ self._description += _(
97
103
  "is below %(threshold)s units on Liquid Ozone.\n"
98
104
  "Remaining units: %(remaining)s."
99
- % {
100
- "threshold": f"{Webhook.text_bold(threshold_str)}",
101
- "remaining": f"{Webhook.text_bold(quantity_str)}",
102
- }
103
- )
105
+ ) % {
106
+ "threshold": f"{Webhook.text_bold(threshold_str)}",
107
+ "remaining": f"{Webhook.text_bold(quantity_str)}",
108
+ }
104
109
  self._color = Webhook.Color.WARNING
105
110
 
106
111
 
@@ -108,9 +113,9 @@ class NotificationStructureRefueledExtra(NotificationStructureEmbed):
108
113
  def __init__(self, notification: Notification) -> None:
109
114
  super().__init__(notification)
110
115
  target_date = self.fuel_expires_target_date()
111
- self._title = __("Structure refueled")
116
+ self._title = _("Structure refueled")
112
117
  self._description += (
113
- __("has been refueled. Fuel will last until %s.") % target_date
118
+ _("has been refueled. Fuel will last until %s.") % target_date
114
119
  )
115
120
  self._color = Webhook.Color.INFO
116
121
 
@@ -118,8 +123,8 @@ class NotificationStructureRefueledExtra(NotificationStructureEmbed):
118
123
  class NotificationStructureServicesOffline(NotificationStructureEmbed):
119
124
  def __init__(self, notification: Notification) -> None:
120
125
  super().__init__(notification)
121
- self._title = __("Structure services off-line")
122
- self._description += __("has all services off-lined.")
126
+ self._title = _("Structure services off-line")
127
+ self._description += _("has all services off-lined.")
123
128
  if self._structure and self._structure.services.count() > 0:
124
129
  qs = self._structure.services.all().order_by("name")
125
130
  services_list = "\n".join([x.name for x in qs])
@@ -130,27 +135,27 @@ class NotificationStructureServicesOffline(NotificationStructureEmbed):
130
135
  class NotificationStructureWentLowPower(NotificationStructureEmbed):
131
136
  def __init__(self, notification: Notification) -> None:
132
137
  super().__init__(notification)
133
- self._title = __("Structure low power")
134
- self._description += __("went to low power mode.")
138
+ self._title = _("Structure low power")
139
+ self._description += _("went to low power mode.")
135
140
  self._color = Webhook.Color.WARNING
136
141
 
137
142
 
138
143
  class NotificationStructureWentHighPower(NotificationStructureEmbed):
139
144
  def __init__(self, notification: Notification) -> None:
140
145
  super().__init__(notification)
141
- self._title = __("Structure full power")
142
- self._description += __("went to full power mode.")
146
+ self._title = _("Structure full power")
147
+ self._description += _("went to full power mode.")
143
148
  self._color = Webhook.Color.SUCCESS
144
149
 
145
150
 
146
151
  class NotificationStructureUnanchoring(NotificationStructureEmbed):
147
152
  def __init__(self, notification: Notification) -> None:
148
153
  super().__init__(notification)
149
- self._title = __("Structure un-anchoring")
154
+ self._title = _("Structure un-anchoring")
150
155
  unanchored_at = notification.timestamp + ldap_timedelta_2_timedelta(
151
156
  self._parsed_text["timeLeft"]
152
157
  )
153
- self._description += __(
158
+ self._description += _(
154
159
  "has started un-anchoring. It will be fully un-anchored at: %s"
155
160
  ) % target_datetime_formatted(unanchored_at)
156
161
  self._color = Webhook.Color.INFO
@@ -159,11 +164,11 @@ class NotificationStructureUnanchoring(NotificationStructureEmbed):
159
164
  class NotificationStructureUnderAttack(NotificationStructureEmbed):
160
165
  def __init__(self, notification: Notification) -> None:
161
166
  super().__init__(notification)
162
- self._title = __("Structure under attack")
163
- self._description += __("is under attack by %s.\n%s") % (
164
- self._get_attacker_link(),
165
- self.compile_damage_text("Percentage"),
166
- )
167
+ self._title = _("Structure under attack")
168
+ self._description += _("is under attack by %(attacker)s.\n%(damage_text)s") % {
169
+ "attacker": self._get_attacker_link(),
170
+ "damage_text": self.compile_damage_text("Percentage"),
171
+ }
167
172
  self._color = Webhook.Color.DANGER
168
173
 
169
174
  def _get_attacker_link(self) -> str:
@@ -174,17 +179,17 @@ class NotificationStructureUnderAttack(NotificationStructureEmbed):
174
179
  if self._parsed_text.get("corpName"):
175
180
  return gen_corporation_link(self._parsed_text["corpName"])
176
181
 
177
- return "(unknown)"
182
+ return _("(unknown)")
178
183
 
179
184
 
180
185
  class NotificationStructureLostShield(NotificationStructureEmbed):
181
186
  def __init__(self, notification: Notification) -> None:
182
187
  super().__init__(notification)
183
- self._title = __("Structure lost shield")
188
+ self._title = _("Structure lost shield")
184
189
  timer_ends_at = notification.timestamp + ldap_timedelta_2_timedelta(
185
190
  self._parsed_text["timeLeft"]
186
191
  )
187
- self._description += __(
192
+ self._description += _(
188
193
  "has lost its shields. Armor timer end at: %s"
189
194
  ) % target_datetime_formatted(timer_ends_at)
190
195
  self._color = Webhook.Color.DANGER
@@ -193,11 +198,11 @@ class NotificationStructureLostShield(NotificationStructureEmbed):
193
198
  class NotificationStructureLostArmor(NotificationStructureEmbed):
194
199
  def __init__(self, notification: Notification) -> None:
195
200
  super().__init__(notification)
196
- self._title = __("Structure lost armor")
201
+ self._title = _("Structure lost armor")
197
202
  timer_ends_at = notification.timestamp + ldap_timedelta_2_timedelta(
198
203
  self._parsed_text["timeLeft"]
199
204
  )
200
- self._description += __(
205
+ self._description += _(
201
206
  "has lost its armor. Hull timer end at: %s"
202
207
  ) % target_datetime_formatted(timer_ends_at)
203
208
  self._color = Webhook.Color.DANGER
@@ -206,8 +211,8 @@ class NotificationStructureLostArmor(NotificationStructureEmbed):
206
211
  class NotificationStructureDestroyed(NotificationStructureEmbed):
207
212
  def __init__(self, notification: Notification) -> None:
208
213
  super().__init__(notification)
209
- self._title = __("Structure destroyed")
210
- self._description += __("has been destroyed.")
214
+ self._title = _("Structure destroyed")
215
+ self._description += _("has been destroyed.")
211
216
  self._color = Webhook.Color.DANGER
212
217
 
213
218
 
@@ -215,7 +220,7 @@ class NotificationStructureOwnershipTransferred(NotificationBaseEmbed):
215
220
  def __init__(self, notification: Notification) -> None:
216
221
  super().__init__(notification)
217
222
  structure_type = self._notification.eve_structure_type()
218
- self._description = __(
223
+ self._description = _(
219
224
  "The %(structure_type)s %(structure_name)s in %(solar_system)s "
220
225
  ) % {
221
226
  "structure_type": structure_type.name,
@@ -224,16 +229,14 @@ class NotificationStructureOwnershipTransferred(NotificationBaseEmbed):
224
229
  self._notification.eve_solar_system()
225
230
  ),
226
231
  }
227
- from_corporation, _ = EveEntity.objects.get_or_create_esi(
228
- id=self._parsed_text["oldOwnerCorpID"]
229
- )
230
- to_corporation, _ = EveEntity.objects.get_or_create_esi(
231
- id=self._parsed_text["newOwnerCorpID"]
232
+ from_corporation = get_or_create_esi_obj(
233
+ EveEntity, id=self._parsed_text["oldOwnerCorpID"]
232
234
  )
233
- character, _ = EveEntity.objects.get_or_create_esi(
234
- id=self._parsed_text["charID"]
235
+ to_corporation = get_or_create_esi_obj(
236
+ EveEntity, id=self._parsed_text["newOwnerCorpID"]
235
237
  )
236
- self._description += __(
238
+ character = get_or_create_esi_obj(EveEntity, id=self._parsed_text["charID"])
239
+ self._description += _(
237
240
  "has been transferred from %(from_corporation)s "
238
241
  "to %(to_corporation)s by %(character)s."
239
242
  ) % {
@@ -241,7 +244,7 @@ class NotificationStructureOwnershipTransferred(NotificationBaseEmbed):
241
244
  "to_corporation": gen_corporation_link(to_corporation.name),
242
245
  "character": character.name,
243
246
  }
244
- self._title = __("Ownership transferred")
247
+ self._title = _("Ownership transferred")
245
248
  self._color = Webhook.Color.INFO
246
249
  self._thumbnail = dhooks_lite.Thumbnail(
247
250
  structure_type.icon_url(size=self.ICON_DEFAULT_SIZE)
@@ -256,7 +259,7 @@ class NotificationStructureAnchoring(NotificationBaseEmbed):
256
259
  owner_link = gen_corporation_link(
257
260
  self._parsed_text.get("ownerCorpName", "(unknown)")
258
261
  )
259
- self._description = __(
262
+ self._description = _(
260
263
  "A %(structure_type)s belonging to %(owner_link)s "
261
264
  "has started anchoring in %(solar_system)s. "
262
265
  ) % {
@@ -264,7 +267,7 @@ class NotificationStructureAnchoring(NotificationBaseEmbed):
264
267
  "owner_link": owner_link,
265
268
  "solar_system": gen_solar_system_text(solar_system),
266
269
  }
267
- self._title = __("Structure anchoring")
270
+ self._title = _("Structure anchoring")
268
271
  self._color = Webhook.Color.INFO
269
272
  self._thumbnail = dhooks_lite.Thumbnail(
270
273
  structure_type.icon_url(size=self.ICON_DEFAULT_SIZE)
@@ -292,7 +295,7 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
292
295
  id=structure_info[2]
293
296
  ),
294
297
  eve_solar_system=None,
295
- owner_link="(unknown)",
298
+ owner_link=_("(unknown)"),
296
299
  )
297
300
  )
298
301
  else:
@@ -305,14 +308,14 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
305
308
  )
306
309
  )
307
310
 
308
- self._title = __("Structure reinforcement time changed")
311
+ self._title = _("Structure reinforcement time changed")
309
312
  change_effective = ldap_time_2_datetime(self._parsed_text["timestamp"])
310
- self._description = __(
313
+ self._description = _(
311
314
  "Reinforcement hour has been changed to %s "
312
315
  "for the following structures:\n"
313
316
  ) % Webhook.text_bold(self._parsed_text["hour"])
314
317
  for structure_info in all_structure_info:
315
- self._description += __(
318
+ self._description += _(
316
319
  "- %(structure_type)s %(structure_name)s in %(solar_system)s "
317
320
  "belonging to %(owner_link)s"
318
321
  ) % {
@@ -322,7 +325,7 @@ class NotificationStructureReinforceChange(NotificationBaseEmbed):
322
325
  "owner_link": structure_info.owner_link,
323
326
  }
324
327
 
325
- self._description += __(
326
- "\n\nChange becomes effective at %s."
328
+ self._description += _(
329
+ _("\n\nChange becomes effective at %s.")
327
330
  ) % target_datetime_formatted(change_effective)
328
331
  self._color = Webhook.Color.INFO
@@ -6,7 +6,7 @@ import datetime as dt
6
6
 
7
7
  import dhooks_lite
8
8
 
9
- from django.utils.translation import gettext as __
9
+ from django.utils.translation import gettext as _
10
10
 
11
11
  from structures.core import starbases
12
12
  from structures.models import GeneratedNotification, Notification, Structure, Webhook
@@ -36,15 +36,21 @@ class NotificationTowerEmbed(NotificationBaseEmbed):
36
36
  self._thumbnail = dhooks_lite.Thumbnail(
37
37
  structure_type.icon_url(size=self.ICON_DEFAULT_SIZE)
38
38
  )
39
- self._description = __(
40
- "The starbase %(structure_name)s at %(moon)s "
41
- "in %(solar_system)s belonging to %(owner_link)s "
42
- ) % {
43
- "structure_name": Webhook.text_bold(structure_name),
44
- "moon": eve_moon.name,
45
- "solar_system": gen_solar_system_text(eve_moon.eve_planet.eve_solar_system),
46
- "owner_link": gen_corporation_link(str(notification.owner)),
47
- }
39
+ self._description = (
40
+ _(
41
+ "The starbase %(structure_name)s at %(moon)s "
42
+ "in %(solar_system)s belonging to %(owner_link)s"
43
+ )
44
+ % {
45
+ "structure_name": Webhook.text_bold(structure_name),
46
+ "moon": eve_moon.name,
47
+ "solar_system": gen_solar_system_text(
48
+ eve_moon.eve_planet.eve_solar_system
49
+ ),
50
+ "owner_link": gen_corporation_link(str(notification.owner)),
51
+ }
52
+ + " "
53
+ )
48
54
 
49
55
 
50
56
  class NotificationTowerAlertMsg(NotificationTowerEmbed):
@@ -52,10 +58,11 @@ class NotificationTowerAlertMsg(NotificationTowerEmbed):
52
58
  super().__init__(notification)
53
59
  aggressor_link = self.get_aggressor_link()
54
60
  damage_text = self.compile_damage_text("Value", 100)
55
- self._title = __("Starbase under attack")
56
- self._description += __(
57
- "is under attack by %(aggressor)s.\n%(damage_text)s"
58
- ) % {"aggressor": aggressor_link, "damage_text": damage_text}
61
+ self._title = _("Starbase under attack")
62
+ self._description += _("is under attack by %(aggressor)s.\n%(damage_text)s") % {
63
+ "aggressor": aggressor_link,
64
+ "damage_text": damage_text,
65
+ }
59
66
  self._color = Webhook.Color.WARNING
60
67
 
61
68
 
@@ -79,8 +86,8 @@ class NotificationTowerResourceAlertMsg(NotificationTowerEmbed):
79
86
  hours_left = timeuntil(self._structure.fuel_expires_at)
80
87
  else:
81
88
  hours_left = "?"
82
- self._title = __("Starbase fuel alert")
83
- self._description += __("is running out of fuel in %s.") % Webhook.text_bold(
89
+ self._title = _("Starbase fuel alert")
90
+ self._description += _("is running out of fuel in %s.") % Webhook.text_bold(
84
91
  hours_left
85
92
  )
86
93
  self._color = Webhook.Color.WARNING
@@ -90,9 +97,9 @@ class NotificationTowerRefueledExtra(NotificationTowerEmbed):
90
97
  def __init__(self, notification: Notification) -> None:
91
98
  super().__init__(notification)
92
99
  target_date = self.fuel_expires_target_date()
93
- self._title = __("Starbase refueled")
100
+ self._title = _("Starbase refueled")
94
101
  self._description += (
95
- __("has been refueled. Fuel will last until %s.") % target_date
102
+ _("has been refueled. Fuel will last until %s.") % target_date
96
103
  )
97
104
  self._color = Webhook.Color.INFO
98
105
 
@@ -117,7 +124,7 @@ class GeneratedNotificationTowerEmbed(GeneratedNotificationBaseEmbed):
117
124
 
118
125
  def __init__(self, notification: GeneratedNotification) -> None:
119
126
  super().__init__(notification)
120
- self._description = __(
127
+ self._description = _(
121
128
  "The starbase %(structure_name)s at %(moon)s "
122
129
  "in %(solar_system)s belonging to %(owner_link)s "
123
130
  ) % {
@@ -131,16 +138,16 @@ class GeneratedNotificationTowerEmbed(GeneratedNotificationBaseEmbed):
131
138
  class NotificationTowerReinforcedExtra(GeneratedNotificationTowerEmbed):
132
139
  def __init__(self, notification: GeneratedNotification) -> None:
133
140
  super().__init__(notification)
134
- self._title = __("Starbase reinforced")
141
+ self._title = _("Starbase reinforced")
135
142
  try:
136
143
  reinforced_until = target_datetime_formatted(
137
144
  dt.datetime.fromisoformat(notification.details["reinforced_until"])
138
145
  )
139
146
  except (KeyError, ValueError):
140
- reinforced_until = "(unknown)"
147
+ reinforced_until = _("(unknown)")
141
148
 
142
149
  self._description += (
143
- __("has been reinforced and will come out at: %s.") % reinforced_until
150
+ _("has been reinforced and will come out at: %s.") % reinforced_until
144
151
  )
145
152
 
146
153
  self._color = Webhook.Color.DANGER
@@ -6,11 +6,12 @@
6
6
  import dhooks_lite
7
7
 
8
8
  from django.utils.html import strip_tags
9
- from django.utils.translation import gettext as __
9
+ from django.utils.translation import gettext as _
10
10
  from eveuniverse.models import EveEntity
11
11
 
12
12
  from app_utils.datetime import ldap_time_2_datetime
13
13
 
14
+ from structures.helpers import get_or_create_esi_obj
14
15
  from structures.models import Notification, Webhook
15
16
 
16
17
  from .helpers import (
@@ -24,11 +25,11 @@ from .main import NotificationBaseEmbed
24
25
  class NotificationWarEmbed(NotificationBaseEmbed):
25
26
  def __init__(self, notification: Notification) -> None:
26
27
  super().__init__(notification)
27
- self._declared_by, _ = EveEntity.objects.get_or_create_esi(
28
- id=self._parsed_text["declaredByID"]
28
+ self._declared_by = get_or_create_esi_obj(
29
+ EveEntity, id=self._parsed_text["declaredByID"]
29
30
  )
30
- self._against, _ = EveEntity.objects.get_or_create_esi(
31
- id=self._parsed_text["againstID"]
31
+ self._against = get_or_create_esi_obj(
32
+ EveEntity, id=self._parsed_text["againstID"]
32
33
  )
33
34
  self._thumbnail = dhooks_lite.Thumbnail(
34
35
  self._declared_by.icon_url(size=self.ICON_DEFAULT_SIZE)
@@ -38,8 +39,8 @@ class NotificationWarEmbed(NotificationBaseEmbed):
38
39
  class NotificationCorpWarSurrenderMsg(NotificationWarEmbed):
39
40
  def __init__(self, notification: Notification) -> None:
40
41
  super().__init__(notification)
41
- self._title = __("One party has surrendered")
42
- self._description = __(
42
+ self._title = _("One party has surrendered")
43
+ self._description = _(
43
44
  "The war between %(against)s and %(declared_by)s is coming to an end "
44
45
  "as one party has surrendered. "
45
46
  "The war will be declared as being over after approximately 24 hours."
@@ -53,14 +54,12 @@ class NotificationCorpWarSurrenderMsg(NotificationWarEmbed):
53
54
  class NotificationWarAdopted(NotificationWarEmbed):
54
55
  def __init__(self, notification: Notification) -> None:
55
56
  super().__init__(notification)
56
- alliance, _ = EveEntity.objects.get_or_create_esi(
57
- id=self._parsed_text["allianceID"]
58
- )
59
- self._title = __("War update: %(against)s has left %(alliance)s") % {
57
+ alliance = get_or_create_esi_obj(EveEntity, id=self._parsed_text["allianceID"])
58
+ self._title = _("War update: %(against)s has left %(alliance)s") % {
60
59
  "against": self._against.name,
61
60
  "alliance": alliance.name,
62
61
  }
63
- self._description = __(
62
+ self._description = _(
64
63
  "There has been a development in the war between %(declared_by)s "
65
64
  "and %(alliance)s.\n"
66
65
  "%(against)s is no longer a member of %(alliance)s, "
@@ -76,11 +75,11 @@ class NotificationWarAdopted(NotificationWarEmbed):
76
75
  class NotificationWarDeclared(NotificationWarEmbed):
77
76
  def __init__(self, notification: Notification) -> None:
78
77
  super().__init__(notification)
79
- self._title = __("%(declared_by)s Declares War Against %(against)s") % {
78
+ self._title = _("%(declared_by)s Declares War Against %(against)s") % {
80
79
  "declared_by": self._declared_by.name,
81
80
  "against": self._against.name,
82
81
  }
83
- self._description = __(
82
+ self._description = _(
84
83
  "%(declared_by)s has declared war on %(against)s with %(war_hq)s "
85
84
  "as the designated war headquarters.\n"
86
85
  "Within %(delay_hours)s hours fighting can legally occur "
@@ -97,20 +96,14 @@ class NotificationWarDeclared(NotificationWarEmbed):
97
96
  class NotificationWarInherited(NotificationWarEmbed):
98
97
  def __init__(self, notification: Notification) -> None:
99
98
  super().__init__(notification)
100
- alliance, _ = EveEntity.objects.get_or_create_esi(
101
- id=self._parsed_text["allianceID"]
102
- )
103
- opponent, _ = EveEntity.objects.get_or_create_esi(
104
- id=self._parsed_text["opponentID"]
105
- )
106
- quitter, _ = EveEntity.objects.get_or_create_esi(
107
- id=self._parsed_text["quitterID"]
108
- )
109
- self._title = __("%(alliance)s inherits war against %(opponent)s") % {
99
+ alliance = get_or_create_esi_obj(EveEntity, id=self._parsed_text["allianceID"])
100
+ opponent = get_or_create_esi_obj(EveEntity, id=self._parsed_text["opponentID"])
101
+ quitter = get_or_create_esi_obj(EveEntity, id=self._parsed_text["quitterID"])
102
+ self._title = _("%(alliance)s inherits war against %(opponent)s") % {
110
103
  "alliance": alliance.name,
111
104
  "opponent": opponent.name,
112
105
  }
113
- self._description = __(
106
+ self._description = _(
114
107
  "%(alliance)s has inherited the war between %(declared_by)s and "
115
108
  "%(against)s from newly joined %(quitter)s. "
116
109
  "Within **24** hours fighting can legally occur with %(alliance)s."
@@ -126,9 +119,9 @@ class NotificationWarInherited(NotificationWarEmbed):
126
119
  class NotificationWarRetractedByConcord(NotificationWarEmbed):
127
120
  def __init__(self, notification: Notification) -> None:
128
121
  super().__init__(notification)
129
- self._title = __("CONCORD invalidates war")
122
+ self._title = _("CONCORD invalidates war")
130
123
  war_ends = ldap_time_2_datetime(self._parsed_text["endDate"])
131
- self._description = __(
124
+ self._description = _(
132
125
  "The war between %(declared_by)s and %(against)s "
133
126
  "has been retracted by CONCORD.\n"
134
127
  "After %(end_date)s CONCORD will again respond to any hostilities "
@@ -144,10 +137,10 @@ class NotificationWarRetractedByConcord(NotificationWarEmbed):
144
137
  class NotificationWarCorporationBecameEligible(NotificationBaseEmbed):
145
138
  def __init__(self, notification: Notification) -> None:
146
139
  super().__init__(notification)
147
- self._title = __(
140
+ self._title = _(
148
141
  "Corporation or alliance is now eligible for formal war declarations"
149
142
  )
150
- self._description = __(
143
+ self._description = _(
151
144
  "Your corporation or alliance is **now eligible** to participate in "
152
145
  "formal war declarations. This could be because your corporation "
153
146
  "and/or one of the corporations in your alliance owns a structure "
@@ -159,10 +152,10 @@ class NotificationWarCorporationBecameEligible(NotificationBaseEmbed):
159
152
  class NotificationWarCorporationNoLongerEligible(NotificationBaseEmbed):
160
153
  def __init__(self, notification: Notification) -> None:
161
154
  super().__init__(notification)
162
- self._title = __(
155
+ self._title = _(
163
156
  "Corporation or alliance is no longer eligible for formal war declarations"
164
157
  )
165
- self._description = __(
158
+ self._description = _(
166
159
  "Your corporation or alliance is **no longer eligible** to participate "
167
160
  "in formal war declarations.\n"
168
161
  "Neither your corporation nor any of the corporations "
@@ -177,13 +170,11 @@ class NotificationWarSurrenderOfferMsg(NotificationBaseEmbed):
177
170
  def __init__(self, notification: Notification) -> None:
178
171
  super().__init__(notification)
179
172
  isk_value = self._parsed_text.get("iskValue", 0)
180
- owner_1, _ = EveEntity.objects.get_or_create_esi(
181
- id=self._parsed_text.get("ownerID1")
182
- )
173
+ owner_1 = get_or_create_esi_obj(EveEntity, id=self._parsed_text.get("ownerID1"))
183
174
  owner_1_link = gen_eve_entity_link(owner_1)
184
175
  owner_2_link = gen_eve_entity_link_from_id(self._parsed_text.get("ownerID2"))
185
- self._title = __("%s has offered a surrender") % (owner_1,)
186
- self._description = __(
176
+ self._title = _("%s has offered a surrender") % (owner_1,)
177
+ self._description = _(
187
178
  "%s has offered to end the war with %s in the exchange for %s ISK. "
188
179
  "If accepted, the war will end in 24 hours and your organizations will "
189
180
  "be unable to declare new wars against each other for the next 2 weeks."
@@ -194,16 +185,14 @@ class NotificationWarSurrenderOfferMsg(NotificationBaseEmbed):
194
185
  class NotificationAllyJoinedWarMsg(NotificationBaseEmbed):
195
186
  def __init__(self, notification: Notification) -> None:
196
187
  super().__init__(notification)
197
- self._title = __("Ally Has Joined a War")
198
- aggressor, _ = EveEntity.objects.get_or_create_esi(
199
- id=self._parsed_text["aggressorID"]
200
- )
201
- ally, _ = EveEntity.objects.get_or_create_esi(id=self._parsed_text["allyID"])
202
- defender, _ = EveEntity.objects.get_or_create_esi(
203
- id=self._parsed_text["defenderID"]
188
+ self._title = _("Ally Has Joined a War")
189
+ aggressor = get_or_create_esi_obj(
190
+ EveEntity, id=self._parsed_text["aggressorID"]
204
191
  )
192
+ ally = get_or_create_esi_obj(EveEntity, id=self._parsed_text["allyID"])
193
+ defender = get_or_create_esi_obj(EveEntity, id=self._parsed_text["defenderID"])
205
194
  start_time = ldap_time_2_datetime(self._parsed_text["startTime"])
206
- self._description = __(
195
+ self._description = _(
207
196
  "%(ally)s has joined %(defender)s in a war against %(aggressor)s. "
208
197
  "Their participation in the war will start at %(start_time)s."
209
198
  ) % {
@@ -12,7 +12,7 @@ from django.urls import reverse
12
12
  from django.utils.html import escape, format_html
13
13
  from django.utils.safestring import mark_safe
14
14
  from django.utils.timezone import now
15
- from django.utils.translation import gettext as _
15
+ from django.utils.translation import gettext_lazy as _
16
16
  from eveuniverse.models import EvePlanet
17
17
 
18
18
  from allianceauth.eveonline.evelinks import dotlan
structures/helpers.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Helpers for Structures."""
2
2
 
3
3
  import datetime as dt
4
- from typing import Optional
4
+ from typing import Any, Optional
5
5
  from urllib.parse import urlparse
6
6
 
7
7
  from django.utils.timezone import now
@@ -33,3 +33,9 @@ def datetime_almost_equal(
33
33
  def is_absolute_url(url: str) -> bool:
34
34
  """Return True if URL is absolute else False."""
35
35
  return bool(urlparse(url).netloc)
36
+
37
+
38
+ def get_or_create_esi_obj(model_class: type, *args, **kwargs) -> Any:
39
+ """Get or create an object from ESI and return it."""
40
+ obj, _ = model_class.objects.get_or_create_esi(*args, **kwargs)
41
+ return obj