diff --git a/modules/websubmit/lib/functions/Add_Files.py b/modules/websubmit/lib/functions/Add_Files.py index ad1ae0ea2..fe9e57332 100644 --- a/modules/websubmit/lib/functions/Add_Files.py +++ b/modules/websubmit/lib/functions/Add_Files.py @@ -1,31 +1,31 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" from invenio.bibdocfile import BibRecDocs -def Add_Files(parameters, curdir, form): +def Add_Files(parameters, curdir, form, user_info=None): if os.path.exists("%s/files" % curdir): bibrecdocs = BibRecDocs(sysno) for file in os.listdir("%s/files" % curdir): fullpath = "%s/files/%s" % (curdir,file) if not bibrecdocs.check_file_exists(fullpath): bibrecdocs.add_new_file(fullpath, "Main", never_fail=True) return "" diff --git a/modules/websubmit/lib/functions/Allocate_ALEPH_SYS.py b/modules/websubmit/lib/functions/Allocate_ALEPH_SYS.py index 9c9ba11ce..c8808dc07 100644 --- a/modules/websubmit/lib/functions/Allocate_ALEPH_SYS.py +++ b/modules/websubmit/lib/functions/Allocate_ALEPH_SYS.py @@ -1,369 +1,369 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Allocate an ALEPH system number (SYS) for a record.""" __revision__ = "$Id$" import os.path from random import randint, seed from os import getpid, unlink, access, rename, R_OK, W_OK from os.path import getmtime from shutil import copyfile from time import strftime, localtime, mktime, sleep import time from invenio.config import \ adminemail, \ cdsname, \ counters, \ supportemail from invenio.websubmit_config import InvenioWebSubmitFunctionError from invenio.mailutils import send_email CFG_WARNING_MAX_SYS_APPROACHING = 2000 CFG_MAX_AGE_LOCKFILE = 300 ## (300 seconds is the maximum age that we allow for a lockfile) CFG_LEGAL_ALEPH_DATABASES = ["CER", "IEX", "MAN", "MMD"] -def Allocate_ALEPH_SYS(parameters, curdir, form): +def Allocate_ALEPH_SYS(parameters, curdir, form, user_info=None): """Get the next available ALEPH SYS from the counter file, and allocate it as the SYS for this record. Increment the counterby one. ALEPH SYS allocation works in "slots" of free numbers. For example, 000425201 -> 000634452 for a given database may be available. This means that it is necessary to care about not over-stepping the maximum boundary. To this end, two counters (for each ALEPH Database) must be present: - last_SYS_ (this contains the last SYS allocated for a database) - maximum_SYS_ (this contains the MAXIMUM SYS allowed for a database) So, for example, for the CER database, there would be: - last_SYS_CER - maximum_SYS_CER When the maximum SYS has been reached, all further attempts to obtain ALEPH SYSs will fail, as this function will fail with an error. To prevent this from coming as a surprise, however, when "last_SYS_" gets somewhere near to the value stored in "maximum_SYS_", a mail will be sent to the Admin with every SYS allocated, warning them that only N numbers remain free for the XY database. The number until MAX SYS which determines this period of warning emails is determined by a variable "warn_admin_at_N_sys_remaining". It is set to 2000 by default, but can be changed. When the system allocates a new sys and there are 2000 or less free SYS remaining, the warning mails to ADMIN will be sent. @param alephdatabase: (string) the name of the ALEPH database for which a SYS is to be allocated. E.g. "CER". The he absence of this will cause the function to fail. Also, the absence of either of the 2 counter files "last_SYS_${database}" and "maximum_SYS_${database}" will cause the function to fail. """ mailfrom_addr = '%s Submission Engine <%s>' % (cdsname, supportemail) database = parameters['alephdatabase'].strip() counter_lastsys = "last_SYS_%s" % database counter_maxsys = "maximum_SYS_%s" % database ## ensure that "database" param is not empty, and exists in the list of legal DBs if database == "" or database not in CFG_LEGAL_ALEPH_DATABASES: ## error with supplied database msg = """ERROR: When trying to allocate an ALEPH SYS for a record, an invalid database name was"""\ """ supplied: [%s]. It was therefore not possible to allocate the SYS.""" % database raise InvenioWebSubmitFunctionError(msg) ## before trying to make a lockfile, test if one exists and whether it is older than "CFG_MAX_AGE_LOCKFILE" seconds ## if so, raise an error and warn the admin: counter_lockfile = "last_SYS_%s.lock" % database try: lockfile_modtime = getmtime("%s/%s" % (counters, counter_lockfile)) time_now = mktime(localtime()) time_since_last_lockfile_mod = time_now - lockfile_modtime if time_since_last_lockfile_mod > CFG_MAX_AGE_LOCKFILE: ## lockfile is old - warn admin and stop admin_msg = """ERROR: When trying to allocate an ALEPH SYS for a record in the [%s] DB, it was not possible """\ """to create a lockfile. An attempt was made at [%s], but a lockfile already existed with a """\ """last modification time of [%s]. It was therefore not possible to allocate the SYS.""" \ % (database, strftime("%d/%m/%Y %H:%M:%S", localtime(time_now)), strftime("%d/%m/%Y %H:%M:%S", localtime(lockfile_modtime))) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - OLD ALEPH SYS LOCKFILE ENCOUNTERED!", content=admin_msg) user_msg = """ERROR: When trying to allocate an ALEPH SYS for a record in the [%s] DB, it was not possible""" \ """ to create a lockfile. It was therefore not possible to allocate the SYS.""" \ % database raise InvenioWebSubmitFunctionError(user_msg) except OSError: ## no lockfile pass ## before any counter operations, create a lockfile: got_lock = _create_SYS_counter_lockfile(database) if got_lock == 0: ## unable to create lockfile! msg = """ERROR: When trying to allocate an ALEPH SYS for a record in the [%s] DB, it was not possible"""\ """ to create a lockfile within 60 seconds. It was therefore not possible to allocate the SYS.""" % database send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT CREATE LOCKFILE!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## test that counter files exist for "database": rw_count_lastsys_ok = access("%s/%s" % (counters, counter_lastsys), R_OK|W_OK) rw_count_maxsys_ok = access("%s/%s" % (counters, counter_maxsys), R_OK|W_OK) if not rw_count_lastsys_ok or not rw_count_maxsys_ok: ## cannot access the ALEPH counter files - critical error msg = """ERROR: When trying to allocate an ALEPH SYS for a record, either [%s] or [%s] (or both) was not"""\ """ accessible. It was therefore not possible to allocate the SYS.""" % (counter_lastsys, counter_maxsys) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT ACCESS ALEPH SYS COUNTER(S)!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## read last-sys and max-sys: try: fp = open("%s/%s" % (counters, counter_lastsys), "r") fileval_lastsys = fp.read() fp.close() fp = open("%s/%s" % (counters, counter_maxsys), "r") fileval_maxsys = fp.read() fp.close() except IOError: ## could not read one or both of the files msg = """ERROR: When trying to allocate an ALEPH SYS for a record, either [%s] or [%s] (or both) could not"""\ """ be read. It was therefore not possible to allocate the SYS.""" % (counter_lastsys, counter_maxsys) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT ACCESS ALEPH SYS COUNTER(S)!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## for the values from both files, clean any whitespace from beginning or end of file text and cast the result to an integer: try: lastsys = int(fileval_lastsys.strip()) maxsys = int(fileval_maxsys.strip()) except ValueError: ## the value in one or both of the files did not cast to an int! msg = """ERROR: When trying to allocate an ALEPH SYS for a record, either [%s] or [%s] (or both) contained invalid"""\ """ (non-integer) values. It was therefore not possible to allocate the SYS.""" % (counter_lastsys, counter_maxsys) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - ALEPH SYS COUNTER(S) CONTAINS INVALID DATA!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## check that "fileval_lastsys" is less than "fileval_maxsys". If yes, proceed - else fail and mail ADMIN if not (lastsys < maxsys): ## MAX SYS EXCEEDED msg = """ERROR: When trying to allocate an ALEPH SYS for a record, the value of [%s -> %d] is not less than the """\ """value of [%s -> %d]. It was therefore not possible to allocate the SYS. A new SYS range must be allocated!"""\ % (counter_lastsys, lastsys, counter_maxsys, maxsys) ## mail admin: send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - MAXIMUM ALEPH SYS COUNTER VALUE EXCEEDED!", content=msg) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) raise InvenioWebSubmitFunctionError(msg) if maxsys - lastsys < CFG_WARNING_MAX_SYS_APPROACHING: ## WARN admin that MAX ALEPH SYS for this DB is approaching: _warn_admin_counterlimit_approaching(db=database, lastsys=lastsys, maxsys=maxsys) ## increment the value of the last SYS lastsys += 1 ## cast sys to a string and pad the value on the left with leading zeros to 9 characters: cursys = "%09d%s" % (lastsys, database[0:3].upper().strip()) ## now write out the new value of lastsys to the relevant counter file: ## make temporary file then move it later tmpfname = "%s_%s_%s" % (counter_lastsys, strftime("%Y%m%d%H%M%S", localtime()), getpid()) ## open temp counter file for writing: try: fp = open("%s/%s" % (counters, tmpfname), "w") fp.write("%d" % (lastsys,)) fp.flush() fp.close() except IOError: ## could not write to temp file msg = """ERROR: When trying to allocate an ALEPH SYS for a record, could not write out new value for last SYS used """\ """to a temporary file [%s]. It was therefore not possible to allocate a SYS for the record ([%s] was not """\ """incremented.)""" % ("%s/%s" % (counters, tmpfname), counter_lastsys) ## remove the "lock file" lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT CREATE TEMPORARY ALEPH SYS COUNTER FILE!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## copy old counter file to backup version: try: copyfile("%s/%s" % (counters, counter_lastsys), "%s/%s.bk" % (counters, counter_lastsys)) except IOError: ## unable to make backup of counter file: msg = """ERROR: When trying to allocate an ALEPH SYS for a record, could not write out new value for last SYS used."""\ """ Couldn't make a back-up copy of the SYS counter file [%s].""" % ("%s/%s" % (counters, counter_lastsys),) ## remove the "lock file" lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT WRITE BACK-UP ALEPH SYS COUNTER!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## rename temp counter file to final counter file: try: rename("%s/%s" % (counters, tmpfname), "%s/%s" % (counters, counter_lastsys)) except OSError: ## couldnt rename the tmp file to final file name msg = """ERROR: When trying to allocate an ALEPH SYS for a record, could not write out new value for last SYS used."""\ """ Created the temporary last SYS counter file [%s], but couldn't then rename it to the final counter file [%s]."""\ """ It was therefore not possible to allocate a SYS for the record ([%s] was not incremented.)"""\ % ("%s/%s" % (counters, tmpfname), "%s/%s" % (counters, counter_lastsys), counter_lastsys) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT WRITE ALEPH SYS COUNTER FILE!", content=msg) raise InvenioWebSubmitFunctionError(msg) ## now that counter has been successfully incremented, write cursys out to the file "SNa500": try: fp = open("%s/SNa500" % curdir, "w") fp.write("%s" % cursys) fp.flush() fp.close() except IOError: ## unable to write out the SYS! msg = """ERROR: When trying to allocate an ALEPH SYS for a record, could not write out new SYS to file [%s/SNa500]."""\ """ It was therefore not possible to allocate the SYS ([%s] was not incremented.)"""\ % (curdir, counter_lastsys) lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) raise InvenioWebSubmitFunctionError(msg) ## finally, unlink the lock file: lockfile_removed = _unlink_SYS_counter_lockfile(database) if lockfile_removed == 0: ## couldn't remove lockfile - mail ADMIN msg = """ERROR: After allocating an ALEPH SYS for a record, it was not possible to remove the lock file [last_SYS_%s.lock] after the """\ """SYS was allocated.""" % ("%s/%s" % (counters, database),) _mail_admin_because_lockfile_not_removeable(lockfilename="last_SYS_%s" % database, extramsg="\n\n"+msg) raise InvenioWebSubmitFunctionError(msg) return "" def _warn_admin_counterlimit_approaching(db, lastsys, maxsys): mailfrom_addr = '%s Submission Engine <%s>' % (cdsname, supportemail) mailtxt = """WARNING: The maxmimum ALEPH SYS value for the [%s] database is approaching!\n"""\ """The last SYS allocated was [%d]; The maximum SYS allowed is [%d].\n\n"""\ """You should be thinking about allocating a new range of SYS now!\n"""\ % (db, lastsys, maxsys) send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit WARNING - MAXIMUM SYS IN [%s] APPROACHING!" % db, content=mailtxt) def _mail_admin_because_lockfile_not_removeable(lockfilename, extramsg=""): mailfrom_addr = '%s Submission Engine <%s>' % (cdsname, supportemail) mailtxt = """ERROR: When trying to allocate an ALEPH SYS for a record, it was not possible to remove the lockfile [%s]!"""\ """ This means that all attempted new submissions to that database will be blocked and fail, as it is not"""\ """ possible to allocate them a SYS in ALEPH. Please investigate and remove the lockfile ASAP.\n\n"""\ % (lockfilename,) mailtxt += extramsg send_email(fromaddr=mailfrom_addr, toaddr=adminemail, subject="WebSubmit ERROR - CANNOT REMOVE ALEPH SYS LOCKFILE!", content=mailtxt) def _create_SYS_counter_lockfile(database): """Write a lock-file for "last_SYS_%(database)s" to the "counters" directory, thus ensuring that only one process will access the counter at any one time. If the lockfile doesn't already exist, it will be created in the counters directory with the name "last_SYS_%(database)s.lock" (e.g. "last_SYS_CER.lock".) If the lockfile does exist, the process will sleep for 1 second and then try again. In all, it will try 60 times to create a lockfile before giving up. When a lockfile is created, it will contain a string of the format "processPID->YYYYMMDDhhmmss->random int, between 1-1000000" (E.g. something like this: "856->20060705120533->324".) When the lockfile has been written, it will be re-read and the string inside of it compared with the string that was written. If they match, then it shall be assumed that this is the lockfile owned by this process. If they do not match, then it shall be assumed that at the time of lockfile creation, another process also created its own lockfile, and this one belongs to the other process. In such a case, this process will sleep for one second and then try again. @param database: (string) the name of the database whose counter file has been locked. This is used to determine the name of the lockfile. @return: (integer) an error flag - 0 (ZERO) or 1 (ONE). 0 means lockfile could not be created; 1 means that it was successfully created. """ seed() counter_lockfile = "last_SYS_%s.lock" % database lockfile_text = """%s->%.7f->%d""" % (getpid(), time.time(), randint(0,1000000)) got_lock = 0 ## get lock on counter: for i in range(0, 60): if os.path.exists("%s/%s" % (counters, counter_lockfile)): ## lock file exists - sleep 1 second and try again sleep(1) continue else: ## lock file doesn't exist - make it try: fp = open("%s/%s" % (counters, counter_lockfile), "w") fp.write("%s" % (lockfile_text,)) fp.flush() fp.close() ## open and read the contents of the lock file back to ensure that it *really* belongs to this process: fp = open("%s/%s" % (counters, counter_lockfile), "r") read_lockfile_contents = fp.readline() fp.close() if read_lockfile_contents.strip() != lockfile_text: ## this is not our lockfile, or it has been corrupted ## probably another process has written its own lockfile in the mean time sleep(1) continue else: got_lock = 1 break except IOError: ## could not create - pass and go on to next iteration got_lock = 0 sleep(1) return got_lock def _unlink_SYS_counter_lockfile(database): """Remove the lockfile that was created for this session of SYS allocation. @param database: (string) the name of the database whose counter file has been locked. This is used to determine the name of the lockfile. @return: (integer) an error flag - 0 (ZERO) or 1 (ONE). 0 means lockfile could not be removed; 1 means that it was successfully removed. """ counter_lockfile = "last_SYS_%s.lock" % (database,) unlinked_lockfile = 0 try: unlink("%s/%s" % (counters, counter_lockfile)) unlinked_lockfile = 1 except OSError: ## unable to remove lockfile: pass return unlinked_lockfile diff --git a/modules/websubmit/lib/functions/CaseEDS.py b/modules/websubmit/lib/functions/CaseEDS.py index 97eecf693..300df5cae 100644 --- a/modules/websubmit/lib/functions/CaseEDS.py +++ b/modules/websubmit/lib/functions/CaseEDS.py @@ -1,78 +1,78 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """This is the CaseEDS module. Contains the CaseEDS WebSubmit function. """ __revision__ = "$Id$" import os from invenio.websubmit_config import \ InvenioWebSubmitFunctionStop, \ InvenioWebSubmitFunctionError -def CaseEDS(parameters, curdir, form): +def CaseEDS(parameters, curdir, form, user_info=None): """This function compares the content of a file to different values and directly goes to a different step in the action according to the value. @param parameters: (dictionary) of parameters (relating to the given doctype/action) that are to be passed to the function: + casevariable: name of the file containing the value + casevalues: comma-separated list of values + casesteps: comma-separated list of steps + casedefault: default step if no value is mapped @return: (string) - empty string """ ## Get the values of the parameters passed to this function via the ## parameters array: casevariable = parameters['casevariable'] casevalue = parameters['casevalues'] casestep = parameters['casesteps'] casedefault = parameters['casedefault'] casevalues = casevalue.split(",") casesteps = casestep.split(",") cases = {} for a, b in map(None, casevalues, casesteps): cases[a] = b nextstep = "" if not os.path.exists("%s/%s" % (curdir, casevariable)): nextstep = casedefault else: fp = open("%s/%s" % (curdir, casevariable), "r") value = fp.read() fp.close() if cases.has_key(value): nextstep = cases[value] else: nextstep = casedefault if nextstep != "": t = "Please wait..." t = """ """ % nextstep raise InvenioWebSubmitFunctionStop(t) else: raise InvenioWebSubmitFunctionError("Case function: Could not " \ "determine next action step") return "" diff --git a/modules/websubmit/lib/functions/Check_Group.py b/modules/websubmit/lib/functions/Check_Group.py index f72445b8a..098b97cef 100644 --- a/modules/websubmit/lib/functions/Check_Group.py +++ b/modules/websubmit/lib/functions/Check_Group.py @@ -1,63 +1,63 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Update_Approval_DB ## This function updates the approval database with the ## decision of the referee ## Author: T.Baron ## PARAMETERS: categformatDAM: variable used to compute the category ## of the document from its reference import os import re import time from invenio.dbquery import run_sql from invenio.websubmit_config import InvenioWebSubmitFunctionStop -def Check_Group(parameters,curdir,form): +def Check_Group(parameters, curdir, form, user_info=None): #Path of file containing group if os.path.exists("%s/%s" % (curdir,'Group')): fp = open("%s/%s" % (curdir,'Group'),"r") group = fp.read() group = group.replace("/","_") group = re.sub("[\n\r]+","",group) res = run_sql ("""SELECT id FROM usergroup WHERE name = %s""", (group,)) if len(res) == 0: raise InvenioWebSubmitFunctionStop(""" """ % (group,)) else: raise InvenioWebSubmitFunctionStop(""" """ % (group,)) return "" diff --git a/modules/websubmit/lib/functions/Convert_RecXML_to_RecALEPH.py b/modules/websubmit/lib/functions/Convert_RecXML_to_RecALEPH.py index 7e355d674..17bddcf2b 100644 --- a/modules/websubmit/lib/functions/Convert_RecXML_to_RecALEPH.py +++ b/modules/websubmit/lib/functions/Convert_RecXML_to_RecALEPH.py @@ -1,90 +1,90 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """This is the Convert_RecXML_to_RecALEPH module. It contains the Convert_RecXML_to_RecALEPH WebSubmit function. """ __revision__ = "$Id$" import os from os import access, R_OK, W_OK from invenio.config import xmlmarc2textmarc from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Convert_RecXML_to_RecALEPH(parameters, curdir, form): +def Convert_RecXML_to_RecALEPH(parameters, curdir, form, user_info=None): """Function to create an ALEPH 500 MARC record from a MARC XML record. This function depends upon the following: * "recmysql" is a file that already exists in the working submission directory. I.e. "Make_Record" has already been called and the MARC XML record created. * "recmysql" must contain an ALEPH 500 SYS in the field "970__a". That is to say, the function "Allocate_ALEPH_SYS" should have been called and an ALEPH 500 SYS allocated to this record. *** NOTE: "xmlmarc2textmarc" is left to check for this in the record It is run in --aleph-marc=r mode, which creates an ALEPH "replace" record. Given the valid "recmysql" in the working submission directory, this function will use the "xmlmarc2textmarc" tool to convert that record into the ALEPH MARC record. The record will then be written into the file "recaleph500" in the current working submission directory. @parameters: None @return: (string) - Empty string. """ ## If recmysql does not exist in the current working submission directory, ## or it is not readable, fail by raising a InvenioWebSubmitFunctionError: if not access("%s/recmysql" % curdir, R_OK|W_OK): ## FAIL - recmysql cannot be accessed: msg = """No recmysql in submission dir %s - """ \ """Cannot create recaleph500!""" % curdir raise InvenioWebSubmitFunctionError(msg) ## Command to perform conversion of recmysql -> recaleph500: convert_cmd = \ """%(xmlmarc2alephmarc)s --aleph-marc=r %(curdir)s/recmysql > """ \ """%(curdir)s/recaleph500""" \ % { 'xmlmarc2alephmarc' : xmlmarc2textmarc, 'curdir' : curdir, } ## Perform the conversion of MARC XML record to ALEPH500 record: pipe_in, pipe_out, pipe_err = os.popen3("%s" % convert_cmd) pipe_in.close() pipe_out.close() conversion_errors = pipe_err.readlines() pipe_err.close() ## Check that the conversion was performed without error: if conversion_errors != []: ## It was not possible to successfully create the ALEPH500 record, quit: msg = """An error was encountered when attempting to """ \ """convert %s/recmysql into recaleph500 - stopping [%s]""" % (curdir, "".join(conversion_errors)) raise InvenioWebSubmitFunctionError(msg) ## Check for presence of recaleph500 in the current ## working submission directory: if not access("%s/recaleph500" % curdir, R_OK|W_OK): ## Either not present, or not readable - ERROR msg = """An error was encountered when attempting to convert """ \ """%s/recmysql into recaleph500. After the conversion, """ \ """recaleph500 could not be accessed.""" % curdir raise InvenioWebSubmitFunctionError(msg) ## Everything went OK: return "" diff --git a/modules/websubmit/lib/functions/Create_Cplx_Approval.py b/modules/websubmit/lib/functions/Create_Cplx_Approval.py index 30dbcd8a6..bee9e4bd3 100644 --- a/modules/websubmit/lib/functions/Create_Cplx_Approval.py +++ b/modules/websubmit/lib/functions/Create_Cplx_Approval.py @@ -1,70 +1,70 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Update_Approval_DB ## This function updates the approval database with the ## decision of the referee ## Author: T.Baron ## PARAMETERS: categformatDAM: variable used to compute the category ## of the document from its reference import os import re import time from invenio.dbquery import run_sql -def Create_Cplx_Approval(parameters,curdir,form): +def Create_Cplx_Approval(parameters, curdir, form, user_info=None): global rn doctype = form['doctype'] act = form['act'] categformat = parameters['categformatDAM'] # retrieve category if re.search("","") if os.path.exists("%s/%s" % (curdir,filename)): fp = open("%s/%s" % (curdir,filename)) category = fp.read() fp.close() else: category="" category = category.replace("\n","") else: categformat = categformat.replace("","([^-]*)") category = re.match(categformat,rn).group(1) if category == "": category = "unknown" #Path of file containing group if os.path.exists("%s/%s" % (curdir,'Group')): fp = open("%s/%s" % (curdir,'Group'),"r") group = fp.read() group = group.replace("/","_") group = re.sub("[\n\r]+","",group) group_id = run_sql ("""SELECT id FROM usergroup WHERE name = %s""", (group,))[0][0] sth = run_sql("SELECT rn FROM sbmCPLXAPPROVAL WHERE doctype=%s and categ=%s and rn=%s and type=%s and id_group=%s", (doctype,category,rn,act,group_id)) if len(sth) == 0: run_sql("INSERT INTO sbmCPLXAPPROVAL values(%s,%s,%s,%s,'waiting',%s,'','',NOW(),NOW(),'','','','','','')", (doctype,category,rn,act,group_id,)) else: run_sql("UPDATE sbmCPLXAPPROVAL SET dLastReq=NOW(), status='waiting', dProjectLeaderAction='' WHERE doctype=%s and categ=%s and rn=%s and type=%s and id_group=%s", (doctype,category,rn,act,group_id)) return "" diff --git a/modules/websubmit/lib/functions/Create_Modify_Interface.py b/modules/websubmit/lib/functions/Create_Modify_Interface.py index da1278d0f..7bd2891c8 100644 --- a/modules/websubmit/lib/functions/Create_Modify_Interface.py +++ b/modules/websubmit/lib/functions/Create_Modify_Interface.py @@ -1,216 +1,216 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """ This is the Create_Modify_Interface function (along with its helpers). It is used by WebSubmit for the "Modify Bibliographic Information" action. Create_Modify_Interface expects the following parameters: * "fieldnameMBI" - the name of a text file in the submission working directory that contains a list of the names of the WebSubmit fields to include in the Modification interface. These field names are separated by "\n" or "+". Given the list of WebSubmit fields to be included in the modification interface, the values for each field are retrieved for the given record (by way of each WebSubmit field being configured with a MARC Code in the WebSubmit database). An HTML FORM is then created. This form allows a user to modify certain field values for a record. """ __revision__ = "$Id$" import os import re import time from invenio.dbquery import run_sql from invenio.websubmit_config import InvenioWebSubmitFunctionError from invenio.websubmit_functions.Retrieve_Data import Get_Field def Create_Modify_Interface_getfieldval_fromfile(cur_dir, fld=""): """Read a field's value from its corresponding text file in 'cur_dir' (if it exists) into memory. Delete the text file after having read-in its value. This function is called on the reload of the modify-record page. This way, the field in question can be populated with the value last entered by the user (before reload), instead of always being populated with the value still found in the DB. """ fld_val = "" if len(fld) > 0 and os.access("%s/%s" % (cur_dir, fld), os.R_OK|os.W_OK): fp = open( "%s/%s" % (cur_dir, fld), "r" ) fld_val = fp.read() fp.close() try: os.unlink("%s/%s"%(cur_dir, fld)) except OSError: # Cannot unlink file - ignore, let WebSubmit main handle this pass fld_val = fld_val.strip() return fld_val def Create_Modify_Interface_getfieldval_fromDBrec(fieldcode, recid): """Read a field's value from the record stored in the DB. This function is called when the Create_Modify_Interface function is called for the first time when modifying a given record, and field values must be retrieved from the database. """ fld_val = "" if fieldcode != "": for next_field_code in [x.strip() for x in fieldcode.split(",")]: fld_val += "%s\n" % Get_Field(next_field_code, recid) fld_val = fld_val.rstrip('\n') return fld_val def Create_Modify_Interface_transform_date(fld_val): """Accept a field's value as a string. If the value is a date in one of the following formats: DD Mon YYYY (e.g. 23 Apr 2005) YYYY-MM-DD (e.g. 2005-04-23) ...transform this date value into "DD/MM/YYYY" (e.g. 23/04/2005). """ if re.search("^[0-9]{2} [a-z]{3} [0-9]{4}$", fld_val, re.IGNORECASE) is not None: try: fld_val = time.strftime("%d/%m/%Y", time.strptime(fld_val, "%d %b %Y")) except (ValueError, TypeError): # bad date format: pass elif re.search("^[0-9]{4}-[0-9]{2}-[0-9]{2}$", fld_val, re.IGNORECASE) is not None: try: fld_val = time.strftime("%d/%m/%Y", time.strptime(fld_val, "%Y-%m-%d")) except (ValueError,TypeError): # bad date format: pass return fld_val -def Create_Modify_Interface(parameters, curdir, form): +def Create_Modify_Interface(parameters, curdir, form, user_info=None): """Create an interface for the modification of a document, based on the fields that the user has chosen to modify """ global sysno,rn t = "" # variables declaration fieldname = parameters['fieldnameMBI'] # Path of file containing fields to modify if os.path.exists("%s/%s" % (curdir, fieldname)): fp = open( "%s/%s" % (curdir, fieldname), "r" ) fieldstext = fp.read() fp.close() fieldstext = re.sub("\+","\n", fieldstext) fields = fieldstext.split("\n") else: res = run_sql("SELECT fidesc FROM sbmFIELDDESC WHERE name=%s", (fieldname,)) if len(res) == 1: fields = res[0][0].replace(" ", "") fields = re.findall("", fields) regexp = re.compile("""['|"]?)(?P.*?)(?P=quote)""") fields = [regexp.search(x) for x in fields] fields = [x.group("value") for x in fields if x is not None] fields = [x for x in fields if x not in ("Select", "select")] else: raise InvenioWebSubmitFunctionError("cannot find fields to modify") #output some text t = t+"
The document %s has been found in the database.

