<commit_before>## $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, 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="<br><br><B>Your decision has been taken into account!</B><br><BR>"
        if decision == "approve":
            t+="The document will be soon available with the following reference: <b>%s</b><BR>" % rn
    return t
<commit_msg>Wanted to add a new parameter "decision_file", because the function previously looked for the hard-coded filename "decision", which meant that any referee's decision field on the form had to be called "decision". Anyway, because the function was so short, and a mess, I decided to rewrite it. Sadly, it's still not perfect because it needs to make use of the global variable "rn" in the message. Although it now has some exception-registering, it still needs work in the situation where it wasn't possible to read from the referee's decision file at all, yet should still return a message to be deisplayed in the user's browser (I'd have liked to have raised an InvenioWebSubmitFunctionWarning there, but that would prevent the return of a string for the user. So, this needs to be touched-up at some point . . . )<commit_after>## $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.

"""Return a message to the user's browser saying that their decision was taken
   into account. Intended for use in an approval submission (the referee should
   be the recipient of any message created by this function.)
"""

__revision__ = "$Id$"

import os, cgi
from invenio.errorlib import register_exception

def Print_Success_APP(parameters, curdir, form, user_info=None):
    """Return a message to be displayed by the referee's browser after (s)he
       has refereed an item.
       @param parameters: (dictionary) - parameters needed by this function.
        Contains:
          + decision_file: (string) - the name of the file in which the
                           referee's decision is stored.
       @param curdir: (string) - the current submission's working directory.
       @param form: (dictionary) - submitted form values.
       @param user_info: (dictionary) - information about the user.
       @return: (string) - a message to be displayed by the user's browser.
    """
    global rn  ## Unfortunately, it's necessary to use the magic "rn" global:
    ## Get the name of the decision file:
    try:
        decision_filename = parameters['decision_file']
    except KeyError:
        decision_filename = ""

    ## Now try to read the decision from the decision_filename:
    if decision_filename in (None, "", "NULL"):
        ## We don't have a name for the decision file.
        ## For backward compatibility reasons, try to read the decision from
        ## a file called 'decision' in curdir:
        if os.path.exists("%s/decision" % curdir):
            try:
                fh_decision = open("%s/decision" % curdir, "r")
                decision = fh_decision.read()
                fh_decision.close()
            except IOError:
                ## Unable to open the decision file
                exception_prefix = "Error in WebSubmit function " \
                                   "Print_Success_APP. Tried to open " \
                                   "decision file [%s/decision] but was " \
                                   "unable to." % curdir
                register_exception(prefix=exception_prefix)
                decision = ""
            else:
                decision = decision.strip()
        else:
            decision = ""
    else:
        ## Try to read the decision from the decision file:
        try:
            fh_decision = open("%s/%s" % (curdir, decision_filename), "r")
            decision = fh_decision.read()
            fh_decision.close()
        except IOError:
            ## Oops, unable to open the decision file.
            decision = ""
            exception_prefix = "Error in WebSubmit function " \
                               "Print_Success_APP. Tried to open decision " \
                               "file [%s/%s] but was unable to." \
                               % (curdir, decision_filename)
            register_exception(prefix=exception_prefix)
        else:
            decision = decision.strip()

    ## Create the message:
    if decision != "":
        msg = "<br /><div>Your decision was: <b>%(decision)s</b>.<br />\n" \
              "It has been taken into account.<br />\n" \
              "%(additional-info)s</div><br />\n" \
              % { 'decision'        : cgi.escape(decision),
                  'additional-info' : ((decision == "approve" and \
                                       "The item will now be integrated into " \
                                        "the relevant collection with the " \
                                        "reference number <b>%s</b>." \
                                        % cgi.escape(rn)) \
                                       or "")
                }
    else:
        ## Since the decision could not be read from the decision file, we will
        ## just display a generic "thank you for your decision" message.
        ## FIXME: We should really report this to WebSubmit core.
        msg = "<br /><div>Thank you for your decision.</div><br />\n"
    ## Return the message to WebSubmit core.
    return msg
{'fraction_non_alphanumeric': 0.08772395487723955, 'fraction_numerical': 0.011413404114134041, 'mean_word_length': 2.3038141166155195, 'pattern_counts': {'":': 2, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6075556', 'n_tokens_mistral': 2034, 'n_tokens_neox': 1882, 'n_words': 857}