Skip to content

Commit

Permalink
update script to use new core validation routine
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-jones committed Oct 24, 2023
1 parent 6374e7c commit 66ca4a4
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 183 deletions.
27 changes: 21 additions & 6 deletions portality/bll/services/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from portality import lock
from portality.bll.doaj import DOAJ
from portality.ui.messages import Messages
from portality.crosswalks.journal_questions import Journal2QuestionXwalk, Journal2PublisherUploadQuestionsXwalk
from portality.crosswalks.journal_questions import Journal2PublisherUploadQuestionsXwalk
from portality.crosswalks.journal_form import JournalFormXWalk
from portality.bll.exceptions import AuthoriseException
from portality.forms.application_forms import ApplicationFormFactory
Expand Down Expand Up @@ -323,7 +323,7 @@ def update_request_for_journal(self, journal_id, account=None, lock_timeout=None
# first retrieve the journal, and return empty if there isn't one.
# We don't attempt to obtain a lock at this stage, as we want to check that the user is authorised first
journal_lock = None
journal, _ = journalService.journal(journal_id, lock_journal=lock_records, lock_timeout=lock_timeout)
journal, _ = journalService.journal(journal_id)
if journal is None:
app.logger.info("Request for journal {x} did not find anything in the database".format(x=journal_id))
return None, None, None
Expand All @@ -345,7 +345,8 @@ def update_request_for_journal(self, journal_id, account=None, lock_timeout=None
application = journalService.journal_2_application(journal, account=account)
application.set_is_update_request(True)
if account is not None:
journal_lock = lock.lock("journal", journal_id, account.id)
if lock_records:
journal_lock = lock.lock("journal", journal_id, account.id)

# otherwise check that the user (if given) has the rights to edit the application
# then lock the application and journal to the account.
Expand Down Expand Up @@ -645,7 +646,6 @@ def validate_update_csv(self, file_path, account: models.Account):

[validation.log(upd) for upd in updates]


# If a field is disabled in the UR Form Context, then we must confirm that the form data from the
# file has not changed from that provided in the source
formulaic_context = ApplicationFormFactory.context("update_request")
Expand Down Expand Up @@ -718,28 +718,43 @@ def __init__(self):
self._row = {}
self._values = {}
self._log = []
self._errors = False
self._warnings = False

def has_errors_or_warnings(self):
return self._errors or self._warnings

def record_error_type(self, error_type):
if error_type == self.WARN:
self._warnings = True
elif error_type == self.ERROR:
self._errors = True

def general(self, error_type, msg):
msg = self._cleanhtml(msg)
self.log("[" + error_type + "] " + msg)
self._general.append((error_type, msg))
self.record_error_type(error_type)

def header(self, error_type, pos, msg):
msg = self._cleanhtml(msg)
self.log("[" + error_type + "] " + msg)
self._headers[pos] = (error_type, msg)
self.record_error_type(error_type)

def row(self, error_type, row, msg):
msg = self._cleanhtml(msg)
self.log("[" + error_type + "] " + msg)
self._row[row] = (error_type, msg)
self.record_error_type(error_type)

def value(self, error_type, row, pos, msg, was, now):
msg = self._cleanhtml(msg)
if row not in self._values:
self._values[row] = {}
self.log("[" + error_type + "] " + msg)
self._values[row][pos] = (error_type, msg, was, now)
self.record_error_type(error_type)

def log(self, msg):
msg = self._cleanhtml(msg)
Expand All @@ -749,12 +764,12 @@ def _cleanhtml(self, raw_html):
cleantext = re.sub(self.CLEANR, '', raw_html)
return cleantext

def json(self):
def json(self, indent=None):
repr = {
"general": self._general,
"headers": self._headers,
"rows": self._row,
"values": self._values,
"log": self._log
}
return json.dumps(repr)
return json.dumps(repr, indent=indent)
Loading

0 comments on commit 66ca4a4

Please sign in to comment.