mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2025-12-14 22:57:11 +00:00
Rename lookupAttribs and nonLookupAttribs + add slug to Person
This commit is contained in:
@@ -276,8 +276,8 @@ def writetrogglefile(filepath, filecontent):
|
||||
# not catching and re-raising any exceptions yet, inc. the stderr etc.,. We should do that.
|
||||
|
||||
|
||||
def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
|
||||
"""Looks up instance using lookupAttribs and carries out the following:
|
||||
def save_carefully(objectType, coUniqueAttribs={}, otherAttribs={}):
|
||||
"""Looks up instance using coUniqueAttribs and carries out the following:
|
||||
-if instance does not exist in DB: add instance to DB, return (new instance, True)
|
||||
-if instance exists in DB and was modified using Troggle: do nothing, return (existing instance, False)
|
||||
-if instance exists in DB and was not modified using Troggle: overwrite instance, return (instance, False)
|
||||
@@ -293,15 +293,15 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
|
||||
|
||||
"""
|
||||
try:
|
||||
instance, created = objectType.objects.get_or_create(defaults=nonLookupAttribs, **lookupAttribs)
|
||||
instance, created = objectType.objects.get_or_create(defaults=otherAttribs, **coUniqueAttribs)
|
||||
except:
|
||||
print(" !! - FAIL in SAVE CAREFULLY ===================", objectType)
|
||||
print(" !! - -- objects.get_or_create()")
|
||||
print(f" !! - lookupAttribs:{lookupAttribs}\n !! - nonLookupAttribs:{nonLookupAttribs}")
|
||||
print(f" !! - coUniqueAttribs:{coUniqueAttribs}\n !! - otherAttribs:{otherAttribs}")
|
||||
raise
|
||||
if not created and not instance.new_since_parsing:
|
||||
for k, v in list(
|
||||
nonLookupAttribs.items()
|
||||
otherAttribs.items()
|
||||
): # overwrite the existing attributes from the logbook text (except date and title)
|
||||
setattr(instance, k, v)
|
||||
try:
|
||||
@@ -309,7 +309,7 @@ def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
|
||||
except:
|
||||
print(" !! - SAVE CAREFULLY ===================", objectType)
|
||||
print(" !! - -- instance.save()")
|
||||
print(f" !! - lookupAttribs:{lookupAttribs}\n !! - nonLookupAttribs:{nonLookupAttribs}")
|
||||
print(f" !! - coUniqueAttribs:{coUniqueAttribs}\n !! - otherAttribs:{otherAttribs}")
|
||||
raise
|
||||
try:
|
||||
str(instance)
|
||||
|
||||
Reference in New Issue
Block a user