diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/TESTS/test_parsers.py | 18 | ||||
-rw-r--r-- | core/models/troggle.py | 2 | ||||
-rw-r--r-- | core/utils.py | 12 | ||||
-rw-r--r-- | core/views/uploads.py | 12 |
4 files changed, 23 insertions, 21 deletions
diff --git a/core/TESTS/test_parsers.py b/core/TESTS/test_parsers.py index fd87af3..21f79c7 100644 --- a/core/TESTS/test_parsers.py +++ b/core/TESTS/test_parsers.py @@ -39,13 +39,13 @@ class ImportTest(TestCase): def setUpTestData(cls): def make_person(firstname, lastname, nickname=False, vfho=False, guest=False): fullname = f"{firstname} {lastname}" - lookupAttribs = {"first_name": firstname, "last_name": (lastname or "")} - nonLookupAttribs = {"is_vfho": vfho, "fullname": fullname, "nickname": nickname} - person = Person.objects.create(**nonLookupAttribs, **lookupAttribs) + coUniqueAttribs = {"first_name": firstname, "last_name": (lastname or "")} + otherAttribs = {"is_vfho": vfho, "fullname": fullname, "nickname": nickname} + person = Person.objects.create(**otherAttribs, **coUniqueAttribs) - lookupAttribs = {"person": person, "expedition": cls.test_expo} - nonLookupAttribs = {"is_guest": guest} - pe = PersonExpedition.objects.create(**nonLookupAttribs, **lookupAttribs) + coUniqueAttribs = {"person": person, "expedition": cls.test_expo} + otherAttribs = {"is_guest": guest} + pe = PersonExpedition.objects.create(**otherAttribs, **coUniqueAttribs) return person @@ -58,9 +58,9 @@ class ImportTest(TestCase): if frontmatter_file.is_file(): frontmatter_file.unlink() # delete if it exists - lookupAttribs = {"year": TEST_YEAR} - nonLookupAttribs = {"name": f"CUCC expo-test {TEST_YEAR}"} - cls.test_expo = Expedition.objects.create(**nonLookupAttribs, **lookupAttribs) + coUniqueAttribs = {"year": TEST_YEAR} + otherAttribs = {"name": f"CUCC expo-test {TEST_YEAR}"} + cls.test_expo = Expedition.objects.create(**otherAttribs, **coUniqueAttribs) fred = make_person("Fred", "Smartarse", nickname="freddy") phil = make_person("Phil", "Tosser", nickname="tosspot") diff --git a/core/models/troggle.py b/core/models/troggle.py index 38850ee..5db2d10 100644 --- a/core/models/troggle.py +++ b/core/models/troggle.py @@ -82,6 +82,8 @@ class Person(TroggleModel): last_name = models.CharField(max_length=100) fullname = models.CharField(max_length=200) nickname = models.CharField(max_length=200) + slug = models.SlugField(max_length=50, unique=True) + is_vfho = models.BooleanField( help_text="VFHO is the Vereines für Höhlenkunde in Obersteier, a nearby Austrian caving club.", default=False, diff --git a/core/utils.py b/core/utils.py index 17bd953..b7f3417 100644 --- a/core/utils.py +++ b/core/utils.py @@ -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) diff --git a/core/views/uploads.py b/core/views/uploads.py index 8bec24e..0c2f655 100644 --- a/core/views/uploads.py +++ b/core/views/uploads.py @@ -77,7 +77,7 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t DataIssue.objects.create(parser="logbooks", message=message) slug = slug + "_" + unique_slug(text,2) - nonLookupAttribs = { + otherAttribs = { "place": place, "text": text, "expedition": expedition, @@ -86,9 +86,9 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t "title": f"{place} - {title}", # "other_people": others } - lookupAttribs = {"slug": slug, "date": date } + coUniqueAttribs = {"slug": slug, "date": date } - lbo = LogbookEntry.objects.create(**nonLookupAttribs, **lookupAttribs) + lbo = LogbookEntry.objects.create(**otherAttribs, **coUniqueAttribs) pt_list = [] # These entities have to be PersonExpedition objects @@ -116,9 +116,9 @@ def store_edited_entry_into_database(date, place, title, text, others, author, t print(message) DataIssue.objects.create(parser="logbooks", message=message) else: - lookupAttribs = {"personexpedition": personyear, "nickname_used": name, "logbook_entry": lbo} # lbo is primary key - nonLookupAttribs = {"time_underground": tu, "is_logbook_entry_author": (name==author)} - pt_list.append(PersonLogEntry(**nonLookupAttribs, **lookupAttribs)) + coUniqueAttribs = {"personexpedition": personyear, "nickname_used": name, "logbook_entry": lbo} # lbo is primary key + otherAttribs = {"time_underground": tu, "is_logbook_entry_author": (name==author)} + pt_list.append(PersonLogEntry(**otherAttribs, **coUniqueAttribs)) except: # This should not happen. We do not raise exceptions in that function |