Page MenuHomec4science

publiline.py.wml
No OneTemporary

File Metadata

Created
Thu, May 30, 21:58

publiline.py.wml

## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
## read config variables:
#include "config.wml"
#include "configbis.wml"
pylibdir = "<LIBDIR>/python"
<protect>
## $Id$
## DO NOT EDIT THIS FILE! IT WAS AUTOMATICALLY GENERATED FROM CDSware WML SOURCES.
## import interesting modules:
import string
import os
import sys
import time
import types
import re
import MySQLdb
import shutil
sys.path.append('%s' % pylibdir)
from cdsware.config import cdsname,cdslang,supportemail
from cdsware.dbquery import run_sql
from cdsware.access_control_engine import acc_authorize_action
from cdsware.access_control_admin import *
from cdsware.webpage import page, create_error_box
from cdsware.webuser import getUid, get_email, list_registered_users
from cdsware.messages import *
from cdsware.websubmit_config import *
from cdsware.search_engine import search_pattern
execfile("%s/cdsware/websubmit_functions/Retrieve_Data.py" % pylibdir)
execfile("%s/cdsware/websubmit_functions/mail.py" % pylibdir)
def index(req,c=cdsname,ln=cdslang,doctype="",categ="",RN="",send=""):
global uid
ln = wash_language(ln)
t=""
# get user ID:
try:
uid = getUid(req)
uid_email = get_email(uid)
except MySQLdb.Error, e:
return errorMsg(e.value,req)
if doctype == "":
t=selectDoctype()
elif categ == "":
t=selectCateg(doctype)
elif RN == "":
t=selectDocument(doctype,categ)
else:
t=displayDocument(doctype,categ,RN,send)
return page(title="publication line",
body=t,
description="",
keywords="",
uid=uid,
language=ln,
urlargs=req.args)
def selectDoctype():
t="""
<table class="searchbox" width="100%" summary="">
<tr>
<th class="portalboxheader">List of refereed types of documents</th>
</tr>
<tr>
<td class="portalboxbody">
Select one of the following types of documents to check the documents status:</small>
<blockquote>"""
res = run_sql("select DISTINCT doctype from sbmAPPROVAL")
for row in res:
res2 = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s", (row[0],))
t+="<li><A HREF='publiline.py?doctype=%s'>%s</A><BR>" % (row[0],res2[0][0])
t+="""</blockquote>
</td>
</tr>
</table>"""
return t
def selectCateg(doctype):
t=""
res = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s",(doctype,))
title = res[0][0]
sth = run_sql("select * from sbmCATEGORIES where doctype=%s order by lname",(doctype,))
if len(sth) == 0:
categ = "unknown"
return selectDocument(doctype,categ)
t+="""
<table class="searchbox" width="100%" summary="">
<tr>"""
t+= "<th class=\"portalboxheader\">%s: List of refereed categories</th>" % title
t+="""
</tr>
<tr>
<td class="portalboxbody">
Please choose a category
<blockquote>
<FORM action="publiline.py" method=get>"""
t+=" <INPUT type=hidden name=doctype value='%s'>\n" % doctype
t+=" <INPUT type=hidden name=categ value=''>\n"
t+=" </FORM>\n"
t+="""
<TABLE>
<TR>
<TD align=left>"""
for arr in sth:
waiting = 0
rejected = 0
approved = 0
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and categ=%s and status='waiting'", (doctype,arr[1],))
waiting = sth2[0][0]
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and categ=%s and status='approved'",(doctype,arr[1],))
approved = sth2[0][0]
sth2 = run_sql("select COUNT(*) from sbmAPPROVAL where doctype=%s and categ=%s and status='rejected'",(doctype,arr[1],))
rejected = sth2[0][0]
num = waiting + approved + rejected
if waiting != 0:
classtext = "class=blocknote"
else:
classtext = ""
t+="<A href=\"\" onClick=\"document.forms[0].categ.value='%s';document.forms[0].submit();return false;\"><SMALL %s>%s</SMALL></A><SMALL> (%s document<SMALL>(</SMALL>s<SMALL>)</SMALL>\n" % (arr[1],classtext,arr[2],num)
if waiting != 0:
t+= "| %s<IMG ALT=\"pending\" SRC=\"%s/waiting_or.gif\" border=0>\n" % (waiting,images)
if approved != 0:
t+= "| %s<IMG ALT=\"approved\" SRC=\"%s/smchk_gr.gif\" border=0>\n" % (approved,images)
if rejected != 0:
t+= "| %s<IMG ALT=\"rejected\" SRC=\"%s/cross_red.gif\" border=0>" % (rejected,images)
t+=")</SMALL><BR>\n"
t+="""
</TD>
<TD>
<table class="searchbox" width="100%" summary="">
<tr>
<th class="portalboxheader">Key:</th>
<tr>
<tr>
<td>"""
t+=" <IMG ALT=\"pending\" SRC=\"%s/waiting_or.gif\" border=0> waiting for approval<BR>" % images
t+=" <IMG ALT=\"approved\" SRC=\"%s/smchk_gr.gif\" border=0> already approved<BR>" % images
t+=" <IMG ALT=\"rejected\" SRC=\"%s/cross_red.gif\" border=0> rejected<BR><BR>\n" % images
t+="""
<SMALL class=blocknote>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SMALL> some documents are pending<BR></SMALL>
</td>
</tr>
</table>
</TD>
</TR>
</TABLE>
</blockquote>
</td>
</tr>
</table>"""
return t
def selectDocument(doctype,categ):
t=""
res = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s", (doctype,))
title = res[0][0]
if categ == "":
categ == "unknown"
t+="""
<table class="searchbox" width="100%" summary="">
<tr>"""
t+= "<th class=\"portalboxheader\">%s - %s: List of refereed documents</th>" % (title,categ)
t+="""
</tr>
<tr>
<td class="portalboxbody">
Click on a report number to have more information
<blockquote>
<FORM action="publiline.py" method=get>"""
t+=" <INPUT type=hidden name=doctype value='%s'>\n" % doctype
t+=" <INPUT type=hidden name=categ value='%s'>\n" % categ
t+=" <INPUT type=hidden name=RN value=''>\n"
t+=" </FORM>\n"
t+="<TABLE class=\"searchbox\">"
t+="<TR><TH class=\"portalboxheader\">Report Number</TH><TH class=\"portalboxheader\">Pending</TH><TH class=\"portalboxheader\">Approved</TH><TH class=\"portalboxheader\">Rejected</TH></TR>"
sth = run_sql("select rn,status from sbmAPPROVAL where doctype=%s and categ=%s order by status DESC,rn DESC",(doctype,categ))
for arr in sth:
RN = arr[0]
status = arr[1]
if status == "waiting":
t+= "<TR><TD align=center><A HREF=\"\" onClick=\"document.forms[0].RN.value='%s';document.forms[0].submit();return false;\">%s</A></TD><TD align=center><IMG ALT=\"check\" SRC=\"%s/waiting_or.gif\"></TD><TD align=center>&nbsp;</TD><TD align=center>&nbsp;</TD></TR>" % (RN,RN,images)
elif status == "rejected":
t+="<TR><TD align=center><A HREF=\"\" onClick=\"document.forms[0].RN.value='%s';document.forms[0].submit();return false;\">%s</A></TD><TD align=center>&nbsp;</TD><TD align=center>&nbsp;</TD><TD align=center><IMG ALT=\"check\" SRC=\"%s/cross_red.gif\"></TD></TR>" % (RN,RN,images)
elif status == "approved":
t+="<TR><TD align=center><A HREF=\"\" onClick=\"document.forms[0].RN.value='%s';document.forms[0].submit();return false;\">%s</A></TD><TD align=center>&nbsp;</TD><TD align=center><IMG ALT=\"check\" SRC=\"%s/smchk_gr.gif\"></TD><TD align=center>&nbsp;</TD></TR>" % (RN,RN,images)
t+= """</TABLE>
</blockquote>
</td>
</tr>
</table>"""
return t
def displayDocument(doctype,categ,RN,send):
t=""
res = run_sql("select ldocname from sbmDOCTYPE where sdocname=%s", (doctype,))
docname = res[0][0]
if categ == "":
categ = "unknown"
sth = run_sql("select rn,status,dFirstReq,dLastReq,dAction,access from sbmAPPROVAL where rn=%s",(RN,))
if len(sth) > 0:
arr = sth[0]
status = arr[1]
dFirstReq = arr[2]
dLastReq = arr[3]
dAction = arr[4]
access = arr[5]
if status == "waiting":
image = "<IMG SRC=\"%s/waiting_or.gif\" ALT=\"\" align=right>" % images
elif status == "approved":
image = "<IMG SRC=\"%s/smchk_gr.gif\" ALT=\"\" align=right>" % images
elif status == "rejected":
image = "<IMG SRC=\"%s/iconcross.gif\" ALT=\"\" align=right>" % images
else:
image = ""
t+="""
<table class="searchbox" summary="">
<tr>"""
t+= "<th class=\"portalboxheader\">%s%s</th>" % (image,RN)
t+="""
</tr>
<tr>
<td class="portalboxbody">"""
else:
return warningMsg("This document has never been requested for approval!<BR>&nbsp;")
(authors,title,sysno,newrn) = getInfo(doctype,categ,RN)
if send == "Send Again":
if authors == "unknown" or title == "unknown":
SendWarning(doctype,categ,RN,title,authors,access)
else:
SendEnglish(doctype,categ,RN,title,authors,access,sysno)
run_sql("update sbmAPPROVAL set dLastReq=NOW() where rn=%s",(RN,))
t+= "<I><strong class=headline>Your request has been sent to the referee!</strong></I><BR><BR>"
t+= "<FORM action=\"publiline.py\">\n"
t+= "<INPUT type=hidden name=RN value=\"%s\">\n" % RN
t+= "<INPUT type=hidden name=categ value=\"%s\">\n" % categ
t+= "<INPUT type=hidden name=doctype value=\"%s\">\n" % doctype
t+="<SMALL>\n"
if title != "unknown":
t+= "<strong class=headline>Title:</strong>%s<BR><BR>\n" % title
if authors != "":
t+="<strong class=headline>Author:</strong>%s<BR><BR>\n" % authors
if sysno != "":
t+="<strong class=headline>More information:</strong>"
t+= " <A HREF=\"%s?id=%s\">click here</A><BR><BR>\n" % (accessurl,sysno)
if status == "waiting":
t+= "This Document is still <strong class=headline>waiting for approval</strong>.<BR><BR>"
t+="It has first been sent to approval on: <strong class=headline>%s</strong><BR>" % dFirstReq
if dLastReq == "0000-00-00 00:00:00":
t+= "Last approval e-mail was sent on: <strong class=headline>%s</strong><BR>" % dFirstReq
else:
t+= "Last approval e-mail was sent on: <strong class=headline>%s</strong><BR>" % dLastReq
t+="<BR>You can send an approval request e-mail again by clicking the following button:"
t+= "<BR><INPUT class=\"adminbutton\" type=submit name=send value=\"Send Again\" onClick=\"return confirm('WARNING! An e-mail will be send to your referee if you confirm.')\">"
# We also display a button for the referee
if acc_authorize_action(uid, "referee",verbose=0,doctype=doctype, categ=categ):
t+= "<br>As a referee for this document, you may click this button to approve or reject it:"
t+= "<BR><INPUT class=\"adminbutton\" type=submit name=approval value=\"Approve/Reject\" onClick=\"window.location='approve.py?%s';return false;\">" % access
if status == "approved":
t+="This Document has been <strong class=headline>approved</strong>.<BR>Its approved reference is: <strong class=headline>%s</strong><BR><BR>" % newrn
t+="It has first been sent to approval on: <strong class=headline>%s</strong><BR>" % dFirstReq
if dLastReq == "0000-00-00 00:00:00":
t+= "Last approval e-mail was sent on: <strong class=headline>%s</STRONG><BR>" % dFirstReq
else:
t+= "Last approval e-mail was sent on: <strong class=headline>%s</STRONG><BR>" % dLastReq
t+="It has been approved on: <strong class=headline>%s</STRONG><BR>" % dAction
if status == "rejected":
t+= "This Document has been <strong class=headline>rejected</STRONG>.<BR><BR>"
t+="It has first been sent to approval on: <strong class=headline>%s</STRONG><BR>" % dFirstReq
if dLastReq == "0000-00-00 00:00:00":
t+= "Last approval e-mail was sent on: <strong class=headline>%s</STRONG><BR>" % dFirstReq
else:
t+="Last approval e-mail was sent on: <strong class=headline>%s</STRONG><BR>" % dLastReq
t+= "It has been rejected on: <strong class=headline>%s</STRONG><BR>" % dAction
t+= "</SMALL></FORM>"
t+= """<BR></TD></TR></TABLE>
</blockquote>
</td>
</tr>
</table>"""
return t
# Retrieve info about document
def getInfo(doctype,categ,RN):
result = getInPending(doctype,categ,RN)
if not result:
result = getInAlice(doctype,categ,RN)
return result
#seek info in pending directory
def getInPending(doctype,categ,RN):
PENDIR="%s/pending" % storage
if os.path.exists("%s/%s/%s/AU" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/AU" % (PENDIR,doctype,RN),"r")
authors=fp.read()
fp.close()
else:
authors = ""
if os.path.exists("%s/%s/%s/TI" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/TI" % (PENDIR,doctype,RN),"r")
title=fp.read()
fp.close()
else:
title = ""
if os.path.exists("%s/%s/%s/SN" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/SN" % (PENDIR,doctype,RN),"r")
sysno=fp.read()
fp.close()
else:
sysno = ""
if title == "" and os.path.exists("%s/%s/%s/TIF" % (PENDIR,doctype,RN)):
fp = open("%s/%s/%s/TIF" % (PENDIR,doctype,RN),"r")
title=fp.read()
fp.close()
if title == "":
return 0
else:
return (authors,title,sysno,"")
#seek info in Alice database
def getInAlice(doctype,categ,RN):
# initialize sysno variable
sysno = ""
searchresults = search_pattern(req=None, p=RN, f="reportnumber").items().tolist()
if len(searchresults) == 0:
return 0
sysno = searchresults[0]
if sysno != "":
title = Get_Field('245__a',sysno)
emailvalue = Get_Field('8560_f',sysno)
authors = Get_Field('100__a',sysno)
authors += "\n%s" % Get_Field('700__a',sysno)
newrn = Get_Field('037__a',sysno)
return (authors,title,sysno,newrn)
else:
return 0
def SendEnglish(doctype,categ,RN,title,authors,access,sysno):
FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail)
# retrieve useful information from webSubmit configuration
res = run_sql("select value from sbmPARAMETERS where name='categformatDAM' and doctype=%s", (doctype,))
categformat = res[0][0]
categformat = re.sub("<CATEG>","([^-]*)",categformat)
categs = re.match(categformat,RN)
if categs != None:
categ = categs.group(1)
else:
categ = "unknown"
res = run_sql("select value from sbmPARAMETERS where name='addressesDAM' and doctype=%s",(doctype,))
if len(res) > 0:
otheraddresses = res[0][0]
otheraddresses = otheraddresses.replace("<CATEG>",categ)
else:
otheraddresses = ""
# Build referee's email address
refereeaddress = ""
# Try to retrieve the referee's email from the referee's database
for user in acc_getRoleUsers(acc_getRoleId("referee_%s_%s" % (doctype,categ))):
refereeaddress += user[1] + ","
# And if there are general referees
for user in acc_getRoleUsers(acc_getRoleId("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)
if addresses=="":
SendWarning(doctype,categ,RN,title,authors,access)
return 0
if authors == "":
authors = "-"
res = run_sql("select value from sbmPARAMETERS where name='directory' and doctype=%s", (doctype,))
directory = res[0][0]
message = """
The document %s has been published as a Communication.
Your approval is requested for it to become an official Note.
Title: %s
Author(s): %s
To access the document(s), select the file(s) from the location:
<%s/getfile.py?recid=%s>
To approve/reject the document, you should go to this URL:
<%s/approve.py?%s>
---------------------------------------------
Best regards.
The submission team.""" % (RN,title,authors,urlpath,sysno,urlpath,access)
# send the mail
body = forge_email(FROMADDR,addresses,adminemail,"Request for Approval of %s" % RN,message)
send_email(FROMADDR,addresses,body,0)
return ""
def SendWarning(doctype,categ,RN,title,authors,access):
FROMADDR = '%s Submission Engine <%s>' % (cdsname,supportemail)
message = "Failed sending approval email request for %s" % RN
# send the mail
body = forge_email(FROMADDR,adminemail,"","Failed sending approval email request",message)
send_email(FROMADDR,adminemail,body,0)
return ""
</protect>

Event Timeline