Please modify the following fields:
Then press the 'END' button at the bottom of the page
\n" % rn for field in fields: subfield = "" value = "" marccode = "" text = "" # retrieve and display the modification text t = t + "\n" res = run_sql("SELECT modifytext FROM sbmFIELDDESC WHERE name=%s", (field,)) if len(res)>0: t = t + "%s \n" % res[0][0] # retrieve the marc code associated with the field res = run_sql("SELECT marccode FROM sbmFIELDDESC WHERE name=%s", (field,)) if len(res) > 0: marccode = res[0][0] # then retrieve the previous value of the field if os.path.exists("%s/%s" % (curdir, "Create_Modify_Interface_DONE")): # Page has been reloaded - get field value from text file on server, not from DB record value = Create_Modify_Interface_getfieldval_fromfile(curdir, field) else: # First call to page - get field value from DB record value = Create_Modify_Interface_getfieldval_fromDBrec(marccode, sysno) # If field is a date value, transform date into format DD/MM/YYYY: value = Create_Modify_Interface_transform_date(value) res = run_sql("SELECT * FROM sbmFIELDDESC WHERE name=%s", (field,)) if len(res) > 0: element_type = res[0][3] numcols = res[0][6] numrows = res[0][5] size = res[0][4] maxlength = res[0][7] val = res[0][8] fidesc = res[0][9] if element_type == "T": text = "" % (field, numrows, numcols, value) elif element_type == "F": text = "" % (field, size, maxlength) elif element_type == "I": value = re.sub("[\n\r\t]+", "", value) text = " " % (field, size, val) text = text + "" % (field, value) elif element_type == "H": text = "" % (field, val) text = text + "" % (field, value) elif element_type == "S": values = re.split("[\n\r]+", value) text = fidesc if re.search("%s\[\]" % field, fidesc): multipletext = "[]" else: multipletext = "" if len(values) > 0 and not(len(values) == 1 and values[0] == ""): text += "\n" elif element_type == "D": text = fidesc elif element_type == "R": co = compile(fidesc.replace("\r\n", "\n"), "", "exec") exec(co) else: text = "%s: unknown field type" % field t = t + "%s" % text # output some more text t = t + "

