diff options
author | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:17:09 +0100 |
---|---|---|
committer | substantialnoninfringinguser <substantialnoninfringinguser@gmail.com> | 2009-05-13 06:17:09 +0100 |
commit | a19781d7ddfcdc794c9276d62381534054e18d2e (patch) | |
tree | 88c3355ecc5e2ebf5403b8665241505b727e5351 /save_carefully.py | |
parent | 8ae5232d87a6a0c43a4274c00a6b3c8aee5de210 (diff) | |
download | troggle-a19781d7ddfcdc794c9276d62381534054e18d2e.tar.gz troggle-a19781d7ddfcdc794c9276d62381534054e18d2e.tar.bz2 troggle-a19781d7ddfcdc794c9276d62381534054e18d2e.zip |
[svn] fix import naming mistake
Copied from http://cucc@cucc.survex.com/svn/trunk/expoweb/troggle/, rev. 8326 by cucc @ 5/3/2009 6:17 AM
Diffstat (limited to 'save_carefully.py')
-rw-r--r-- | save_carefully.py | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/save_carefully.py b/save_carefully.py index 1631618..f72b4fa 100644 --- a/save_carefully.py +++ b/save_carefully.py @@ -1,5 +1,16 @@ -def save(objectType, lookupAttribs={}, nonLookupAttribs={}):
+from settings import LOGFILE
+def save_carefully(objectType, lookupAttribs={}, nonLookupAttribs={}):
+ """Looks up instance using lookupAttribs 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)
+
+ The checking is accomplished using Django's get_or_create and the new_since_parsing boolean field
+ defined in expo.models.TroggleModel.
+
+ """
+
instance, created=objectType.objects.get_or_create(defaults=nonLookupAttribs, **lookupAttribs)
if not created and not instance.new_since_parsing:
@@ -7,4 +18,14 @@ def save(objectType, lookupAttribs={}, nonLookupAttribs={}): setattr(instance, k, v)
instance.save()
- return instance
\ No newline at end of file + if LOGFILE:
+ if created:
+ LOGFILE.write(unicode(instance)+u' was just added to the database for the first time. \n')
+
+ if not created and instance.new_since_parsing:
+ LOGFILE.write(unicode(instance)+" has been modified using Troggle, so the current script left it as is. \n")
+
+ if not created and not instance.new_since_parsing:
+ LOGFILE.write(unicode(instance)+" existed in the database unchanged since last parse. It was overwritten by the current script. \n")
+ LOGFILE.flush()
+ return (instance, created)
\ No newline at end of file |