From 3a8ad6ebefdcbb8837dd25770669e1cbb9d3502f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominic=20K=C3=B6nig?= Date: Fri, 25 Nov 2022 08:48:12 +0100 Subject: [PATCH] Release RLPPTM-1.19.3 --- VERSION | 2 +- .../templates/RLPPTM/upgrade/1.19.2-1.19.3.py | 85 +++++++++++++++++++ .../templates/RLPPTM/upgrade/fixup-1.19.2.py | 59 +++++++++++++ 3 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 modules/templates/RLPPTM/upgrade/1.19.2-1.19.3.py create mode 100644 modules/templates/RLPPTM/upgrade/fixup-1.19.2.py diff --git a/VERSION b/VERSION index 7b08685cf..dde62871e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -RLPPTM-1.19.2 (2022-11-22 21:11:25) +RLPPTM-1.19.3 (2022-11-25 08:11:12) diff --git a/modules/templates/RLPPTM/upgrade/1.19.2-1.19.3.py b/modules/templates/RLPPTM/upgrade/1.19.2-1.19.3.py new file mode 100644 index 000000000..138c5e3a2 --- /dev/null +++ b/modules/templates/RLPPTM/upgrade/1.19.2-1.19.3.py @@ -0,0 +1,85 @@ +# Database upgrade script +# +# RLPPTM Template Version 1.19.2 => 1.19.3 +# +# Execute in web2py folder after code upgrade like: +# python web2py.py -S eden -M -R applications/eden/modules/templates/RLPPTM/upgrade/1.19.2-1.19.3.py +# +import sys + +from core import S3Duplicate +from templates.RLPPTM.config import TESTSTATIONS +from templates.RLPPTM.models.org import TestProvider + +# Override auth (disables all permission checks) +auth.override = True + +# Initialize failed-flag +failed = False + +# Info +def info(msg): + sys.stderr.write("%s" % msg) +def infoln(msg): + sys.stderr.write("%s\n" % msg) + +# Load models for tables +#otable = s3db.org_organisation + +# Paths +IMPORT_XSLT_FOLDER = os.path.join(request.folder, "static", "formats", "s3csv") +TEMPLATE_FOLDER = os.path.join(request.folder, "modules", "templates", "RLPPTM") + +# ----------------------------------------------------------------------------- +# Deploy new CMS items +# +if not failed: + info("Deploy new CMS items") + + resource = s3db.resource("cms_post") + + # File and stylesheet paths + stylesheet = os.path.join(IMPORT_XSLT_FOLDER, "cms", "post.xsl") + filename = os.path.join(TEMPLATE_FOLDER, "cms_post.csv") + + # Only import relevant CMS posts, do not update existing ones + def cms_post_duplicate(item): + name = item.data.get("name") + if name in ("CommissionYYYYMMDD", + ): + S3Duplicate(noupdate=True)(item) + else: + item.skip = True + resource.configure(deduplicate = cms_post_duplicate) + + # Import, capture errors + try: + with open(filename, "r") as File: + resource.import_xml(File, + source_type = "csv", + stylesheet = stylesheet, + ) + except Exception as e: + error = sys.exc_info()[1] or "unknown error" + else: + error = resource.error + + # Fail on any error + if error: + infoln("...failed") + infoln(error) + failed = True + else: + infoln("...done") + +# ----------------------------------------------------------------------------- +# Finishing up +# +if failed: + db.rollback() + infoln("UPGRADE FAILED - Action rolled back.") +else: + db.commit() + infoln("UPGRADE SUCCESSFUL.") + +# END ========================================================================= diff --git a/modules/templates/RLPPTM/upgrade/fixup-1.19.2.py b/modules/templates/RLPPTM/upgrade/fixup-1.19.2.py new file mode 100644 index 000000000..964a2db58 --- /dev/null +++ b/modules/templates/RLPPTM/upgrade/fixup-1.19.2.py @@ -0,0 +1,59 @@ +# Database upgrade script +# +# RLPPTM Template Version 1.19.1 +# +# Execute in web2py folder after code upgrade like: +# python web2py.py -S eden -M -R applications/eden/modules/templates/RLPPTM/upgrade/fixup-1.19.1.py +# +import sys + +#from core import S3Duplicate + +# Override auth (disables all permission checks) +auth.override = True + +# Initialize failed-flag +failed = False + +# Info +def info(msg): + sys.stderr.write("%s" % msg) +def infoln(msg): + sys.stderr.write("%s\n" % msg) + +# Load models for tables +ctable = s3db.org_commission + +# Paths +IMPORT_XSLT_FOLDER = os.path.join(request.folder, "static", "formats", "s3csv") +TEMPLATE_FOLDER = os.path.join(request.folder, "modules", "templates", "RLPPTM") + +# ----------------------------------------------------------------------------- +# Fix end date of commissions +# +if not failed: + info("Fix end date of commissions...") + + old = datetime.date(2022,11,24) + new = datetime.date(2022,11,25) + + query = (ctable.end_date == old) & \ + (ctable.deleted == False) + updated = db(query).update(end_date = new, + modified_by = ctable.modified_by, + modified_on = ctable.modified_on, + ) + + infoln("...done (%s records updated)" % updated) + +# ----------------------------------------------------------------------------- +# Finishing up +# +if failed: + db.rollback() + infoln("UPGRADE FAILED - Action rolled back.") +else: + db.commit() + infoln("UPGRADE SUCCESSFUL.") + +# END =========================================================================