" # Flag File to be written if first call to page, which tells function that if page is reloaded, # it should get field values from text files in curdir, instead of from DB record: if not os.path.exists("%s/%s" % (curdir, "Create_Modify_Interface_DONE")): # Write flag file: try: fp = open("%s/%s" % (curdir, "Create_Modify_Interface_DONE"), "w") fp.write("DONE\n") fp.flush() fp.close() except IOError, e: # Can't open flag file for writing pass return t diff --git a/modules/websubmit/lib/functions/Create_Recid.py b/modules/websubmit/lib/functions/Create_Recid.py index b86ef68cc..d57651b6f 100644 --- a/modules/websubmit/lib/functions/Create_Recid.py +++ b/modules/websubmit/lib/functions/Create_Recid.py @@ -1,38 +1,38 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" import os from invenio.dbquery import run_sql -def Create_Recid(parameters,curdir,form): +def Create_Recid(parameters, curdir, form, user_info=None): global sysno if not os.path.exists("%s/SN" % curdir): recid = run_sql("insert into bibrec (creation_date,modification_date) values(NOW(),NOW())") fp = open("%s/SN" % curdir,"w") fp.write(str(recid)) sysno = recid else: fp = open("%s/SN" % curdir,"r") sysno = fp.read() fp.close() return "" diff --git a/modules/websubmit/lib/functions/Finish_Submission.py b/modules/websubmit/lib/functions/Finish_Submission.py index 796db0ad3..44522a3ca 100644 --- a/modules/websubmit/lib/functions/Finish_Submission.py +++ b/modules/websubmit/lib/functions/Finish_Submission.py @@ -1,38 +1,38 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## ## Name: Finish_Submission ## Description: function Finish_Submission ## This function sets some global variables so that even if ## we are not in the last step of an action, the action stops ## anyway. ## Author: T.Baron ## PARAMETERS: - ## OUTPUT: HTML ## -def Finish_Submission(parameters,curdir,form): +def Finish_Submission(parameters, curdir, form, user_info=None): global last_step,action_score last_step = 1 action_score = "-1" return "" diff --git a/modules/websubmit/lib/functions/Format_Record.py b/modules/websubmit/lib/functions/Format_Record.py index 5f496f1ac..901a168a9 100644 --- a/modules/websubmit/lib/functions/Format_Record.py +++ b/modules/websubmit/lib/functions/Format_Record.py @@ -1,27 +1,27 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" import os from invenio.config import bibformat -def Format_Record(parameters,curdir,form): +def Format_Record(parameters, curdir, form, user_info=None): os.system("%s < %s/recmysql > %s/recmysqlfmt" % (bibformat,curdir,curdir)) return "" diff --git a/modules/websubmit/lib/functions/Get_Info.py b/modules/websubmit/lib/functions/Get_Info.py index 5d7d6609f..b593c237b 100644 --- a/modules/websubmit/lib/functions/Get_Info.py +++ b/modules/websubmit/lib/functions/Get_Info.py @@ -1,105 +1,105 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## ## Name: Get_Info.py ## Description: function Get_Info ## This function retrieves some bibliographic data (title, ## submitter email, author and sets global variables with ## the values, so that other functions may use them. ## Author: T.Baron ## PARAMETERS: authorFile: name of the file in which the author is stored ## emailFile: name of the file in which the email is stored ## titleFile: name of the file in which the title is stored ## OUTPUT: HTML ## import os from invenio.websubmit_config import InvenioWebSubmitFunctionStop from invenio.websubmit_functions.Retrieve_Data import Get_Field titlevalue = "" emailvalue = "" authorvalue = "" -def Get_Info(parameters,curdir,form): +def Get_Info(parameters, curdir, form, user_info=None): global titlevalue,emailvalue,authorvalue,rn doctype = form['doctype'] titlefile = parameters["titleFile"] emailfile = parameters["emailFile"] authorfile = parameters["authorFile"] if not Get_Info_In_Curdir(rn,titlefile,emailfile,authorfile,doctype): if not Get_Info_In_DB(rn,parameters,curdir): DocumentNotFound(rn) return "" def Get_Info_In_Curdir(repno,titlefile,emailfile,authorfile,doctype): global titlevalue,emailvalue,authorvalue if not os.path.exists("%s/%s" % (curdir,titlefile)): return 0 else: if os.path.exists("%s/%s" % (curdir,titlefile)): fp = open("%s/%s" % (curdir,titlefile),"r") titlevalue = fp.read() fp.close() else : titlevalue = "-" if os.path.exists("%s/%s" % (curdir,emailfile)): fp = open("%s/%s" % (curdir,emailfile),"r") emailvalue = fp.read() fp.close() else : emailvalue = "-" if os.path.exists("%s/%s" % (curdir,authorfile)): fp = open("%s/%s" % (curdir,authorfile),"r") authorvalue = fp.read() fp.close() else : authorvalue = "-" return 1 def Get_Info_In_DB(rn,parameters,curdir): global titlevalue,emailvalue,authorvalue,sysno if sysno != "": titlevalue = Get_Field('245__a',sysno) emailvalue = Get_Field('8560_f',sysno) authorvalue = Get_Field('100__a',sysno) authorvalue += "\n%s" % Get_Field('700__a',sysno) # save result fp = open("%s/SN" % curdir,"w") fp.write(sysno) fp.close() return 1 else: return 0 def DocumentNotFound(repno): raise InvenioWebSubmitFunctionStop(""" """ % repno) return 0 diff --git a/modules/websubmit/lib/functions/Get_Recid.py b/modules/websubmit/lib/functions/Get_Recid.py index 819df94fd..eda2f0963 100644 --- a/modules/websubmit/lib/functions/Get_Recid.py +++ b/modules/websubmit/lib/functions/Get_Recid.py @@ -1,164 +1,164 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Get the recid of a record with a given report-number (from the global 'rn'), and store it into the global 'sysno'. """ __revision__ = "$Id$" from os import access, F_OK, R_OK from invenio.search_engine import record_exists, search_pattern from invenio.websubmit_config import \ InvenioWebSubmitFunctionStop, \ InvenioWebSubmitFunctionError ## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop" ## when a document recid for the given report-number cannot be found: CFG_ALERT_DOCUMENT_NOT_FOUND = """\n""" ## JavaScript action and message to be passed to "InvenioWebSubmitFunctionStop" ## when multiple document recids for the given report-number are found found: CFG_ALERT_MULTIPLE_DOCUMENTS_FOUND = """\n""" -def Get_Recid(parameters, curdir, form): +def Get_Recid(parameters, curdir, form, user_info=None): """Given the report number of a notice (the global "rn"), retrieve the "recid" (001). The function first of all checks for the existence of the file "SN" in the current submission's working directory. If it exists, it is read in and used as the "recid". Otherwise, this function will contact the database in order to obtain the recid of a record. The function depends upon the global value "rn" having been set. It will use this value when searching for a record. Note: If "rn" is empty, the search for the document will not be conducted. Exceptions raised: + InvenioWebSubmitFunctionError: - if unable to open curdir/SN for reading; - if unable to open curdir/SN for writing; + InvenioWebSubmitFunctionStop: - if the global 'rn' is empty (no rn to search with); - if no recid found for 'rn' value; - if multiple recids found for 'rn' value; """ global rn, sysno ## initialize sysno sysno = "" if access("%s/SN" % curdir, F_OK|R_OK): ## SN exists and should contain the recid; get it from there. try: fptr = open("%s/SN" % curdir, "r") except IOError: ## Unable to read the SN file's contents msg = """Unable to correctly read the current submission's recid""" raise InvenioWebSubmitFunctionError(msg) else: ## read in the submission details: sysno = fptr.read().strip() fptr.close() else: ## SN doesn't exist; Check the DB for a record with this reportnumber. ## First, if rn is empty, don't conduct the search: if rn.strip() in ("", None): ## No report-numer provided: raise InvenioWebSubmitFunctionStop(CFG_ALERT_DOCUMENT_NOT_FOUND \ % "NO REPORT NUMBER PROVIDED") ## Get a list of recids of LIVE records associated with the report num recids = get_existing_records_for_reportnumber(rn) ## There should only be 1 _existing_ record for the report-number: if len(recids) == 1: ## Only one record found - save it to a text file called SN ## in the current submission's working directory: try: fptr = open("%s/SN" % curdir, "w") except IOError: ## Unable to read the SN file's contents msg = """Unable to save the recid for report [%s]""" \ % rn raise InvenioWebSubmitFunctionError(msg) else: ## Save recid to SN and to the global scope: sysno = recids[0] fptr.write("%s" % sysno) fptr.flush() fptr.close() elif len(recids) < 1: ## No recid found for this report number: msg = CFG_ALERT_DOCUMENT_NOT_FOUND % rn raise InvenioWebSubmitFunctionStop(msg) else: ## Multiple recids found for this report-number: msg = CFG_ALERT_MULTIPLE_DOCUMENTS_FOUND % rn raise InvenioWebSubmitFunctionStop(msg) ## Everything seems to have run smoothly: return "" def get_existing_records_for_reportnumber(reportnum): """Given a report number, return a list of recids of real (live) records that are associated with it. That's to say if the record does not exist (prehaps deleted, for example) it's recid will now be returned in the list. @param reportnum: (string) - the report number for which recids are to be returned. @return: (list) of recids. """ existing_records = [] ## List of the report numbers of existing records ## Get list of records with the report-number rn: reclist = \ list(search_pattern(req=None, \ p=reportnum, \ f="reportnumber", \ m="e")) ## Loop through all recids retrieved and testing to see whether the record ## actually exists or not. If none of the records exist, there is no record ## with this reportnumber; If more than one of the records exists, then ## there are multiple records with the report-number; If only one record ## exists, then everything is OK, for rec in reclist: rec_exists = record_exists(rec) if rec_exists == 1: ## This is a live record record the recid and augment the counter of ## records found: existing_records.append(rec) return existing_records diff --git a/modules/websubmit/lib/functions/Get_Report_Number.py b/modules/websubmit/lib/functions/Get_Report_Number.py index f35741590..494a099b3 100644 --- a/modules/websubmit/lib/functions/Get_Report_Number.py +++ b/modules/websubmit/lib/functions/Get_Report_Number.py @@ -1,47 +1,47 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## ## Name: Get_Report_Number.py ## Description: function Get_Report_Number ## This function retrieves the reference of the document from ## the name of the file it is stored in. ## Author: T.Baron ## PARAMETERS: edsrn: name of the file in which the reference is stored ## OUTPUT: HTML ## import os import re -def Get_Report_Number (parameters,curdir,form): +def Get_Report_Number(parameters, curdir, form, user_info=None): global rn #Path of file containing report number if os.path.exists("%s/%s" % (curdir,parameters['edsrn'])): fp = open("%s/%s" % (curdir,parameters['edsrn']),"r") rn = fp.read() rn = rn.replace("/","_") rn = re.sub("[\n\r ]+","",rn) else: rn = "" return "" diff --git a/modules/websubmit/lib/functions/Get_Sysno.py b/modules/websubmit/lib/functions/Get_Sysno.py index bfcab5a5c..eae11c924 100644 --- a/modules/websubmit/lib/functions/Get_Sysno.py +++ b/modules/websubmit/lib/functions/Get_Sysno.py @@ -1,70 +1,70 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Get the recid of a record based upon report-number, as stored in the global variable 'rn'. **Deprecated - Use Get_Recid Instead** """ __revision__ = "$Id$" ## ## Name: Get_Sysno.py ## Description: function Get_Sysno ## This function retrieves the system number of a document ## given its reference ## Author: T.Baron ## PARAMETERS: - ## OUTPUT: HTML ## import os from invenio.search_engine import search_pattern from invenio.websubmit_config import InvenioWebSubmitFunctionStop -def Get_Sysno(parameters,curdir,form): +def Get_Sysno(parameters, curdir, form, user_info=None): """Get the recid of a record based upon report-number, as stored in the global variable 'rn'. Store the recid in the global variable 'sysno' and in the file 'SN' in the current submission directory. **Deprecated - Use Get_Recid Instead** """ global rn,sysno # initialize sysno variable sysno = "" if os.path.exists("%s/SN" % curdir): fp = open("%s/SN" % curdir,"r") sysno = fp.read() fp.close() else: searchresults = list(search_pattern(req=None, p=rn, f="reportnumber")) if len(searchresults) == 0: raise InvenioWebSubmitFunctionStop("" % rn) elif len(searchresults) > 1: raise InvenioWebSubmitFunctionStop("" % rn) else: sysno = searchresults[0] # save resultin a file fp = open("%s/SN" % curdir,"w") fp.write(str(sysno)) fp.close() return "" diff --git a/modules/websubmit/lib/functions/Insert_Modify_Record.py b/modules/websubmit/lib/functions/Insert_Modify_Record.py index 18c9356ee..dfc6ecbde 100644 --- a/modules/websubmit/lib/functions/Insert_Modify_Record.py +++ b/modules/websubmit/lib/functions/Insert_Modify_Record.py @@ -1,43 +1,43 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" import os import shutil import time from invenio.config import \ bibupload, \ tmpdir from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Insert_Modify_Record(parameters,curdir,form): +def Insert_Modify_Record(parameters, curdir, form, user_info=None): global rn if os.path.exists("%s/recmysqlfmt" % curdir): recfile = "recmysqlfmt" elif os.path.exists("%s/recmysql" % curdir): recfile = "recmysql" else: raise InvenioWebSubmitFunctionError("Could not find record file") initialfile = "%s/%s" % (curdir,recfile) finalfile = "%s/%s_%s" % (tmpdir,rn,time.strftime("%Y-%m-%d_%H:%M:%S")) shutil.copy(initialfile,finalfile) os.system("%s -c %s" % (bibupload,finalfile)) return "" diff --git a/modules/websubmit/lib/functions/Insert_Record.py b/modules/websubmit/lib/functions/Insert_Record.py index 2f922bd7d..2f8337e2f 100644 --- a/modules/websubmit/lib/functions/Insert_Record.py +++ b/modules/websubmit/lib/functions/Insert_Record.py @@ -1,41 +1,41 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" import os import time import shutil from invenio.config import \ bibupload, \ tmpdir from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Insert_Record(parameters,curdir,form): +def Insert_Record(parameters, curdir, form, user_info=None): global rn if os.path.exists("%s/recmysql" % curdir): recfile = "recmysql" else: raise InvenioWebSubmitFunctionError("Could not find record file") initialfile = "%s/%s" % (curdir,recfile) finalfile = "%s/%s_%s" % (tmpdir,rn,time.strftime("%Y-%m-%d_%H:%M:%S")) shutil.copy(initialfile,finalfile) os.system("%s -r -i %s" % (bibupload,finalfile)) return "" diff --git a/modules/websubmit/lib/functions/Is_Original_Submitter.py b/modules/websubmit/lib/functions/Is_Original_Submitter.py index affa0cddb..b8c3933f1 100644 --- a/modules/websubmit/lib/functions/Is_Original_Submitter.py +++ b/modules/websubmit/lib/functions/Is_Original_Submitter.py @@ -1,64 +1,64 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## ## Name: Is_Original_Submitter ## Description: function Is_Original_Submitter ## This function compares the email of the current logged ## user with the original submitter of the document, then ## check whether the user has special rights. ## Author: T.Baron ## ## PARAMETERS: - ## OUTPUT: HTML ## import re from invenio.access_control_engine import acc_authorize_action from invenio.websubmit_config import InvenioWebSubmitFunctionStop from invenio.websubmit_functions.Retrieve_Data import Get_Field -def Is_Original_Submitter(parameters,curdir,form): - global uid_email,sysno,uid,user_info +def Is_Original_Submitter(parameters, curdir, form, user_info=None): + global uid_email,sysno,uid doctype = form['doctype'] act = form['act'] email = Get_Field("8560_f",sysno) email = re.sub("[\n\r ]+","",email) uid_email = re.sub("[\n\r ]+","",uid_email) (auth_code, auth_message) = acc_authorize_action(user_info, "submit",verbose=0,doctype=doctype, act=act) if re.search(uid_email,email,re.IGNORECASE) is None and auth_code != 0: raise InvenioWebSubmitFunctionStop(""" """ % (uid_email,email)) elif re.search(uid_email,email,re.IGNORECASE) is None and auth_code == 0: return (""" """ % (uid_email,email)) return "" diff --git a/modules/websubmit/lib/functions/Is_Referee.py b/modules/websubmit/lib/functions/Is_Referee.py index b7fd61be0..154d152bd 100644 --- a/modules/websubmit/lib/functions/Is_Referee.py +++ b/modules/websubmit/lib/functions/Is_Referee.py @@ -1,48 +1,48 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" from invenio.config import supportemail from invenio.dbquery import run_sql from invenio.access_control_engine import acc_authorize_action from invenio.websubmit_config import InvenioWebSubmitFunctionStop -def Is_Referee(parameters,curdir,form): - global uid_email,sysno,rn,uid,user_info +def Is_Referee(parameters, curdir, form, user_info=None): + global uid_email,sysno,rn,uid doctype = form['doctype'] # Get document category res = run_sql("SELECT categ FROM sbmAPPROVAL WHERE rn=%s", (rn,)) if len(res) >0: categ = res[0][0] else: categ="" # Try to retrieve the referee's email from the referee's database (auth_code, auth_message) = acc_authorize_action(user_info, "referee",doctype=doctype, categ=categ) if auth_code != 0: raise InvenioWebSubmitFunctionStop(""" """ % (uid_email,supportemail)) return "" diff --git a/modules/websubmit/lib/functions/Mail_New_Record_Notification.py b/modules/websubmit/lib/functions/Mail_New_Record_Notification.py index 0c5b2ad83..bf93f2079 100644 --- a/modules/websubmit/lib/functions/Mail_New_Record_Notification.py +++ b/modules/websubmit/lib/functions/Mail_New_Record_Notification.py @@ -1,289 +1,289 @@ # -*- coding: utf-8 -*- ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """This module contains the WebSubmit function "Mail_New_Record_Notification", which should be called when a new record has been submitted to the repository and notified of the fact should be sent by mail to the submitters/requester/ admins/other general managers. """ __revision__ = "$Id$" from invenio.config import cdsname, supportemail, weburl, adminemail from invenio.webuser import email_valid_p from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email CFG_EMAIL_FROM_ADDRESS = '%s Submission Engine <%s>' % (cdsname, supportemail) -def Mail_New_Record_Notification(parameters, curdir, form): +def Mail_New_Record_Notification(parameters, curdir, form, user_info=None): """This function sends a mail giving notification about the submission of a new item to the relevant recipients, including: + The record's Submitter(s); + The site ADMIN; + The record-type's "managers" (signified by the "submit_managers" parameter); The mail contains details of the new item's reference number(s), its title and its author(s). It also contains a link to the item in the CDS Invenio repository. @param parameters: (dictionary) - contains the following parameter strings used by this function: + item_status: (string) - the status of the new item. It can be either "ADDED" (in which case the new item has been integrated into the repository), or "APPROVAL" (in which case the item is awaiting a referee's approval before being integrated into the repository, and the mail should state this fact); + mail_submitters: (string) - a flag containing "Y" or "N" (defaulting to "Y"). Determines whether or not the notification mail will be sent to the submitters; + item_managers: (string) - a comma-separated list of email addresses, each of which corresponds to a "manager" for the class of item that has been submitted. These managers will receive the notification message sent by this function; + author_file: (string) - the name of a file that contains the names of the item's authors (one author per line); + title_file: (string) - the name of a file that contains the title of the new item; + owners_file: (string) - the name of a file that contains the email addresses of the "owners" of the submitted item. I.e. those who will be classed as "submitters" of the item and will therefore have modification rights over it. The mail will be sent to these people. There should be one email-address per line in this file; + rn_file1: (string) - the name of the the file containing the item's principal reference number; + rn_file2: (string) - the name of the file containing the item's additional reference number(s) (e.g. sometimes two reference numbers are allocated during the submission process; @param curdir: (string) - the current submission's working directory. All files containing data related to the submission are stored here and therefore all of the files referred to in the "parameters" dictionary are considered to be within "curdir"; @param form: (string) - a dictionary-like structure containing the fields that were present in the WebSubmit submission form; @return: (string) - an empty string; """ global sysno ## (I'm really sorry for that! :-O ) ## Read items from the parameters array into local vars: item_status = parameters["item_status"] mail_submitters = parameters["mail_submitters"] item_managers = parameters["item_managers"] author_file = parameters["author_file"] title_file = parameters["title_file"] owners_file = parameters["owners_file"] rn_file1 = parameters["rn_file1"] rn_file2 = parameters["rn_file2"] ## Now wash the parameters' values: ## ## item_status: try: ## If item_status isn't "added" or "approval", make it "added" by ## default. Else, keep its value: item_status = (item_status.upper() in ("ADDED", "APPROVAL") \ and item_status.upper()) or "ADDED" except AttributeError: ## Oops - item_status wasn't a string (NoneType?) Anyway, default ## it to "ADDED". item_status = "ADDED" ## mail_submitters: try: ## If mail_submitters isn't "Y" or "N", make it "Y" by ## default. Else, keep its value: mail_submitters = (mail_submitters.upper() in ("Y", "N") \ and mail_submitters.upper()) or "Y" except AttributeError: ## Oops - mail_submitters wasn't a string (NoneType?) Anyway, default ## it to "Y". mail_submitters = "Y" ## item_managers: ## A string in which the item_managers' email addresses will be stored: managers_email = "" try: ## We assume that the email addresses of item managers are ## separated by commas. item_managers_list = item_managers.split(",") for manager in item_managers_list: manager_address = manager.strip() ## Test that this manager's email address is OK, adding it if so: if email_valid_p(manager_address): ## This address is OK - add it to the string of manager ## addresses: managers_email += "%s," % manager_address ## Strip the trailing comma from managers_email (if there is one): managers_email = managers_email.strip().rstrip(",") except AttributeError: ## Oops - item_managers doesn't seem to be a string? Treat it as ## though it were empty: managers_email = "" ## author_file: authors = "" try: ## Read in the authors from author_file, putting them into the "authors" ## variable, one per line: fp_author_file = open("%s/%s" % (curdir, author_file), "r") for author in fp_author_file: authors += "%s\n" % author.strip() fp_author_file.close() except IOError: ## Unable to correctly read from "author_file", Skip it as though ## there were no authors: authors = "-" ## title_file: title = "" try: ## Read in the lines from title_file, putting them into the "title" ## variable on one line: fp_title_file = open("%s/%s" % (curdir, title_file), "r") for line in fp_title_file: title += "%s " % line.strip() fp_title_file.close() title = title.strip() except IOError: ## Unable to correctly read from "title_file", Skip it as though ## there were no title: title = "-" ## owners_file: ## A string in which the item_owners' email addresses will be stored: owners_email = "" try: fp_owners_file = open("%s/%s" % (curdir, owners_file), "r") for line in fp_owners_file: owner_address = line.strip() ## Test that this owner's email address is OK, adding it if so: if email_valid_p(owner_address): ## This address is OK - add it to the string of item owner ## addresses: owners_email += "%s," % owner_address ## Strip the trailing comma from owners_email (if there is one): owners_email = owners_email.strip().rstrip(",") except IOError: ## Unable to correctly read from "owners_file", Skip it as though ## there were no title: owners_email = "" ## Add "SuE" (the submitter) into the list of document "owners": try: fp_sue = open("%s/SuE" % curdir, "r") sue = fp_sue.readline() fp_sue.close() except IOError: sue = "" else: if sue.lower() not in owners_email.lower().split(","): ## The submitter is not listed in the "owners" mails, ## add her: owners_email = "%s,%s" % (sue, owners_email) owners_email = owners_email.strip().rstrip(",") ## rn_file1 & rn_file2: reference_numbers = "" try: fp_rnfile1 = open("%s/%s" % (curdir, rn_file1), "r") for line in fp_rnfile1: reference_number = line.strip() reference_number = \ reference_number.replace("\n", "").replace("\r", "").\ replace(" ", "") if reference_number != "": ## Add this reference number into the "reference numbers" ## variable: reference_numbers += "%s " % reference_number fp_rnfile1.close() except IOError: reference_numbers = "" try: fp_rnfile2 = open("%s/%s" % (curdir, rn_file2), "r") for line in fp_rnfile2: reference_number = line.strip() reference_number = \ reference_number.replace("\n", "").replace("\r", "").\ replace(" ", "") if reference_number != "": ## Add this reference number into the "reference numbers" ## variable: reference_numbers += "%s " % reference_number fp_rnfile2.close() except IOError: pass ## Strip any trailing whitespace from the reference numbers: reference_numbers = reference_numbers.strip() ## Now build the email from the information we've collected: email_txt = """ The following item has been submitted to %(cdsname)s: Reference(s): %(reference)s Title: %(title)s Author(s): %(author)s """ % { 'cdsname' : cdsname, 'reference' : reference_numbers, 'title' : title, 'author' : authors, } if item_status == "ADDED": ## The item has been added into the repository. email_txt += """ It will soon be made available and you will be able to check it at the following URL: <%(weburl)s/record/%(record-id)s> Please report any problems to <%(supportemail)s>. """ % { 'weburl' : weburl, 'record-id' : sysno, 'supportemail' : supportemail, } else: ## The item has not yet been added - instead it awaits the ## approval of a referee. Let the email reflect this detail: email_txt += """ The item is now awaiting a referee's approval before being integrated into the repository. You will be alerted by email as soon as a decision has been taken. """ ## Finish the message with a signature: email_txt += """ Thank you for submitting your item into %(cdsname)s. """ % { 'cdsname' : cdsname, } ## Send the email: if mail_submitters == "Y" and len(owners_email) != "": ## Mail-to is "owners_email": if managers_email != "": ## Managers should also be copied into the mail: owners_email += ",%s" % managers_email ## Post the mail: send_email(CFG_EMAIL_FROM_ADDRESS, owners_email, \ "[%s] Submitted" % reference_numbers, \ email_txt, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) elif CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN: ## We don't want to mail the "owners". Let's mail the admin instead: send_email(CFG_EMAIL_FROM_ADDRESS, adminemail, \ "[%s] Submitted" % reference_numbers, email_txt) ## Return an empty string return "" diff --git a/modules/websubmit/lib/functions/Mail_Submitter.py b/modules/websubmit/lib/functions/Mail_Submitter.py index 5492eb85f..e14762984 100644 --- a/modules/websubmit/lib/functions/Mail_Submitter.py +++ b/modules/websubmit/lib/functions/Mail_Submitter.py @@ -1,104 +1,104 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## ## Name: Mail_Submitter.py ## Description: function Mail_Submitter ## This function sends a confirmation email to the submitter ## of the document ## Author: T.Baron ## ## PARAMETERS: authorfile: name of the file containing the author ## titleFile: name of the file containing the title ## emailFile: name of the file containing the email ## status: one of "ADDED" (the document has been integrated ## into the database) or "APPROVAL" (an email has ## been sent to a referee - simple approval) ## edsrn: name of the file containing the reference ## newrnin: name of the file containing the 2nd reference ## (if any) ## OUTPUT: HTML ## import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Mail_Submitter (parameters,curdir,form): +def Mail_Submitter (parameters, curdir, form, user_info=None): FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) # retrieve report number edsrn = parameters['edsrn'] newrnin = parameters['newrnin'] fp = open("%s/%s" % (curdir,edsrn),"r") rn = fp.read() fp.close() rn = re.sub("[\n\r]+","",rn) if newrnin != "" and os.path.exists("%s/%s" % (curdir,newrnin)): fp = open("%s/%s" % (curdir,newrnin),"r") additional_rn = fp.read() fp.close() additional_rn = re.sub("[\n\r]+","",additional_rn) fullrn = "%s and %s" % (additional_rn,rn) else: fullrn = rn fullrn = fullrn.replace("\n"," ") # The title is read from the file specified by 'titlefile' try: fp = open("%s/%s" % (curdir,parameters['titleFile']),"r") m_title = fp.read().replace("\n"," ") fp.close() except: m_title = "-" # The name of the author is read from the file specified by 'authorfile' try: fp = open("%s/%s" % (curdir,parameters['authorfile']),"r") m_author = fp.read().replace("\n"," ") fp.close() except: m_author = "-" # The submitters email address is read from the file specified by 'emailFile' try: fp = open("%s/%s" % (curdir,parameters['emailFile']),"r") m_recipient = fp.read().replace ("\n"," ") fp.close() except: m_recipient = "" # create email body email_txt = "The document %s\nTitle: %s\nAuthor(s): %s\n\nhas been correctly received\n\n" % (fullrn,m_title,m_author) # The user is either informed that the document has been added to the database, or sent for approval if parameters['status'] == "APPROVAL": email_txt = email_txt + "An email has been sent to the referee. You will be warned by email as soon as the referee takes his/her decision regarding your document.\n\n" elif parameters['status'] == "ADDED": email_txt = email_txt + "It will be soon added to our Document Server.\n\nOnce inserted, you will be able to check the bibliographic information and the quality of the electronic documents at this URL:\n<%s/record/%s>\nIf you detect an error please let us know by sending an email to %s. \n\n" % (htdocsurl,sysno,supportemail) email_txt = email_txt + "Thank you for using %s Submission Interface.\n" % cdsname # send the mail send_email(FROMADDR, m_recipient.strip(), "%s: Document Received" % fullrn, email_txt, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Make_Modify_Record.py b/modules/websubmit/lib/functions/Make_Modify_Record.py index 3bbbd88b5..71570c137 100644 --- a/modules/websubmit/lib/functions/Make_Modify_Record.py +++ b/modules/websubmit/lib/functions/Make_Modify_Record.py @@ -1,72 +1,72 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Make_Modify_Record ## This function creates the bibliographic record ## using bibConvert and the configuration files passed as ## parameters ## Author: T.Baron ## ## PARAMETERS: sourceModify: source description file ## mysqlModify: template description file ## OUTPUT: HTML import os from invenio.config import \ bibconvert, \ bibconvertconf from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Make_Modify_Record(parameters,curdir,form): +def Make_Modify_Record(parameters, curdir, form, user_info=None): # Get rid of "invisible" white spaces source = parameters['sourceTemplate'].replace(" ","") modify = parameters['modifyTemplate'].replace(" ","") # We use bibconvert to create the xml record call_uploader_txt = "%s -l1 -d'%s' -Cs'%s/%s' -Ct'%s/%s' > %s/recmysql" % (bibconvert,curdir,bibconvertconf,source,bibconvertconf,modify,curdir) os.system(call_uploader_txt) # Then we have to format this record (turn & into & and < into < # After all we know nothing about the text entered by the users at submission time if os.path.exists("%s/recmysql" % curdir): fp = open("%s/recmysql" % curdir,"r") rectext = fp.read() fp.close() else: raise InvenioWebSubmitFunctionError("Cannot create database record") # First of all the & rectext = rectext.replace("&","&") rectext = rectext.replace("&","&") # Then the < - More difficult! rectext = rectext.replace("<","<") rectext = rectext.replace("<record","elemfilename[re]* where re is an regexp to select(using re.sub) what part of the elem file has to be selected.e.g file:TEST_FILE_RN +parameters['documenttype']: if given, other formats are created. It has 2 possible values: - if "picture" icon in gif format is created - if "fulltext" ps, gz .... formats are created +parameters['paths_and_suffixes']: directories to look into and corresponding suffix to add to every file inside. It must have the same structure as a python dictionnary of the following form {'FrenchAbstract':'french', 'EnglishAbstract':''} The keys are the file input element name from the form <=> directories in curdir/files The values associated are the suffixes which will be added to all the files in e.g. curdir/files/FrenchAbstract +parameters['iconsize'] need only if "icon" is selected in parameters['documenttype'] """ global sysno paths_and_suffixes = parameters['paths_and_suffixes'] rename = parameters['rename'] documenttype = parameters['documenttype'] iconsize = parameters['iconsize'] ## Create an instance of BibRecDocs for the current recid(sysno) bibrecdocs = BibRecDocs(sysno) paths_and_suffixes = get_dictionary_from_string(paths_and_suffixes) ## Go through all the directory specified in the keys ## of parameters['paths_and_suffixes'] for path in paths_and_suffixes.keys(): ## Check if there is a directory for the current path if os.path.exists("%s/files/%s" % (curdir, path)): mybibdoc = None ## Check if there is no document with the same status (status=path) ## already associated with the current recid existing_with_same_status = bibrecdocs.list_bibdocs(path) ## If yes, use the existing docid if existing_with_same_status: mybibdoc = existing_with_same_status[0] ## Go through all the files in curdir/files/path for current_file in os.listdir("%s/files/%s" % (curdir, path)): ## retrieve filename and extension filename, extension = os.path.splitext(current_file) if len(paths_and_suffixes[path]) != 0: extension = "_%s%s" % (paths_and_suffixes[path], extension) ## Build the new file name if rename paramter has been given if rename: filename = re.sub('(?P[^<]*)', \ get_pa_tag_content, \ parameters['rename']) if rename or len(paths_and_suffixes[path]) != 0: ## Rename the file try: # Write the log rename_cmd fd = open("%s/rename_cmd" % curdir, "a+") fd.write("%s/files/%s/%s" % (curdir, path, current_file) + " to " +\ "%s/files/%s/%s%s" % (curdir, path, filename, extension) + "\n\n") ## Rename os.rename("%s/files/%s/%s" % (curdir, path, current_file), \ "%s/files/%s/%s%s" % (curdir, path, filename, extension)) fd.close() ## Save the new name in a text file in curdir so that ## the new filename can be used by templates to created the recmysl fd = open("%s/%s_RENAMED" % (curdir, path), "w") fd.write("%s%s" % (filename, extension)) fd.close() except OSError, err: msg = "Cannot rename the file.[%s]" msg %= str(err) raise InvenioWebSubmitFunctionWarning(msg) fullpath = "%s/files/%s/%s%s" % (curdir, path, filename, extension) ## Check if there is any existing similar file if not bibrecdocs.check_file_exists(fullpath): if not mybibdoc: ## New docid is created mybibdoc = bibrecdocs.add_new_file(fullpath, never_fail=True) else: ## No new docid created but the file ## is archive in /bibdoc ID/ directory mybibdoc = bibrecdocs.add_new_format(fullpath, mybibdoc.get_docname()) ## Create related formats if mybibdoc: ## Fulltext if documenttype == "fulltext": additionalformats = createRelatedFormats(fullpath) if len(additionalformats) > 0: for additionalformat in additionalformats: mybibdoc.add_file_new_format(additionalformat) ## Icon elif documenttype == "picture": iconpath = createIcon(fullpath, iconsize) if iconpath is not None and mybibdoc is not None: mybibdoc.add_icon(iconpath) ## Save the new icon filename in a text file in curdir so that ## it can be used by templates to created the recmysl try: fd = open("%s/%s_ICON" % (curdir, path), "w") fd.write(os.path.basename(iconpath)) fd.close() except OSError, err: msg = "Cannot store icon filename.[%s]" msg %= str(err) raise InvenioWebSubmitFunctionWarning(msg) elif mybibdoc is not None: mybibdoc.delete_icon() return "" def get_pa_tag_content(pa_content): """Get content for XXX. @param pa_content: MatchObject for (.*). return: the content of the file possibly filtered by an regular expression if pa_content=file[re]:a_file => first line of file a_file matching re if pa_content=file*p[re]:a_file => all lines of file a_file, matching re, separated by - (dash) char. """ pa_content = pa_content.groupdict()['content'] sep = '-' out = '' if pa_content.startswith('file'): filename = "" regexp = "" if "[" in pa_content: split_index_start = pa_content.find("[") split_index_stop = pa_content.rfind("]") regexp = pa_content[split_index_start+1:split_index_stop] filename = pa_content[split_index_stop+2:]## ]: else : filename = pa_content.split(":")[1] if os.path.exists(os.path.join(curdir, filename)): fp = open(os.path.join(curdir, filename), 'r') if pa_content[:5] == "file*": out = sep.join(map(lambda x: re.split(regexp, x.strip())[-1], fp.readlines())) else: out = re.split(regexp, fp.readline().strip())[-1] fp.close() return out diff --git a/modules/websubmit/lib/functions/Move_From_Pending.py b/modules/websubmit/lib/functions/Move_From_Pending.py index b7c27ee62..4405760fc 100644 --- a/modules/websubmit/lib/functions/Move_From_Pending.py +++ b/modules/websubmit/lib/functions/Move_From_Pending.py @@ -1,47 +1,47 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Move_From_Pending ## This function retrieves an old submisison directory which ## had been saved in /pending and moves all the data files ## in the current working directory ## Author: T.Baron ## PARAMETERS: - import os from invenio.config import storage from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Move_From_Pending(parameters,curdir,form): +def Move_From_Pending(parameters, curdir, form, user_info=None): global rn doctype = form['doctype'] srcdir = "%s/pending/%s/%s" % (storage,doctype,rn) if os.path.exists(srcdir): if rn != "": files = os.listdir(srcdir) for file in files: os.rename("%s/%s" % (srcdir,file), "%s/%s" % (curdir,file)) os.rmdir(srcdir) else: raise InvenioWebSubmitFunctionError("Move_From_Pending: Cannot retrieve reference information %s" % srcdir) return "" diff --git a/modules/websubmit/lib/functions/Move_to_Done.py b/modules/websubmit/lib/functions/Move_to_Done.py index 6dad8514e..41a72ad2a 100644 --- a/modules/websubmit/lib/functions/Move_to_Done.py +++ b/modules/websubmit/lib/functions/Move_to_Done.py @@ -1,62 +1,62 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Move_to_Done ## This function move the current working directory to the ## /done directory and compress it ## Author: T.Baron ## PARAMETERS: - import os import re import time from invenio.config import \ CFG_PATH_GZIP, \ CFG_PATH_TAR, \ storage from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Move_to_Done(parameters,curdir,form): +def Move_to_Done(parameters, curdir, form, user_info=None): global rn data = re.search(".*/([^/]*)/([^/]*)/[^/]*$",curdir) dir = data.group(1) doctype = data.group(2) DONEDIR = "%s/done/%s/%s" % (storage,dir,doctype) if not os.path.exists(DONEDIR): try: os.makedirs(DONEDIR) except: raise InvenioWebSubmitFunctionError("Cannot create done directory %s" % DONEDIR) # Moves the files to the done diectory and creates an archive rn = rn.replace("/","-") namedir = "%s_%s" % (rn,time.strftime("%Y%m%d%H%M%S")) FINALDIR = "%s/%s" % (DONEDIR,namedir) os.rename(curdir,FINALDIR) if CFG_PATH_TAR != "" and CFG_PATH_GZIP != "": os.chdir(DONEDIR) tar_txt = "%s -cf - %s > %s.tar" % (CFG_PATH_TAR,namedir,namedir) os.system(tar_txt) zip_txt = "%s %s.tar" % (CFG_PATH_GZIP,namedir) os.system(zip_txt) rm_txt = "rm -R %s" % namedir os.system(rm_txt) return "" diff --git a/modules/websubmit/lib/functions/Move_to_Pending.py b/modules/websubmit/lib/functions/Move_to_Pending.py index 46fd7a521..6552ca7d8 100644 --- a/modules/websubmit/lib/functions/Move_to_Pending.py +++ b/modules/websubmit/lib/functions/Move_to_Pending.py @@ -1,48 +1,48 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Move_to_Pending ## This function moves the current working directory to ## /pending (usually the document is then waiting for ## approval) ## Author: T.Baron ## PARAMETERS: - import os from invenio.config import storage from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Move_to_Pending(parameters,curdir,form): +def Move_to_Pending(parameters, curdir, form, user_info=None): global rn doctype = form['doctype'] PENDIR = "%s/pending/%s" % (storage,doctype) if not os.path.exists(PENDIR): try: os.makedirs(PENDIR) except: raise InvenioWebSubmitFunctionError("Cannot create pending directory %s" % PENDIR) # Moves the files to the pending directory rn = rn.replace("/","-") namedir = rn FINALDIR = "%s/%s" % (PENDIR,namedir) os.rename(curdir,FINALDIR) return "" diff --git a/modules/websubmit/lib/functions/Print_Success.py b/modules/websubmit/lib/functions/Print_Success.py index 88b0269d7..7dc77d184 100644 --- a/modules/websubmit/lib/functions/Print_Success.py +++ b/modules/websubmit/lib/functions/Print_Success.py @@ -1,50 +1,50 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" import os from invenio.config import cdsname # FIXME: cannot import Request_Print(), is defined in websubmit_engine.py -def Print_Success(parameters,curdir,form): +def Print_Success(parameters, curdir, form, user_info=None): t="" edsrn = parameters['edsrn'] newrnin = parameters['newrnin'] status = parameters['status'] fp = open("%s/%s" % (curdir,edsrn),"r") rn = fp.read() fp.close() if newrnin != "" and os.path.exists("%s/%s" % (curdir,newrnin)): fp = open("%s/%s" % (curdir,newrnin),"r") additional_rn = fp.read() fp.close() additional_rn = " and %s" % additional_rn else: additional_rn = "" t=t+Request_Print("A", "

