pretix-map 0.1.0__py3-none-any.whl → 0.1.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.
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/METADATA +3 -1
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/RECORD +8 -8
- pretix_mapplugin/__init__.py +1 -1
- pretix_mapplugin/tasks.py +60 -60
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/WHEEL +0 -0
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/entry_points.txt +0 -0
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/licenses/LICENSE +0 -0
- {pretix_map-0.1.0.dist-info → pretix_map-0.1.1.dist-info}/top_level.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: pretix-map
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: An overview map of the catchment area of previous orders. Measured by postcode
|
5
5
|
Author-email: MarkenJaden <jjsch1410@gmail.com>
|
6
6
|
Maintainer-email: MarkenJaden <jjsch1410@gmail.com>
|
@@ -140,10 +140,12 @@ This command is essential for processing orders that were placed *before* the ma
|
|
140
140
|
**Example Workflow:**
|
141
141
|
|
142
142
|
1. **Test with Dry Run (All Organizers):**
|
143
|
+
|
143
144
|
.. code-block:: bash
|
144
145
|
|
145
146
|
python manage.py geocode_existing_orders --dry-run
|
146
147
|
2. **(If satisfied) Run for Real (All Organizers):**
|
148
|
+
|
147
149
|
.. code-block:: bash
|
148
150
|
|
149
151
|
python manage.py geocode_existing_orders
|
@@ -1,10 +1,10 @@
|
|
1
|
-
pretix_map-0.1.
|
2
|
-
pretix_mapplugin/__init__.py,sha256=
|
1
|
+
pretix_map-0.1.1.dist-info/licenses/LICENSE,sha256=RhQ89ePNDClBzEROahhwjDrBSEb5Zpx6XewZfGlY4Ss,569
|
2
|
+
pretix_mapplugin/__init__.py,sha256=5xvN_gb61nKeq5TER5dSfcArTP3DVasZGN_MQq5dNpA,23
|
3
3
|
pretix_mapplugin/apps.py,sha256=AnThwyRw2AAz5f-kmXZ8hm85OmKnlDkRosVoQOBgPzE,830
|
4
4
|
pretix_mapplugin/geocoding.py,sha256=lBmwMvmE_cPyOHxWE8H3Se2P-2Eq0UjDTCv9gUs97Fo,4018
|
5
5
|
pretix_mapplugin/models.py,sha256=v0v9K0sb5OQHs5Gc6-jea_aEGECUQp1tZoYMwwb3YIM,994
|
6
6
|
pretix_mapplugin/signals.py,sha256=maBMMSq5M7diy_EaNgKr8KRfGFj0U437u-MEl2NVYBw,3661
|
7
|
-
pretix_mapplugin/tasks.py,sha256=
|
7
|
+
pretix_mapplugin/tasks.py,sha256=Blpleq0J3Sos7LDEXpH3EOkZcqE2y4VSiZDLyC2YWgU,4411
|
8
8
|
pretix_mapplugin/urls.py,sha256=o5407vULF4S-bUihU7AeRxUcMyazg2lPjbvqRflsGxE,838
|
9
9
|
pretix_mapplugin/views.py,sha256=7WgmNZeqwmOesT6PrkAIRC8fNfAcWGm-j9-2YqF5egI,7146
|
10
10
|
pretix_mapplugin/locale/de/LC_MESSAGES/django.mo,sha256=6VVRAqa0ixL-lDA1QwoVvG0wd5ZBwYjaR4P8T73hxhU,269
|
@@ -39,8 +39,8 @@ pretix_mapplugin/static/pretix_mapplugin/libs/leaflet-sales-map/images/marker-ic
|
|
39
39
|
pretix_mapplugin/static/pretix_mapplugin/libs/leaflet-sales-map/images/marker-shadow.png,sha256=Jk9cZAM58ELdcpBiz8BMF_jqDymIK1OOOEjtjxDttNo,618
|
40
40
|
pretix_mapplugin/templates/pretix_mapplugin/.gitkeep,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
41
41
|
pretix_mapplugin/templates/pretix_mapplugin/map_page.html,sha256=jUfPrCkwcbcTXgZ2d9a5wpUD1U7Y8g5rnB20hklKQ-k,2252
|
42
|
-
pretix_map-0.1.
|
43
|
-
pretix_map-0.1.
|
44
|
-
pretix_map-0.1.
|
45
|
-
pretix_map-0.1.
|
46
|
-
pretix_map-0.1.
|
42
|
+
pretix_map-0.1.1.dist-info/METADATA,sha256=az-2dh7UXVgqNYPr2ubPxeKnM2rBsRCNeyqb_V0pMiM,9518
|
43
|
+
pretix_map-0.1.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
44
|
+
pretix_map-0.1.1.dist-info/entry_points.txt,sha256=C3NAjeZHoCekafkLMCJynPcABRTK8AUprtQv7sUNDZs,137
|
45
|
+
pretix_map-0.1.1.dist-info/top_level.txt,sha256=CAtEnkgA73zE9Gadm5mjt1SpXHBPOS-QWP0dQVoNToE,17
|
46
|
+
pretix_map-0.1.1.dist-info/RECORD,,
|
pretix_mapplugin/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.1.
|
1
|
+
__version__ = "0.1.1"
|
pretix_mapplugin/tasks.py
CHANGED
@@ -2,89 +2,89 @@ import logging
|
|
2
2
|
from django.db import transaction
|
3
3
|
from django.core.exceptions import ObjectDoesNotExist
|
4
4
|
|
5
|
+
# --- Import django-scopes ---
|
6
|
+
from django_scopes import scope
|
7
|
+
|
5
8
|
# --- Use Pretix Celery app instance ---
|
6
9
|
from pretix.celery_app import app
|
7
10
|
# --- Import necessary Pretix models ---
|
8
|
-
from pretix.base.models import Order
|
11
|
+
from pretix.base.models import Order, Organizer # Import Organizer
|
9
12
|
|
10
13
|
# --- Import your Geocode model and geocoding functions ---
|
11
14
|
from .models import OrderGeocodeData
|
12
15
|
from .geocoding import (
|
13
16
|
get_formatted_address_from_order,
|
14
17
|
geocode_address,
|
15
|
-
DEFAULT_NOMINATIM_USER_AGENT
|
18
|
+
DEFAULT_NOMINATIM_USER_AGENT
|
16
19
|
)
|
17
20
|
|
18
21
|
logger = logging.getLogger(__name__)
|
19
22
|
|
20
23
|
|
21
|
-
# Define the Celery task
|
22
|
-
# bind=True gives access to self (the task instance) for retrying
|
23
|
-
# ignore_result=True as we don't need the return value stored in Celery backend
|
24
24
|
@app.task(bind=True, max_retries=3, default_retry_delay=60, ignore_result=True)
|
25
|
-
def geocode_order_task(self, order_pk: int,
|
26
|
-
nominatim_user_agent: str | None = None): # Added nominatim_user_agent kwarg
|
25
|
+
def geocode_order_task(self, order_pk: int, nominatim_user_agent: str | None = None):
|
27
26
|
"""
|
28
27
|
Celery task to geocode the address for a given order PK.
|
29
28
|
Accepts the Nominatim User-Agent as an argument.
|
29
|
+
Activates django-scopes organizer scope before querying scoped models.
|
30
30
|
"""
|
31
|
+
order = None # Initialize order to None
|
31
32
|
try:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
try:
|
34
|
+
order = Order.objects.select_related('event__organizer', 'invoice_address').get(pk=order_pk)
|
35
|
+
organizer = order.event.organizer # Get organizer from the fetched order
|
36
|
+
except ObjectDoesNotExist:
|
37
|
+
logger.error(f"Order with PK {order_pk} not found in geocode_order_task.")
|
38
|
+
return
|
39
|
+
with scope(organizer=organizer):
|
40
|
+
logger.info(
|
41
|
+
f"Starting geocoding task for Order {order.code} (PK: {order_pk}) within scope of Organizer '{organizer.slug}'")
|
37
42
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
return # Exit successfully
|
43
|
+
relation_name = 'geocode_data' # Ensure this matches your model
|
44
|
+
# Check existence within scope (safer)
|
45
|
+
if OrderGeocodeData.objects.filter(order_id=order_pk).exists():
|
46
|
+
logger.info(f"Geocode data already exists for Order {order.code} (checked within scope). Skipping.")
|
47
|
+
return
|
44
48
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
)
|
55
|
-
return # Exit successfully, nothing to geocode
|
49
|
+
address_str = get_formatted_address_from_order(order)
|
50
|
+
if not address_str:
|
51
|
+
logger.info(f"Order {order.code} has no address suitable for geocoding. Storing null coordinates.")
|
52
|
+
# Store null within scope
|
53
|
+
with transaction.atomic():
|
54
|
+
OrderGeocodeData.objects.update_or_create(
|
55
|
+
order=order, defaults={'latitude': None, 'longitude': None}
|
56
|
+
)
|
57
|
+
return
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
coordinates = geocode_address(address_str, nominatim_user_agent=nominatim_user_agent)
|
59
|
+
logger.debug(f"Attempting to geocode address for Order {order.code}: '{address_str}'")
|
60
|
+
coordinates = geocode_address(address_str, nominatim_user_agent=nominatim_user_agent)
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
logger.log(log_level,
|
81
|
-
f"Saved{' new' if created else ' updated'} null geocode data for Order {order.code} after failed attempt.")
|
62
|
+
# Store result within scope
|
63
|
+
with transaction.atomic():
|
64
|
+
if coordinates:
|
65
|
+
latitude, longitude = coordinates
|
66
|
+
obj, created = OrderGeocodeData.objects.update_or_create(
|
67
|
+
order=order, defaults={'latitude': latitude, 'longitude': longitude}
|
68
|
+
)
|
69
|
+
log_level = logging.INFO if created else logging.DEBUG
|
70
|
+
logger.log(log_level,
|
71
|
+
f"Saved{' new' if created else ' updated'} geocode data for Order {order.code}: ({latitude}, {longitude})")
|
72
|
+
else:
|
73
|
+
logger.warning(f"Geocoding failed for Order {order.code}. Storing null coordinates.")
|
74
|
+
obj, created = OrderGeocodeData.objects.update_or_create(
|
75
|
+
order=order, defaults={'latitude': None, 'longitude': None}
|
76
|
+
)
|
77
|
+
log_level = logging.INFO if created else logging.DEBUG
|
78
|
+
logger.log(log_level,
|
79
|
+
f"Saved{' new' if created else ' updated'} null geocode data for Order {order.code} after failed attempt.")
|
80
|
+
# --- Scope deactivated automatically here ---
|
82
81
|
|
83
|
-
|
84
|
-
|
85
|
-
#
|
82
|
+
# Keep outer exception handling
|
83
|
+
except ObjectDoesNotExist:
|
84
|
+
# This case is now handled earlier, but keep for safety
|
85
|
+
logger.error(f"Order with PK {order_pk} not found outside scope handling.")
|
86
86
|
except Exception as e:
|
87
|
-
|
88
|
-
|
89
|
-
# Retry on
|
90
|
-
raise self.retry(exc=e)
|
87
|
+
logger.exception(
|
88
|
+
f"Unexpected error in geocode_order_task for Order PK {order_pk} (potentially outside scope): {e}")
|
89
|
+
# Retry on unexpected errors before scope activation
|
90
|
+
raise self.retry(exc=e)
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|