aa-structures 2.14.1__py3-none-any.whl → 2.15.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aa-structures
3
- Version: 2.14.1
3
+ Version: 2.15.0
4
4
  Summary: App for managing Eve Online structures with Alliance Auth.
5
5
  Author-email: Erik Kalkoken <kalkoken87@gmail.com>
6
6
  Requires-Python: >=3.8
@@ -1,5 +1,5 @@
1
- structures/__init__.py,sha256=AKjtjd55mt0eK2ld7jC0D_ZbzHd-XxjqCBgxuBaz_vQ,204
2
- structures/admin.py,sha256=cA04JFghU-zIGC168fhZ5Hj_FYAQxlF6TFVDb8sgO4A,40066
1
+ structures/__init__.py,sha256=DW_FAyoVYr5DMbDmmJQ_yaBVMMVB07QHRZP71oApKTA,204
2
+ structures/admin.py,sha256=K7wh8mHFfGHONn7oLdqXsBAxq0rmYrwbZ7S3uIOuMtg,41303
3
3
  structures/app_settings.py,sha256=aWA2bTcv_vVwIyisx-G7GBSpfM6JDyt2MWcXKtHnjK0,6651
4
4
  structures/apps.py,sha256=MNZH9l3qWCwuS7OGiKGkBVrDzKoOFlqwDdEgyEFzxVA,195
5
5
  structures/auth_hooks.py,sha256=nRbrixFkAE5gphDokB1E8xhH8FY2VtXVwu0XMmSGBAw,1013
@@ -160,7 +160,7 @@ structures/templates/structures/templatetags/list_title.html,sha256=C2NWwo27TGfG
160
160
  structures/templatetags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  structures/templatetags/structures.py,sha256=vSt5AnfYuo11q1SxiskT4oshSMsZ9ZgM0nYpYiMl8bA,1637
162
162
  structures/tests/__init__.py,sha256=9MrJzKr8DdsQY3-79v188pTpwqT4TDQ46vKnBJAGqic,75
163
- structures/tests/test_admin.py,sha256=cb_AbOanp31k-oZhaUXCqnlkUu87EgNddq_VQKbB_Dk,26839
163
+ structures/tests/test_admin.py,sha256=aDd88Ry0ahitpYyF_wa1jG_pWJ5m5w3jsat45sBhEmo,27493
164
164
  structures/tests/test_helpers.py,sha256=BQC-4H-9-v5qW4nugqy0bkxuGlA3UO2clYY2lI2LjoY,4893
165
165
  structures/tests/test_managers_1.py,sha256=4dnlK7Le04eJUPjJc9ex5BxZWIJGAyEvdKuuYXU2gqY,34846
166
166
  structures/tests/test_managers_2.py,sha256=FISr_NT1Qnu9j1JYYTceNsUk8k9rfCTKwjKi5WUVbPs,3025
@@ -217,13 +217,13 @@ structures/views/statistics.py,sha256=7jj8b9ATsYwE7Cg6gMp-bYx29nV43GdWYun9WBggGk
217
217
  structures/views/status.py,sha256=gcahbk6dPIZDqkaNHDAsEHyDWLzicTK18Fom0A6xx3c,718
218
218
  structures/views/structures.py,sha256=Wb57jFfRa0Zxo6TxKmOCQ-jtopzPtHe0go6gnJn40CA,22584
219
219
  structures/webhooks/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
220
- structures/webhooks/core.py,sha256=mP25MbQG8Yv2YayDFcR6x2V30eqXhR2q5u4SRefblf4,6573
220
+ structures/webhooks/core.py,sha256=kvbMQ_kjJleQanlFFoiN52wIkBG_4u0ONfcHfCU5lgA,6604
221
221
  structures/webhooks/managers.py,sha256=L3G3AmsyDeif_lfpWshmAxQ61UGJ9w8i9lZaF2jbOtQ,1117
222
222
  structures/webhooks/models.py,sha256=kUkt9rnRQIJIrU9Bjcs34rvkb-TMbUubHdn-kny08kI,2067
223
223
  structures/webhooks/tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
224
224
  structures/webhooks/tests/test_core.py,sha256=4NcEAQgK2KhQkFOxYh2ad0S-qUWh1DNGDmLo5Mo5opI,6762
225
225
  structures/webhooks/tests/test_utils.py,sha256=ekADFv0JOEtXeqdiejbeqrABO__Q1flJHzVieQ7L9e0,459