Submission Complete!

") t=t+Request_Print("A", "Your document has the following reference(s): %s%s

" % (rn,additional_rn)) if status == "APPROVAL": t=t+Request_Print("A", "An email has been sent to the referee. You will be warned by email as soon as the referee takes his/her decision regarding your document.

\n") if status == "ADDED": t=t+Request_Print("A", "It will soon appear on our server.

\n") t=t+Request_Print("A", "Thank you for using %s!" % cdsname) t=t+Request_Print("A", "



") return t diff --git a/modules/websubmit/lib/functions/Print_Success_APP.py b/modules/websubmit/lib/functions/Print_Success_APP.py index b73e49b70..a3a5beb4a 100644 --- a/modules/websubmit/lib/functions/Print_Success_APP.py +++ b/modules/websubmit/lib/functions/Print_Success_APP.py @@ -1,45 +1,45 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Print_Success_APP ## This function outputs a message telling the user his/her ## decision was taken into account. ## Author: T.Baron ## PARAMETERS: - import os from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Print_Success_APP(parameters,curdir,form): +def Print_Success_APP(parameters, curdir, form, user_info=None): global rn # the field containing the decision of the referee must be called "decision". if not os.path.exists("%s/decision" % curdir): raise InvenioWebSubmitFunctionError("Could not find decision file") else: fp = open("%s/decision" % curdir,"r") decision = fp.read() fp.close() t="

