aa-ledger 1.0.4__py3-none-any.whl → 2.0.0__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 (280) hide show
  1. {aa_ledger-1.0.4.dist-info → aa_ledger-2.0.0.dist-info}/METADATA +5 -6
  2. aa_ledger-2.0.0.dist-info/RECORD +267 -0
  3. ledger/__init__.py +2 -2
  4. ledger/admin.py +23 -18
  5. ledger/api/__init__.py +23 -7
  6. ledger/api/{ledger/admin.py → admin.py} +25 -31
  7. ledger/api/alliance.py +755 -0
  8. ledger/api/character.py +786 -0
  9. ledger/api/corporation.py +1141 -0
  10. ledger/api/{helpers.py → helpers/core.py} +33 -33
  11. ledger/api/helpers/icons.py +372 -0
  12. ledger/api/helpers/planetary_helper.py +354 -0
  13. ledger/api/planetary.py +354 -0
  14. ledger/api/schema.py +240 -15
  15. ledger/app_settings.py +11 -27
  16. ledger/auth_hooks.py +2 -2
  17. ledger/constants.py +50 -177
  18. ledger/decorators.py +2 -46
  19. ledger/forms.py +133 -39
  20. ledger/helpers/billboard.py +194 -144
  21. ledger/helpers/cache.py +105 -0
  22. ledger/helpers/discord.py +2 -4
  23. ledger/helpers/eveonline.py +160 -0
  24. ledger/helpers/ledger_data.py +23 -0
  25. ledger/helpers/ref_type.py +53 -78
  26. ledger/locale/cs_CZ/LC_MESSAGES/django.mo +0 -0
  27. ledger/locale/cs_CZ/LC_MESSAGES/django.po +349 -193
  28. ledger/locale/de/LC_MESSAGES/django.mo +0 -0
  29. ledger/locale/de/LC_MESSAGES/django.po +528 -379
  30. ledger/locale/django.pot +721 -546
  31. ledger/locale/es/LC_MESSAGES/django.mo +0 -0
  32. ledger/locale/es/LC_MESSAGES/django.po +349 -194
  33. ledger/locale/fr_FR/LC_MESSAGES/django.mo +0 -0
  34. ledger/locale/fr_FR/LC_MESSAGES/django.po +349 -193
  35. ledger/locale/it_IT/LC_MESSAGES/django.mo +0 -0
  36. ledger/locale/it_IT/LC_MESSAGES/django.po +349 -193
  37. ledger/locale/ja/LC_MESSAGES/django.mo +0 -0
  38. ledger/locale/ja/LC_MESSAGES/django.po +348 -193
  39. ledger/locale/ko_KR/LC_MESSAGES/django.mo +0 -0
  40. ledger/locale/ko_KR/LC_MESSAGES/django.po +349 -193
  41. ledger/locale/nl_NL/LC_MESSAGES/django.mo +0 -0
  42. ledger/locale/nl_NL/LC_MESSAGES/django.po +349 -193
  43. ledger/locale/pl_PL/LC_MESSAGES/django.mo +0 -0
  44. ledger/locale/pl_PL/LC_MESSAGES/django.po +350 -193
  45. ledger/locale/ru/LC_MESSAGES/django.mo +0 -0
  46. ledger/locale/ru/LC_MESSAGES/django.po +348 -193
  47. ledger/locale/sk/LC_MESSAGES/django.mo +0 -0
  48. ledger/locale/sk/LC_MESSAGES/django.po +348 -193
  49. ledger/locale/uk/LC_MESSAGES/django.mo +0 -0
  50. ledger/locale/uk/LC_MESSAGES/django.po +348 -193
  51. ledger/locale/zh_Hans/LC_MESSAGES/django.mo +0 -0
  52. ledger/locale/zh_Hans/LC_MESSAGES/django.po +348 -193
  53. ledger/managers/character_audit_manager.py +28 -20
  54. ledger/managers/character_journal_manager.py +185 -357
  55. ledger/managers/character_mining_manager.py +52 -26
  56. ledger/managers/character_planetary_manager.py +178 -136
  57. ledger/managers/corporation_audit_manager.py +36 -27
  58. ledger/managers/corporation_journal_manager.py +92 -56
  59. ledger/managers/general_manager.py +8 -7
  60. ledger/migrations/0018_remove_characterplanet_ledger_char_planet__58a5b6_idx_and_more.py +44 -0
  61. ledger/migrations/0019_rename_characteraudit_characterowner_and_more.py +48 -0
  62. ledger/models/__init__.py +5 -11
  63. ledger/models/characteraudit.py +101 -109
  64. ledger/models/corporationaudit.py +94 -49
  65. ledger/models/general.py +105 -211
  66. ledger/models/helpers/update_manager.py +302 -0
  67. ledger/models/planetary.py +60 -205
  68. ledger/providers.py +101 -0
  69. ledger/static/ledger/css/{ledger.css → aa-ledger.css} +54 -28
  70. ledger/static/ledger/js/aa-ledger.js +124 -0
  71. ledger/static/ledger/js/charts.js +25 -1
  72. ledger/static/ledger/js/view-alliance-ledger.js +383 -0
  73. ledger/static/ledger/js/view-character-ledger.js +388 -0
  74. ledger/static/ledger/js/view-corporation-ledger.js +402 -0
  75. ledger/static/ledger/js/view-planetary.js +492 -0
  76. ledger/static/ledger/libs/amCharts/5.14.4/js/flow.js +2 -0
  77. ledger/static/ledger/libs/amCharts/5.14.4/js/index.js +2 -0
  78. ledger/static/ledger/libs/amCharts/5.14.4/js/percent.js +2 -0
  79. ledger/static/ledger/libs/amCharts/5.14.4/js/themes/Animated.js +2 -0
  80. ledger/static/ledger/libs/amCharts/5.14.4/js/themes/Dark.js +2 -0
  81. ledger/static/ledger/libs/amCharts/5.14.4/js/xy.js +2 -0
  82. ledger/static/ledger/libs/datatables/2.3.5/css/dataTables.bootstrap5.css +610 -0
  83. ledger/static/ledger/libs/datatables/2.3.5/js/dataTables.bootstrap5.js +122 -0
  84. ledger/static/ledger/libs/datatables/2.3.5/js/dataTables.js +14127 -0
  85. ledger/static/ledger/libs/datatables/Extensions/ColumnControl/1.1.1/css/columnControl.bootstrap5.css +516 -0
  86. ledger/static/ledger/libs/datatables/Extensions/ColumnControl/1.1.1/css/columnControl.dataTables.css +529 -0
  87. ledger/static/ledger/libs/datatables/Extensions/ColumnControl/1.1.1/js/columnControl.bootstrap5.js +73 -0
  88. ledger/static/ledger/libs/datatables/Extensions/ColumnControl/1.1.1/js/dataTables.columnControl.js +3090 -0
  89. ledger/static/ledger/libs/datatables/Extensions/FixedHeader/4.0.4/css/fixedHeader.bootstrap5.css +20 -0
  90. ledger/static/ledger/libs/datatables/Extensions/FixedHeader/4.0.4/js/dataTables.fixedHeader.js +1203 -0
  91. ledger/static/ledger/libs/datatables/Extensions/FixedHeader/4.0.4/js/fixedHeader.bootstrap5.js +59 -0
  92. ledger/tasks.py +157 -141
  93. ledger/templates/ledger/base.html +59 -21
  94. ledger/templates/ledger/bundles/aa-ledger-css.html +3 -0
  95. ledger/templates/ledger/bundles/aa-ledger-js.html +3 -0
  96. ledger/templates/ledger/bundles/view-alliance-ledger-js.html +14 -0
  97. ledger/templates/ledger/bundles/view-character-ledger-js.html +15 -0
  98. ledger/templates/ledger/bundles/view-character-planetary-css.html +3 -0
  99. ledger/templates/ledger/bundles/view-character-planetary-js.html +4 -0
  100. ledger/templates/ledger/bundles/view-corporation-ledger-js.html +15 -0
  101. ledger/templates/ledger/partials/modal/confirm.html +0 -1
  102. ledger/templates/ledger/partials/modal/request-accept-delete-alliance.html +38 -0
  103. ledger/templates/ledger/partials/modal/request-accept-delete-character.html +38 -0
  104. ledger/templates/ledger/partials/modal/request-accept-delete-corporation.html +38 -0
  105. ledger/templates/ledger/partials/modal/request-accept-switch-notification.html +38 -0
  106. ledger/templates/ledger/partials/modal/request-view-alliance-details.html +26 -0
  107. ledger/templates/ledger/partials/modal/request-view-character-details.html +26 -0
  108. ledger/templates/ledger/partials/modal/request-view-corporation-details.html +26 -0
  109. ledger/templates/ledger/partials/modal/request-view-extractor.html +32 -0
  110. ledger/templates/ledger/partials/modal/request-view-factory.html +31 -0
  111. ledger/templates/ledger/partials/{menu → navigation}/administration.html +8 -0
  112. ledger/templates/ledger/partials/{menu → navigation}/navigation.html +2 -2
  113. ledger/templates/ledger/partials/{administration → view-alliance-administration}/alliance_corporations.html +3 -3
  114. ledger/templates/ledger/partials/view-alliance-administration/dashboard.html +81 -0
  115. ledger/templates/ledger/partials/view-alliance-ledger/alliance-billboard.html +25 -0
  116. ledger/templates/ledger/partials/view-alliance-ledger/alliance-ledger-details.html +21 -0
  117. ledger/templates/ledger/partials/view-alliance-ledger/alliance-table.html +24 -0
  118. ledger/templates/ledger/partials/view-alliance-ledger/information/daily.html +18 -0
  119. ledger/templates/ledger/partials/view-alliance-ledger/information/hourly.html +18 -0
  120. ledger/templates/ledger/partials/view-alliance-ledger/information/summary.html +19 -0
  121. ledger/templates/ledger/partials/{administration → view-character-administration}/character.html +1 -9
  122. ledger/templates/ledger/partials/{administration → view-character-administration}/dashboard.html +0 -34
  123. ledger/templates/ledger/partials/view-character-ledger/character-billboard.html +25 -0
  124. ledger/templates/ledger/partials/view-character-ledger/character-ledger-details.html +21 -0
  125. ledger/templates/ledger/partials/view-character-ledger/character-table.html +25 -0
  126. ledger/templates/ledger/partials/view-character-ledger/information/daily.html +18 -0
  127. ledger/templates/ledger/partials/view-character-ledger/information/hourly.html +18 -0
  128. ledger/templates/ledger/partials/view-character-ledger/information/summary.html +19 -0
  129. ledger/templates/ledger/partials/view-character-planetary/extractor-table.html +24 -0
  130. ledger/templates/ledger/partials/view-character-planetary/factory-table.html +24 -0
  131. ledger/templates/ledger/partials/view-character-planetary/planetary-table.html +22 -0
  132. ledger/templates/ledger/partials/view-character-planetary/storage-table.html +23 -0
  133. ledger/templates/ledger/partials/{administration → view-corporation-administration}/corporation.html +5 -13
  134. ledger/templates/ledger/partials/{administration → view-corporation-administration}/corporation_characters.html +1 -1
  135. ledger/templates/ledger/partials/view-corporation-administration/dashboard.html +81 -0
  136. ledger/templates/ledger/partials/view-corporation-ledger/corporation-billboard.html +25 -0
  137. ledger/templates/ledger/partials/view-corporation-ledger/corporation-ledger-details.html +21 -0
  138. ledger/templates/ledger/partials/view-corporation-ledger/corporation-table.html +26 -0
  139. ledger/templates/ledger/partials/view-corporation-ledger/information/daily.html +18 -0
  140. ledger/templates/ledger/partials/view-corporation-ledger/information/hourly.html +18 -0
  141. ledger/templates/ledger/partials/view-corporation-ledger/information/summary.html +19 -0
  142. ledger/templates/ledger/view-administration.html +62 -0
  143. ledger/templates/ledger/view-alliance-administration.html +49 -0
  144. ledger/templates/ledger/view-alliance-ledger.html +72 -0
  145. ledger/templates/ledger/view-alliance-overview.html +131 -0
  146. ledger/templates/ledger/view-character-administration.html +42 -0
  147. ledger/templates/ledger/view-character-ledger.html +73 -0
  148. ledger/templates/ledger/view-character-overview.html +135 -0
  149. ledger/templates/ledger/view-character-planetary-overview.html +135 -0
  150. ledger/templates/ledger/view-character-planetary.html +73 -0
  151. ledger/templates/ledger/view-corporation-administration.html +42 -0
  152. ledger/templates/ledger/view-corporation-ledger.html +73 -0
  153. ledger/templates/ledger/view-corporation-overview.html +131 -0
  154. ledger/templatetags/ledger.py +3 -5
  155. ledger/tests/__init__.py +187 -0
  156. ledger/tests/test_admin.py +164 -68
  157. ledger/tests/test_auth_hook.py +31 -13
  158. ledger/tests/test_decarators.py +14 -79
  159. ledger/tests/test_discord_installed.py +0 -1
  160. ledger/tests/test_helpers/test_ledger_data.py +19 -0
  161. ledger/tests/test_managers/test_character_audit_manager.py +111 -69
  162. ledger/tests/test_managers/test_character_journal_manager.py +48 -208
  163. ledger/tests/test_managers/test_character_mining_manager.py +37 -16
  164. ledger/tests/test_managers/test_corporation_division_manager.py +66 -28
  165. ledger/tests/test_managers/test_corporation_journal_manager.py +39 -42
  166. ledger/tests/test_managers/test_general_manager.py +78 -18
  167. ledger/tests/test_managers/test_planetary_manager.py +73 -32
  168. ledger/tests/test_models/test_characteraudit.py +58 -74
  169. ledger/tests/test_models/test_characterminingledger.py +20 -26
  170. ledger/tests/test_models/test_characterwalletjournal.py +10 -33
  171. ledger/tests/test_models/test_corporationaudit.py +41 -35
  172. ledger/tests/test_models/test_corporationwalletjournal.py +35 -32
  173. ledger/tests/test_models/test_general.py +44 -11
  174. ledger/tests/test_models/test_planetary.py +14 -80
  175. ledger/tests/test_templatetags.py +2 -7
  176. ledger/tests/test_views/corporation/test_add_corp.py +16 -35
  177. ledger/tests/test_views/corporation/test_delete_corporation.py +66 -42
  178. ledger/tests/test_views/test_access.py +512 -545
  179. ledger/tests/test_views/test_add_ally.py +57 -46
  180. ledger/tests/test_views/test_add_char.py +21 -33
  181. ledger/tests/test_views/test_delete_character.py +24 -21
  182. ledger/tests/testdata/README_ESI_STUB.md +430 -0
  183. ledger/tests/testdata/esi_stub_openapi.py +511 -0
  184. ledger/tests/testdata/integrations/__init__.py +0 -0
  185. ledger/tests/testdata/{load_eveuniverse.py → integrations/eveuniverse.py} +0 -1
  186. ledger/tests/testdata/integrations/planetary.py +13 -0
  187. ledger/tests/testdata/json/factory.json +281 -0
  188. ledger/tests/testdata/json/inactive.json +281 -0
  189. ledger/tests/testdata/json/pins.json +175 -272
  190. ledger/tests/testdata/json/route.json +95 -528
  191. ledger/tests/testdata/test_esi_stub.py +468 -0
  192. ledger/tests/testdata/utils.py +601 -0
  193. ledger/thirdparty/charlink_hook.py +60 -30
  194. ledger/urls.py +0 -135
  195. ledger/views/alliance/add_ally.py +2 -4
  196. ledger/views/alliance/alliance_ledger.py +64 -147
  197. ledger/views/character/add_char.py +8 -10
  198. ledger/views/character/character_ledger.py +60 -126
  199. ledger/views/character/planetary.py +5 -98
  200. ledger/views/corporation/add_corp.py +10 -12
  201. ledger/views/corporation/corporation_ledger.py +65 -327
  202. ledger/views/index.py +92 -30
  203. aa_ledger-1.0.4.dist-info/RECORD +0 -236
  204. ledger/api/api_helper/planetary_helper.py +0 -107
  205. ledger/api/ledger/__init__.py +0 -7
  206. ledger/api/ledger/planetary.py +0 -231
  207. ledger/helpers/alliance.py +0 -317
  208. ledger/helpers/character.py +0 -251
  209. ledger/helpers/core.py +0 -665
  210. ledger/helpers/corporation.py +0 -427
  211. ledger/helpers/data_exporter.py +0 -452
  212. ledger/static/ledger/js/planetary-confirm.js +0 -66
  213. ledger/static/ledger/js/planetary.js +0 -143
  214. ledger/templates/ledger/admin.html +0 -43
  215. ledger/templates/ledger/allyledger/admin/alliance_administration.html +0 -46
  216. ledger/templates/ledger/allyledger/admin/alliance_overview.html +0 -108
  217. ledger/templates/ledger/allyledger/alliance_ledger.html +0 -86
  218. ledger/templates/ledger/bundles/character-ledger-bundles.html +0 -66
  219. ledger/templates/ledger/bundles/corporation-ledger-bundles.html +0 -75
  220. ledger/templates/ledger/bundles/ledger-bundles.html +0 -23
  221. ledger/templates/ledger/bundles/ledger-css.html +0 -3
  222. ledger/templates/ledger/bundles/planetary-bundles.html +0 -50
  223. ledger/templates/ledger/bundles/table-css.html +0 -3
  224. ledger/templates/ledger/charledger/admin/character_administration.html +0 -39
  225. ledger/templates/ledger/charledger/admin/character_overview.html +0 -106
  226. ledger/templates/ledger/charledger/character_ledger.html +0 -94
  227. ledger/templates/ledger/charledger/planetary/admin/planetary_overview.html +0 -123
  228. ledger/templates/ledger/charledger/planetary/planetary_ledger.html +0 -54
  229. ledger/templates/ledger/corpledger/admin/corporation_administration.html +0 -39
  230. ledger/templates/ledger/corpledger/admin/corporation_overview.html +0 -108
  231. ledger/templates/ledger/corpledger/corporation_ledger.html +0 -129
  232. ledger/templates/ledger/data-export.html +0 -78
  233. ledger/templates/ledger/error.html +0 -31
  234. ledger/templates/ledger/partials/form/error-message.html +0 -1
  235. ledger/templates/ledger/partials/information/daily.html +0 -56
  236. ledger/templates/ledger/partials/information/day.html +0 -48
  237. ledger/templates/ledger/partials/information/error.html +0 -8
  238. ledger/templates/ledger/partials/information/hourly.html +0 -53
  239. ledger/templates/ledger/partials/information/summary.html +0 -88
  240. ledger/templates/ledger/partials/information/view_character_content.html +0 -35
  241. ledger/templates/ledger/partials/modal/switchalarm_confirm.html +0 -39
  242. ledger/templates/ledger/partials/modal/view_extractor.html +0 -48
  243. ledger/templates/ledger/partials/modal/view_factory.html +0 -123
  244. ledger/templates/ledger/partials/table/char-ledger.html +0 -85
  245. ledger/templates/ledger/partials/table/corp-ledger.html +0 -66
  246. ledger/templates/ledger/partials/table/planetary.html +0 -18
  247. ledger/templates/ledger/partials/thirdparty/billboard.html +0 -22
  248. ledger/templates/ledger/partials/view/card.html +0 -160
  249. ledger/templates/ledger/permission.html +0 -2
  250. ledger/tests/test_helpers/test_billboard.py +0 -11
  251. ledger/tests/test_helpers/test_data_exporter.py +0 -207
  252. ledger/tests/test_tasks.py +0 -282
  253. ledger/tests/test_view_helpers/test_core.py +0 -47
  254. ledger/tests/test_views/corporation/test_corporation.py +0 -267
  255. ledger/tests/test_views/test_planetary.py +0 -137
  256. ledger/tests/testdata/esi_stub.py +0 -109
  257. ledger/tests/testdata/esi_stub_migration.py +0 -80
  258. ledger/tests/testdata/generate_characteraudit.py +0 -106
  259. ledger/tests/testdata/generate_corporationaudit.py +0 -74
  260. ledger/tests/testdata/generate_events.py +0 -31
  261. ledger/tests/testdata/generate_miningledger.py +0 -13
  262. ledger/tests/testdata/generate_planets.py +0 -48
  263. ledger/tests/testdata/generate_walletjournal.py +0 -42
  264. ledger/tests/testdata/json/czarno-pins.json +0 -240
  265. ledger/tests/testdata/json/czarno-routes.json +0 -165
  266. ledger/tests/testdata/json/pins2.json +0 -538
  267. {aa_ledger-1.0.4.dist-info → aa_ledger-2.0.0.dist-info}/WHEEL +0 -0
  268. {aa_ledger-1.0.4.dist-info → aa_ledger-2.0.0.dist-info}/licenses/LICENSE +0 -0
  269. /ledger/{tests/test_view_helpers → api/helpers}/__init__.py +0 -0
  270. /ledger/templates/ledger/bundles/{ally-administration-bundles.html → view-alliance-administration-js.html} +0 -0
  271. /ledger/templates/ledger/bundles/{char-administration-bundles.html → view-character-administration-js.html} +0 -0
  272. /ledger/templates/ledger/bundles/{corp-administration-bundles.html → view-corporation-administration-js.html} +0 -0
  273. /ledger/templates/ledger/partials/{administration → view-alliance-administration}/alliance.html +0 -0
  274. /ledger/tests/testdata/{esi.json → esi_test_data.json} +0 -0
  275. /ledger/tests/testdata/{allianceauth.json → integrations/allianceauth.json} +0 -0
  276. /ledger/tests/testdata/{load_allianceauth.py → integrations/allianceauth.py} +0 -0
  277. /ledger/tests/testdata/{eveentity.json → integrations/eveentity.json} +0 -0
  278. /ledger/tests/testdata/{load_eveentity.py → integrations/eveentity.py} +0 -0
  279. /ledger/tests/testdata/{eveuniverse.json → integrations/eveuniverse.json} +0 -0
  280. /ledger/tests/testdata/{planetary.json → integrations/planetary.json} +0 -0
