2009-06-29 07:06:01 -05:00
|
|
|
'''This package contains base classes for wrappers that hide to the Appy
|
2009-09-18 07:42:31 -05:00
|
|
|
developer the real classes used by the underlying web framework.'''
|
2009-06-29 07:06:01 -05:00
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2011-11-25 11:01:20 -06:00
|
|
|
import os, os.path, mimetypes
|
2009-12-17 14:14:52 -06:00
|
|
|
import appy.pod
|
2013-07-08 16:39:16 -05:00
|
|
|
from appy.gen import Field, Search, Ref, String, WorkflowAnonymous
|
2012-09-26 16:13:02 -05:00
|
|
|
from appy.gen.indexer import defaultIndexes
|
2014-09-11 09:41:08 -05:00
|
|
|
from appy.gen.layout import defaultPageLayouts
|
2012-01-12 14:49:23 -06:00
|
|
|
from appy.gen.utils import createObject
|
2013-06-25 05:04:23 -05:00
|
|
|
from appy.px import Px
|
2012-01-12 14:49:23 -06:00
|
|
|
from appy.shared.utils import getOsTempFolder, executeCommand, \
|
|
|
|
normalizeString, sequenceTypes
|
2009-11-11 13:22:13 -06:00
|
|
|
from appy.shared.xml_parser import XmlMarshaller
|
2011-02-12 10:09:11 -06:00
|
|
|
from appy.shared.csv_parser import CsvMarshaller
|
2009-07-10 08:01:50 -05:00
|
|
|
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
2011-09-06 18:33:09 -05:00
|
|
|
class AbstractWrapper(object):
|
2012-06-02 07:36:49 -05:00
|
|
|
'''Any real Appy-managed Zope object has a companion object that is an
|
|
|
|
instance of this class.'''
|
|
|
|
|
2014-10-21 02:25:37 -05:00
|
|
|
# Input field for going to element number ...
|
|
|
|
pxGotoNumber = Px('''
|
|
|
|
<x var2="label=_('goto_number');
|
|
|
|
gotoName='%s_%s_goto' % (obj.id, field.name)">
|
|
|
|
<span class="discreet" style="padding-left: 5px">:label</span>
|
|
|
|
<input type="text" size=":(len(str(totalNumber))-1) or 1"
|
|
|
|
onclick="this.select()"
|
|
|
|
onkeydown=":'if (event.keyCode==13) document.getElementById' \
|
|
|
|
'(%s).click()' % q(gotoName)"/><img
|
|
|
|
id=":gotoName" name=":gotoName"
|
|
|
|
class="clickable" src=":url('gotoNumber')" title=":label"
|
2015-01-06 14:13:30 -06:00
|
|
|
onclick=":'gotoTied(%s,%s,this.previousSibling,%s)' % \
|
2014-10-21 02:25:37 -05:00
|
|
|
(q(sourceUrl), q(field.name), totalNumber)"/></x>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
pxNavigationStrip = Px('''
|
2014-04-29 12:02:06 -05:00
|
|
|
<table width="100%">
|
2014-08-05 07:53:08 -05:00
|
|
|
<tr valign="top">
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Breadcrumb -->
|
2014-04-29 12:02:06 -05:00
|
|
|
<td var="sup=zobj.getSupBreadCrumb();
|
2014-06-15 17:58:45 -05:00
|
|
|
breadcrumb=zobj.getBreadCrumb(inPopup=inPopup);
|
2014-04-29 12:02:06 -05:00
|
|
|
sub=zobj.getSubBreadCrumb()" class="breadcrumb">
|
|
|
|
<x if="sup">::sup</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
<x for="bc in breadcrumb" var2="nb=loop.bc.nb">
|
2013-07-20 12:56:17 -05:00
|
|
|
<img if="nb != 0" src=":url('to')"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Display only the title of the current object -->
|
2013-08-21 15:25:27 -05:00
|
|
|
<span if="nb == len(breadcrumb)-1">:bc.title</span>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Display a link for parent objects -->
|
2013-08-21 15:25:27 -05:00
|
|
|
<a if="nb != len(breadcrumb)-1" href=":bc.url">:bc.title</a>
|
2013-06-27 04:57:39 -05:00
|
|
|
</x>
|
2014-04-29 12:02:06 -05:00
|
|
|
<x if="sub">::sub</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Object navigation -->
|
2014-10-21 02:25:37 -05:00
|
|
|
<td var="nav=req.get('nav', None)" if="nav"
|
|
|
|
var2="self=ztool.getNavigationInfo(nav, inPopup)" align=":dright"
|
|
|
|
width="150px">:self.pxNavigate</td>
|
2013-06-27 04:57:39 -05:00
|
|
|
</tr>
|
2014-04-29 12:02:06 -05:00
|
|
|
</table>
|
|
|
|
<!-- Object phases and pages -->
|
2014-09-23 05:47:44 -05:00
|
|
|
<x if="zobj.mayNavigate()" var2="phases=zobj.getAppyPhases()">
|
|
|
|
<x if="phases">:phases[0].pxAllPhases</x></x>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
2013-06-28 08:00:02 -05:00
|
|
|
# The template PX for all pages.
|
2013-06-25 05:04:23 -05:00
|
|
|
pxTemplate = Px('''
|
2013-08-21 05:35:30 -05:00
|
|
|
<html var="ztool=tool.o; user=tool.user;
|
2014-07-18 09:54:11 -05:00
|
|
|
req=ztool.REQUEST; resp=req.RESPONSE;
|
|
|
|
inPopup=req.get('popup') == '1';
|
|
|
|
obj=obj or ztool.getHomeObject(inPopup);
|
2013-08-21 05:35:30 -05:00
|
|
|
zobj=obj and obj.o or None;
|
|
|
|
isAnon=user.login=='anon'; app=ztool.getApp();
|
2013-07-20 12:56:17 -05:00
|
|
|
appFolder=app.data; url = ztool.getIncludeUrl;
|
2013-06-25 16:22:33 -05:00
|
|
|
appName=ztool.getAppName(); _=ztool.translate;
|
2013-09-20 10:42:07 -05:00
|
|
|
dummy=setattr(req, 'pxContext', _ctx_);
|
2013-07-08 16:39:16 -05:00
|
|
|
lang=ztool.getUserLanguage(); q=ztool.quote;
|
2013-06-25 16:22:33 -05:00
|
|
|
layoutType=ztool.getLayoutType();
|
2014-06-15 17:58:45 -05:00
|
|
|
showPortlet=not inPopup and ztool.showPortlet(obj, layoutType);
|
2013-06-25 16:22:33 -05:00
|
|
|
dir=ztool.getLanguageDirection(lang);
|
2014-05-13 09:41:59 -05:00
|
|
|
cfg=ztool.getProductConfig(True);
|
2013-06-25 16:22:33 -05:00
|
|
|
dleft=(dir == 'ltr') and 'left' or 'right';
|
|
|
|
dright=(dir == 'ltr') and 'right' or 'left';
|
|
|
|
x=resp.setHeader('Content-type', ztool.xhtmlEncoding);
|
|
|
|
x=resp.setHeader('Expires', 'Thu, 11 Dec 1975 12:05:00 GMT+2');
|
|
|
|
x=resp.setHeader('Content-Language', lang)"
|
|
|
|
dir=":ztool.getLanguageDirection(lang)">
|
|
|
|
<head>
|
|
|
|
<title>:_('app_name')</title>
|
|
|
|
<link rel="icon" type="image/x-icon" href="/favicon.ico"/>
|
2014-01-20 09:30:14 -06:00
|
|
|
<x for="name in ztool.getGlobalCssJs(dir)">
|
|
|
|
<link if="name.endswith('.css')" rel="stylesheet" type="text/css"
|
|
|
|
href=":url(name)"/>
|
2013-06-25 16:22:33 -05:00
|
|
|
<script if="name.endswith('.js')" type="text/javascript"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url(name)"></script>
|
2013-06-25 16:22:33 -05:00
|
|
|
</x>
|
|
|
|
</head>
|
2014-05-13 09:41:59 -05:00
|
|
|
<body style=":(cfg.skin == 'wide') and 'margin:0' or ''">
|
2013-06-25 16:22:33 -05:00
|
|
|
<!-- Google Analytics stuff, if enabled -->
|
|
|
|
<script var="gaCode=ztool.getGoogleAnalyticsCode()" if="gaCode"
|
|
|
|
type="text/javascript">:gaCode</script>
|
|
|
|
|
|
|
|
<!-- Popup for confirming an action -->
|
|
|
|
<div id="confirmActionPopup" class="popup">
|
2013-07-15 04:23:29 -05:00
|
|
|
<form id="confirmActionForm" method="post">
|
|
|
|
<div align="center">
|
|
|
|
<p id="appyConfirmText"></p>
|
|
|
|
<input type="hidden" name="actionType"/>
|
|
|
|
<input type="hidden" name="action"/>
|
|
|
|
<div id="commentArea" align=":dleft"><br/>
|
|
|
|
<span class="discreet">:_('workflow_comment')</span>
|
|
|
|
<textarea name="comment" cols="30" rows="3"></textarea>
|
|
|
|
<br/>
|
|
|
|
</div><br/>
|
|
|
|
<input type="button" onclick="doConfirm()" value=":_('yes')"/>
|
|
|
|
<input type="button" onclick="closePopup('confirmActionPopup')"
|
2013-06-26 06:44:31 -05:00
|
|
|
value=":_('no')"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
</div>
|
|
|
|
</form>
|
2013-06-25 16:22:33 -05:00
|
|
|
</div>
|
|
|
|
|
2014-03-24 16:55:00 -05:00
|
|
|
<!-- Popup for uploading a file in a pod field -->
|
|
|
|
<div id="uploadPopup" class="popup" align="center">
|
|
|
|
<form id="uploadForm" name="uploadForm" enctype="multipart/form-data"
|
2014-03-25 06:05:07 -05:00
|
|
|
method="post" action=":ztool.absolute_url() + '/doPod'">
|
2014-03-24 16:55:00 -05:00
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
<input type="hidden" name="fieldName"/>
|
|
|
|
<input type="hidden" name="template"/>
|
|
|
|
<input type="hidden" name="podFormat"/>
|
2014-03-25 06:05:07 -05:00
|
|
|
<input type="hidden" name="action" value="upload"/>
|
2014-03-24 16:55:00 -05:00
|
|
|
<input type="file" name="uploadedFile"/><br/><br/>
|
|
|
|
<input type="submit" value=":_('object_save')"/>
|
|
|
|
<input type="button" onclick="closePopup('uploadPopup')"
|
|
|
|
value=":_('object_cancel')"/>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
|
2013-06-25 16:22:33 -05:00
|
|
|
<!-- Popup for reinitializing the password -->
|
|
|
|
<div id="askPasswordReinitPopup" class="popup"
|
|
|
|
if="isAnon and ztool.showForgotPassword()">
|
2013-07-15 04:23:29 -05:00
|
|
|
<form id="askPasswordReinitForm" method="post"
|
2013-06-25 16:22:33 -05:00
|
|
|
action=":ztool.absolute_url() + '/askPasswordReinit'">
|
2013-07-15 04:23:29 -05:00
|
|
|
<div align="center">
|
|
|
|
<p>:_('app_login')</p>
|
|
|
|
<input type="text" size="35" name="login" id="login" value=""/>
|
|
|
|
<br/><br/>
|
|
|
|
<input type="button" onclick="doAskPasswordReinit()"
|
|
|
|
value=":_('ask_password_reinit')"/>
|
|
|
|
<input type="button" onclick="closePopup('askPasswordReinitPopup')"
|
|
|
|
value=":_('object_cancel')"/>
|
|
|
|
</div>
|
|
|
|
</form>
|
2013-06-25 16:22:33 -05:00
|
|
|
</div>
|
|
|
|
|
2014-04-05 03:54:40 -05:00
|
|
|
<!-- Popup for displaying an error message (~JS alert()) -->
|
|
|
|
<div id="alertPopup" class="popup">
|
|
|
|
<img src=":url('warningBig')" align=":dleft" style="margin-right: 10px"/>
|
|
|
|
<p id="appyAlertText" style="margin-bottom: 15px"></p>
|
|
|
|
<div align="center">
|
|
|
|
<input type="button" onclick="closePopup('alertPopup')"
|
|
|
|
value=":_('appy_ok')"/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
2014-06-15 17:58:45 -05:00
|
|
|
<!-- Popup containing the Appy iframe -->
|
|
|
|
<div id="iframePopup" class="popup" if="not inPopup"
|
|
|
|
style="background-color: #fbfbfb">
|
|
|
|
<img align=":dright" src=":url('close')" class="clickable"
|
|
|
|
onclick="closePopup('iframePopup')"/>
|
|
|
|
<iframe id="appyIFrame" name="appyIFrame" frameborder="0"></iframe>
|
|
|
|
</div>
|
|
|
|
|
2014-05-13 09:41:59 -05:00
|
|
|
<table class=":(cfg.skin == 'wide') and 'mainWide main' or 'main'"
|
|
|
|
align="center" cellpadding="0">
|
2014-07-28 10:35:49 -05:00
|
|
|
<!-- The browser incompatibility message when relevant -->
|
|
|
|
<tr var="bi=ztool.getBrowserIncompatibility()" if="bi"
|
|
|
|
class="wrongBrowser"><td>:bi</td></tr>
|
|
|
|
|
2014-06-15 17:58:45 -05:00
|
|
|
<tr class="top" if="not inPopup">
|
2013-06-26 06:44:31 -05:00
|
|
|
<!-- Top banner -->
|
|
|
|
<td var="bannerName=(dir == 'ltr') and 'banner' or 'bannerrtl'"
|
2014-03-05 15:01:51 -06:00
|
|
|
style=":url(bannerName, bg=True) + '; background-repeat:no-repeat;\
|
|
|
|
position:relative'">
|
|
|
|
<!-- Logo (transparent clickable zone by default) -->
|
2014-07-10 02:46:39 -05:00
|
|
|
<div align=":dleft" style="position: absolute">
|
|
|
|
<a href=":ztool.getSiteUrl()"><img src=":url('logo')"/></a></div>
|
2013-06-26 06:44:31 -05:00
|
|
|
|
|
|
|
<!-- Top links -->
|
|
|
|
<div style="margin-top: 4px" align=":dright">
|
2014-03-05 15:01:51 -06:00
|
|
|
<!-- Custom links -->
|
2013-08-21 05:35:30 -05:00
|
|
|
<x>:tool.pxLinks</x>
|
2013-06-26 06:44:31 -05:00
|
|
|
|
|
|
|
<!-- Top-level pages -->
|
|
|
|
<a for="page in tool.pages" class="pageLink"
|
|
|
|
href=":page.url">:page.title</a>
|
|
|
|
|
|
|
|
<!-- Connect link if discreet login -->
|
2014-05-13 09:41:59 -05:00
|
|
|
<a if="isAnon and cfg.discreetLogin" id="loginLink" name="loginLink"
|
2013-07-15 09:41:45 -05:00
|
|
|
onclick="showLoginForm()"
|
|
|
|
class="pageLink clickable">:_('app_connect')</a>
|
2013-06-26 06:44:31 -05:00
|
|
|
|
|
|
|
<!-- Language selector -->
|
2014-04-15 06:01:39 -05:00
|
|
|
<select if="ztool.showLanguageSelector()" class="pageLink"
|
2013-07-15 04:23:29 -05:00
|
|
|
var2="languages=ztool.getLanguages();
|
2014-08-13 10:17:25 -05:00
|
|
|
defaultLanguage=languages[0]"
|
2014-04-15 06:01:39 -05:00
|
|
|
onchange=":'switchLanguage(this,%s)' % q(ztool.getSiteUrl())">
|
2013-07-15 04:23:29 -05:00
|
|
|
<option for="lg in languages" value=":lg"
|
|
|
|
selected=":lang == lg">:ztool.getLanguageName(lg)</option>
|
|
|
|
</select>
|
2013-06-26 06:44:31 -05:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2013-06-26 10:06:06 -05:00
|
|
|
|
|
|
|
<!-- The message strip -->
|
2014-01-20 09:30:14 -06:00
|
|
|
<tr height="0px">
|
|
|
|
<td><div style="position:relative">:tool.pxMessage</div></td>
|
2013-06-26 10:06:06 -05:00
|
|
|
</tr>
|
|
|
|
|
|
|
|
<!-- The user strip -->
|
2014-06-15 17:58:45 -05:00
|
|
|
<tr height=":cfg.discreetLogin and '5px' or '28px'" if="not inPopup">
|
2013-06-26 10:06:06 -05:00
|
|
|
<td>
|
2014-01-20 09:30:14 -06:00
|
|
|
<table class="userStrip">
|
2013-06-26 10:06:06 -05:00
|
|
|
<tr>
|
|
|
|
<!-- The user login form for anonymous users -->
|
|
|
|
<td align="center"
|
|
|
|
if="isAnon and ('/temp_folder/' not in req['ACTUAL_URL'])">
|
|
|
|
<form id="loginForm" name="loginForm" method="post" class="login"
|
|
|
|
action=":tool.url + '/performLogin'">
|
|
|
|
<input type="hidden" name="js_enabled" id="js_enabled" value="0"/>
|
|
|
|
<input type="hidden" name="cookies_enabled" id="cookies_enabled"
|
|
|
|
value=""/>
|
|
|
|
<input type="hidden" name="login_name" id="login_name" value=""/>
|
|
|
|
<input type="hidden" name="pwd_empty" id="pwd_empty" value="0"/>
|
2014-05-13 09:41:59 -05:00
|
|
|
<!-- Login fields directly shown or not depending on
|
|
|
|
discreetLogin. -->
|
2013-06-26 10:06:06 -05:00
|
|
|
<span id="loginFields" name="loginFields"
|
2014-05-13 09:41:59 -05:00
|
|
|
style=":cfg.discreetLogin and 'display:none' or \
|
|
|
|
'display:block'">
|
2013-06-26 10:06:06 -05:00
|
|
|
<span class="userStripText">:_('app_login')</span>
|
|
|
|
<input type="text" name="__ac_name" id="__ac_name" value=""
|
|
|
|
style="width: 142px"/>
|
|
|
|
<span class="userStripText">:_('app_password')</span>
|
|
|
|
<input type="password" name="__ac_password" id="__ac_password"
|
|
|
|
style="width: 142px"/>
|
|
|
|
<input type="submit" name="submit" onclick="setLoginVars()"
|
|
|
|
var="label=_('app_connect')" value=":label" alt=":label"/>
|
|
|
|
<!-- Forgot password? -->
|
|
|
|
<a if="ztool.showForgotPassword()"
|
|
|
|
href="javascript: openPopup('askPasswordReinitPopup')"
|
|
|
|
class="lostPassword">:_('forgot_password')</a>
|
|
|
|
</span>
|
|
|
|
</form>
|
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- User info and controls for authenticated users -->
|
|
|
|
<td if="not isAnon">
|
|
|
|
<table class="buttons" width="99%">
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<!-- Config -->
|
|
|
|
<a if="user.has_role('Manager')" href=":tool.url"
|
2013-06-27 04:57:39 -05:00
|
|
|
title=":_('%sTool' % appName)">
|
2013-07-20 12:56:17 -05:00
|
|
|
<img src=":url('appyConfig.gif')"/></a>
|
2013-06-28 08:00:02 -05:00
|
|
|
<!-- Additional icons -->
|
2013-08-21 05:35:30 -05:00
|
|
|
<x>:tool.pxIcons</x>
|
2013-06-26 10:06:06 -05:00
|
|
|
<!-- Log out -->
|
|
|
|
<a href=":tool.url + '/performLogout'" title=":_('app_logout')">
|
2013-07-20 12:56:17 -05:00
|
|
|
<img src=":url('logout.gif')"/></a>
|
2013-06-26 10:06:06 -05:00
|
|
|
</td>
|
2014-11-14 06:19:47 -06:00
|
|
|
<x>:user.pxUserLink</x>
|
2013-06-26 10:06:06 -05:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
2014-01-20 11:43:18 -06:00
|
|
|
<tr valign="top">
|
2013-06-26 10:06:06 -05:00
|
|
|
<td>
|
2014-01-20 09:30:14 -06:00
|
|
|
<table width="100%" height="100%" cellpadding="0" cellspacing="0">
|
2013-06-26 10:06:06 -05:00
|
|
|
<tr valign="top">
|
|
|
|
<!-- The portlet -->
|
2013-08-21 05:35:30 -05:00
|
|
|
<td if="showPortlet" class="portlet">:tool.pxPortlet</td>
|
2014-04-29 12:02:06 -05:00
|
|
|
<td class="content">
|
|
|
|
<table cellpadding="0" cellspacing="0" width="100%">
|
|
|
|
<!-- Navigation strip -->
|
|
|
|
<tr if="zobj and (layoutType != 'edit')"
|
|
|
|
height="26px"><td>:obj.pxNavigationStrip</td>
|
|
|
|
</tr>
|
|
|
|
<!-- Page content -->
|
|
|
|
<tr><td>:content</td></tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
2013-06-26 10:06:06 -05:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<!-- Footer -->
|
2014-06-15 17:58:45 -05:00
|
|
|
<tr height="26px" if="not inPopup"><td>:tool.pxFooter</td></tr>
|
2013-06-26 10:06:06 -05:00
|
|
|
</table>
|
2013-06-25 05:04:23 -05:00
|
|
|
</body>
|
2013-06-27 04:57:39 -05:00
|
|
|
</html>''', prologue=Px.xhtmlPrologue)
|
|
|
|
|
2013-06-27 10:40:01 -05:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# PXs for rendering graphical elements tied to a given object
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
2015-01-02 09:16:48 -06:00
|
|
|
# This PX displays an object's history
|
2013-08-21 05:35:30 -05:00
|
|
|
pxHistory = Px('''
|
2013-09-23 15:36:09 -05:00
|
|
|
<x var="startNumber=req.get('startNumber', 0);
|
2013-06-27 10:40:01 -05:00
|
|
|
startNumber=int(startNumber);
|
|
|
|
batchSize=int(req.get('maxPerPage', 5));
|
2013-07-23 03:29:39 -05:00
|
|
|
historyInfo=zobj.getHistory(startNumber,batchSize=batchSize)"
|
2013-08-21 15:25:27 -05:00
|
|
|
if="historyInfo.events"
|
|
|
|
var2="objs=historyInfo.events;
|
|
|
|
totalNumber=historyInfo.totalNumber;
|
2013-09-23 15:36:09 -05:00
|
|
|
batchNumber=len(objs);
|
2013-07-15 04:23:29 -05:00
|
|
|
ajaxHookId='appyHistory';
|
|
|
|
navBaseCall='askObjectHistory(%s,%s,%d,**v**)' % \
|
2013-07-23 03:29:39 -05:00
|
|
|
(q(ajaxHookId), q(zobj.absolute_url()), batchSize)">
|
2013-07-15 04:23:29 -05:00
|
|
|
|
|
|
|
<!-- Navigate between history pages -->
|
2013-08-21 05:35:30 -05:00
|
|
|
<x>:tool.pxNavigate</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- History -->
|
|
|
|
<table width="100%" class="history">
|
|
|
|
<tr>
|
|
|
|
<th align=":dleft">:_('object_action')</th>
|
|
|
|
<th align=":dleft">:_('object_author')</th>
|
|
|
|
<th align=":dleft">:_('action_date')</th>
|
|
|
|
<th align=":dleft">:_('action_comment')</th>
|
|
|
|
</tr>
|
|
|
|
<tr for="event in objs"
|
2014-05-02 05:35:09 -05:00
|
|
|
var2="rhComments=event.get('comments', None);
|
2013-07-15 04:23:29 -05:00
|
|
|
state=event.get('review_state', None);
|
|
|
|
action=event['action'];
|
|
|
|
isDataChange=action == '_datachange_'"
|
2014-05-02 05:35:09 -05:00
|
|
|
class=":loop.event.odd and 'even' or 'odd'" valign="top">
|
2013-07-15 04:23:29 -05:00
|
|
|
<td if="isDataChange">
|
|
|
|
<x>:_('data_change')</x>
|
2013-07-15 06:39:05 -05:00
|
|
|
<img if="user.has_role('Manager')" class="clickable"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('delete')"
|
2013-07-15 04:23:29 -05:00
|
|
|
onclick=":'onDeleteEvent(%s,%s)' % \
|
2014-05-02 05:35:09 -05:00
|
|
|
(q(zobj.id), q(event['time']))"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
</td>
|
2013-07-23 03:29:39 -05:00
|
|
|
<td if="not isDataChange">:_(zobj.getWorkflowLabel(action))</td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<td var="actorId=event.get('actor')">
|
|
|
|
<x if="not actorId">?</x>
|
|
|
|
<x if="actorId">:ztool.getUserName(actorId)</x>
|
|
|
|
</td>
|
2013-09-23 15:36:09 -05:00
|
|
|
<td>:ztool.formatDate(event['time'], withHour=True)</td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<td if="not isDataChange">
|
2013-07-23 03:29:39 -05:00
|
|
|
<x if="rhComments">::zobj.formatText(rhComments)</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
<x if="not rhComments">-</x>
|
|
|
|
</td>
|
|
|
|
<td if="isDataChange">
|
|
|
|
<!-- Display the previous values of the fields whose value were
|
|
|
|
modified in this change. -->
|
2014-10-15 08:39:11 -05:00
|
|
|
<table class="appyChanges" width="100%" if="event['changes']">
|
2013-07-15 04:23:29 -05:00
|
|
|
<tr>
|
|
|
|
<th align=":dleft" width="30%">:_('modified_field')</th>
|
|
|
|
<th align=":dleft" width="70%">:_('previous_value')</th>
|
|
|
|
</tr>
|
|
|
|
<tr for="change in event['changes'].items()" valign="top"
|
2014-09-03 11:18:27 -05:00
|
|
|
var2="elems=change[0].split('-');
|
|
|
|
field=zobj.getAppyType(elems[0]);
|
|
|
|
lg=(len(elems) == 2) and elems[1] or ''">
|
|
|
|
<td><x>::_(field.labelId)</x>
|
|
|
|
<x if="lg">:' (%s)' % ztool.getLanguageName(lg, True)</x></td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<td>::change[1][0]</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2014-10-15 08:39:11 -05:00
|
|
|
<!-- There may also be a comment, too -->
|
|
|
|
<x if="rhComments">::zobj.formatText(rhComments)</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</x>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
pxTransitions = Px('''
|
2013-09-18 05:06:07 -05:00
|
|
|
<form var="transitions=targetObj.getTransitions()" if="transitions"
|
2014-04-21 10:19:27 -05:00
|
|
|
var2="formId='trigger_%s' % targetObj.id" method="post"
|
2014-10-22 15:17:26 -05:00
|
|
|
id=":formId" action=":targetObj.absolute_url() + '/do'"
|
|
|
|
style="display: inline">
|
2013-07-15 04:23:29 -05:00
|
|
|
<input type="hidden" name="action" value="Trigger"/>
|
2014-04-21 05:11:41 -05:00
|
|
|
<input type="hidden" name="transition"/>
|
2013-09-24 05:26:31 -05:00
|
|
|
<!-- Input field for storing the comment coming from the popup -->
|
|
|
|
<textarea id="comment" name="comment" cols="30" rows="3"
|
|
|
|
style="display:none"></textarea>
|
2014-10-22 15:17:26 -05:00
|
|
|
<x for="transition in transitions">
|
|
|
|
<!-- Render a transition or a group of transitions. -->
|
|
|
|
<x if="transition.type == 'transition'">:transition.pxView</x>
|
|
|
|
<x if="transition.type == 'group'"
|
|
|
|
var2="uiGroup=transition">:uiGroup.px</x>
|
|
|
|
</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
</form>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
# Displays header information about an object: title, workflow-related info,
|
|
|
|
# history...
|
2013-08-21 05:35:30 -05:00
|
|
|
pxHeader = Px('''
|
2013-07-23 03:29:39 -05:00
|
|
|
<div if="not zobj.isTemporary()"
|
|
|
|
var2="hasHistory=zobj.hasHistory();
|
2013-07-15 04:23:29 -05:00
|
|
|
historyMaxPerPage=req.get('maxPerPage', 5);
|
2015-01-26 10:26:05 -06:00
|
|
|
collapse=zobj.getHistoryCollapse();
|
2013-07-23 03:29:39 -05:00
|
|
|
creator=zobj.Creator()">
|
2014-06-15 17:58:45 -05:00
|
|
|
<table width="100%" class="summary" cellpadding="0" cellspacing="0">
|
2013-06-27 10:40:01 -05:00
|
|
|
<tr>
|
|
|
|
<td colspan="2" class="by">
|
|
|
|
<!-- Plus/minus icon for accessing history -->
|
2015-01-26 10:26:05 -06:00
|
|
|
<x if="hasHistory"><x>:collapse.px</x>
|
2014-05-02 05:35:09 -05:00
|
|
|
<x>:_('object_history')</x> —
|
2013-06-27 10:40:01 -05:00
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- Creator and last modification date -->
|
2013-09-23 15:36:09 -05:00
|
|
|
<x>:_('object_created_by')</x> <x>:ztool.getUserName(creator)</x>
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
<!-- Creation and last modification dates -->
|
|
|
|
<x>:_('object_created_on')</x>
|
2013-07-23 03:29:39 -05:00
|
|
|
<x var="creationDate=zobj.Created();
|
|
|
|
modificationDate=zobj.Modified()">
|
2013-09-23 15:36:09 -05:00
|
|
|
<x>:ztool.formatDate(creationDate, withHour=True)</x>
|
2013-06-27 10:40:01 -05:00
|
|
|
<x if="modificationDate != creationDate">—
|
|
|
|
<x>:_('object_modified_on')</x>
|
|
|
|
<x>:ztool.formatDate(modificationDate, withHour=True)</x>
|
|
|
|
</x>
|
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- State -->
|
2013-07-23 03:29:39 -05:00
|
|
|
<x if="zobj.showState()">—
|
|
|
|
<x>:_('workflow_state')</x> : <b>:_(zobj.getWorkflowLabel())</b>
|
2013-06-27 10:40:01 -05:00
|
|
|
</x>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<!-- Object history -->
|
|
|
|
<tr if="hasHistory">
|
|
|
|
<td colspan="2">
|
2015-01-26 10:26:05 -06:00
|
|
|
<span id=":collapse.id" style=":collapse.style">
|
2014-05-02 05:35:09 -05:00
|
|
|
<div var="ajaxHookId=zobj.id + '_history'" id=":ajaxHookId">
|
2013-09-23 15:36:09 -05:00
|
|
|
<script type="text/javascript">::'askObjectHistory(%s,%s,%d,0)' % \
|
2013-07-23 03:29:39 -05:00
|
|
|
(q(ajaxHookId), q(zobj.absolute_url()), \
|
2013-07-15 04:23:29 -05:00
|
|
|
historyMaxPerPage)</script>
|
2013-06-27 10:40:01 -05:00
|
|
|
</div>
|
|
|
|
</span>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
2013-07-15 04:23:29 -05:00
|
|
|
</div>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
# Shows the range of buttons (next, previous, save,...) and the workflow
|
2013-08-21 05:35:30 -05:00
|
|
|
# transitions for a given object.
|
|
|
|
pxButtons = Px('''
|
2014-11-13 08:02:33 -06:00
|
|
|
<div class="objectButtons"
|
2014-10-22 15:17:26 -05:00
|
|
|
var="previousPage=phaseObj.getPreviousPage(page)[0];
|
|
|
|
nextPage=phaseObj.getNextPage(page)[0];
|
|
|
|
isEdit=layoutType == 'edit';
|
|
|
|
mayAct=not isEdit and zobj.mayAct();
|
|
|
|
pageInfo=phaseObj.pagesInfo[page]">
|
|
|
|
<!-- Refresh -->
|
|
|
|
<a if="zobj.isDebug()"
|
|
|
|
href=":zobj.getUrl(mode=layoutType, page=page, refresh='yes', \
|
|
|
|
inPopup=inPopup)">
|
|
|
|
<img title="Refresh" style="vertical-align:top" src=":url('refresh')"/>
|
|
|
|
</a>
|
|
|
|
<!-- Previous -->
|
|
|
|
<x if="previousPage and pageInfo.showPrevious"
|
|
|
|
var2="label=_('page_previous');
|
2015-01-19 08:44:09 -06:00
|
|
|
css=ztool.getButtonCss(label, small=False)">
|
2014-10-22 15:17:26 -05:00
|
|
|
<!-- Button on the edit page -->
|
|
|
|
<x if="isEdit">
|
2015-01-19 08:44:09 -06:00
|
|
|
<input type="button" class=":css" value=":label"
|
2015-01-06 14:13:30 -06:00
|
|
|
onclick="submitAppyForm('previous')"
|
2015-01-19 08:44:09 -06:00
|
|
|
style=":url('previous', bg=True)"/>
|
2014-10-22 15:17:26 -05:00
|
|
|
<input type="hidden" name="previousPage" value=":previousPage"/>
|
|
|
|
</x>
|
|
|
|
<!-- Button on the view page -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="not isEdit" type="button" class=":css" value=":label"
|
|
|
|
style=":url('previous', bg=True)"
|
2014-10-22 15:17:26 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(page=previousPage, \
|
|
|
|
inPopup=inPopup))"/>
|
|
|
|
</x>
|
|
|
|
<!-- Save -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="isEdit and pageInfo.showSave" type="button"
|
|
|
|
var2="label=_('object_save');
|
|
|
|
css=ztool.getButtonCss(label, small=False)"
|
|
|
|
class=":css" onclick="submitAppyForm('save')"
|
|
|
|
value=":label" style=":url('save', bg=True)" />
|
2014-10-22 15:17:26 -05:00
|
|
|
<!-- Cancel -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="isEdit and pageInfo.showCancel" type="button"
|
|
|
|
var2="label=_('object_cancel');
|
|
|
|
css=ztool.getButtonCss(label, small=False)"
|
|
|
|
class=":css" onclick="submitAppyForm('cancel')" value=":label"
|
|
|
|
style=":url('cancel', bg=True)"/>
|
2014-10-22 15:17:26 -05:00
|
|
|
<x if="not isEdit"
|
|
|
|
var2="locked=zobj.isLocked(user, page);
|
|
|
|
editable=pageInfo.showOnEdit and pageInfo.showEdit and \
|
|
|
|
mayAct and zobj.mayEdit()">
|
|
|
|
<!-- Edit -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="editable and not locked" type="button"
|
|
|
|
var="label=_('object_edit');
|
|
|
|
css=ztool.getButtonCss(label, small=False)"
|
|
|
|
value=":label" class=":css" style=":url('edit', bg=True)"
|
2014-10-22 15:17:26 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(mode='edit', page=page, \
|
|
|
|
inPopup=inPopup))"/>
|
|
|
|
<!-- Locked -->
|
|
|
|
<a if="editable and locked">
|
2015-01-19 08:44:09 -06:00
|
|
|
<img class="help"
|
2014-10-22 15:17:26 -05:00
|
|
|
var="lockDate=ztool.formatDate(locked[1]);
|
|
|
|
lockMap={'user':ztool.getUserName(locked[0]), \
|
|
|
|
'date':lockDate};
|
|
|
|
lockMsg=_('page_locked', mapping=lockMap)"
|
|
|
|
src=":url('lockedBig')" title=":lockMsg"/></a>
|
|
|
|
<a if="editable and locked and user.has_role('Manager')">
|
|
|
|
<img class="clickable" title=":_('page_unlock')"
|
|
|
|
src=":url('unlockBig')"
|
|
|
|
onclick=":'onUnlockPage(%s,%s)' % (q(zobj.id), q(page))"/></a>
|
|
|
|
</x>
|
2015-01-06 14:13:30 -06:00
|
|
|
<!-- Delete -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="not isEdit and not inPopup and zobj.mayDelete()" type="button"
|
|
|
|
var2="label=_('object_delete');
|
|
|
|
css=ztool.getButtonCss(label, small=False)"
|
|
|
|
value=":label" class=":css" style=":url('delete', bg=True)"
|
|
|
|
onclick=":'onDeleteObject(%s)' % q(zobj.id)"/>
|
2014-10-22 15:17:26 -05:00
|
|
|
<!-- Next -->
|
|
|
|
<x if="nextPage and pageInfo.showNext"
|
|
|
|
var2="label=_('page_next');
|
2015-01-19 08:44:09 -06:00
|
|
|
css=ztool.getButtonCss(label, small=False)">
|
2014-10-22 15:17:26 -05:00
|
|
|
<!-- Button on the edit page -->
|
|
|
|
<x if="isEdit">
|
2015-01-19 08:44:09 -06:00
|
|
|
<input type="button" class=":css" onclick="submitAppyForm('next')"
|
|
|
|
style=":url('next', bg=True)" value=":label"/>
|
2014-10-22 15:17:26 -05:00
|
|
|
<input type="hidden" name="nextPage" value=":nextPage"/>
|
|
|
|
</x>
|
|
|
|
<!-- Button on the view page -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<input if="not isEdit" type="button" class=":css" value=":label"
|
|
|
|
style=":url('next', bg=True)"
|
2014-10-22 15:17:26 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(page=nextPage, \
|
|
|
|
inPopup=inPopup))"/>
|
|
|
|
</x>
|
|
|
|
<!-- Workflow transitions -->
|
|
|
|
<x var="targetObj=zobj; buttonsMode='normal'"
|
|
|
|
if="mayAct and \
|
|
|
|
targetObj.showTransitions(layoutType)">:obj.pxTransitions</x>
|
2014-11-13 08:02:33 -06:00
|
|
|
<!-- Fields (actions) defined with layout "buttons" -->
|
|
|
|
<x if="layoutType != 'edit'"
|
|
|
|
var2="fields=zobj.getAppyTypes('buttons', page, type='Action');
|
|
|
|
layoutType='view'">
|
|
|
|
<!-- Call pxView and not pxRender to avoid having a table -->
|
|
|
|
<x for="field in fields" var2="name=field.name">:field.pxView</x>
|
|
|
|
</x>
|
|
|
|
</div>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
2014-12-09 08:19:28 -06:00
|
|
|
# Display the fields of a given page for a given object
|
2013-08-21 05:35:30 -05:00
|
|
|
pxFields = Px('''
|
2013-08-21 15:25:27 -05:00
|
|
|
<table width=":layout.width">
|
2013-08-21 05:35:30 -05:00
|
|
|
<tr for="field in groupedFields">
|
|
|
|
<td if="field.type == 'group'">:field.pxView</td>
|
|
|
|
<td if="field.type != 'group'">:field.pxRender</td>
|
|
|
|
</tr>
|
|
|
|
</table>''')
|
|
|
|
|
2014-12-19 04:21:43 -06:00
|
|
|
pxIndexedContent = Px('''
|
|
|
|
<form name="reindexForm" method="post" action=":'%s/onReindex' % obj.url">
|
|
|
|
<input type="hidden" name="indexName"/>
|
|
|
|
<table var="indexes=obj.getIndexes(asList=True)" class="list compact">
|
2015-01-09 05:05:49 -06:00
|
|
|
<!-- 1st line: dump local roles, by the way -->
|
|
|
|
<tr>
|
|
|
|
<td>Local roles</td>
|
|
|
|
<td colspan="2"><x>:zobj.__ac_local_roles__</x></td>
|
|
|
|
</tr>
|
2014-12-19 04:21:43 -06:00
|
|
|
<tr><th>Index name</th><th>Type</th><th>Content
|
|
|
|
<img src=":url('reindex')" class="clickable" title="Reindex all indexes"
|
|
|
|
onclick="reindexObject(\'_all_\')"/></th></tr>
|
|
|
|
<tr for="info in indexes"
|
|
|
|
class=":loop.info.odd and 'odd' or 'even'">
|
|
|
|
<td>:info[0]</td><td>:info[1]</td>
|
|
|
|
<td><img src=":url('reindex')" class="clickable"
|
|
|
|
title="Reindex this index only"
|
|
|
|
onclick=":'reindexObject(%s)' % q(info[0])"/>
|
|
|
|
<x>:ztool.getCatalogValue(zobj, info[0])</x></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>''')
|
|
|
|
|
2013-06-27 04:57:39 -05:00
|
|
|
pxView = Px('''
|
2014-05-03 15:45:51 -05:00
|
|
|
<x var="x=zobj.mayView(raiseError=True);
|
2013-06-27 04:57:39 -05:00
|
|
|
errors=req.get('errors', {});
|
2013-07-23 03:29:39 -05:00
|
|
|
layout=zobj.getPageLayout(layoutType);
|
2013-08-21 05:35:30 -05:00
|
|
|
phaseObj=zobj.getAppyPhases(currentOnly=True, layoutType='view');
|
|
|
|
phase=phaseObj.name;
|
2013-06-27 04:57:39 -05:00
|
|
|
cssJs={};
|
2013-07-23 03:29:39 -05:00
|
|
|
page=req.get('page',None) or zobj.getDefaultViewPage();
|
|
|
|
x=zobj.removeMyLock(user, page);
|
2013-08-21 05:35:30 -05:00
|
|
|
groupedFields=zobj.getGroupedFields(layoutType, page,cssJs=cssJs)">
|
|
|
|
<x>:tool.pxPagePrologue</x>
|
2015-01-09 05:05:49 -06:00
|
|
|
<x if="('indexed' in req) and \
|
|
|
|
user.has_role('Manager')">:obj.pxIndexedContent</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
<x var="tagId='pageLayout'; tagName=''; tagCss='';
|
|
|
|
layoutTarget=obj">:tool.pxLayoutedObject</x>
|
|
|
|
<x>:tool.pxPageBottom</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</x>''', template=pxTemplate, hook='content')
|
|
|
|
|
|
|
|
pxEdit = Px('''
|
2014-05-03 15:45:51 -05:00
|
|
|
<x var="x=zobj.mayEdit(raiseError=True, permOnly=zobj.isTemporary());
|
2014-03-04 08:03:37 -06:00
|
|
|
errors=req.get('errors', {});
|
2013-07-23 03:29:39 -05:00
|
|
|
layout=zobj.getPageLayout(layoutType);
|
2013-06-27 04:57:39 -05:00
|
|
|
cssJs={};
|
2013-08-21 05:35:30 -05:00
|
|
|
phaseObj=zobj.getAppyPhases(currentOnly=True, \
|
|
|
|
layoutType=layoutType);
|
|
|
|
phase=phaseObj.name;
|
2013-07-23 03:29:39 -05:00
|
|
|
page=req.get('page', None) or zobj.getDefaultEditPage();
|
|
|
|
x=zobj.setLock(user, page);
|
2013-06-27 04:57:39 -05:00
|
|
|
confirmMsg=req.get('confirmMsg', None);
|
2013-08-21 05:35:30 -05:00
|
|
|
groupedFields=zobj.getGroupedFields(layoutType,page, cssJs=cssJs)">
|
|
|
|
<x>:tool.pxPagePrologue</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
<!-- Warn the user that the form should be left via buttons -->
|
2013-09-11 15:11:44 -05:00
|
|
|
<script type="text/javascript">protectAppyForm()</script>
|
2013-06-27 04:57:39 -05:00
|
|
|
<form id="appyForm" name="appyForm" method="post"
|
2013-07-23 03:29:39 -05:00
|
|
|
enctype="multipart/form-data" action=":zobj.absolute_url()+'/do'">
|
2013-07-15 04:23:29 -05:00
|
|
|
<input type="hidden" name="action" value="Update"/>
|
|
|
|
<input type="hidden" name="button" value=""/>
|
2014-06-15 17:58:45 -05:00
|
|
|
<input type="hidden" name="popup" value=":inPopup and '1' or '0'"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
<input type="hidden" name="page" value=":page"/>
|
|
|
|
<input type="hidden" name="nav" value=":req.get('nav', None)"/>
|
|
|
|
<input type="hidden" name="confirmed" value="False"/>
|
2013-08-21 05:35:30 -05:00
|
|
|
<x var="tagId='pageLayout'; tagName=''; tagCss='';
|
|
|
|
layoutTarget=obj">:tool.pxLayoutedObject</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</form>
|
|
|
|
<script type="text/javascript"
|
2014-03-26 08:01:03 -05:00
|
|
|
if="confirmMsg">::'askConfirm(%s,%s,%s)' % \
|
2013-07-15 04:23:29 -05:00
|
|
|
(q('script'), q('postConfirmedEditForm()'), q(confirmMsg))</script>
|
2013-08-21 05:35:30 -05:00
|
|
|
<x>:tool.pxPageBottom</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</x>''', template=pxTemplate, hook='content')
|
2013-06-25 05:04:23 -05:00
|
|
|
|
2013-08-21 05:35:30 -05:00
|
|
|
# PX called via asynchronous requests from the browser. Keys "Expires" and
|
|
|
|
# "CacheControl" are used to prevent IE to cache returned pages (which is
|
|
|
|
# the default IE behaviour with Ajax requests).
|
|
|
|
pxAjax = Px('''
|
|
|
|
<x var="zobj=obj.o; ztool=tool.o; user=tool.user;
|
|
|
|
isAnon=user.login == 'anon'; app=ztool.getApp();
|
|
|
|
appFolder=app.data; url = ztool.getIncludeUrl;
|
|
|
|
appName=ztool.getAppName(); _=ztool.translate;
|
|
|
|
req=ztool.REQUEST; resp=req.RESPONSE;
|
2013-09-20 10:42:07 -05:00
|
|
|
dummy=setattr(req, 'pxContext', _ctx_);
|
2013-08-21 05:35:30 -05:00
|
|
|
lang=ztool.getUserLanguage(); q=ztool.quote;
|
2014-08-05 07:53:08 -05:00
|
|
|
action=req.get('action', '');
|
2013-08-21 05:35:30 -05:00
|
|
|
px=req['px'].split(':');
|
2014-06-15 17:58:45 -05:00
|
|
|
inPopup=req.get('popup') == '1';
|
2014-03-05 06:25:36 -06:00
|
|
|
className=(len(px) == 3) and px[0] or None;
|
|
|
|
field=className and zobj.getAppyType(px[1], className) or None;
|
|
|
|
field=(len(px) == 2) and zobj.getAppyType(px[0]) or field;
|
2013-08-21 05:35:30 -05:00
|
|
|
dir=ztool.getLanguageDirection(lang);
|
|
|
|
dleft=(dir == 'ltr') and 'left' or 'right';
|
|
|
|
dright=(dir == 'ltr') and 'right' or 'left';
|
|
|
|
x=resp.setHeader('Content-type', ztool.xhtmlEncoding);
|
|
|
|
x=resp.setHeader('Expires', 'Thu, 11 Dec 1975 12:05:00 GMT+2');
|
|
|
|
x=resp.setHeader('Content-Language', lang);
|
2014-11-10 06:34:52 -06:00
|
|
|
x=resp.setHeader('Cache-Control', 'no-cache')">
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- If an action is defined, execute it on p_zobj or on p_field. -->
|
2014-11-10 06:34:52 -06:00
|
|
|
<x if="action"
|
|
|
|
var2="msg=ztool.executeAjaxAction(action, obj, field) or '';
|
|
|
|
x=resp.setHeader('Appy-Message', msg)"></x>
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- Then, call the PX on p_obj or on p_field. -->
|
|
|
|
<x if="not field">:getattr(obj, px[0])</x>
|
2014-03-05 06:25:36 -06:00
|
|
|
<x if="field">:getattr(field, px[-1])</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
</x>''')
|
|
|
|
|
2012-06-02 07:36:49 -05:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Class methods
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
@classmethod
|
|
|
|
def _getParentAttr(klass, attr):
|
|
|
|
'''Gets value of p_attr on p_klass base classes (if this attr exists).
|
|
|
|
Scan base classes in the reverse order as Python does. Used by
|
2013-08-23 11:57:27 -05:00
|
|
|
classmethod m_getWorkflow below. Scanning base classes in reverse
|
|
|
|
order allows user-defined elements to override default Appy
|
|
|
|
elements.'''
|
2012-06-02 07:36:49 -05:00
|
|
|
i = len(klass.__bases__) - 1
|
|
|
|
res = None
|
|
|
|
while i >= 0:
|
|
|
|
res = getattr(klass.__bases__[i], attr, None)
|
|
|
|
if res: return res
|
|
|
|
i -= 1
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getWorkflow(klass):
|
|
|
|
'''Returns the workflow tied to p_klass.'''
|
|
|
|
res = klass._getParentAttr('workflow')
|
|
|
|
# Return a default workflow if no workflow was found.
|
|
|
|
if not res: res = WorkflowAnonymous
|
|
|
|
return res
|
|
|
|
|
2014-09-11 09:41:08 -05:00
|
|
|
@classmethod
|
|
|
|
def getPageLayouts(klass):
|
|
|
|
'''Returns the page layouts for p_klass.'''
|
|
|
|
res = klass._getParentAttr('layouts')
|
|
|
|
# Return the default page layout if no layout was found.
|
|
|
|
if not res: res = defaultPageLayouts
|
|
|
|
return res
|
|
|
|
|
2012-09-04 11:00:22 -05:00
|
|
|
@classmethod
|
2014-12-19 04:21:43 -06:00
|
|
|
def getIndexes(klass, includeDefaults=True, asList=False):
|
2012-09-04 11:00:22 -05:00
|
|
|
'''Returns a dict whose keys are the names of the indexes that are
|
|
|
|
applicable to instances of this class, and whose values are the
|
2014-12-19 04:21:43 -06:00
|
|
|
(Zope) types of those indexes. If p_asList is True, it returns a
|
|
|
|
list of tuples insteadof a dict.'''
|
2015-01-02 09:16:48 -06:00
|
|
|
# Start with the standard indexes applicable for any Appy class
|
2012-09-04 11:00:22 -05:00
|
|
|
if includeDefaults:
|
|
|
|
res = defaultIndexes.copy()
|
|
|
|
else:
|
|
|
|
res = {}
|
|
|
|
# Add the indexed fields found on this class
|
|
|
|
for field in klass.__fields__:
|
2015-01-02 09:16:48 -06:00
|
|
|
if not field.indexed or \
|
|
|
|
(field.name in ('title', 'state', 'SearchableText')): continue
|
2012-09-04 11:00:22 -05:00
|
|
|
n = field.name
|
|
|
|
indexName = 'get%s%s' % (n[0].upper(), n[1:])
|
|
|
|
res[indexName] = field.getIndexType()
|
2014-11-28 07:42:32 -06:00
|
|
|
# Add the secondary index if present
|
|
|
|
if field.hasSortIndex(): res['%s_sort' % indexName] = 'FieldIndex'
|
2014-12-19 04:21:43 -06:00
|
|
|
if asList:
|
|
|
|
res = res.items()
|
|
|
|
res.sort(key=lambda e: e[0])
|
2012-09-04 11:00:22 -05:00
|
|
|
return res
|
|
|
|
|
2012-06-02 07:36:49 -05:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Instance methods
|
|
|
|
# --------------------------------------------------------------------------
|
2010-11-26 10:30:46 -06:00
|
|
|
def __init__(self, o): self.__dict__['o'] = o
|
2011-02-12 10:09:11 -06:00
|
|
|
def appy(self): return self
|
2010-11-26 10:30:46 -06:00
|
|
|
|
|
|
|
def __setattr__(self, name, value):
|
2014-09-14 14:40:35 -05:00
|
|
|
field = self.o.getAppyType(name)
|
|
|
|
if not field:
|
|
|
|
raise AttributeError('Attribute "%s" does not exist.' % name)
|
|
|
|
field.store(self.o, value)
|
2010-11-26 10:30:46 -06:00
|
|
|
|
2011-09-06 18:33:09 -05:00
|
|
|
def __getattribute__(self, name):
|
|
|
|
'''Gets the attribute named p_name. Lot of cheating here.'''
|
|
|
|
if name == 'o': return object.__getattribute__(self, name)
|
|
|
|
elif name == 'tool': return self.o.getTool().appy()
|
2012-10-18 13:57:03 -05:00
|
|
|
elif name == 'request':
|
|
|
|
# The request may not be present, ie if we are at Zope startup.
|
2013-04-16 12:56:47 -05:00
|
|
|
res = getattr(self.o, 'REQUEST', None)
|
|
|
|
if res != None: return res
|
|
|
|
return self.o.getProductConfig().fakeRequest
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'session': return self.o.REQUEST.SESSION
|
|
|
|
elif name == 'typeName': return self.__class__.__bases__[-1].__name__
|
|
|
|
elif name == 'id': return self.o.id
|
2014-05-02 05:35:09 -05:00
|
|
|
elif name == 'uid': return self.o.id
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'klass': return self.__class__.__bases__[-1]
|
2013-06-07 04:32:23 -05:00
|
|
|
elif name == 'created': return self.o.created
|
2014-05-02 05:35:09 -05:00
|
|
|
elif name == 'creator': return self.o.creator
|
2013-06-07 04:32:23 -05:00
|
|
|
elif name == 'modified': return self.o.modified
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'url': return self.o.absolute_url()
|
2011-11-25 11:01:20 -06:00
|
|
|
elif name == 'state': return self.o.State()
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'stateLabel':
|
2012-05-03 03:51:54 -05:00
|
|
|
return self.o.translate(self.o.getWorkflowLabel())
|
2014-09-15 11:32:45 -05:00
|
|
|
elif name == 'history': return self.o.workflow_history['appy']
|
2013-08-21 05:35:30 -05:00
|
|
|
elif name == 'user': return self.o.getTool().getUser()
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'fields': return self.o.getAllAppyTypes()
|
2013-04-26 19:15:44 -05:00
|
|
|
elif name == 'siteUrl': return self.o.getTool().getSiteUrl()
|
2014-07-29 12:21:37 -05:00
|
|
|
elif name == 'initiator': return self.o.getInitiatorInfo(True)
|
2011-09-06 18:33:09 -05:00
|
|
|
# Now, let's try to return a real attribute.
|
2011-09-14 14:01:58 -05:00
|
|
|
res = object.__getattribute__(self, name)
|
2014-04-17 10:10:38 -05:00
|
|
|
# If we got an Appy field, return its value for this object
|
2013-07-08 16:39:16 -05:00
|
|
|
if isinstance(res, Field):
|
2011-09-06 18:33:09 -05:00
|
|
|
o = self.o
|
|
|
|
if isinstance(res, Ref):
|
|
|
|
return res.getValue(o, noListIfSingleObj=True)
|
|
|
|
else:
|
|
|
|
return res.getValue(o)
|
|
|
|
return res
|
|
|
|
|
2009-11-11 13:22:13 -06:00
|
|
|
def __repr__(self):
|
2014-05-14 08:10:41 -05:00
|
|
|
return '<%s at %s>' % (self.klass.__name__, id(self))
|
2010-11-26 10:30:46 -06:00
|
|
|
|
2009-06-29 07:06:01 -05:00
|
|
|
def __cmp__(self, other):
|
2009-10-27 08:48:04 -05:00
|
|
|
if other: return cmp(self.o, other.o)
|
2011-07-26 15:15:04 -05:00
|
|
|
return 1
|
2010-11-26 10:30:46 -06:00
|
|
|
|
2012-09-17 14:11:54 -05:00
|
|
|
def _getCustomMethod(self, methodName):
|
|
|
|
'''See docstring of _callCustom below.'''
|
|
|
|
if len(self.__class__.__bases__) > 1:
|
|
|
|
# There is a custom user class
|
|
|
|
custom = self.__class__.__bases__[-1]
|
|
|
|
if custom.__dict__.has_key(methodName):
|
|
|
|
return custom.__dict__[methodName]
|
|
|
|
|
2011-01-14 02:06:25 -06:00
|
|
|
def _callCustom(self, methodName, *args, **kwargs):
|
|
|
|
'''This wrapper implements some methods like "validate" and "onEdit".
|
|
|
|
If the user has defined its own wrapper, its methods will not be
|
|
|
|
called. So this method allows, from the methods here, to call the
|
|
|
|
user versions.'''
|
2012-09-17 14:11:54 -05:00
|
|
|
custom = self._getCustomMethod(methodName)
|
|
|
|
if custom: return custom(self, *args, **kwargs)
|
2011-01-14 02:06:25 -06:00
|
|
|
|
2011-02-17 11:13:42 -06:00
|
|
|
def getField(self, name): return self.o.getAppyType(name)
|
2014-09-08 08:13:18 -05:00
|
|
|
|
|
|
|
def getValue(self, name, formatted=False, language=None):
|
2014-09-10 09:26:19 -05:00
|
|
|
'''Gets the possibly p_formatted value of field p_name. If this
|
|
|
|
formatting implies translating something, it will be done in
|
|
|
|
p_language, or in the user language if not specified. If the "shown"
|
|
|
|
value is required instead of the "formatted" value (see methods
|
|
|
|
getFormattedValue and getShownValue from class appy.fields.Field),
|
|
|
|
use p_formatted="shown" instead of p_formatted=True.'''
|
2014-09-08 08:13:18 -05:00
|
|
|
field = self.o.getAppyType(name)
|
|
|
|
obj = self.o
|
|
|
|
val = field.getValue(obj)
|
|
|
|
if not formatted: return val
|
2014-09-10 09:26:19 -05:00
|
|
|
method = (formatted == 'shown') and 'getShownValue' or \
|
|
|
|
'getFormattedValue'
|
|
|
|
return getattr(field, method)(obj, val, language=language)
|
2014-09-08 08:13:18 -05:00
|
|
|
|
2014-05-02 05:35:09 -05:00
|
|
|
def getLabel(self, name, type='field'):
|
|
|
|
'''Gets the translated label of field named p_name. If p_type is
|
|
|
|
"workflow", p_name denotes a workflow state or transition, not a
|
|
|
|
field.'''
|
|
|
|
o = self.o
|
|
|
|
if type == 'field': return o.translate(o.getAppyType(name).labelId)
|
|
|
|
elif type == 'workflow': return o.translate(o.getWorkflowLabel(name))
|
|
|
|
|
2012-06-13 02:31:09 -05:00
|
|
|
def isEmpty(self, name):
|
|
|
|
'''Returns True if value of field p_name is considered as being
|
|
|
|
empty.'''
|
|
|
|
obj = self.o
|
|
|
|
if hasattr(obj.aq_base, name):
|
|
|
|
field = obj.getAppyType(name)
|
2014-09-05 10:13:23 -05:00
|
|
|
return field.isEmptyValue(obj, getattr(obj, name))
|
2012-06-13 02:31:09 -05:00
|
|
|
return True
|
2011-02-17 11:13:42 -06:00
|
|
|
|
2014-07-14 06:21:38 -05:00
|
|
|
def isTemp(self):
|
|
|
|
'''Is this object a temporary object being created?'''
|
|
|
|
return self.o.isTemporary()
|
|
|
|
|
2014-09-29 03:06:40 -05:00
|
|
|
def link(self, fieldName, obj, noSecurity=True, executeMethods=True):
|
2011-01-19 13:51:43 -06:00
|
|
|
'''This method links p_obj (which can be a list of objects) to this one
|
2014-09-29 03:06:40 -05:00
|
|
|
through reference field p_fieldName. For understanding the 2 last
|
|
|
|
params, check Ref's m_linkObject's doc.'''
|
|
|
|
field = self.getField(fieldName)
|
|
|
|
return field.linkObject(self, obj, noSecurity=noSecurity,
|
|
|
|
executeMethods=executeMethods)
|
2011-01-19 13:51:43 -06:00
|
|
|
|
2014-09-29 03:06:40 -05:00
|
|
|
def unlink(self, fieldName, obj, noSecurity=True, executeMethods=True):
|
2011-01-19 13:51:43 -06:00
|
|
|
'''This method unlinks p_obj (which can be a list of objects) from this
|
2014-09-29 03:06:40 -05:00
|
|
|
one through reference field p_fieldName. For understanding the 2 last
|
|
|
|
params, check Ref's m_unlinkObject's doc.'''
|
|
|
|
field = self.getField(fieldName)
|
|
|
|
return field.unlinkObject(self, obj, noSecurity=noSecurity,
|
|
|
|
executeMethods=executeMethods)
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2010-04-30 05:05:29 -05:00
|
|
|
def sort(self, fieldName, sortKey='title', reverse=False):
|
|
|
|
'''Sorts referred elements linked to p_self via p_fieldName according
|
|
|
|
to a given p_sortKey which must be an attribute set on referred
|
2015-01-08 06:18:14 -06:00
|
|
|
objects ("title", by default) or None. If None, default sorting will
|
|
|
|
occur, using the method stored in field.insert.'''
|
2011-11-25 11:01:20 -06:00
|
|
|
refs = getattr(self.o, fieldName, None)
|
2011-09-26 14:19:34 -05:00
|
|
|
if not refs: return
|
2011-11-25 11:01:20 -06:00
|
|
|
tool = self.tool
|
2015-01-08 06:18:14 -06:00
|
|
|
# refs is a PersistentList: param "key" is not available for method
|
|
|
|
# "sort". So perform the sort on the real list and then indicate that
|
|
|
|
# the persistent list has changed (the ZODB way).
|
|
|
|
if not sortKey:
|
|
|
|
# Sort according to field.insert
|
|
|
|
field = self.getField(fieldName)
|
|
|
|
insertMethod = field.insert
|
|
|
|
if not insertMethod:
|
|
|
|
raise Exception('Param "insert" for Ref field %s is None.' % \
|
|
|
|
fieldName)
|
|
|
|
if not callable(insertMethod): insertMethod = insertMethod[1]
|
|
|
|
keyMethod = lambda uid: insertMethod(self, tool.getObject(uid))
|
|
|
|
else:
|
|
|
|
# Sort according to p_sortKey
|
|
|
|
keyMethod = lambda uid: getattr(tool.getObject(uid), sortKey)
|
|
|
|
refs.data.sort(key=keyMethod, reverse=reverse)
|
2013-03-10 10:31:49 -05:00
|
|
|
refs._p_changed = 1
|
2009-10-27 08:48:04 -05:00
|
|
|
|
2014-09-14 14:40:35 -05:00
|
|
|
def create(self, fieldNameOrClass, noSecurity=False,
|
2014-09-29 03:06:40 -05:00
|
|
|
raiseOnWrongAttribute=True, executeMethods=True, **kwargs):
|
2014-09-14 14:40:35 -05:00
|
|
|
'''This method creates a new instance of a gen-class.
|
|
|
|
|
|
|
|
If p_fieldNameOrClass is the name of a field, the created object will
|
|
|
|
be linked to p_self via this field. If p_fieldNameOrClass is a class
|
|
|
|
from the gen-application, it must correspond to a root class: the
|
|
|
|
created object will be stored in the main application folder (and no
|
|
|
|
link will exist between it and p_self).
|
|
|
|
|
|
|
|
p_kwargs allow to specify values for object fields.
|
|
|
|
If p_noSecurity is True, security checks will not be performed.
|
|
|
|
|
|
|
|
If p_raiseOnWrongAttribute is True, if a value from p_kwargs does not
|
|
|
|
correspond to a field on the created object, an AttributeError will
|
|
|
|
be raised. Else, the value will be silently ignored.
|
2014-09-25 02:52:22 -05:00
|
|
|
|
2014-09-29 03:06:40 -05:00
|
|
|
If p_executeMethods is False, the gen-class's onEdit method, if
|
|
|
|
present, will not be called; any other defined method will not be
|
|
|
|
called neither (ie, Ref.insert, Ref.beforeLink, Ref.afterLink...).
|
2014-09-14 14:40:35 -05:00
|
|
|
'''
|
2009-07-10 08:01:50 -05:00
|
|
|
isField = isinstance(fieldNameOrClass, basestring)
|
2011-11-25 11:01:20 -06:00
|
|
|
tool = self.tool.o
|
2013-04-16 12:56:47 -05:00
|
|
|
# Determine the class of the object to create
|
2009-07-10 08:01:50 -05:00
|
|
|
if isField:
|
2011-11-25 11:01:20 -06:00
|
|
|
fieldName = fieldNameOrClass
|
2014-09-29 03:06:40 -05:00
|
|
|
field = self.o.getAppyType(fieldName)
|
|
|
|
portalType = tool.getPortalType(field.klass)
|
2009-07-10 08:01:50 -05:00
|
|
|
else:
|
2010-09-02 09:16:08 -05:00
|
|
|
klass = fieldNameOrClass
|
2011-11-25 11:01:20 -06:00
|
|
|
portalType = tool.getPortalType(klass)
|
2009-07-10 08:01:50 -05:00
|
|
|
# Determine object id
|
2009-06-29 07:06:01 -05:00
|
|
|
if kwargs.has_key('id'):
|
|
|
|
objId = kwargs['id']
|
|
|
|
del kwargs['id']
|
|
|
|
else:
|
2011-11-25 11:01:20 -06:00
|
|
|
objId = tool.generateUid(portalType)
|
2009-07-10 08:01:50 -05:00
|
|
|
# Where must I create the object?
|
|
|
|
if not isField:
|
2011-11-25 11:01:20 -06:00
|
|
|
folder = tool.getPath('/data')
|
2009-06-29 07:06:01 -05:00
|
|
|
else:
|
2012-06-02 07:36:49 -05:00
|
|
|
folder = self.o.getCreateFolder()
|
|
|
|
if not noSecurity:
|
|
|
|
# Check that the user can edit this field.
|
2014-09-29 03:06:40 -05:00
|
|
|
field.checkAdd(self.o)
|
2009-06-29 07:06:01 -05:00
|
|
|
# Create the object
|
2012-06-02 07:36:49 -05:00
|
|
|
zopeObj = createObject(folder, objId, portalType, tool.getAppName(),
|
|
|
|
noSecurity=noSecurity)
|
2011-11-25 11:01:20 -06:00
|
|
|
appyObj = zopeObj.appy()
|
2009-06-29 07:06:01 -05:00
|
|
|
# Set object attributes
|
|
|
|
for attrName, attrValue in kwargs.iteritems():
|
2014-09-14 14:40:35 -05:00
|
|
|
try:
|
|
|
|
setattr(appyObj, attrName, attrValue)
|
|
|
|
except AttributeError, ae:
|
|
|
|
if raiseOnWrongAttribute: raise ae
|
2014-12-15 12:36:00 -06:00
|
|
|
# Call custom early initialization
|
|
|
|
if executeMethods and hasattr(appyObj, 'onEditEarly'):
|
|
|
|
appyObj.onEditEarly()
|
2009-07-10 08:01:50 -05:00
|
|
|
if isField:
|
|
|
|
# Link the object to this one
|
2014-09-29 03:06:40 -05:00
|
|
|
field.linkObject(self, appyObj, executeMethods=executeMethods)
|
2009-07-10 08:01:50 -05:00
|
|
|
# Call custom initialization
|
2014-09-29 03:06:40 -05:00
|
|
|
if executeMethods and hasattr(appyObj, 'onEdit'): appyObj.onEdit(True)
|
2011-11-25 11:01:20 -06:00
|
|
|
zopeObj.reindex()
|
2009-06-29 07:06:01 -05:00
|
|
|
return appyObj
|
|
|
|
|
2014-09-25 02:52:22 -05:00
|
|
|
def createFrom(self, fieldNameOrClass, other, noSecurity=False,
|
2015-01-06 14:13:30 -06:00
|
|
|
executeMethods=True, exclude=(), keepBase=False):
|
2014-09-14 14:40:35 -05:00
|
|
|
'''Similar to m_create above, excepted that we will use another object
|
2015-01-02 09:16:48 -06:00
|
|
|
(p_other) as base for filling in data for the object to create.
|
2015-01-06 14:13:30 -06:00
|
|
|
p_exclude can list fields (by their names) that will not be copied on
|
|
|
|
p_other. If p_keepBase is True, basic attributes will be kept on the
|
|
|
|
new object: creator and dates "created" and "modified". Else, the
|
|
|
|
new object's creator will be the logged user.
|
|
|
|
|
|
|
|
Note that this method does not perform a deep copy: objects linked
|
|
|
|
via Ref fields from p_self will be referenced by the clone, but not
|
|
|
|
themselves copied.'''
|
2014-09-14 14:40:35 -05:00
|
|
|
# Get the field values to set from p_other and store it in a dict.
|
|
|
|
# p_other may not be of the same class as p_self.
|
|
|
|
params = {}
|
|
|
|
for field in other.fields:
|
2015-01-02 09:16:48 -06:00
|
|
|
# Skip non persistent fields, back references and p_excluded fields
|
|
|
|
if not field.persist or (field.name in exclude) or \
|
|
|
|
((field.type == 'Ref') and field.isBack): continue
|
2014-09-14 14:40:35 -05:00
|
|
|
params[field.name] = field.getCopyValue(other.o)
|
2015-01-06 14:13:30 -06:00
|
|
|
res = self.create(fieldNameOrClass, noSecurity=noSecurity,
|
|
|
|
raiseOnWrongAttribute=False,
|
|
|
|
executeMethods=executeMethods, **params)
|
|
|
|
# Propagate base attributes if required
|
|
|
|
if keepBase:
|
|
|
|
for name in ('creator', 'created', 'modified'):
|
|
|
|
setattr(res.o, name, getattr(other.o, name))
|
|
|
|
return res
|
2014-09-14 14:40:35 -05:00
|
|
|
|
2014-03-24 16:55:00 -05:00
|
|
|
def freeze(self, fieldName, template=None, format='pdf', noSecurity=True,
|
|
|
|
freezeOdtOnError=True):
|
2014-03-21 10:50:48 -05:00
|
|
|
'''This method freezes the content of pod field named p_fieldName, for
|
|
|
|
the given p_template (several templates can be given in
|
|
|
|
podField.template), in the given p_format ("pdf" by default).'''
|
2011-02-16 06:43:58 -06:00
|
|
|
field = self.o.getAppyType(fieldName)
|
2014-03-21 10:50:48 -05:00
|
|
|
if field.type!= 'Pod': raise Exception('Cannot freeze non-Pod field.')
|
2014-03-24 16:55:00 -05:00
|
|
|
return field.freeze(self, template, format, noSecurity=noSecurity,
|
|
|
|
freezeOdtOnError=freezeOdtOnError)
|
2014-03-21 10:50:48 -05:00
|
|
|
|
2014-03-24 16:55:00 -05:00
|
|
|
def unfreeze(self, fieldName, template=None, format='pdf', noSecurity=True):
|
2014-03-21 10:50:48 -05:00
|
|
|
'''This method unfreezes a pod field.'''
|
2011-02-16 06:43:58 -06:00
|
|
|
field = self.o.getAppyType(fieldName)
|
2014-03-21 10:50:48 -05:00
|
|
|
if field.type!= 'Pod': raise Exception('Cannot unfreeze non-Pod field.')
|
2014-03-24 16:55:00 -05:00
|
|
|
field.unfreeze(self, template, format, noSecurity=noSecurity)
|
2011-02-16 06:43:58 -06:00
|
|
|
|
2010-11-26 10:30:46 -06:00
|
|
|
def delete(self):
|
|
|
|
'''Deletes myself.'''
|
|
|
|
self.o.delete()
|
|
|
|
|
2011-06-28 02:12:20 -05:00
|
|
|
def translate(self, label, mapping={}, domain=None, language=None,
|
|
|
|
format='html'):
|
2009-10-18 07:52:27 -05:00
|
|
|
'''Check documentation of self.o.translate.'''
|
2011-06-28 02:12:20 -05:00
|
|
|
return self.o.translate(label, mapping, domain, language=language,
|
|
|
|
format=format)
|
2009-06-29 07:06:01 -05:00
|
|
|
|
2014-10-28 11:48:54 -05:00
|
|
|
def do(self, name, comment='', doAction=True, doHistory=True,
|
2014-04-21 05:11:41 -05:00
|
|
|
noSecurity=False):
|
|
|
|
'''Triggers on p_self a transition named p_name programmatically.'''
|
|
|
|
o = self.o
|
|
|
|
wf = o.getWorkflow()
|
|
|
|
tr = getattr(wf, name, None)
|
|
|
|
if not tr or (tr.__class__.__name__ != 'Transition'):
|
|
|
|
raise Exception('Transition "%s" not found.' % name)
|
|
|
|
return tr.trigger(name, o, wf, comment, doAction=doAction,
|
2014-10-28 11:48:54 -05:00
|
|
|
doHistory=doHistory, doSay=False,
|
2014-04-21 05:11:41 -05:00
|
|
|
noSecurity=noSecurity)
|
2009-07-10 08:01:50 -05:00
|
|
|
|
2011-02-12 10:09:11 -06:00
|
|
|
def log(self, message, type='info'): return self.o.log(message, type)
|
|
|
|
def say(self, message, type='info'): return self.o.say(message, type)
|
2009-12-17 14:14:52 -06:00
|
|
|
|
2010-02-12 03:59:42 -06:00
|
|
|
def normalize(self, s, usage='fileName'):
|
2009-11-06 04:33:56 -06:00
|
|
|
'''Returns a version of string p_s whose special chars have been
|
|
|
|
replaced with normal chars.'''
|
2010-03-25 10:34:37 -05:00
|
|
|
return normalizeString(s, usage)
|
2009-11-06 04:33:56 -06:00
|
|
|
|
2014-04-22 12:37:36 -05:00
|
|
|
def search(self, klass, sortBy='', sortOrder='asc', maxResults=None,
|
|
|
|
noSecurity=False, **fields):
|
2009-11-06 04:33:56 -06:00
|
|
|
'''Searches objects of p_klass. p_sortBy must be the name of an indexed
|
2014-04-22 12:37:36 -05:00
|
|
|
field (declared with indexed=True); p_sortOrder can be "asc"
|
|
|
|
(ascending, the defaut) or "desc" (descending); every param in
|
|
|
|
p_fields must take the name of an indexed field and take a possible
|
|
|
|
value of this field. You can optionally specify a maximum number of
|
|
|
|
results in p_maxResults. If p_noSecurity is specified, you get all
|
|
|
|
objects, even if the logged user does not have the permission to
|
|
|
|
view it.'''
|
2009-11-06 04:33:56 -06:00
|
|
|
# Find the content type corresponding to p_klass
|
2011-11-25 11:01:20 -06:00
|
|
|
tool = self.tool.o
|
|
|
|
contentType = tool.getPortalType(klass)
|
2009-11-06 04:33:56 -06:00
|
|
|
# Create the Search object
|
2014-04-22 12:37:36 -05:00
|
|
|
search = Search('customSearch', sortBy=sortBy, sortOrder=sortOrder,
|
|
|
|
**fields)
|
2009-12-21 13:45:29 -06:00
|
|
|
if not maxResults:
|
|
|
|
maxResults = 'NO_LIMIT'
|
|
|
|
# If I let maxResults=None, only a subset of the results will be
|
|
|
|
# returned by method executeResult.
|
2011-11-25 11:01:20 -06:00
|
|
|
res = tool.executeQuery(contentType, search=search,
|
|
|
|
maxResults=maxResults, noSecurity=noSecurity)
|
2013-08-21 15:25:27 -05:00
|
|
|
return [o.appy() for o in res.objects]
|
2009-11-06 04:33:56 -06:00
|
|
|
|
2012-02-09 09:36:50 -06:00
|
|
|
def search1(self, *args, **kwargs):
|
|
|
|
'''Identical to m_search above, but returns a single result (if any).'''
|
|
|
|
res = self.search(*args, **kwargs)
|
|
|
|
if res: return res[0]
|
|
|
|
|
2010-01-14 10:54:18 -06:00
|
|
|
def count(self, klass, noSecurity=False, **fields):
|
2009-11-24 15:41:42 -06:00
|
|
|
'''Identical to m_search above, but returns the number of objects that
|
|
|
|
match the search instead of returning the objects themselves. Use
|
|
|
|
this method instead of writing len(self.search(...)).'''
|
2011-11-25 11:01:20 -06:00
|
|
|
tool = self.tool.o
|
|
|
|
contentType = tool.getPortalType(klass)
|
2009-11-24 15:41:42 -06:00
|
|
|
search = Search('customSearch', **fields)
|
2011-11-25 11:01:20 -06:00
|
|
|
res = tool.executeQuery(contentType, search=search, brainsOnly=True,
|
2014-07-25 08:07:31 -05:00
|
|
|
noSecurity=noSecurity, maxResults='NO_LIMIT')
|
2009-11-24 15:41:42 -06:00
|
|
|
if res: return res._len # It is a LazyMap instance
|
|
|
|
else: return 0
|
|
|
|
|
2014-07-29 12:21:37 -05:00
|
|
|
def ids(self, fieldName):
|
|
|
|
'''Returns the identifiers of the objects linked to this one via field
|
|
|
|
name p_fieldName. WARNING: do not modify this list, it is the true
|
|
|
|
list that is stored in the database (excepted if empty). Modifying it
|
|
|
|
will probably corrupt the database.'''
|
|
|
|
return getattr(self.o.aq_base, fieldName, ())
|
|
|
|
|
2013-06-07 04:32:23 -05:00
|
|
|
def countRefs(self, fieldName):
|
|
|
|
'''Counts the number of objects linked to this one via Ref field
|
|
|
|
p_fieldName.'''
|
|
|
|
uids = getattr(self.o.aq_base, fieldName, None)
|
|
|
|
if not uids: return 0
|
|
|
|
return len(uids)
|
|
|
|
|
2010-02-22 08:28:20 -06:00
|
|
|
def compute(self, klass, sortBy='', maxResults=None, context=None,
|
|
|
|
expression=None, noSecurity=False, **fields):
|
2010-01-18 08:12:22 -06:00
|
|
|
'''This method, like m_search and m_count above, performs a query on
|
|
|
|
objects of p_klass. But in this case, instead of returning a list of
|
|
|
|
matching objects (like m_search) or counting elements (like p_count),
|
|
|
|
it evaluates, on every matching object, a Python p_expression (which
|
|
|
|
may be an expression or a statement), and returns, if needed, a
|
|
|
|
result. The result may be initialized through parameter p_context.
|
|
|
|
p_expression is evaluated with 2 variables in its context: "obj"
|
|
|
|
which is the currently walked object, instance of p_klass, and "ctx",
|
|
|
|
which is the context as initialized (or not) by p_context. p_context
|
|
|
|
may be used as
|
2010-02-22 08:28:20 -06:00
|
|
|
(1) a variable or instance that is updated on every call to
|
|
|
|
produce a result;
|
|
|
|
(2) an input variable or instance;
|
2010-01-18 08:12:22 -06:00
|
|
|
(3) both.
|
|
|
|
|
|
|
|
The method returns p_context, modified or not by evaluation of
|
|
|
|
p_expression on every matching object.
|
|
|
|
|
|
|
|
When you need to perform an action or computation on a lot of
|
|
|
|
objects, use this method instead of doing things like
|
|
|
|
|
|
|
|
"for obj in self.search(MyClass,...)"
|
|
|
|
'''
|
2011-11-25 11:01:20 -06:00
|
|
|
tool = self.tool.o
|
|
|
|
contentType = tool.getPortalType(klass)
|
2010-02-22 08:28:20 -06:00
|
|
|
search = Search('customSearch', sortBy=sortBy, **fields)
|
2010-01-18 08:12:22 -06:00
|
|
|
# Initialize the context variable "ctx"
|
|
|
|
ctx = context
|
2011-11-25 11:01:20 -06:00
|
|
|
for brain in tool.executeQuery(contentType, search=search, \
|
2010-10-14 07:43:56 -05:00
|
|
|
brainsOnly=True, maxResults=maxResults, noSecurity=noSecurity):
|
2010-01-18 08:12:22 -06:00
|
|
|
# Get the Appy object from the brain
|
2011-02-22 07:16:42 -06:00
|
|
|
if noSecurity: method = '_unrestrictedGetObject'
|
|
|
|
else: method = 'getObject'
|
|
|
|
exec 'obj = brain.%s().appy()' % method
|
2010-01-18 08:12:22 -06:00
|
|
|
exec expression
|
|
|
|
return ctx
|
|
|
|
|
2013-02-06 10:15:01 -06:00
|
|
|
def reindex(self, fields=None, unindex=False):
|
2009-11-06 04:33:56 -06:00
|
|
|
'''Asks a direct object reindexing. In most cases you don't have to
|
|
|
|
reindex objects "manually" with this method. When an object is
|
|
|
|
modified after some user action has been performed, Appy reindexes
|
|
|
|
this object automatically. But if your code modifies other objects,
|
|
|
|
Appy may not know that they must be reindexed, too. So use this
|
2013-02-06 10:15:01 -06:00
|
|
|
method in those cases.
|
|
|
|
'''
|
|
|
|
if fields:
|
2014-11-28 07:42:32 -06:00
|
|
|
# Get names of indexes from field names
|
|
|
|
indexes = []
|
|
|
|
for name in fields:
|
|
|
|
field = self.getField(name)
|
2014-12-15 03:30:24 -06:00
|
|
|
if not field:
|
|
|
|
# The index may be a standard Appy index that does not
|
|
|
|
# correspond to a field.
|
|
|
|
indexes.append(name)
|
|
|
|
continue
|
2014-11-28 07:42:32 -06:00
|
|
|
if not field.indexed: continue
|
|
|
|
# A field may have 2 different indexes
|
|
|
|
iName = field.getIndexName(usage='search')
|
|
|
|
indexes.append(iName)
|
|
|
|
sName = field.getIndexName(usage='sort')
|
|
|
|
if sName != iName: indexes.append(sName)
|
2013-02-06 10:15:01 -06:00
|
|
|
else:
|
|
|
|
indexes = None
|
|
|
|
self.o.reindex(indexes=indexes, unindex=unindex)
|
2009-11-06 04:33:56 -06:00
|
|
|
|
2011-02-12 10:09:11 -06:00
|
|
|
def export(self, at='string', format='xml', include=None, exclude=None):
|
2011-02-23 04:30:44 -06:00
|
|
|
'''Creates an "exportable" version of this object. p_format is "xml" by
|
2011-02-12 10:09:11 -06:00
|
|
|
default, but can also be "csv". If p_format is:
|
|
|
|
* "xml", if p_at is "string", this method returns the XML version,
|
|
|
|
without the XML prologue. Else, (a) if not p_at, the XML
|
|
|
|
will be exported on disk, in the OS temp folder, with an
|
|
|
|
ugly name; (b) else, it will be exported at path p_at.
|
|
|
|
* "csv", if p_at is "string", this method returns the CSV data as a
|
|
|
|
string. If p_at is an opened file handler, the CSV line will
|
|
|
|
be appended in it.
|
|
|
|
If p_include is given, only fields whose names are in it will be
|
|
|
|
included. p_exclude, if given, contains names of fields that will
|
|
|
|
not be included in the result.
|
|
|
|
'''
|
|
|
|
if format == 'xml':
|
|
|
|
# Todo: take p_include and p_exclude into account.
|
|
|
|
# Determine where to put the result
|
|
|
|
toDisk = (at != 'string')
|
|
|
|
if toDisk and not at:
|
2014-05-02 05:35:09 -05:00
|
|
|
at = getOsTempFolder() + '/' + self.o.id + '.xml'
|
2011-02-12 10:09:11 -06:00
|
|
|
# Create the XML version of the object
|
|
|
|
marshaller = XmlMarshaller(cdata=True, dumpUnicode=True,
|
|
|
|
dumpXmlPrologue=toDisk,
|
|
|
|
rootTag=self.klass.__name__)
|
|
|
|
xml = marshaller.marshall(self.o, objectType='appy')
|
|
|
|
# Produce the desired result
|
|
|
|
if toDisk:
|
|
|
|
f = file(at, 'w')
|
|
|
|
f.write(xml.encode('utf-8'))
|
|
|
|
f.close()
|
|
|
|
return at
|
|
|
|
else:
|
|
|
|
return xml
|
|
|
|
elif format == 'csv':
|
|
|
|
if isinstance(at, basestring):
|
|
|
|
marshaller = CsvMarshaller(include=include, exclude=exclude)
|
|
|
|
return marshaller.marshall(self)
|
|
|
|
else:
|
|
|
|
marshaller = CsvMarshaller(at, include=include, exclude=exclude)
|
|
|
|
marshaller.marshall(self)
|
2009-11-11 13:22:13 -06:00
|
|
|
|
2010-01-14 01:56:04 -06:00
|
|
|
def historize(self, data):
|
|
|
|
'''This method allows to add "manually" a "data-change" event into the
|
|
|
|
object's history. Indeed, data changes are "automatically" recorded
|
|
|
|
only when an object is edited through the edit form, not when a
|
|
|
|
setter is called from the code.
|
|
|
|
|
|
|
|
p_data must be a dictionary whose keys are field names (strings) and
|
|
|
|
whose values are the previous field values.'''
|
2010-10-14 07:43:56 -05:00
|
|
|
self.o.addDataChange(data)
|
2011-02-23 04:30:44 -06:00
|
|
|
|
2014-11-20 02:47:37 -06:00
|
|
|
def getLastEvent(self, transition, notBefore=None, history=None):
|
|
|
|
'''Gets, from the object history (or from p_history if not None), the
|
|
|
|
last occurrence of transition named p_transition. p_transition can be
|
|
|
|
a list of names: in this case, it returns the most recent occurrence
|
|
|
|
of those transitions. If p_notBefore is given, it corresponds to a
|
|
|
|
kind of start transition for the search: we will not search in the
|
2014-11-25 05:50:59 -06:00
|
|
|
history preceding the last occurrence of this transition. Note that
|
|
|
|
p_notBefore can hold a list of transitions.'''
|
2014-11-20 02:47:37 -06:00
|
|
|
history = history or self.history
|
|
|
|
i = len(history) - 1
|
2013-09-20 16:15:54 -05:00
|
|
|
while i >= 0:
|
|
|
|
event = history[i]
|
2014-11-25 05:50:59 -06:00
|
|
|
if notBefore:
|
|
|
|
if isinstance(notBefore, str):
|
|
|
|
condition = event['action'] == notBefore
|
|
|
|
else:
|
|
|
|
condition = event['action'] in notBefore
|
|
|
|
if condition: return
|
|
|
|
if isinstance(transition, str):
|
2013-09-20 16:15:54 -05:00
|
|
|
condition = event['action'] == transition
|
|
|
|
else:
|
|
|
|
condition = event['action'] in transition
|
|
|
|
if condition: return event
|
|
|
|
i -= 1
|
|
|
|
|
2014-10-21 08:39:29 -05:00
|
|
|
def removeEvent(self, event):
|
|
|
|
'''Removes p_event from this object's history.'''
|
|
|
|
res = []
|
|
|
|
# Because data change events carry the workflow state, we must ensure
|
|
|
|
# that, after having removed p_event, this workflow state is still
|
|
|
|
# correct.
|
|
|
|
lastState = None
|
|
|
|
for e in self.history:
|
|
|
|
# Ignore this event if it is p_event
|
|
|
|
if (e['action'] == event['action']) and \
|
|
|
|
(e['time'] == event['time']): continue
|
|
|
|
if e['action'] == '_datachange_':
|
|
|
|
e['review_state'] = lastState
|
|
|
|
res.append(e)
|
|
|
|
lastState = e['review_state']
|
|
|
|
self.o.workflow_history['appy'] = tuple(res)
|
|
|
|
|
2011-02-23 04:30:44 -06:00
|
|
|
def formatText(self, text, format='html'):
|
|
|
|
'''Produces a representation of p_text into the desired p_format, which
|
|
|
|
is 'html' by default.'''
|
|
|
|
return self.o.formatText(text, format)
|
2013-09-24 05:26:31 -05:00
|
|
|
|
|
|
|
def listStates(self):
|
|
|
|
'''Lists the possible states for this object.'''
|
|
|
|
res = []
|
|
|
|
o = self.o
|
|
|
|
workflow = o.getWorkflow()
|
|
|
|
for name in dir(workflow):
|
2015-01-21 07:30:42 -06:00
|
|
|
state = getattr(workflow, name)
|
|
|
|
if state.__class__.__name__ != 'State': continue
|
|
|
|
if state.isIsolated(workflow) : continue
|
2013-09-24 05:26:31 -05:00
|
|
|
res.append((name, o.translate(o.getWorkflowLabel(name))))
|
|
|
|
return res
|
2014-05-02 05:35:09 -05:00
|
|
|
|
|
|
|
def path(self, name):
|
|
|
|
'''Returns the absolute file name of file stored in File field p_nnamed
|
|
|
|
p_name.'''
|
|
|
|
v = getattr(self, name)
|
|
|
|
if v: return v.getFilePath(self)
|
2014-05-02 07:34:10 -05:00
|
|
|
|
|
|
|
def getIndexOf(self, name, obj):
|
|
|
|
'''Returns, as an integer starting at 0, the position of p_obj within
|
|
|
|
objects linked to p_self via field p_name.'''
|
|
|
|
o = self.o
|
|
|
|
return o.getAppyType(name).getIndexOf(o, obj.uid)
|
|
|
|
|
|
|
|
def allows(self, permission, raiseError=False):
|
|
|
|
'''Check doc @Mixin.allows.'''
|
|
|
|
return self.o.allows(permission, raiseError=raiseError)
|
2014-06-01 04:44:07 -05:00
|
|
|
|
|
|
|
def resetLocalRoles(self):
|
|
|
|
'''Removes all local roles defined on this object, excepted local role
|
|
|
|
Owner, granted to the item creator.'''
|
|
|
|
from persistent.mapping import PersistentMapping
|
|
|
|
localRoles = PersistentMapping({ self.o.creator: ['Owner'] })
|
|
|
|
self.o.__ac_local_roles__ = localRoles
|
|
|
|
return localRoles
|
2014-08-05 07:53:08 -05:00
|
|
|
|
|
|
|
def raiseUnauthorized(self, msg=None): return self.o.raiseUnauthorized(msg)
|
2014-10-22 15:17:26 -05:00
|
|
|
|
|
|
|
def sendMailIf(self, privilege, subject, body, attachments=None,
|
2014-11-04 05:50:36 -06:00
|
|
|
privilegeType='permission'):
|
2014-10-22 15:17:26 -05:00
|
|
|
'''Sends a mail related to this object to any active user having
|
2014-11-04 05:50:36 -06:00
|
|
|
p_privilege on it. If p_privilegeType is:
|
|
|
|
- "permission", p_privilege is a permission;
|
|
|
|
- "role", p_privilege is a role;
|
2014-11-10 03:01:20 -06:00
|
|
|
- "group", p_privilege is a group login;
|
|
|
|
- "user", p_privilege is a user login.'''
|
2014-11-04 05:50:36 -06:00
|
|
|
# Determine the set of users to work with
|
2014-11-10 03:01:20 -06:00
|
|
|
checkPermissionOrRole = False
|
|
|
|
if privilegeType == 'user':
|
|
|
|
user = self.search1('User', noSecurity=True, login=privilege)
|
|
|
|
if not user:
|
|
|
|
raise Exception('user "%s" does not exist.' % privilege)
|
|
|
|
users = [user]
|
|
|
|
elif privilegeType == 'group':
|
2014-11-04 05:50:36 -06:00
|
|
|
# Get the users belonging to this group
|
|
|
|
group = self.search1('Group', noSecurity=True, login=privilege)
|
|
|
|
if not group:
|
|
|
|
raise Exception('group "%s" does not exist.' % privilege)
|
|
|
|
users = group.users
|
|
|
|
else:
|
|
|
|
# Get all users
|
|
|
|
users = self.tool.users
|
2014-11-10 03:01:20 -06:00
|
|
|
checkPermissionOrRole = True
|
2014-10-22 15:17:26 -05:00
|
|
|
# Determine the list of recipients based on active users having
|
|
|
|
# p_privilege on p_self.
|
|
|
|
recipients = []
|
2014-11-04 05:50:36 -06:00
|
|
|
for user in users:
|
2014-10-22 15:17:26 -05:00
|
|
|
if (user.state == 'inactive'): continue
|
2014-11-04 05:50:36 -06:00
|
|
|
# Check if the user has p_privilege on this object (only applicable
|
|
|
|
# if the privilege does not represent a group).
|
2014-11-10 03:01:20 -06:00
|
|
|
if checkPermissionOrRole:
|
2014-11-04 05:50:36 -06:00
|
|
|
hasPrivilege = (privilegeType == 'permission') and \
|
|
|
|
user.has_permission or user.has_role
|
|
|
|
if not hasPrivilege(privilege, self): continue
|
2014-10-22 15:17:26 -05:00
|
|
|
# Get the mail recipient for this user
|
|
|
|
recipient = user.getMailRecipient()
|
|
|
|
if not recipient: continue
|
|
|
|
recipients.append(recipient)
|
|
|
|
if recipients:
|
|
|
|
self.tool.sendMail(recipients, subject, body, attachments)
|
|
|
|
else:
|
|
|
|
self.log('no recipient for sending mail about %s with %s %s.' % \
|
2014-11-04 05:50:36 -06:00
|
|
|
(self.id, privilegeType, privilege))
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|