Your decision has been taken into account!

" if decision == "approve": t+="The document will be soon available with the following reference: %s
" % rn return t diff --git a/modules/websubmit/lib/functions/Print_Success_CPLX.py b/modules/websubmit/lib/functions/Print_Success_CPLX.py index f1653f290..50e60fa31 100644 --- a/modules/websubmit/lib/functions/Print_Success_CPLX.py +++ b/modules/websubmit/lib/functions/Print_Success_CPLX.py @@ -1,41 +1,41 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. #__revision__ = "$Id$" ## Description: function Print_Success_CPLX ## This function outputs a message telling the user his/her ## request was taken into account. ## Author: A.Voitier ## PARAMETERS: - import os from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Print_Success_CPLX(parameters,curdir,form): +def Print_Success_CPLX(parameters, curdir, form, user_info=None): global rn act = form['act'] t="

Your request has been taken into account!

" if (act == "RRP") or (act == "RPB"): t+="An email has been sent to the Publication Committee Chair. You will be warned by email as soon as the Project Leader takes his/her decision regarding your document.

" elif act == "RDA": t+="An email has been sent to the Project Leader. You will be warned by email as soon as the Project Leader takes his/her decision regarding your document.

" return t diff --git a/modules/websubmit/lib/functions/Print_Success_DEL.py b/modules/websubmit/lib/functions/Print_Success_DEL.py index 3fa96e117..ff2c5e11d 100644 --- a/modules/websubmit/lib/functions/Print_Success_DEL.py +++ b/modules/websubmit/lib/functions/Print_Success_DEL.py @@ -1,32 +1,32 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Print_Success_DEL ## This function displays a message telling the user the ## record has actually been deleted ## Author: T.Baron ## PARAMETERS: - -def Print_Success_DEL(parameters,curdir,form): +def Print_Success_DEL(parameters, curdir, form, user_info=None): global rn t="