226
- aa_structures-2.14.1.dist-info/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
227
- aa_structures-2.14.1.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
228
- aa_structures-2.14.1.dist-info/METADATA,sha256=9vdeZ6CyZ-97fnE0YXmYsN_w_T8TUBRfj840AVZgN0w,5972
229
- aa_structures-2.14.1.dist-info/RECORD,,
226
+ aa_structures-2.15.0.dist-info/LICENSE,sha256=XZiwB_S_40_HhnvLg5xvtBb3g1oGjPrk0rpFwk8iInE,1070
227
+ aa_structures-2.15.0.dist-info/WHEEL,sha256=EZbGkh7Ie4PoZfRQ8I0ZuP9VklN_TvcZ6DSE5Uar4z4,81
228
+ aa_structures-2.15.0.dist-info/METADATA,sha256=UZGw51TIsMgIdznKyyE9prBvlgDQQpJ3k3z4Url-DEE,5972
229
+ aa_structures-2.15.0.dist-info/RECORD,,
structures/__init__.py CHANGED
@@ -3,5 +3,5 @@
3
3
  # pylint: disable = invalid-name
4
4
  default_app_config = "structures.apps.StructuresConfig"
5
5
 
6
- __version__ = "2.14.1"
6
+ __version__ = "2.15.0"
7
7
  __title__ = "Structures"
structures/admin.py CHANGED
@@ -1,10 +1,13 @@
1
1
  """Admin site for Structures."""
2
2
 
3
+ import functools
3
4
  import statistics
4
5
  from typing import Optional
5
6
 
7
+ from django import forms
6
8
  from django.conf import settings
7
9
  from django.contrib import admin
10
+ from django.contrib.admin.widgets import FilteredSelectMultiple
8
11
  from django.db import models
9
12
  from django.db.models import Prefetch
10
13
  from django.db.models.functions import Lower
@@ -1028,8 +1031,44 @@ class StructureAdmin(admin.ModelAdmin):
1028
1031
  )
1029
1032
 
1030
1033
 
1034
+ class WebhookAdminForm(forms.ModelForm):
1035
+ owners = forms.ModelMultipleChoiceField(
1036
+ queryset=Owner.objects.order_by(Lower("corporation__corporation_name")),
1037
+ required=False,
1038
+ widget=FilteredSelectMultiple(verbose_name=_("Users"), is_stacked=False),
1039
+ )
1040
+
1041
+ def __init__(self, *args, **kwargs):
1042
+ super().__init__(*args, **kwargs)
1043
+
1044
+ if self.instance and self.instance.pk:
1045
+ self.fields["owners"].initial = self.instance.owners.all()
1046
+
1047
+ def save(self, commit=True):
1048
+ webhook: Webhook = super().save(commit=False)
1049
+
1050
+ if commit:
1051
+ webhook.save()
1052
+
1053
+ owners = self.cleaned_data["owners"]
1054
+ if webhook.pk:
1055
+ self._save_m2m_and_users(webhook, owners)
1056
+ else:
1057
+ self.save_m2m = functools.partial(
1058
+ self._save_m2m_and_users, webhook=webhook, owners=owners
1059
+ )
1060
+
1061
+ return webhook
1062
+
1063
+ def _save_m2m_and_users(self, webhook, owners):
1064
+ """Save m2m relations incl. users."""
1065
+ webhook.owners.set(owners)
1066
+ self._save_m2m()
1067
+
1068
+
1031
1069
  @admin.register(Webhook)
1032
1070
  class WebhookAdmin(admin.ModelAdmin):
1071
+ form = WebhookAdminForm
1033
1072
  list_display = (
1034
1073
  "name",
1035
1074
  "_ping_groups",
@@ -1057,6 +1096,7 @@ class WebhookAdmin(admin.ModelAdmin):
1057
1096
  "name",
1058
1097
  "url",
1059
1098
  "notes",
1099
+ "owners",
1060
1100
  "notification_types",
1061
1101
  "ping_groups",
1062
1102
  "is_active",
@@ -719,3 +719,22 @@ class TestWebhookAdmin(TestCase):
719
719
  webhook.refresh_from_db()
720
720
  self.assertFalse(webhook.is_active)
721
721
  self.assertTrue(mock_message_user.called)
722
+
723
+ def test_can_assign_owner(self):
724
+ # given
725
+ owner = OwnerFactory()
726
+ webhook = WebhookFactory()
727
+ self.client.force_login(self.user)
728
+ data = {
729
+ "name": webhook.name,
730
+ "notification_types": NotificationType.webhook_defaults(),
731
+ "owners": [owner.pk],
732
+ "url": webhook.url,
733
+ "webhook_type": webhook.webhook_type,
734
+ }
735
+ r = self.client.post(
736
+ f"/admin/structures/webhook/{webhook.pk}/change/", data=data
737
+ )
738
+ self.assertEqual(r.status_code, 302)
739
+ webhook.refresh_from_db()
740
+ self.assertIn(owner, webhook.owners.all())
@@ -61,7 +61,7 @@ class DiscordWebhookMixin:
61
61
 
62
62
  return counter
63
63
 
64
- # pylint: disable = too-many-arguments
64
+ # pylint: disable = too-many-positional-arguments, too-many-arguments
65
65
  def send_message(
66
66
  self,
67
67
  content: Optional[str] = None,