@@ -0,0 +1,105 @@
1
+ # Standard Library
2
+ from hashlib import md5
3
+
4
+ # Django
5
+ from django.core.cache import cache
6
+
7
+ # Alliance Auth
8
+ from allianceauth.services.hooks import get_extension_logger
9
+
10
+ # AA Ledger
11
+ from ledger.app_settings import (
12
+ LEDGER_CACHE_ENABLED,
13
+ LEDGER_CACHE_KEY,
14
+ LEDGER_CACHE_STALE,
15
+ )
16
+ from ledger.providers import AppLogger
17
+
18
+ logger = AppLogger(get_extension_logger(__name__), "Ledger")
19
+
20
+
21
+ class CacheManager:
22
+ """
23
+ Cache Manager for Ledger Data.
24
+ """
25
+
26
+ @staticmethod
27
+ def create_ledger_hash(ids: list[int]) -> str:
28
+ """
29
+ Create a hash from a list of IDs.
30
+
31
+ Args:
32
+ ids (list[int]): List of IDs to hash.
33
+
34
+ Returns:
35
+ str: The resulting hash string.
36
+ """
37
+ hash_object = md5()
38
+
39
+ # Handle empty ID list
40
+ if not ids:
41
+ return hash_object.hexdigest()
42
+
43
+ # Ensure consistent ordering
44
+ for _id in sorted(set(ids)):
45
+ hash_object.update(f"{_id},".encode())
46
+ return hash_object.hexdigest()
47
+
48
+ @staticmethod
49
+ def build_ledger_cache_key(header_key: str) -> str:
50
+ """Build a cache key for ledger data."""
51
+ logger.debug(f"Building Ledger Cache Key for Header Key: {header_key}")
52
+ return f"{LEDGER_CACHE_KEY}-{header_key}"
53
+
54
+ def get_cache_key(self, ledger_hash: str, key: str) -> str:
55
+ """
56
+ Get the cache for ledger data.
57
+
58
+ This function retrieves the cache for ledger data using a key for identification.
59
+
60
+ Args:
61
+ ledger_hash (str): The ledger hash to identify the cache.
62
+ key (str): The specific key for the cache data.
63
+ Returns:
64
+ (str | bool): The cached ledger data or False if not found.
65
+ """
66
+ cache_header = cache.get(ledger_hash, False)
67
+
68
+ logger.debug(f"Cache Header: {cache_header}, Journal Hash: {ledger_hash}")
69
+
70
+ journal_is_up_to_date = cache_header == ledger_hash
71
+ hash_key = self.build_ledger_cache_key(ledger_hash)
72
+
73
+ if journal_is_up_to_date and LEDGER_CACHE_ENABLED:
74
+ logger.debug(f"Ledger Cache Hit: {hash_key} for Key: {key}")
75
+ cached_ledger = cache.get(f"{hash_key}-{key}", False)
76
+ return cached_ledger
77
+ return False
78
+
79
+ def set_cache_key(self, key: str, ledger_hash: str, ledger_data) -> None:
80
+ """
81
+ Set the cache for ledger data.
82
+
83
+ This function sets the cache for ledger data using a key for identification.
84
+
85
+ Args:
86
+ key: (str): The specific key for the cache data.
87
+ ledger_hash (str): The ledger hash to identify the cache.
88
+ ledger_data (LedgerResponse): The ledger data to cache.
89
+ Returns:
90
+ None
91
+ """
92
+ hash_key = self.build_ledger_cache_key(ledger_hash)
93
+
94
+ if LEDGER_CACHE_ENABLED is False:
95
+ logger.debug("Caching is Disabled")
96
+ return False
97
+
98
+ logger.debug(f"Setting Cache: {hash_key} for Key: {key}")
99
+ # Set the data in the cache
100
+ cache.set(
101
+ key=f"{hash_key}-{key}", value=ledger_data, timeout=LEDGER_CACHE_STALE
102
+ )
103
+ # Set the cache header to indicate the cache is up-to-date
104
+ cache.set(key=ledger_hash, value=ledger_hash, timeout=None)
105
+ return True
ledger/helpers/discord.py CHANGED
@@ -12,14 +12,12 @@ from allianceauth.authentication.models import User
12
12
  from allianceauth.notifications import notify