Document %s was successfully deleted." % rn return t diff --git a/modules/websubmit/lib/functions/Print_Success_MBI.py b/modules/websubmit/lib/functions/Print_Success_MBI.py index 46854d0e7..c68d7ce7a 100644 --- a/modules/websubmit/lib/functions/Print_Success_MBI.py +++ b/modules/websubmit/lib/functions/Print_Success_MBI.py @@ -1,36 +1,36 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" from invenio.config import \ cdsname ## Description: function Print_Success_MBI ## This function displays a message telling the user the ## modification has been taken into account ## Author: T.Baron ## PARAMETERS: - -def Print_Success_MBI(parameters,curdir,form): +def Print_Success_MBI(parameters, curdir, form, user_info=None): global rn t="Modification completed!

" t+="These modifications on document %s will be processed as quickly as possible and made
available on the %s Server" % (rn,cdsname) return t diff --git a/modules/websubmit/lib/functions/Print_Success_SRV.py b/modules/websubmit/lib/functions/Print_Success_SRV.py index b9502712f..47ebd0b4d 100644 --- a/modules/websubmit/lib/functions/Print_Success_SRV.py +++ b/modules/websubmit/lib/functions/Print_Success_SRV.py @@ -1,32 +1,32 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Print_Success_SRV ## This function displays a message telling the user the ## revised files have been correctly received ## Author: T.Baron ## PARAMETERS: - -def Print_Success_SRV(parameters,curdir,form): +def Print_Success_SRV(parameters, curdir, form, user_info=None): global rn t="

