mirror of
https://github.com/pretix/pretix.git
synced 2026-08-11 10:57:00 +00:00
Rename mapping.pk -> mapping.id
This commit is contained in:
@@ -75,7 +75,7 @@ shown. Therein, a ``sync_object_with_properties`` method is defined like as foll
|
||||
.. code-block:: python
|
||||
|
||||
def sync_object_with_properties(
|
||||
self, identifier_field, identifier_value, properties: list, inputs: dict,
|
||||
self, external_id_field, id_value, properties: list, inputs: dict,
|
||||
mapping, mapped_objects: dict, **kwargs,
|
||||
):
|
||||
# First, we query the external service if our object-to-sync already exists there.
|
||||
@@ -83,8 +83,8 @@ shown. Therein, a ``sync_object_with_properties`` method is defined like as foll
|
||||
# data gracefully.
|
||||
pre_existing_object = self.fake_api_client.retrieve_object(
|
||||
mapping.external_object_type,
|
||||
identifier_field,
|
||||
identifier_value
|
||||
external_id_field,
|
||||
id_value
|
||||
)
|
||||
|
||||
# We use the helper function ``assign_properties`` to update a pre-existing object.
|
||||
@@ -100,21 +100,21 @@ shown. Therein, a ``sync_object_with_properties`` method is defined like as foll
|
||||
# other properties.
|
||||
result = self.fake_api_client.create_or_update_object(mapping.external_object_type, {
|
||||
**update_values,
|
||||
identifier_field: identifier_value,
|
||||
external_id_field: id_value,
|
||||
"_id": pre_existing_object and pre_existing_object.get("_id"),
|
||||
})
|
||||
|
||||
# Finally, return a dictionary containing at least `object_type`, `identifier_field`,
|
||||
# `identifier_value`, `external_link_href`, and `external_link_display_name` keys.
|
||||
# Finally, return a dictionary containing at least `object_type`, `external_id_field`,
|
||||
# `id_value`, `external_link_href`, and `external_link_display_name` keys.
|
||||
# Further keys may be provided for your internal use. This dictionary is provided
|
||||
# in following calls in the ``mapped_objects`` dict, to allow creating associations
|
||||
# to this object.
|
||||
return {
|
||||
"object_type": mapping.external_object_type,
|
||||
"identifier_field": identifier_field,
|
||||
"identifier_value": identifier_value,
|
||||
"external_link_href": f"https://example.org/external-system/{mapping.external_object_type}/{identifier_value}/",
|
||||
"external_link_display_name": f"Contact #{identifier_value} - Jane Doe",
|
||||
"external_id_field": external_id_field,
|
||||
"id_value": id_value,
|
||||
"external_link_href": f"https://example.org/external-system/{mapping.external_object_type}/{id_value}/",
|
||||
"external_link_display_name": f"Contact #{id_value} - Jane Doe",
|
||||
"my_result": result,
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class RecoverableSyncError(BaseSyncError):
|
||||
pass
|
||||
|
||||
|
||||
StaticMapping = namedtuple('StaticMapping', ('pk', 'pretix_model', 'external_object_type', 'pretix_id_field', 'external_id_field', 'property_mapping'))
|
||||
StaticMapping = namedtuple('StaticMapping', ('id', 'pretix_model', 'external_object_type', 'pretix_id_field', 'external_id_field', 'property_mapping'))
|
||||
|
||||
|
||||
class OutboundSyncProvider:
|
||||
@@ -195,7 +195,7 @@ class OutboundSyncProvider:
|
||||
|
||||
:return: The returned objects must have at least the following properties:
|
||||
|
||||
- `pk`: Unique identifier
|
||||
- `id`: Unique identifier
|
||||
- `pretix_model`: Which pretix model to use as data source in this mapping. Possible values are
|
||||
the keys of ``sourcefields.AVAILABLE_MODELS``
|
||||
- `external_object_type`: Destination object type in the target system. opaque string of maximum 128 characters.
|
||||
@@ -322,7 +322,7 @@ class OutboundSyncProvider:
|
||||
:param mapping: The mapping object as returned by ``self.mappings``
|
||||
:param mapped_objects: Information about objects that were synced in the same sync run, by mapping definitions
|
||||
*before* the current one in order of ``self.mappings``.
|
||||
Type is a dictionary ``{mapping.pk: [list of return values of this method]}``
|
||||
Type is a dictionary ``{mapping.id: [list of return values of this method]}``
|
||||
Useful to create associations between objects in the target system.
|
||||
|
||||
Example code to create return value::
|
||||
@@ -342,7 +342,7 @@ class OutboundSyncProvider:
|
||||
This method needs to be idempotent, i.e. calling it multiple times with the same input values should create
|
||||
only a single object in the target system.
|
||||
|
||||
Subsequent calls with the same mapping and pk_value should update the existing object, instead of creating a new one.
|
||||
Subsequent calls with the same mapping and id_value should update the existing object, instead of creating a new one.
|
||||
In a SQL database, you might use an `INSERT OR UPDATE` or `UPSERT` statement; many REST APIs provide an equivalent API call.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
@@ -397,11 +397,11 @@ class OutboundSyncProvider:
|
||||
mapped_objects = {}
|
||||
for mapping in self.mappings:
|
||||
if mapping.pretix_model == 'Order':
|
||||
mapped_objects[mapping.pk] = [
|
||||
mapped_objects[mapping.id] = [
|
||||
self.sync_object(order_inputs, mapping, mapped_objects)
|
||||
]
|
||||
elif mapping.pretix_model == 'OrderPosition':
|
||||
mapped_objects[mapping.pk] = [
|
||||
mapped_objects[mapping.id] = [
|
||||
self.sync_object({
|
||||
**order_inputs, EVENT_OR_SUBEVENT: op.subevent or self.event, ORDER_POSITION: op
|
||||
}, mapping, mapped_objects)
|
||||
|
||||
@@ -214,7 +214,7 @@ class SimpleOrderSync(OutboundSyncProvider):
|
||||
def mappings(self):
|
||||
return [
|
||||
StaticMapping(
|
||||
pk=1,
|
||||
id=1,
|
||||
pretix_model='Order', external_object_type='ticketorders',
|
||||
pretix_id_field='event_order_code', external_id_field='ordernumber',
|
||||
property_mapping=json.dumps([
|
||||
@@ -311,10 +311,10 @@ def test_simple_order_sync(event):
|
||||
|
||||
|
||||
StaticMappingWithAssociations = namedtuple('StaticMappingWithAssociations', (
|
||||
'pk', 'pretix_model', 'external_object_type', 'pretix_id_field', 'external_id_field', 'property_mapping', 'association_mapping'
|
||||
'id', 'pretix_model', 'external_object_type', 'pretix_id_field', 'external_id_field', 'property_mapping', 'association_mapping'
|
||||
))
|
||||
AssociationMapping = namedtuple('AssociationMapping', (
|
||||
'via_mapping_pk'
|
||||
'via_mapping_id'
|
||||
))
|
||||
|
||||
|
||||
@@ -326,7 +326,7 @@ class OrderAndTicketAssociationSync(OutboundSyncProvider):
|
||||
def mappings(self):
|
||||
return [
|
||||
StaticMappingWithAssociations(
|
||||
pk=1,
|
||||
id=1,
|
||||
pretix_model='OrderPosition', external_object_type='tickets',
|
||||
pretix_id_field='ticket_id', external_id_field='ticketnumber',
|
||||
property_mapping=json.dumps([
|
||||
@@ -379,7 +379,7 @@ class OrderAndTicketAssociationSync(OutboundSyncProvider):
|
||||
association_mapping=[],
|
||||
),
|
||||
StaticMappingWithAssociations(
|
||||
pk=2,
|
||||
id=2,
|
||||
pretix_model='Order', external_object_type='ticketorders',
|
||||
pretix_id_field='event_order_code', external_id_field='ordernumber',
|
||||
property_mapping=json.dumps([
|
||||
@@ -415,7 +415,7 @@ class OrderAndTicketAssociationSync(OutboundSyncProvider):
|
||||
},
|
||||
]),
|
||||
association_mapping=[
|
||||
AssociationMapping(via_mapping_pk=1)
|
||||
AssociationMapping(via_mapping_id=1)
|
||||
],
|
||||
),
|
||||
]
|
||||
@@ -436,7 +436,7 @@ class OrderAndTicketAssociationSync(OutboundSyncProvider):
|
||||
**update_values,
|
||||
external_id_field: id_value,
|
||||
"_id": pre_existing_object and pre_existing_object.get("_id"),
|
||||
"links": [f"link:{obj['object_type']}:{obj['my_result']['_id']}" for am in mapping.association_mapping for obj in mapped_objects[am.via_mapping_pk]]
|
||||
"links": [f"link:{obj['object_type']}:{obj['my_result']['_id']}" for am in mapping.association_mapping for obj in mapped_objects[am.via_mapping_id]]
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user