13
13
  from allianceauth.services.hooks import get_extension_logger
14
14
 
15
- # Alliance Auth (External Libs)
16
- from app_utils.logging import LoggerAddTag
17
-
18
15
  # AA Ledger
19
16
  from ledger import __title__
20
17
  from ledger.constants import DISCORD_EMBED_COLOR_MAP
18
+ from ledger.providers import AppLogger
21
19
 
22
- logger = LoggerAddTag(get_extension_logger(__name__), __title__)
20
+ logger = AppLogger(get_extension_logger(__name__), __title__)
23
21
 
24
22
 
25
23
  def allianceauth_discordbot_installed() -> bool:
@@ -0,0 +1,160 @@
1
+ """This module provides helper functions to get EVE Online related images and renders."""
2
+
3
+ # Django
4
+ from django.utils.html import format_html
5
+ from django.utils.translation import gettext_lazy as _
6
+
7
+ # Alliance Auth
8
+ from allianceauth.eveonline.evelinks.eveimageserver import (
9
+ alliance_logo_url,
10
+ character_portrait_url,
11
+ corporation_logo_url,
12
+ type_icon_url,
13
+ type_render_url,
14
+ )
15
+
16
+
17
+ def get_character_portrait_url(
18
+ character_id: int, size: int = 32, character_name: str = "", as_html: bool = False
19
+ ) -> str:
20
+ """
21
+ Get the character portrait for a character ID.
22
+
23
+ Args:
24
+ character_id (int): The ID of the character.
25
+ size (int, optional): The size of the portrait image.
26
+ character_name (str, optional): The name of the character.
27
+ as_html (bool, optional): Whether to return the portrait as an HTML img tag.
28
+ Returns:
29
+ str: The URL of the character portrait or an HTML img tag.
30
+ """
31
+ try:
32
+ render_url = character_portrait_url(character_id=character_id, size=size)
33
+ except ValueError:
34
+ return ""
35
+
36
+ if as_html:
37
+ render_html = format_html(
38
+ '<img class="character-portrait rounded-circle" src="{}" alt="{}">',
39
+ render_url,
40
+ character_name,
41
+ )
42
+ return render_html
43
+ return render_url
44
+
45
+
46
+ def get_corporation_logo_url(
47
+ corporation_id: int,
48
+ size: int = 32,
49
+ corporation_name: str = "",
50
+ as_html: bool = False,
51
+ ) -> str:
52
+ """
53
+ Get the corporation logo for a corporation ID.
54
+
55
+ Args:
56
+ corporation_id (int): The ID of the corporation.
57
+ size (int, optional): The size of the logo image.
58
+ corporation_name (str, optional): The name of the corporation.
59
+ as_html (bool, optional): Whether to return the logo as an HTML img tag.
60
+ Returns:
61
+ str: The URL of the corporation logo or an HTML img tag.
62
+ """
63
+
64
+ render_url = corporation_logo_url(corporation_id=corporation_id, size=size)
65
+
66
+ if as_html:
67
+ render_html = format_html(
68
+ '<img class="corporation-logo rounded-circle" src="{}" alt="{}">',
69
+ render_url,
70
+ corporation_name,
71
+ )
72
+ return render_html
73
+ return render_url
74
+
75
+
76
+ def get_alliance_logo_url(
77
+ alliance_id: int,
78
+ size: int = 32,
79
+ alliance_name: str = "",
80
+ as_html: bool = False,
81
+ ) -> str:
82
+ """
83
+ Get the alliance logo for a alliance ID.
84
+
85
+ Args:
86
+ alliance_id (int): The ID of the alliance.
87
+ size (int, optional): The size of the logo image.
88
+ alliance_name (str, optional): The name of the alliance.
89
+ as_html (bool, optional): Whether to return the logo as an HTML img tag.
90
+
91
+ Returns:
92
+ str: The URL of the alliance logo or an HTML img tag.
93
+ """
94
+
95
+ render_url = alliance_logo_url(alliance_id=alliance_id, size=size)
96
+
97
+ if as_html:
98
+ render_html = format_html(
99
+ '<img class="alliance-logo rounded-circle" src="{}" alt="{}">',
100
+ render_url,
101
+ alliance_name,
102
+ )
103
+ return render_html
104
+ return render_url
105
+
106
+
107
+ def get_type_render_url(
108
+ type_id: int, size: int = 32, type_name: str = "", as_html: bool = False
109
+ ) -> str:
110
+ """
111
+ Get the type render for a type ID.
112
+
113
+ Args:
114
+ type_id (int): The ID of the type.
115
+ size (int, optional): The size of the render image.
116
+ type_name (str, optional): The name of the type.
117
+ as_html (bool): Whether to return the render as an HTML img tag.
118
+
119
+ Returns:
120
+ str: The URL of the type render or an HTML img tag.
121
+ """
122
+
123
+ render_url = type_render_url(type_id=type_id, size=size)
124
+
125
+ if as_html:
126
+ render_html = format_html(
127
+ '<img class="type-render rounded-circle" src="{}" alt="{}">',
128
+ render_url,
129
+ type_name,
130
+ )
131
+ return render_html
132
+ return render_url
133
+
134
+
135
+ def get_icon_render_url(
136
+ type_id: int, size: int = 32, type_name: str = "", as_html: bool = False
137
+ ) -> str:
138
+ """
139
+ Get the icon render for a type ID.
140
+
141
+ Args:
142
+ type_id (int): The ID of the type.
143
+ size (int, optional): The size of the icon image.
144
+ type_name (str, optional): The name of the type.
145
+ as_html (bool): Whether to return the icon as an HTML img tag.
146
+
147
+ Returns:
148
+ str: The URL of the type icon or an HTML img tag.
149
+ """
150
+
151
+ render_url = type_icon_url(type_id=type_id, size=size)
152
+
153
+ if as_html:
154
+ render_html = format_html(
155
+ '<img class="type-render rounded-circle" data-bs-tooltip="aa-ledger" src="{}" title="{}">',
156
+ render_url,
157
+ type_name,
158
+ )
159
+ return render_html
160
+ return render_url
@@ -0,0 +1,23 @@
1
+ # Standard Library
2
+ from decimal import Decimal
3
+
4
+
5
+ def get_footer_text_class(value: int | float | Decimal, mining=False) -> str:
6
+ """Get the text class for a value.
7
+
8
+ A positive value will return "text-success", a negative value will return "text-danger", and a zero value will return an empty string.
9
+ If the value is related to mining, a positive value will return "text-primary" instead of "text-success".
10
+
11
+ Args:
12
+ value (int | float | Decimal): The value to get the text class for.
13
+ mining (bool, optional): Whether the value is related to mining. Defaults to False.
14
+ Returns:
15
+ str: The text class for the value.
16
+ """
17
+ if value > 0:
18
+ if mining:
19
+ return "text-info"
20
+ return "text-success"
21
+ if value < 0:
22
+ return "text-danger"
23
+ return ""
@@ -2,25 +2,19 @@
2
2
 