Document %s was successfully revised." % rn return t diff --git a/modules/websubmit/lib/functions/Report_Number_Generation.py b/modules/websubmit/lib/functions/Report_Number_Generation.py index 03f5ab4d9..8f3302cff 100644 --- a/modules/websubmit/lib/functions/Report_Number_Generation.py +++ b/modules/websubmit/lib/functions/Report_Number_Generation.py @@ -1,243 +1,243 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Description: function Report_Number_Generation This function creates a reference for the submitted document and saves it in the specified file. Author: T.Baron""" __revision__ = "$Id$" import os import re import time from invenio.config import counters from invenio.websubmit_config import InvenioWebSubmitFunctionError -def Report_Number_Generation(parameters, curdir, form): +def Report_Number_Generation(parameters, curdir, form, user_info=None): """Description: function Report_Number_Generation This function creates a reference for the submitted document and saves it in the specified file. Author: T.Baron PARAMETERS: edsrn: name of the file in which the reference is saved autorngen: one of "A", "N", "Y" "A": The reference is the submission number "N": The reference is taken from a file [edsrn] "Y": The reference is generated rnin: name of the file containing the category counterpath: path to the counter file note you can use: yy to include year categ to include category of the submission file[re]:name_of_file[regular expression to match] first line of file generated by submission, matching [re] file*[re]:name_of_file [regular expression to match] all the lines of a file genereated during submission, matching [re] separated by - (dash) char . rnformat: format for the generated reference. You can use: yy to include year categ to include category of the submission file[re]:name_of_file[regular expression to match] first line of file generated by submission, matching [re] file*[re]:name_of_file [regular expression to match] all the lines of a file genereated during submission, matching [re] separated by - (dash) char . yeargen: if "AUTO", current year, else the year is extracted from the file [yeargen] """ global doctype, access, act, dir, rn # The program must automatically generate the report number # Generate Year if parameters['autorngen'] == "Y": if parameters['yeargen'] == "AUTO": # Current year is used yy = time.strftime("%Y") else : # If yeargen != auto then the contents of the file named 'yeargen' is used # Assumes file uses DD-MM-YYYY format fp = open("%s/%s" % (curdir, parameters['yeargen']), "r") mydate = fp.read() fp.close() yy = re.sub("^......", "", mydate) # Evaluate category - Category is read from the file named 'rnin if os.path.isfile("%s/%s" % (curdir,parameters['rnin'])): fp = open("%s/%s" % (curdir,parameters['rnin']), "r") category = fp.read() category = category.replace("\n", "") else: category = "" def get_pa_tag_content(pa_content): """Get content for XXX. @param pa_content: MatchObject for (.*). return: if pa_content=yy => 4 digits year if pa_content=categ =>category if pa_content=file[re]:a_file => first line of file a_file matching re if pa_content=file*p[re]:a_file => all lines of file a_file, matching re, separated by - (dash) char. """ pa_content=pa_content.groupdict()['content'] sep = '-' out = '' if pa_content=='yy': out = yy elif pa_content=='categ': out = category elif pa_content.startswith('file'): filename = "" with_regexp = 0 regexp = "" if "[" in pa_content: with_regexp = 1 split_index_start = pa_content.find("[") split_index_stop = pa_content.rfind("]") regexp = pa_content[split_index_start+1:split_index_stop] filename = pa_content[split_index_stop+2:]#]: else : filename = pa_content.split(":")[1] if os.path.exists(os.path.join(curdir, filename)): fp = open(os.path.join(curdir, filename), 'r') if pa_content[:5]=="file*": out = sep.join(map(lambda x: re.split(regexp,x.strip())[-1], fp.readlines())) else: out = re.split(regexp, fp.readline().strip())[-1] fp.close() return out counter_path = re.sub('(?P[^<]*)', get_pa_tag_content, parameters['counterpath']) counter_path = counter_path.replace(" ", "") counter_path = counter_path.replace("\n", "") rn_format = re.sub('(?P[^<]*)', get_pa_tag_content, parameters['rnformat']) # Check if the report number does not already exists if os.path.exists("%s/%s" % (curdir, parameters['edsrn'])): fp = open("%s/%s" % (curdir, parameters['edsrn']), "r") oldrn = fp.read() fp.close() if oldrn != "" and not re.search("\?\?\?", oldrn): rn = oldrn return "" # create it rn = Create_Reference(counter_path, rn_format) rn = rn.replace("\n", "") rn = rn.replace("\r", "") rn = rn.replace("\015", "") rn = rn.replace("\013", "") rn = rn.replace("\012", "") # The file edsrn is created in the submission directory, and it stores the report number fp = open("%s/%s" % (curdir, parameters['edsrn']), "w") fp.write(rn) fp.close() # The report number is just read from a specified file elif parameters['autorngen'] == "N": fp = open("%s/%s" % (curdir, parameters['edsrn']), "r") rn = fp.read() fp.close() # Some documents are really annoying and insist on a totally different way of doing things # This code is for documents which have the access number in the report # number (instead of using a counter) elif parameters['autorngen'] == "A": rn = parameters['rnformat'].replace("access", access) # The file accessno/edsrn is created, and it stores the report number fp = open("%s/%s" % (curdir, parameters['edsrn']), "w") fp.write(rn) fp.close() return "" def Create_Reference(counter_path, ref_format): """From the counter-file for this document submission, get the next reference number and create the reference. """ ## Does the WebSubmit counters directory exist? Create it if not. ## (~cds-invenio/var/data/submit/counters) if not os.path.exists(counters): ## Counters dit doesn't exist. Create: try: os.mkdir(counters) except: ## Unable to create the counters Dir. msg = "File System: Cannot create counters directory %s" % counters raise InvenioWebSubmitFunctionError(msg) ## Now, take the "counter_path", and split it into the head (the path ## to the counter file) and tail (the name of the counter file itself). (head_cpath, tail_cpath) = os.path.split(counter_path) if head_cpath.strip() != "": ## There is a "head" for counter-path. If these directories ## don't exist, make them: if not os.path.exists("%s/%s" % (counters, head_cpath)): try: os.makedirs(os.path.normpath("%s/%s" % (counters, head_cpath))) except OSError: msg = "File System: no permission to create counters " \ "directory [%s/%s]" % (counters, head_cpath) raise InvenioWebSubmitFunctionError(msg) ## Now, if the counter-file itself doesn't exist, create it: if not os.path.exists("%s/%s" % (counters, counter_path)): try: fp = open("%s/%s" % (counters, counter_path),"w") except: msg = "File System: no permission to write in counters " \ "directory %s" % counters raise InvenioWebSubmitFunctionError(msg) else: fp.write("0") fp.close() ## retrieve current counter value try: fp = open("%s/%s" % (counters, counter_path), "r") except IOError: ## Unable to open the counter file for reading: msg = "File System: Unable to read from counter-file [%s/%s]." \ % (counters, counter_path) raise InvenioWebSubmitFunctionError(msg) else: id = fp.read() fp.close() if id == "": ## The counter file seems to have been empty. Set the value to 0: id = 0 ## increment the counter by 1: id = int(id) + 1 ## store the new value in the counter file: try: fp = open("%s/%s" % (counters, counter_path), "w") except IOError: ## Unable to open the counter file for writing: msg = "File System: Unable to write to counter-file [%s/%s]. " \ % (counters, counter_path) raise InvenioWebSubmitFunctionError(msg) else: fp.write(str(id)) fp.close() ## create final value reference = "%s-%03d" % (ref_format,id) ## Return the report number prelude with the id concatenated on at the end return reference diff --git a/modules/websubmit/lib/functions/Send_APP_Mail.py b/modules/websubmit/lib/functions/Send_APP_Mail.py index f465d95c5..d7d8b7b64 100644 --- a/modules/websubmit/lib/functions/Send_APP_Mail.py +++ b/modules/websubmit/lib/functions/Send_APP_Mail.py @@ -1,121 +1,121 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Send_APP_Mail ## This function send an email informing the original ## submitter of a document that the referee has approved/ ## rejected the document. The email is also sent to the ## referee for checking. ## Author: T.Baron ## PARAMETERS: ## newrnin: name of the file containing the 2nd reference ## addressesAPP: email addresses to which the email will ## be sent (additionally to the author) ## categformatAPP: variable needed to derive the addresses ## mentioned above import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail from invenio.access_control_admin import acc_get_role_users, acc_get_role_id from invenio.dbquery import run_sql from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_APP_Mail (parameters,curdir,form): +def Send_APP_Mail (parameters, curdir, form, user_info=None): global emailvalue,titlevalue,authorvalue,sysno,rn FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) doctype = form['doctype'] emailvalue = emailvalue.replace("\n","") titlevalue = titlevalue.replace("\n","") authorvalue = authorvalue.replace("\n","") # variables declaration categformat = parameters['categformatAPP'] otheraddresses = parameters['addressesAPP'] newrnpath = parameters['newrnin'] # retrieve values stored into files if os.path.exists("%s/COM" % curdir): fp = open("%s/COM" % curdir, "r") comment = fp.read() fp.close() else: comment = "" if os.path.exists("%s/decision" % curdir): fp = open("%s/decision" % curdir,"r") decision = fp.read() fp.close() else: decision = "" if os.path.exists("%s/%s" % (curdir,newrnpath)): fp = open("%s/%s" % (curdir,newrnpath) , "r") newrn = fp.read() fp.close() else: newrn = "" # Document name res = run_sql("SELECT ldocname FROM sbmDOCTYPE WHERE sdocname=%s", (doctype,)) docname = res[0][0] # retrieve category categformat = categformat.replace("","([^-]*)") categs = re.match(categformat,rn) if categs is not None: category = categs.group(1) else: category = "unknown" # Build referee's email address refereeaddress = "" # Try to retrieve the referee's email from the referee's database for user in acc_get_role_users(acc_get_role_id("referee_%s_%s" % (doctype,category))): refereeaddress += user[1] + "," # And if there is a general referee for user in acc_get_role_users(acc_get_role_id("referee_%s_*" % doctype)): refereeaddress += user[1] + "," refereeaddress = re.sub(",$","",refereeaddress) # Creation of the mail for the referee otheraddresses = otheraddresses.replace("",category) addresses = "" if refereeaddress != "": addresses = refereeaddress + "," if otheraddresses != "": addresses += otheraddresses else: addresses = re.sub(",$","",addresses) if decision == "approve": mailtitle = "%s has been approved" % rn mailbody = "The %s %s has been approved." % (docname,rn) mailbody += "\nIt will soon be accessible here:\n<%s/record/%s>" % (htdocsurl,sysno) else: mailtitle = "%s has been rejected" % rn mailbody = "The %s %s has been rejected." % (docname,rn) if rn != newrn and decision == "approve" and newrn != "": mailbody += "Its new reference number is: %s" % newrn mailbody += "\n\nTitle: %s\n\nAuthor(s): %s\n\n" % (titlevalue,authorvalue) if comment != "": mailbody += "Comments from the referee:\n%s\n" % comment mailbody += "---------------------------------------------\nBest regards.\nThe submission team.\n" # Send mail to referee send_email(FROMADDR,addresses,mailtitle,mailbody, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_Approval_Request.py b/modules/websubmit/lib/functions/Send_Approval_Request.py index 50219e181..ca23a4316 100644 --- a/modules/websubmit/lib/functions/Send_Approval_Request.py +++ b/modules/websubmit/lib/functions/Send_Approval_Request.py @@ -1,113 +1,113 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Send_Approval_Request ## This function sends an email to the referee asking him/her ## to approve/reject a document ## Author: T.Baron ## PARAMETERS: directory: parameter to the link manager program ## addressesDAM: address of the referee(s) ## categformatDAM: variable needed to extract the category ## of the document and use it to derive the ## address. ## authorfile: name of the file containing the author list ## titleFile: name of the file containing the title import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail, \ urlpath from invenio.dbquery import run_sql from invenio.access_control_admin import acc_get_role_users,acc_get_role_id from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_Approval_Request (parameters,curdir,form): +def Send_Approval_Request (parameters, curdir, form, user_info=None): global rn,sysno # variables declaration doctype = re.search(".*/([^/]*)/([^/]*)/[^/]*$",curdir).group(2) FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) otheraddresses = parameters['addressesDAM'] categformat = parameters['categformatDAM'] # retrieve category categformat = categformat.replace("","([^-]*)") categs = re.match(categformat,rn) if categs is not None: category = categs.group(1) else: category = "unknown" # create TI if os.path.exists("%s/date" % curdir): fp = open("%s/date" % curdir, "r") date = fp.read() fp.close() else: date = "" if os.path.exists("%s/%s" % (curdir,parameters['titleFile'])): fp = open("%s/%s" % (curdir,parameters['titleFile']),"r") title = fp.read() fp.close() title = title.replace("\n","") else: title = "" title += " - %s" % date # create AU if os.path.exists("%s/%s" % (curdir,parameters['authorfile'])): fp = open("%s/%s" % (curdir,parameters['authorfile']), "r") author = fp.read() fp.close() else: author = "" # we get the referee password sth = run_sql("SELECT access FROM sbmAPPROVAL WHERE rn=%s", (rn,)) if len(sth) >0: access = sth[0][0] # Build referee's email address refereeaddress = "" # Try to retrieve the referee's email from the referee's database for user in acc_get_role_users(acc_get_role_id("referee_%s_%s" % (doctype,category))): refereeaddress += user[1] + "," # And if there are general referees for user in acc_get_role_users(acc_get_role_id("referee_%s_*" % doctype)): refereeaddress += user[1] + "," refereeaddress = re.sub(",$","",refereeaddress) # Creation of the mail for the referee addresses = "" if refereeaddress != "": addresses = refereeaddress + "," if otheraddresses != "": addresses += otheraddresses else: addresses = re.sub(",$","",addresses) title_referee = "Request for approval of %s" % rn mail_referee = "The document %s has been submitted to the %s Server..\nYour approval is requested on it.\n\n" % (rn,cdsname) mail_referee +="Title: %s\n\nAuthor(s): %s\n\n" % (title,author) mail_referee +="To access the document(s), select the file(s) from the location:<%s/getfile.py?recid=%s>\n\n" % (htdocsurl,sysno) mail_referee +="To approve/reject the document, you should go to this URL:\n<%s/approve.py?%s>\n" % (urlpath,access) mail_referee +="---------------------------------------------\nBest regards.\nThe submission team.\n" #Send mail to referee send_email(FROMADDR, addresses, title_referee, mail_referee, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_Modify_Mail.py b/modules/websubmit/lib/functions/Send_Modify_Mail.py index 38290785c..c626686c7 100644 --- a/modules/websubmit/lib/functions/Send_Modify_Mail.py +++ b/modules/websubmit/lib/functions/Send_Modify_Mail.py @@ -1,78 +1,78 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Send_Modify_Mail ## This function sends an email saying the document has been ## correctly updated ## Author: T.Baron ## PARAMETERS: addressesMBI: email addresses to which the mail is sent ## fieldnameMBI: name of the file containing the modified ## fields ## sourceDoc: name of the type of document ## emailFile: name of the file containing the email of the ## user import os import re from invenio.config import \ accessurl, \ adminemail, \ cdsname, \ supportemail, \ weburl from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_Modify_Mail (parameters,curdir,form): +def Send_Modify_Mail (parameters, curdir, form, user_info=None): FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) global sysno,rn if parameters['emailFile'] is not None and parameters['emailFile']!= "" and os.path.exists("%s/%s" % (curdir,parameters['emailFile'])): fp = open("%s/%s" % (curdir,parameters['emailFile']),"r") sub = fp.read() fp.close() sub = sub.replace ("\n","") else: sub = "" # Copy mail to: addresses = parameters['addressesMBI'] addresses = addresses.strip() m_fields = parameters['fieldnameMBI'] type = parameters['sourceDoc'] rn = re.sub("[\n\r ]+","",rn) if os.path.exists("%s/%s" % (curdir,m_fields)): fp = open("%s/%s" % (curdir,m_fields),"r") fields = fp.read() fp.close() fields = fields.replace ("\n"," | ") fields = re.sub("[| \n\r]+$","",fields) else: fields = "" email_txt = "Dear Sir or Madam, \n%s %s has just been modified.\nModified fields: %s\n\n" % (type,rn,fields) if accessurl != "" and sysno != "": email_txt += "You can check the modified document here:\n" email_txt += "<%s/record/%s>\n\n" % (weburl,sysno) email_txt += "Please note that the modifications will be taken into account in a couple of minutes.\n\nBest regards,\nThe %s Server support Team" % cdsname # send the mail send_email(FROMADDR,sub,"%s modified" % rn,email_txt,copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_Request_For_Direct_Approval.py b/modules/websubmit/lib/functions/Send_Request_For_Direct_Approval.py index 89e9eb85a..e9009e33b 100644 --- a/modules/websubmit/lib/functions/Send_Request_For_Direct_Approval.py +++ b/modules/websubmit/lib/functions/Send_Request_For_Direct_Approval.py @@ -1,113 +1,113 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. #__revision__ = "$Id$" ## Description: function Send_Approval_Request ## This function sends an email to the referee asking him/her ## to approve/reject a document ## Author: T.Baron ## PARAMETERS: directory: parameter to the link manager program ## addressesDAM: address of the referee(s) ## categformatDAM: variable needed to extract the category ## of the document and use it to derive the ## address. ## authorfile: name of the file containing the author list ## titleFile: name of the file containing the title import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail, \ urlpath from invenio.dbquery import run_sql from invenio.access_control_admin import acc_get_role_users,acc_get_role_id from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_Request_For_Direct_Approval (parameters,curdir,form): +def Send_Request_For_Direct_Approval (parameters, curdir, form, user_info=None): global rn,sysno # variables declaration doctype = re.search(".*/([^/]*)/([^/]*)/[^/]*$",curdir).group(2) FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) otheraddresses = parameters['addressesDAM'] categformat = parameters['categformatDAM'] # retrieve category categformat = categformat.replace("","([^-]*)") categs = re.match(categformat,rn) if categs is not None: category = categs.group(1) else: category = "unknown" # create TI if os.path.exists("%s/date" % curdir): fp = open("%s/date" % curdir, "r") date = fp.read() fp.close() else: date = "" if os.path.exists("%s/%s" % (curdir,parameters['titleFile'])): fp = open("%s/%s" % (curdir,parameters['titleFile']),"r") title = fp.read() fp.close() title = title.replace("\n","") else: title = "" title += " - %s" % date # create AU if os.path.exists("%s/%s" % (curdir,parameters['authorfile'])): fp = open("%s/%s" % (curdir,parameters['authorfile']), "r") author = fp.read() fp.close() else: author = "" # we get the referee password #sth = run_sql("SELECT access FROM sbmAPPROVAL WHERE rn=%s", (rn,)) #if len(sth) >0: #access = sth[0][0] # Build referee's email address refereeaddress = "" # Try to retrieve the publication committee chair's email from the role database for user in acc_get_role_users(acc_get_role_id("projectleader_%s_%s" % (doctype,category))): refereeaddress += user[1] + "," # And if there are general referees for user in acc_get_role_users(acc_get_role_id("projectleader_%s_*" % doctype)): refereeaddress += user[1] + "," refereeaddress = re.sub(",$","",refereeaddress) # Creation of the mail for the referee addresses = "" if refereeaddress != "": addresses = refereeaddress + "," if otheraddresses != "": addresses += otheraddresses else: addresses = re.sub(",$","",addresses) title_referee = "Request for direct approval of %s" % rn mail_referee = "The document %s has been asked direct approval to the %s Server..\nYour approval is requested on it.\n\n" % (rn,cdsname) mail_referee +="Title: %s\n\nAuthor(s): %s\n\n" % (title,author) mail_referee +="To access the document(s), select the file(s) from the location:<%s/getfile.py?recid=%s>\n\n" % (htdocsurl,sysno) mail_referee +="To approve/reject the document, you should go to this URL:\n<%s/publiline.py?doctype=%s&categ=%s&RN=%s>\n" % (urlpath,doctype,category,rn) mail_referee +="---------------------------------------------\nBest regards.\nThe submission team.\n" #Send mail to referee send_email(FROMADDR, addresses, title_referee, mail_referee, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_Request_For_Publication.py b/modules/websubmit/lib/functions/Send_Request_For_Publication.py index e08bc3c8a..46f22610a 100644 --- a/modules/websubmit/lib/functions/Send_Request_For_Publication.py +++ b/modules/websubmit/lib/functions/Send_Request_For_Publication.py @@ -1,113 +1,113 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. #__revision__ = "$Id$" ## Description: function Send_Approval_Request ## This function sends an email to the referee asking him/her ## to approve/reject a document ## Author: T.Baron ## PARAMETERS: directory: parameter to the link manager program ## addressesDAM: address of the referee(s) ## categformatDAM: variable needed to extract the category ## of the document and use it to derive the ## address. ## authorfile: name of the file containing the author list ## titleFile: name of the file containing the title import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail, \ urlpath from invenio.dbquery import run_sql from invenio.access_control_admin import acc_get_role_users,acc_get_role_id from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_Request_For_Publication (parameters,curdir,form): +def Send_Request_For_Publication(parameters, curdir, form, user_info=None): global rn,sysno # variables declaration doctype = re.search(".*/([^/]*)/([^/]*)/[^/]*$",curdir).group(2) FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) otheraddresses = parameters['addressesDAM'] categformat = parameters['categformatDAM'] # retrieve category categformat = categformat.replace("","([^-]*)") categs = re.match(categformat,rn) if categs is not None: category = categs.group(1) else: category = "unknown" # create TI if os.path.exists("%s/date" % curdir): fp = open("%s/date" % curdir, "r") date = fp.read() fp.close() else: date = "" if os.path.exists("%s/%s" % (curdir,parameters['titleFile'])): fp = open("%s/%s" % (curdir,parameters['titleFile']),"r") title = fp.read() fp.close() title = title.replace("\n","") else: title = "" title += " - %s" % date # create AU if os.path.exists("%s/%s" % (curdir,parameters['authorfile'])): fp = open("%s/%s" % (curdir,parameters['authorfile']), "r") author = fp.read() fp.close() else: author = "" # we get the referee password #sth = run_sql("SELECT access FROM sbmAPPROVAL WHERE rn=%s", (rn,)) #if len(sth) >0: #access = sth[0][0] # Build referee's email address refereeaddress = "" # Try to retrieve the publication committee chair's email from the role database for user in acc_get_role_users(acc_get_role_id("pubcomchair_%s_%s" % (doctype,category))): refereeaddress += user[1] + "," # And if there are general referees for user in acc_get_role_users(acc_get_role_id("pubcomchair_%s_*" % doctype)): refereeaddress += user[1] + "," refereeaddress = re.sub(",$","",refereeaddress) # Creation of the mail for the referee addresses = "" if refereeaddress != "": addresses = refereeaddress + "," if otheraddresses != "": addresses += otheraddresses else: addresses = re.sub(",$","",addresses) title_referee = "Request for publication of %s" % rn mail_referee = "The document %s has been asked for publication to the %s Server..\nYour have to select an editorial board for it.\n\n" % (rn,cdsname) mail_referee +="Title: %s\n\nAuthor(s): %s\n\n" % (title,author) mail_referee +="To access the document(s), select the file(s) from the location:<%s/getfile.py?recid=%s>\n\n" % (htdocsurl,sysno) mail_referee +="To select an editorial board, you should go to this URL:\n<%s/publiline.py?doctype=%s&categ=%s&RN=%s>\n" % (urlpath,doctype,category,rn) mail_referee +="---------------------------------------------\nBest regards.\nThe submission team.\n" #Send mail to referee send_email(FROMADDR, addresses, title_referee, mail_referee, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_Request_For_Refereeing_Process.py b/modules/websubmit/lib/functions/Send_Request_For_Refereeing_Process.py index 2c334689f..d3d305527 100644 --- a/modules/websubmit/lib/functions/Send_Request_For_Refereeing_Process.py +++ b/modules/websubmit/lib/functions/Send_Request_For_Refereeing_Process.py @@ -1,113 +1,113 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. #__revision__ = "$Id$" ## Description: function Send_Approval_Request ## This function sends an email to the referee asking him/her ## to approve/reject a document ## Author: T.Baron ## PARAMETERS: directory: parameter to the link manager program ## addressesDAM: address of the referee(s) ## categformatDAM: variable needed to extract the category ## of the document and use it to derive the ## address. ## authorfile: name of the file containing the author list ## titleFile: name of the file containing the title import os import re from invenio.config import \ adminemail, \ cdsname, \ htdocsurl, \ supportemail, \ urlpath from invenio.dbquery import run_sql from invenio.access_control_admin import acc_get_role_users,acc_get_role_id from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email -def Send_Request_For_Refereeing_Process (parameters,curdir,form): +def Send_Request_For_Refereeing_Process(parameters, curdir, form, user_info=None): global rn,sysno # variables declaration doctype = re.search(".*/([^/]*)/([^/]*)/[^/]*$",curdir).group(2) FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) otheraddresses = parameters['addressesDAM'] categformat = parameters['categformatDAM'] # retrieve category categformat = categformat.replace("","([^-]*)") categs = re.match(categformat,rn) if categs is not None: category = categs.group(1) else: category = "unknown" # create TI if os.path.exists("%s/date" % curdir): fp = open("%s/date" % curdir, "r") date = fp.read() fp.close() else: date = "" if os.path.exists("%s/%s" % (curdir,parameters['titleFile'])): fp = open("%s/%s" % (curdir,parameters['titleFile']),"r") title = fp.read() fp.close() title = title.replace("\n","") else: title = "" title += " - %s" % date # create AU if os.path.exists("%s/%s" % (curdir,parameters['authorfile'])): fp = open("%s/%s" % (curdir,parameters['authorfile']), "r") author = fp.read() fp.close() else: author = "" # we get the referee password #sth = run_sql("SELECT access FROM sbmAPPROVAL WHERE rn=%s", (rn,)) #if len(sth) >0: #access = sth[0][0] # Build referee's email address refereeaddress = "" # Try to retrieve the publication committee chair's email from the role database for user in acc_get_role_users(acc_get_role_id("pubcomchair_%s_%s" % (doctype,category))): refereeaddress += user[1] + "," # And if there are general referees for user in acc_get_role_users(acc_get_role_id("pubcomchair_%s_*" % doctype)): refereeaddress += user[1] + "," refereeaddress = re.sub(",$","",refereeaddress) # Creation of the mail for the referee addresses = "" if refereeaddress != "": addresses = refereeaddress + "," if otheraddresses != "": addresses += otheraddresses else: addresses = re.sub(",$","",addresses) title_referee = "Request for refereeing process of %s" % rn mail_referee = "The document %s has been asked for refereing process to the %s Server..\nYour have to select an editorial board for it.\n\n" % (rn,cdsname) mail_referee +="Title: %s\n\nAuthor(s): %s\n\n" % (title,author) mail_referee +="To access the document(s), select the file(s) from the location:<%s/getfile.py?recid=%s>\n\n" % (htdocsurl,sysno) mail_referee +="To select an editorial board, you should go to this URL:\n<%s/publiline.py?doctype=%s&categ=%s&RN=%s>\n" % (urlpath,doctype,category,rn) mail_referee +="---------------------------------------------\nBest regards.\nThe submission team.\n" #Send mail to referee send_email(FROMADDR, addresses, title_referee, mail_referee, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Send_SRV_Mail.py b/modules/websubmit/lib/functions/Send_SRV_Mail.py index df39e6b3c..f25deff82 100644 --- a/modules/websubmit/lib/functions/Send_SRV_Mail.py +++ b/modules/websubmit/lib/functions/Send_SRV_Mail.py @@ -1,74 +1,74 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Send_SRV_Mail ## This function sends an email confirming the revision ## has been carried on with success ## Author: T.Baron ## PARAMETERS: addressesSRV: list of addresses to send this email to. ## categformatDAM: variable used to derive the category of ## the document from its reference. This value might then ## be used to derive the list of addresses ## emailFile: name of the file in which the user's email is ## noteFile: name of the file containing a note from the user import os import re from invenio.config import \ accessurl, \ adminemail, \ cdsname, \ supportemail, \ weburl from invenio.websubmit_config import CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN from invenio.mailutils import send_email from invenio.websubmit_functions.Retrieve_Data import Get_Field -def Send_SRV_Mail(parameters,curdir,form): +def Send_SRV_Mail(parameters, curdir, form, user_info=None): global rn,doctype,sysno # variables declaration FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail) addresses = parameters['addressesSRV'] addresses = addresses.strip() if parameters['emailFile'] is not None and parameters['emailFile']!="" and os.path.exists("%s/%s" % (curdir,parameters['emailFile'])): fp = open("%s/%s" % (curdir,parameters['emailFile']), "r") SuE = fp.read() fp.close() else: SuE = "" SuE = SuE.replace("\n",",") if parameters['noteFile'] is not None and parameters['noteFile']!= "" and os.path.exists("%s/%s" % (curdir,parameters['noteFile'])): fp = open("%s/%s" % (curdir,parameters['noteFile']), "r") note = fp.read() fp.close() else: note = "" title = Get_Field("245__a",sysno) author = Get_Field('100__a',sysno) author += Get_Field('700__a',sysno) # create message message = "A revised version of document %s has been submitted.\n\nTitle: %s\nAuthor(s): %s\nURL: <%s/record/%s>%s" % (rn,title,author,weburl,sysno,note) # send the email send_email(FROMADDR, SuE, "%s revised" % rn, message, copy_to_admin=CFG_WEBSUBMIT_COPY_MAILS_TO_ADMIN) return "" diff --git a/modules/websubmit/lib/functions/Test_Status.py b/modules/websubmit/lib/functions/Test_Status.py index 52e120f4d..d5fd837bc 100644 --- a/modules/websubmit/lib/functions/Test_Status.py +++ b/modules/websubmit/lib/functions/Test_Status.py @@ -1,76 +1,76 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Test_Status ## This function checks whether the document is still waiting ## for approval or not. ## Author: T.Baron ## ## PARAMETERS: - from invenio.dbquery import run_sql from invenio.websubmit_config import InvenioWebSubmitFunctionStop -def Test_Status(parameters,curdir,form): +def Test_Status(parameters, curdir, form, user_info=None): global rn res = run_sql("SELECT status, access FROM sbmAPPROVAL WHERE rn=%s", (rn,)) if len(res) == 0: raise InvenioWebSubmitFunctionStop(printNotRequested(rn)) else: if res[0][0] == "approved": raise InvenioWebSubmitFunctionStop(printApproved(rn)) elif res[0][0] == "rejected": raise InvenioWebSubmitFunctionStop(printRejected(rn)) return "" def printNotRequested(rn): t=""" """ % rn return t def printApproved(rn): t=""" """ % rn return t def printRejected(rn): t=""" """ % rn return t diff --git a/modules/websubmit/lib/functions/Update_Approval_DB.py b/modules/websubmit/lib/functions/Update_Approval_DB.py index 268020bc0..3c26fe33d 100644 --- a/modules/websubmit/lib/functions/Update_Approval_DB.py +++ b/modules/websubmit/lib/functions/Update_Approval_DB.py @@ -1,74 +1,74 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. __revision__ = "$Id$" ## Description: function Update_Approval_DB ## This function updates the approval database with the ## decision of the referee ## Author: T.Baron ## PARAMETERS: categformatDAM: variable used to compute the category ## of the document from its reference import os import re import time from invenio.dbquery import run_sql -def Update_Approval_DB(parameters,curdir,form): +def Update_Approval_DB(parameters, curdir, form, user_info=None): global rn doctype = form['doctype'] act = form['act'] categformat = parameters['categformatDAM'] access = "%s%s" % (time.time(),os.getpid()) if act != "APP": # retrieve category if re.search("","") if os.path.exists("%s/%s" % (curdir,filename)): fp = open("%s/%s" % (curdir,filename)) category = fp.read() fp.close() else: category="" category = category.replace("\n","") else: categformat = categformat.replace("","([^-]*)") category = re.match(categformat,rn).group(1) if category == "": category = "unknown" sth = run_sql("SELECT status,dFirstReq,dLastReq,dAction FROM sbmAPPROVAL WHERE doctype=%s and categ=%s and rn=%s", (doctype,category,rn,)) if len(sth) == 0: run_sql("INSERT INTO sbmAPPROVAL values(%s,%s,%s,'waiting',NOW(),NOW(),'',%s)", (doctype,category,rn,access,)) else: run_sql("UPDATE sbmAPPROVAL SET dLastReq=NOW(), status='waiting' WHERE doctype=%s and categ=%s and rn=%s", (doctype,category,rn,)) else: if os.path.exists("%s/decision" % curdir): fp = open("%s/decision" % curdir, "r") decision = fp.read() fp.close() else: decision = "" if decision == "approve": run_sql("UPDATE sbmAPPROVAL SET dAction=NOW(),status='approved' WHERE rn=%s", (rn,)) else: run_sql("UPDATE sbmAPPROVAL SET dAction=NOW(),status='rejected' WHERE rn=%s", (rn,)) return "" diff --git a/modules/websubmit/lib/functions/Upload_Files.py b/modules/websubmit/lib/functions/Upload_Files.py index abd69dfb4..4853213a2 100644 --- a/modules/websubmit/lib/functions/Upload_Files.py +++ b/modules/websubmit/lib/functions/Upload_Files.py @@ -1,229 +1,229 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Function for the upload of files""" __revision__ = "$Id$" from invenio.config import \ CFG_PATH_ACROREAD, \ CFG_PATH_CONVERT, \ CFG_PATH_DISTILLER, \ CFG_PATH_GUNZIP, \ CFG_PATH_GZIP, \ images import os import re from invenio.bibdocfile import BibRecDocs, list_versions_from_array, list_types_from_array from invenio.websubmit_functions.Shared_Functions import createRelatedFormats, createIcon -def Upload_Files(parameters,curdir,form): +def Upload_Files(parameters, curdir, form, user_info=None): global doctype,access,act,dir minsize=parameters['minsize'] maxsize=parameters['maxsize'] iconsize=parameters['iconsize'] type=parameters['type'] t="" bibrecdocs = BibRecDocs(sysno) # first check if a file has been requested for deletion if form.has_key("deleted"): deleted = form['deleted'] else: deleted = "no" if form.has_key("deletedfile"): deletedfile = form['deletedfile'] else: deletedfile = "" if form.has_key("mybibdocname"): mybibdocname = form['mybibdocname'] else: mybibdocname = "" if form.has_key("fileAction"): fileAction = form['fileAction'] else: fileAction = "" if deleted == "yes": bibrecdocs.delete_bibdoc(deletedfile) # then check if a file has been requested for addition if os.path.exists("%s/myfile" % curdir): fp = open("%s/myfile" % curdir,"r") myfile=fp.read() fp.close() extension = re.sub("^[^\.]*\.","",myfile) filename = re.sub("\..*","",os.path.basename(myfile)) fullpath = "%s/files/myfile/%s" % (curdir,myfile) if os.path.getsize(fullpath) < int(minsize): os.unlink("%s/myfile" % curdir) os.unlink(fullpath) t+= """""" % minsize elif os.path.getsize(fullpath) > int(maxsize): os.unlink("%s/myfile" % curdir) os.unlink(fullpath) t+= """""" % maxsize else: bibdoc = None if fileAction == "AddMain": if not bibrecdocs.check_file_exists(fullpath): bibdoc = bibrecdocs.add_new_file(fullpath, "Main", never_fail=True) if fileAction == "AddAdditional": if not bibrecdocs.check_file_exists(fullpath): bibdoc = bibrecdocs.add_new_file(fullpath, "Additional", never_fail=True) if fileAction == "ReviseAdditional" and mybibdocname != "": if not bibrecdocs.check_file_exists(fullpath): bibdoc = bibrecdocs.add_new_version(fullpath, mybibdocname) if fileAction == "AddAdditionalFormat" and mybibdocname != "": bibdoc = bibrecdocs.add_new_format(fullpath, mybibdocname) if type == "fulltext" and fileAction != "AddMainFormat" and fileAction != "AddAdditionalFormat": additionalformats = createRelatedFormats(fullpath) if len(additionalformats) > 0 and bibdoc is not None: for additionalformat in additionalformats: bibdoc.add_file_new_format(additionalformat) if type == "picture" and fileAction != "AddMainFormat" and fileAction != "AddAdditionalFormat": iconpath = createIcon(fullpath,iconsize) if iconpath is not None and bibdoc is not None: bibdoc.add_icon(iconpath) os.unlink(iconpath) elif bibdoc is not None: bibdoc.delete_ocon() bibrecdocs.build_bibdoc_list() os.unlink(fullpath) os.unlink("%s/myfile" % curdir) t+="
" t=t+Display_Form(bibrecdocs) t=t+Display_File_List(bibrecdocs) t=t+ "
" t+="
" return t def Display_File_List(bibrecdocs): t="""

""" bibdocs = bibrecdocs.list_bibdocs() if len(bibdocs) > 0: types = list_types_from_array(bibdocs) for mytype in types: if len(bibrecdocs.list_bibdocs(mytype)) > 1: plural = "s" else: plural = "" t+="%s document%s:" % (mytype,plural) for bibdoc in bibdocs: if mytype == bibdoc.get_type(): t+="
" t+="



" % (bibdoc.get_docname(),bibdoc.get_docname(),images) t+="
" t+=bibdoc.display() t+="
" t+="""
""" return t def Display_Form(bibrecdocs): #output the upload files form. t="" t=t+""" Don't forget to click on the \"End Submission\" button when you have finished managing the files.

Please complete the form below to upload a new file:
1
2
3
""" return t