mirror of
https://github.com/pretix/pretix.git
synced 2026-05-07 15:34:02 +00:00
Use deserialized data structures for mapping configuration (#5351)
This commit is contained in:
@@ -25,7 +25,7 @@ import logging
|
||||
from collections import namedtuple
|
||||
from datetime import timedelta
|
||||
from functools import cached_property
|
||||
from typing import Optional, Protocol
|
||||
from typing import List, Optional, Protocol
|
||||
|
||||
import sentry_sdk
|
||||
from django.db import DatabaseError, transaction
|
||||
@@ -176,7 +176,7 @@ class OutboundSyncProvider:
|
||||
- `pretix_id_field`: Which pretix data field should be used to identify the mapped object. Any ``DataFieldInfo.key``
|
||||
returned by ``sourcefields.get_data_fields()`` for the combination of ``Event`` and ``pretix_model``.
|
||||
- `external_id_field`: Destination identifier field in the target system.
|
||||
- `property_mappings`: Mapping configuration as generated by ``PropertyMappingFormSet.to_property_mappings_json()``.
|
||||
- `property_mappings`: Mapping configuration as generated by ``PropertyMappingFormSet.to_property_mappings_list()``.
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
@@ -270,8 +270,7 @@ class OutboundSyncProvider:
|
||||
val = ",".join(val)
|
||||
return val
|
||||
|
||||
def get_properties(self, inputs: dict, property_mappings: str):
|
||||
property_mappings = json.loads(property_mappings)
|
||||
def get_properties(self, inputs: dict, property_mappings: List[dict]):
|
||||
return [
|
||||
(m["external_field"], self.get_field_value(inputs, m), m["overwrite"])
|
||||
for m in property_mappings
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
# You should have received a copy of the GNU Affero General Public License along with this program. If not, see
|
||||
# <https://www.gnu.org/licenses/>.
|
||||
#
|
||||
import json
|
||||
from typing import List, Tuple
|
||||
|
||||
from pretix.base.datasync.datasync import SyncConfigError
|
||||
@@ -108,15 +107,17 @@ def translate_property_mappings(property_mappings, checkin_list_map):
|
||||
om.save()
|
||||
|
||||
"""
|
||||
mappings = json.loads(property_mappings)
|
||||
mappings = []
|
||||
|
||||
for mapping in mappings:
|
||||
if mapping["pretix_field"].startswith("checkin_date_"):
|
||||
old_id = int(mapping["pretix_field"][len("checkin_date_"):])
|
||||
for mapping in property_mappings:
|
||||
pretix_field = mapping["pretix_field"]
|
||||
if pretix_field.startswith("checkin_date_"):
|
||||
old_id = int(pretix_field[len("checkin_date_"):])
|
||||
if old_id not in checkin_list_map:
|
||||
# old_id might not be in checkin_list_map, because copying of an event series only copies check-in
|
||||
# lists covering the whole series, not individual dates.
|
||||
mapping["pretix_field"] = "_invalid_" + mapping["pretix_field"]
|
||||
pretix_field = "_invalid_" + pretix_field
|
||||
else:
|
||||
mapping["pretix_field"] = "checkin_date_%d" % checkin_list_map[old_id].pk
|
||||
return json.dumps(mappings)
|
||||
pretix_field = "checkin_date_%d" % checkin_list_map[old_id].pk
|
||||
mappings.append({**mapping, "pretix_field": pretix_field})
|
||||
return mappings
|
||||
|
||||
Reference in New Issue
Block a user