3
3
  # Standard Library
4
4
  import enum
5
- from typing import TYPE_CHECKING
6
5
 
7
6
  # Django
8
- from django.utils.translation import gettext as _
7
+ from django.db import models
8
+ from django.utils.translation import gettext_lazy as _
9
9
 
10
10
  # Alliance Auth
11
11
  from allianceauth.services.hooks import get_extension_logger
12
12
 
13
- # Alliance Auth (External Libs)
14
- from app_utils.logging import LoggerAddTag
15
-
16
13
  # AA Ledger
17
14
  from ledger import __title__
15
+ from ledger.providers import AppLogger
18
16
 
19
- if TYPE_CHECKING:
20
- # AA Ledger
21
- from ledger.helpers.core import LedgerEntity
22
-
23
- logger = LoggerAddTag(get_extension_logger(__name__), __title__)
17
+ logger = AppLogger(get_extension_logger(__name__), __title__)
24
18
 
25
19
 
26
20
  # Unified Journal Reference Type Enum - All ref types in one place
@@ -192,13 +186,30 @@ class JournalRefType(enum.Enum):
192
186
  class RefTypeManager:
193
187
  """Categories for wallet journal reference types."""
194
188
 
195
- # Translations for reference types
196
- _("Corporation Contract")
197
- _("Corporation Withdrawal")
198
- _("Mission Reward")
199
- _("Market")
200
- _("Daily Goal Reward")
201
- _("Structure Rental")
189
+ class CategoryChoice(models.TextChoices):
190
+ BOUNTY = "BOUNTY", _("Bounty")
191
+ ESS = "ESS", _("ESS")
192
+ ASSETS = "ASSETS", _("Assets")
193
+ CONTRACT = "CONTRACT", _("Contract")
194
+ CORPORATION_ADMINISTRATION = "CORPORATION_ADMINISTRATION", _(
195
+ "Corporation Administration"
196
+ )
197
+ CORPORATION_CONTRACT = "CORPORATION_CONTRACT", _("Corporation Contract")
198
+ CORPORATION_WITHDRAWAL = "CORPORATION_WITHDRAWAL", _("Corporation Withdrawal")
199
+ DAILY_GOAL_REWARD = "DAILY_GOAL_REWARD", _("Daily Goal Reward")
200
+ DONATION = "DONATION", _("Donation")
201
+ FREELANCE_JOBS = "FREELANCE_JOBS", _("Freelance Jobs")
202
+ INCURSION = "INCURSION", _("Incursion")
203
+ INSURANCE = "INSURANCE", _("Insurance")
204
+ LP = "LP", _("LP Store")
205
+ MARKET = "MARKET", _("Market")
206
+ MISSION_REWARD = "MISSION_REWARD", _("Mission Reward")
207
+ PLANETARY = "PLANETARY", _("Planetary Interaction")
208
+ PRODUCTION = "PRODUCTION", _("Production")
209
+ SKILL = "SKILL", _("Skill Training")
210
+ STRUCTURE_RENTAL = "STRUCTURE_RENTAL", _("Structure Rental")
211
+ TRAVELING = "TRAVELING", _("Traveling Fees")
212
+ UNDEFINED = "UNDEFINED", _("Undefined")
202
213
 
