membershipworks: Ensure that all expected fields are present in data
This commit is contained in:
parent
cd63a169aa
commit
7563e5dcea
@ -15,23 +15,18 @@ class BaseModel(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def _get_header_map(cls):
|
|
||||||
header_map = {
|
|
||||||
field.db_column: field.name
|
|
||||||
for field in cls._meta.get_fields()
|
|
||||||
if not field.auto_created
|
|
||||||
}
|
|
||||||
header_map.update(cls._csv_headers_override)
|
|
||||||
|
|
||||||
return header_map
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _remap_headers(cls, data):
|
def _remap_headers(cls, data):
|
||||||
header_map = cls._get_header_map()
|
for field in cls._meta.get_fields():
|
||||||
for k, v in data.items():
|
# TODO: more robust filtering of fields that don't have a column
|
||||||
if k in header_map:
|
if field.auto_created or field.many_to_many or not field.concrete:
|
||||||
yield header_map.get(k), v
|
continue
|
||||||
|
|
||||||
|
csv_header = field.column
|
||||||
|
if field.name in cls._csv_headers_override:
|
||||||
|
csv_header = cls._csv_headers_override[field.name]
|
||||||
|
|
||||||
|
yield field.name, data[csv_header]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_csv_dict(cls, data):
|
def from_csv_dict(cls, data):
|
||||||
@ -215,10 +210,10 @@ class Member(BaseModel):
|
|||||||
flags = models.ManyToManyField(Flag, through="MemberFlag", related_name="members")
|
flags = models.ManyToManyField(Flag, through="MemberFlag", related_name="members")
|
||||||
|
|
||||||
_csv_headers_override = {
|
_csv_headers_override = {
|
||||||
"Account ID": "uid",
|
"uid": "Account ID",
|
||||||
"Please tell us how you heard about the Claremont MakerSpace and what tools or shops you are most excited to start using:": "how_did_you_hear",
|
"how_did_you_hear": "Please tell us how you heard about the Claremont MakerSpace and what tools or shops you are most excited to start using:",
|
||||||
"Yes - I authorize TwinState MakerSpaces, Inc. to charge my credit card for the membership and other options that I have selected.": "authorize_charge",
|
"authorize_charge": "Yes - I authorize TwinState MakerSpaces, Inc. to charge my credit card for the membership and other options that I have selected.",
|
||||||
"I have read the Claremont MakerSpace Membership Agreement & Policies, and agree to all terms stated therein.": "policy_agreement",
|
"policy_agreement": "I have read the Claremont MakerSpace Membership Agreement & Policies, and agree to all terms stated therein.",
|
||||||
}
|
}
|
||||||
|
|
||||||
_date_fields = {
|
_date_fields = {
|
||||||
@ -318,10 +313,10 @@ class Transaction(BaseModel):
|
|||||||
return super().from_csv_dict(txn)
|
return super().from_csv_dict(txn)
|
||||||
|
|
||||||
_csv_headers_override = {
|
_csv_headers_override = {
|
||||||
"uid": "member_id",
|
"member_id": "uid",
|
||||||
"_dp": "timestamp",
|
"timestamp": "_dp",
|
||||||
"Transaction Type": "type",
|
"type": "Transaction Type",
|
||||||
"Event/Form Name": "for_what",
|
"for_what": "Event/Form Name",
|
||||||
}
|
}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user