203
214
  # Assets/Items
204
215
  ASSETS = [
@@ -372,6 +383,8 @@ class RefTypeManager:
372
383
  def get_all_categories(cls) -> dict[str, list[str]]:
373
384
  """Get all categories and their ref types, sorted alphabetically by key in the dict literal. Add NO_CATEGORY for missing JournalRefType."""
374
385
  categories = {
386
+ "BOUNTY": cls.BOUNTY_PRIZES,
387
+ "ESS": cls.ESS_TRANSFER,
375
388
  "ASSETS": cls.ASSETS,
376
389
  "CONTRACT": cls.CONTRACT,
377
390
  "CORPORATION_ADMINISTRATION": cls.CORPORATION_ADMINISTRATION,
@@ -400,76 +413,38 @@ class RefTypeManager:
400
413
  # Alle JournalRefType-Namen in Kleinbuchstaben
401
414
  all_types = {jt.name.lower() for jt in JournalRefType}
402
415
 
403
- # Exclude Bounty and ESS
404
- pve = set()
405
- # Bounty-Prizes
406
- if hasattr(cls, "BOUNTY_PRIZES"):
407
- pve.update(cls.BOUNTY_PRIZES)
408
- # ESS Transfer
409
- if hasattr(cls, "ESS_TRANSFER"):
410
- pve.update(cls.ESS_TRANSFER)
411
-
412
416
  # Nicht zugeordnete Typen bestimmen, aber special auslassen
413
- not_defined = sorted((all_types - assigned) - pve)
417
+ not_defined = sorted(all_types - assigned)
414
418
  if not_defined:
415
- categories["NOT_DEFINED_CATEGORY"] = not_defined
419
+ categories["UNDEFINED"] = not_defined
416
420
 
417
421
  return categories
418
422
 
419
423
  @classmethod
420
- def all_ref_types(cls) -> list[str]:
421
- """Get all ref types from all categories."""
424
+ def ledger_ref_types(cls) -> list[str]:
425
+ """
426
+ Get all ref types from all categories.
427
+
428
+ This is used to filter journal entries for ledger processing.
429
+
430
+ Excluding Bounty Prizes and ESS transfers for specific handling.
431
+ """
422
432
  all_ref_types = cls.get_all_categories()
423
433
  ref_types_items = []
424
434
  for __, ref_types in all_ref_types.items():
435
+ if __ in ["BOUNTY", "ESS"]:
436
+ continue
425
437
  ref_types_items.extend(ref_types)
426
438
  return ref_types_items
427
439
 
428
- @staticmethod
429
- def special_cases(row: dict, ids: set[int], account_char_ids: set[int]) -> bool:
430
- """Handle special cases in Ledger."""
431
- if isinstance(row, dict) is False:
432
- logger.debug("Row is not a dictionary, skipping special case checks.")
433
- return False
434
-
435
- # Skip Market Transactions from buyer between the corporation and its members (only count transactions from creator)
436
- if row["ref_type"] == "market_transaction" and row["first_party_id"] in ids:
437
- return True
438
-
439
- # Skip Contract if Contract Creator is Registered as a Member of the Corporation (only count the contract creator)
440
- if (
441
- row["ref_type"] == "contract_price_payment_corp"
442
- and row["first_party_id"] in account_char_ids
443
- and row["second_party_id"] in ids
444
- ):
445
- return True
446
- return False
447
-
448
- @staticmethod
449
- def special_cases_details(
450
- value: list,
451
- entity: "LedgerEntity",
452
- kwargs: dict[str, int],
453
- journal_type: str,
454
- char_ids: set[int] = None,
455
- ) -> bool:
456
- """Handle special cases in Ledger for Details View."""
457
- # Skip Contract if Contract Creator is Registered as a Member of the Corporation (only count the contract creator)
458
- if (
459
- "contract_price_payment_corp" in value
460
- and entity.type == "character"
461
- and journal_type == "corporation"
462
- ): # Only Count Contract Creator
463
- kwargs["first_party"] = entity.entity_id
464
- return kwargs
465
-
466
- # Skip Player Donation if it is to own alts
467
- if (
468
- "player_donation" in value
469
- and entity.is_eve_character
470
- and journal_type == "character"
471
- ):
472
- if char_ids is None:
473
- return kwargs
474
- kwargs["exclude"] = char_ids
475
- return kwargs
440
+ @classmethod
441
+ def all_ref_types(cls) -> list[str]:
442
+ """
443
+ Get all ref types from all categories.
444
+ This is used to get a complete list of all reference types.
445
+ """
446
+ all_ref_types = cls.get_all_categories()
447
+ ref_types_items = []
448
+ for __, ref_types in all_ref_types.items():
449
+ ref_types_items.extend(ref_types)
450
+ return ref_types_items
Binary file