2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
2012-07-18 14:58:11 -05:00
|
|
|
import os.path, time
|
2011-01-18 08:48:55 -06:00
|
|
|
import appy
|
2014-02-26 16:40:27 -06:00
|
|
|
from appy.px import Px
|
2013-02-28 16:00:06 -06:00
|
|
|
from appy.gen.mail import sendMail
|
2011-12-05 08:11:29 -06:00
|
|
|
from appy.gen.wrappers import AbstractWrapper
|
2014-02-26 16:40:27 -06:00
|
|
|
from appy.shared.utils import executeCommand
|
2014-12-17 09:19:45 -06:00
|
|
|
from appy.shared.ldap_connector import LdapConnector
|
2010-08-05 11:23:17 -05:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
class ToolWrapper(AbstractWrapper):
|
2013-06-25 05:04:23 -05:00
|
|
|
|
2013-08-21 05:35:30 -05:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Navigation-related PXs
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Icon for hiding/showing details below the title of an object shown in a
|
|
|
|
# list of objects.
|
|
|
|
pxShowDetails = Px('''
|
2014-03-11 10:22:28 -05:00
|
|
|
<img if="(field.name == 'title') and ztool.subTitleIsUsed(className)"
|
2013-08-21 05:35:30 -05:00
|
|
|
class="clickable" src=":url('toggleDetails')"
|
|
|
|
onclick="toggleSubTitles()"/>''')
|
|
|
|
|
|
|
|
# Displays up/down arrows in a table header column for sorting a given
|
|
|
|
# column. Requires variables "sortable", 'filterable' and 'field'.
|
2014-03-11 10:22:28 -05:00
|
|
|
pxSortAndFilter = Px('''
|
2013-08-21 05:35:30 -05:00
|
|
|
<x if="sortable">
|
|
|
|
<img if="(sortKey != field.name) or (sortOrder == 'desc')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunchSorted(%s, %s, %s)' % \
|
|
|
|
(q(ajaxHookId), q(field.name), q('asc'))"
|
2013-08-21 05:35:30 -05:00
|
|
|
src=":url('sortDown.gif')" class="clickable"/>
|
|
|
|
<img if="(sortKey != field.name) or (sortOrder == 'asc')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunchSorted(%s, %s, %s)' % \
|
|
|
|
(q(ajaxHookId), q(field.name), q('desc'))"
|
2013-08-21 05:35:30 -05:00
|
|
|
src=":url('sortUp.gif')" class="clickable"/>
|
|
|
|
</x>
|
2014-07-23 15:29:47 -05:00
|
|
|
<x if="filterable"
|
|
|
|
var2="filterId='%s_%s' % (ajaxHookId, field.name);
|
|
|
|
filterIdIcon='%s_icon' % filterId">
|
2015-02-13 10:29:51 -06:00
|
|
|
<!-- Pressing the "enter" key in the field clicks the icon (onkeydown)-->
|
2014-07-23 15:29:47 -05:00
|
|
|
<input type="text" size="7" id=":filterId"
|
|
|
|
value=":filterKey == field.name and filterValue or ''"
|
|
|
|
onkeydown=":'if (event.keyCode==13) document.getElementById ' \
|
|
|
|
'(%s).click()' % q(filterIdIcon)"/>
|
|
|
|
<img id=":filterIdIcon" class="clickable" src=":url('funnel')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunchFiltered(%s, %s)' % \
|
|
|
|
(q(ajaxHookId), q(field.name))"/>
|
2014-03-11 10:22:28 -05:00
|
|
|
</x>''')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
# Buttons for navigating among a list of objects (from a Ref field or a
|
|
|
|
# query): next,back,first,last...
|
|
|
|
pxNavigate = Px('''
|
2015-02-13 10:29:51 -06:00
|
|
|
<div if="totalNumber > batchSize" align=":dright">
|
2014-10-21 02:25:37 -05:00
|
|
|
<!-- Go to the first page -->
|
|
|
|
<img if="(startNumber != 0) and (startNumber != batchSize)"
|
|
|
|
class="clickable" src=":url('arrowsLeft')" title=":_('goto_first')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q('0'))"/>
|
2014-10-21 02:25:37 -05:00
|
|
|
|
|
|
|
<!-- Go to the previous page -->
|
|
|
|
<img var="sNumber=startNumber - batchSize" if="startNumber != 0"
|
|
|
|
class="clickable" src=":url('arrowLeft')" title=":_('goto_previous')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
|
2014-10-21 02:25:37 -05:00
|
|
|
|
|
|
|
<!-- Explain which elements are currently shown -->
|
|
|
|
<span class="discreet">
|
|
|
|
<x>:startNumber + 1</x> <img src=":url('to')"/>
|
|
|
|
<x>:startNumber + batchNumber</x> <b>//</b>
|
|
|
|
<x>:totalNumber</x>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<!-- Go to the next page -->
|
|
|
|
<img var="sNumber=startNumber + batchSize" if="sNumber < totalNumber"
|
|
|
|
class="clickable" src=":url('arrowRight')" title=":_('goto_next')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
|
2014-10-21 02:25:37 -05:00
|
|
|
|
|
|
|
<!-- Go to the last page -->
|
|
|
|
<img var="lastPageIsIncomplete=totalNumber % batchSize;
|
|
|
|
nbOfCompletePages=totalNumber/batchSize;
|
|
|
|
nbOfCountedPages=lastPageIsIncomplete and \
|
|
|
|
nbOfCompletePages or nbOfCompletePages-1;
|
|
|
|
sNumber= nbOfCountedPages * batchSize"
|
|
|
|
if="(startNumber != sNumber) and \
|
|
|
|
(startNumber != sNumber-batchSize)" class="clickable"
|
|
|
|
src=":url('arrowsRight')" title=":_('goto_last')"
|
2015-02-13 10:29:51 -06:00
|
|
|
onclick=":'askBunch(%s, %s)' % (q(ajaxHookId), q(sNumber))"/>
|
2014-10-21 02:25:37 -05:00
|
|
|
|
|
|
|
<!-- Go to the element number... -->
|
|
|
|
<x var="gotoNumber=gotoNumber|False" if="gotoNumber"
|
|
|
|
var2="sourceUrl=obj.url">:obj.pxGotoNumber</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
</div>''')
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# PXs for graphical elements shown on every page
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Global elements included in every page.
|
2014-03-19 17:13:31 -05:00
|
|
|
pxPagePrologue = Px('''
|
2014-12-29 08:55:17 -06:00
|
|
|
<!-- Include type-specific CSS and JS -->
|
2013-08-21 05:35:30 -05:00
|
|
|
<x if="cssJs">
|
|
|
|
<link for="cssFile in cssJs['css']" rel="stylesheet" type="text/css"
|
|
|
|
href=":url(cssFile)"/>
|
2015-02-03 03:56:15 -06:00
|
|
|
<script for="jsFile in cssJs['js']" src=":url(jsFile)"></script></x>
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- Javascript messages -->
|
2015-02-03 03:56:15 -06:00
|
|
|
<script>::ztool.getJavascriptMessages()</script>
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- Global form for deleting an object -->
|
2015-02-04 11:33:27 -06:00
|
|
|
<form id="deleteForm" method="post" action=":'%s/onDelete' % tool.url">
|
|
|
|
<input type="hidden" name="uid"/>
|
2013-08-21 05:35:30 -05:00
|
|
|
</form>
|
|
|
|
<!-- Global form for deleting an event from an object's history -->
|
|
|
|
<form id="deleteEventForm" method="post" action="do">
|
|
|
|
<input type="hidden" name="action" value="DeleteEvent"/>
|
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
<input type="hidden" name="eventTime"/>
|
|
|
|
</form>
|
2014-04-03 10:32:57 -05:00
|
|
|
<!-- Global form for (un)linking (an) object(s) -->
|
2014-04-01 11:34:12 -05:00
|
|
|
<form id="linkForm" method="post" action="do">
|
|
|
|
<input type="hidden" name="action" value="Link"/>
|
2014-04-03 10:32:57 -05:00
|
|
|
<input type="hidden" name="linkAction"/>
|
2014-04-01 11:34:12 -05:00
|
|
|
<input type="hidden" name="sourceUid"/>
|
|
|
|
<input type="hidden" name="fieldName"/>
|
|
|
|
<input type="hidden" name="targetUid"/>
|
2014-04-03 10:32:57 -05:00
|
|
|
<input type="hidden" name="semantics"/>
|
2014-04-01 11:34:12 -05:00
|
|
|
</form>
|
2013-08-21 05:35:30 -05:00
|
|
|
<!-- Global form for unlocking a page -->
|
|
|
|
<form id="unlockForm" method="post" action="do">
|
|
|
|
<input type="hidden" name="action" value="Unlock"/>
|
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
<input type="hidden" name="pageName"/>
|
|
|
|
</form>
|
2014-03-24 16:55:00 -05:00
|
|
|
<!-- Global form for generating/freezing a document from a pod template -->
|
|
|
|
<form id="podForm" name="podForm" method="post"
|
2015-02-04 11:33:27 -06:00
|
|
|
action=":'%s/doPod' % tool.url">
|
2013-08-21 05:35:30 -05:00
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
<input type="hidden" name="fieldName"/>
|
2014-03-19 17:13:31 -05:00
|
|
|
<input type="hidden" name="template"/>
|
2013-08-21 05:35:30 -05:00
|
|
|
<input type="hidden" name="podFormat"/>
|
|
|
|
<input type="hidden" name="queryData"/>
|
|
|
|
<input type="hidden" name="customParams"/>
|
2014-10-16 10:35:35 -05:00
|
|
|
<input type="hidden" name="showSubTitles" value="true"/>
|
2014-07-10 14:22:52 -05:00
|
|
|
<input type="hidden" name="checkedUids"/>
|
|
|
|
<input type="hidden" name="checkedSem"/>
|
2014-09-17 11:09:30 -05:00
|
|
|
<input type="hidden" name="mailing"/>
|
2014-03-24 16:55:00 -05:00
|
|
|
<input type="hidden" name="action" value="generate"/>
|
2014-03-19 17:13:31 -05:00
|
|
|
</form>''')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
pxPageBottom = Px('''
|
2014-03-04 08:03:37 -06:00
|
|
|
<script var="info=zobj.getSlavesRequestInfo(page)"
|
|
|
|
type="text/javascript">:'initSlaves(%s,%s,%s,%s)' % \
|
|
|
|
(q(zobj.absolute_url()), q(layoutType), info[0], info[1])
|
|
|
|
</script>''')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
2014-12-29 08:55:17 -06:00
|
|
|
pxLiveSearchResults = Px('''
|
|
|
|
<x var="className=req['className'];
|
|
|
|
klass=ztool.getAppyClass(className);
|
|
|
|
search=ztool.getLiveSearch(klass, req['w_SearchableText']);
|
|
|
|
zobjects=ztool.executeQuery(className, search=search, \
|
|
|
|
maxResults=10).objects">
|
|
|
|
<p if="not zobjects" class="lsNoResult">:_('query_no_result')</p>
|
2014-12-30 04:23:03 -06:00
|
|
|
<div for="zobj in zobjects" style="padding: 3px 5px">
|
|
|
|
<a href=":zobj.absolute_url()"
|
|
|
|
var="content=ztool.truncateValue(zobj.Title(), width=80)"
|
|
|
|
title=":zobj.Title()">:content</a>
|
2014-12-29 08:55:17 -06:00
|
|
|
</div>
|
|
|
|
<!-- Go to the page showing all results -->
|
|
|
|
<div if="zobjects" align=":dright" style="padding: 3px">
|
|
|
|
<a class="clickable" style="font-size: 95%; font-style: italic"
|
|
|
|
onclick=":'document.forms[%s].submit()' % \
|
|
|
|
q('%s_LSForm' % className)">:_('search_results_all') + '...'</a>
|
|
|
|
</div>
|
|
|
|
</x>''')
|
|
|
|
|
|
|
|
pxLiveSearch = Px('''
|
|
|
|
<form var="formId='%s_LSForm' % className"
|
|
|
|
id=":formId" name=":formId" action=":'%s/do' % toolUrl">
|
|
|
|
<input type="hidden" name="action" value="SearchObjects"/>
|
|
|
|
<input type="hidden" name="className" value=":className"/>
|
|
|
|
<table cellpadding="0" cellspacing="0"
|
|
|
|
var="searchLabel=_('search_button')">
|
|
|
|
<tr valign="bottom">
|
|
|
|
<td style="position: relative">
|
|
|
|
<input type="text" size="14" name="w_SearchableText" autocomplete="off"
|
|
|
|
id=":'%s_LSinput' % className" class="inputSearch"
|
|
|
|
title=":searchLabel"
|
|
|
|
var="jsCall='onLiveSearchEvent(event, %s, %s, %s)' % \
|
|
|
|
(q(className), q('auto'), q(toolUrl))"
|
|
|
|
onkeyup=":jsCall" onfocus=":jsCall"
|
|
|
|
onblur=":'onLiveSearchEvent(event, %s, %s)' % \
|
|
|
|
(q(className), q('hide'))"/>
|
|
|
|
<!-- Dropdown containing live search results -->
|
|
|
|
<div id=":'%s_LSDropdown' % className" class="dropdown liveSearch">
|
|
|
|
<div id=":'%s_LSResults' % className"></div>
|
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
<td><input type="image" class="clickable" src=":url('search')"
|
|
|
|
title=":searchLabel"/></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>''')
|
|
|
|
|
2013-08-21 05:35:30 -05:00
|
|
|
pxPortlet = Px('''
|
|
|
|
<x var="toolUrl=tool.url;
|
|
|
|
queryUrl='%s/query' % toolUrl;
|
|
|
|
currentSearch=req.get('search', None);
|
|
|
|
currentClass=req.get('className', None);
|
|
|
|
currentPage=req['PATH_INFO'].rsplit('/',1)[-1];
|
2014-04-29 12:02:06 -05:00
|
|
|
rootClasses=ztool.getRootClasses()">
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- One section for every searchable root class -->
|
2013-08-23 11:57:27 -05:00
|
|
|
<x for="rootClass in rootClasses" if="ztool.userMaySearch(rootClass)"
|
|
|
|
var2="className=ztool.getPortalType(rootClass)">
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- A separator if required -->
|
2014-04-29 12:02:06 -05:00
|
|
|
<div class="portletSep" if="loop.rootClass.nb != 0"></div>
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- Section title (link triggers the default search) -->
|
|
|
|
<div class="portletContent"
|
|
|
|
var="searchInfo=ztool.getGroupedSearches(rootClass)">
|
|
|
|
<div class="portletTitle">
|
2013-08-21 15:25:27 -05:00
|
|
|
<a var="queryParam=searchInfo.default and \
|
|
|
|
searchInfo.default.name or ''"
|
2013-08-21 05:35:30 -05:00
|
|
|
href=":'%s?className=%s&search=%s' % \
|
2013-08-23 11:57:27 -05:00
|
|
|
(queryUrl, className, queryParam)"
|
2015-02-10 10:20:50 -06:00
|
|
|
onclick="clickOn(this)"
|
2013-08-23 11:57:27 -05:00
|
|
|
class=":(not currentSearch and (currentClass==className) and \
|
2013-08-21 05:35:30 -05:00
|
|
|
(currentPage=='query')) and \
|
2014-04-29 12:02:06 -05:00
|
|
|
'current' or ''">::_(className + '_plural')</a>
|
2014-06-15 17:58:45 -05:00
|
|
|
<!-- Create instances of this class -->
|
2015-01-19 08:44:09 -06:00
|
|
|
<form if="ztool.userMayCreate(rootClass) and \
|
|
|
|
('form' in ztool.getCreateMeans(rootClass))" class="addForm"
|
|
|
|
var2="target=ztool.getLinksTargetInfo(rootClass)"
|
|
|
|
action=":'%s/do' % toolUrl" target=":target.target">
|
|
|
|
<input type="hidden" name="action" value="Create"/>
|
|
|
|
<input type="hidden" name="className" value=":className"/>
|
|
|
|
<input type="hidden" name="popup"
|
|
|
|
value=":(inPopup or (target.target != '_self')) and '1' or '0'"/>
|
|
|
|
<input var="label=_('query_create');
|
|
|
|
css=ztool.getButtonCss(label)" type="submit" class=":css"
|
|
|
|
value=":label" onclick=":target.openPopup"
|
|
|
|
style=":url('add', bg=True)"/>
|
|
|
|
</form>
|
|
|
|
</div>
|
2013-08-21 05:35:30 -05:00
|
|
|
<!-- Searches -->
|
|
|
|
<x if="ztool.advancedSearchEnabledFor(rootClass)">
|
|
|
|
<!-- Live search -->
|
2014-12-29 08:55:17 -06:00
|
|
|
<x>:tool.pxLiveSearch</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- Advanced search -->
|
2013-08-23 11:57:27 -05:00
|
|
|
<div var="highlighted=(currentClass == className) and \
|
2013-08-21 05:35:30 -05:00
|
|
|
(currentPage == 'search')"
|
2014-04-29 12:02:06 -05:00
|
|
|
class=":highlighted and 'portletSearch current' or \
|
2013-08-21 05:35:30 -05:00
|
|
|
'portletSearch'"
|
2014-05-02 13:22:33 -05:00
|
|
|
align=":dright" style="margin-bottom: 4px">
|
2013-08-21 05:35:30 -05:00
|
|
|
<a var="text=_('search_title')" style="font-size: 88%"
|
2013-08-23 11:57:27 -05:00
|
|
|
href=":'%s/search?className=%s' % (toolUrl, className)"
|
2013-08-21 05:35:30 -05:00
|
|
|
title=":text"><x>:text</x>...</a>
|
|
|
|
</div>
|
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- Predefined searches -->
|
2014-02-26 16:40:27 -06:00
|
|
|
<x for="search in searchInfo.searches" var2="field=search">
|
2013-08-21 15:25:27 -05:00
|
|
|
<x if="search.type == 'group'">:search.px</x>
|
|
|
|
<x if="search.type != 'group'">:search.pxView</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
</x>
|
2014-04-29 12:02:06 -05:00
|
|
|
<!-- Portlet bottom, potentially customized by the app -->
|
|
|
|
<x>::ztool.portletBottom(rootClass)</x>
|
2013-08-21 05:35:30 -05:00
|
|
|
</div>
|
|
|
|
</x>
|
|
|
|
</x>''')
|
|
|
|
|
2015-02-03 03:56:15 -06:00
|
|
|
# The message that is shown when a user triggers an action
|
2013-08-21 05:35:30 -05:00
|
|
|
pxMessage = Px('''
|
2014-11-10 06:34:52 -06:00
|
|
|
<div class=":inPopup and 'messagePopup message' or 'message'"
|
|
|
|
style="display:none" id="appyMessage">
|
2013-08-21 05:35:30 -05:00
|
|
|
<!-- The icon for closing the message -->
|
|
|
|
<img src=":url('close')" align=":dright" class="clickable"
|
|
|
|
onclick="this.parentNode.style.display='none'"/>
|
|
|
|
<!-- The message content -->
|
2014-11-10 06:34:52 -06:00
|
|
|
<div id="appyMessageContent"></div>
|
|
|
|
</div>
|
2015-02-05 07:05:29 -06:00
|
|
|
<script var="messages=ztool.consumeMessages()"
|
2014-11-10 06:34:52 -06:00
|
|
|
if="messages">::'showAppyMessage(%s)' % q(messages)</script>''')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
2015-02-03 03:56:15 -06:00
|
|
|
# The page footer
|
2013-08-21 05:35:30 -05:00
|
|
|
pxFooter = Px('''
|
|
|
|
<table cellpadding="0" cellspacing="0" width="100%" class="footer">
|
|
|
|
<tr>
|
|
|
|
<td align=":dright">Made with
|
|
|
|
<a href="http://appyframework.org" target="_blank">Appy</a></td></tr>
|
|
|
|
</table>''')
|
|
|
|
|
|
|
|
# Hook for defining a PX that proposes additional links, after the links
|
|
|
|
# corresponding to top-level pages.
|
2014-03-03 11:54:21 -06:00
|
|
|
pxLinks = Px('')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
# Hook for defining a PX that proposes additional icons after standard
|
|
|
|
# icons in the user strip.
|
2014-03-03 11:54:21 -06:00
|
|
|
pxIcons = Px('')
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
# Displays the content of a layouted object (a page or a field). If the
|
|
|
|
# layouted object is a page, the "layout target" (where to look for PXs)
|
|
|
|
# will be the object whose page is shown; if the layouted object is a field,
|
|
|
|
# the layout target will be this field.
|
|
|
|
pxLayoutedObject = Px('''
|
2013-08-21 15:25:27 -05:00
|
|
|
<table var="layoutCss=layout.css_class;
|
2013-08-21 05:35:30 -05:00
|
|
|
isCell=layoutType == 'cell'"
|
2013-08-21 15:25:27 -05:00
|
|
|
cellpadding=":layout.cellpadding"
|
|
|
|
cellspacing=":layout.cellspacing"
|
|
|
|
width=":not isCell and layout.width or ''"
|
2013-08-21 05:35:30 -05:00
|
|
|
align=":not isCell and \
|
2013-08-21 15:25:27 -05:00
|
|
|
ztool.flipLanguageDirection(layout.align, dir) or ''"
|
2013-08-21 05:35:30 -05:00
|
|
|
class=":tagCss and ('%s %s' % (tagCss, layoutCss)).strip() or \
|
|
|
|
layoutCss"
|
2013-08-21 15:25:27 -05:00
|
|
|
style=":layout.style" id=":tagId" name=":tagName">
|
2013-08-21 05:35:30 -05:00
|
|
|
|
|
|
|
<!-- The table header row -->
|
2013-08-21 15:25:27 -05:00
|
|
|
<tr if="layout.headerRow" valign=":layout.headerRow.valign">
|
|
|
|
<th for="cell in layout.headerRow.cells" width=":cell.width"
|
|
|
|
align=":ztool.flipLanguageDirection(cell.align, dir)">
|
2013-08-21 05:35:30 -05:00
|
|
|
</th>
|
|
|
|
</tr>
|
|
|
|
<!-- The table content -->
|
2013-08-21 15:25:27 -05:00
|
|
|
<tr for="row in layout.rows" valign=":row.valign">
|
|
|
|
<td for="cell in row.cells" colspan=":cell.colspan"
|
|
|
|
align=":ztool.flipLanguageDirection(cell.align, dir)"
|
2013-08-21 05:35:30 -05:00
|
|
|
class=":not loop.cell.last and 'cellGap' or ''">
|
2013-08-21 15:25:27 -05:00
|
|
|
<x for="pxName in cell.content">
|
2013-08-21 05:35:30 -05:00
|
|
|
<x var="px=(pxName == '?') and 'px%s' % layoutType.capitalize() \
|
|
|
|
or pxName">:getattr(layoutTarget, px)</x>
|
|
|
|
<img if="not loop.pxName.last" src=":url('space.gif')"/>
|
|
|
|
</x>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>''')
|
|
|
|
|
2013-06-25 16:22:33 -05:00
|
|
|
pxHome = Px('''
|
2014-01-20 09:30:14 -06:00
|
|
|
<table>
|
2013-06-25 16:22:33 -05:00
|
|
|
<tr valign="middle">
|
2013-06-26 06:44:31 -05:00
|
|
|
<td align="center">::_('front_page_text')</td>
|
2013-06-25 16:22:33 -05:00
|
|
|
</tr>
|
2013-06-27 04:57:39 -05:00
|
|
|
</table>''', template=AbstractWrapper.pxTemplate, hook='content')
|
|
|
|
|
|
|
|
pxQuery = Px('''
|
2014-07-19 06:42:39 -05:00
|
|
|
<div var="className=req['className'];
|
|
|
|
searchName=req.get('search', '');
|
|
|
|
uiSearch=ztool.getSearch(className, searchName, ui=True);
|
2014-07-28 05:29:16 -05:00
|
|
|
rootHookId=uiSearch.getRootHookId();
|
2014-07-19 06:42:39 -05:00
|
|
|
cssJs=None"
|
|
|
|
id=":rootHookId">
|
2015-02-03 03:56:15 -06:00
|
|
|
<script>:uiSearch.getCbJsInit(rootHookId)</script>
|
|
|
|
<x>:tool.pxPagePrologue</x><x>:uiSearch.pxResult</x>
|
2014-07-19 06:42:39 -05:00
|
|
|
</div>''', template=AbstractWrapper.pxTemplate, hook='content')
|
2013-06-25 05:04:23 -05:00
|
|
|
|
2013-06-28 08:00:02 -05:00
|
|
|
pxSearch = Px('''
|
|
|
|
<x var="className=req['className'];
|
|
|
|
refInfo=req.get('ref', None);
|
|
|
|
searchInfo=ztool.getSearchInfo(className, refInfo);
|
|
|
|
cssJs={};
|
2014-03-05 06:25:36 -06:00
|
|
|
layoutType='search';
|
2013-08-21 05:35:30 -05:00
|
|
|
x=ztool.getCssJs(searchInfo.fields, 'edit', cssJs)">
|
2013-06-28 08:00:02 -05:00
|
|
|
|
2014-12-15 03:30:24 -06:00
|
|
|
<!-- Include type-specific CSS and JS -->
|
2013-06-28 08:00:02 -05:00
|
|
|
<link for="cssFile in cssJs['css']" rel="stylesheet" type="text/css"
|
2013-07-20 12:56:17 -05:00
|
|
|
href=":url(cssFile)"/>
|
2015-02-03 03:56:15 -06:00
|
|
|
<script for="jsFile in cssJs['js']" src=":url(jsFile)"></script>
|
2013-06-28 08:00:02 -05:00
|
|
|
|
|
|
|
<!-- Search title -->
|
|
|
|
<h1><x>:_('%s_plural'%className)</x> –
|
|
|
|
<x>:_('search_title')</x></h1>
|
|
|
|
<!-- Form for searching objects of request/className. -->
|
|
|
|
<form name="search" action=":ztool.absolute_url()+'/do'" method="post">
|
|
|
|
<input type="hidden" name="action" value="SearchObjects"/>
|
|
|
|
<input type="hidden" name="className" value=":className"/>
|
|
|
|
<input if="refInfo" type="hidden" name="ref" value=":refInfo"/>
|
|
|
|
|
2015-01-21 07:30:42 -06:00
|
|
|
<table class="searchFields">
|
2013-06-28 08:00:02 -05:00
|
|
|
<tr for="searchRow in ztool.getGroupedSearchFields(searchInfo)"
|
|
|
|
valign="top">
|
2014-03-05 06:25:36 -06:00
|
|
|
<td for="field in searchRow" class="search"
|
2013-07-15 04:23:29 -05:00
|
|
|
var2="scolspan=field and field.scolspan or 1"
|
|
|
|
colspan=":scolspan"
|
2013-08-21 05:35:30 -05:00
|
|
|
width=":'%d%%' % ((100/searchInfo.nbOfColumns)*scolspan)">
|
2014-03-05 06:25:36 -06:00
|
|
|
<x if="field">:field.pxRender</x>
|
2013-07-15 04:23:29 -05:00
|
|
|
<br class="discreet"/>
|
|
|
|
</td>
|
2013-06-28 08:00:02 -05:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
|
|
|
|
<!-- Submit button -->
|
2015-01-21 07:30:42 -06:00
|
|
|
<input var="label=_('search_button');
|
|
|
|
css=ztool.getButtonCss(label, small=False)" type="submit"
|
|
|
|
class=":css" value=":label" style=":url('search', bg=True)"/>
|
2013-06-28 08:00:02 -05:00
|
|
|
</form>
|
2013-07-15 04:23:29 -05:00
|
|
|
</x>''', template=AbstractWrapper.pxTemplate, hook='content')
|
2013-06-28 08:00:02 -05:00
|
|
|
|
2014-06-15 17:58:45 -05:00
|
|
|
pxBack = Px('''
|
|
|
|
<html>
|
2015-02-03 03:56:15 -06:00
|
|
|
<head><script src=":ztool.getIncludeUrl('appy.js')"></script></head>
|
|
|
|
<body><script>backFromPopup()</script></body>
|
2014-06-15 17:58:45 -05:00
|
|
|
</html>''')
|
|
|
|
|
2012-05-05 10:04:19 -05:00
|
|
|
def isManager(self):
|
2012-11-26 06:58:27 -06:00
|
|
|
'''Some pages on the tool can only be accessed by managers.'''
|
2012-05-05 10:04:19 -05:00
|
|
|
if self.user.has_role('Manager'): return 'view'
|
|
|
|
|
2012-05-08 07:49:45 -05:00
|
|
|
def isManagerEdit(self):
|
2012-11-26 06:58:27 -06:00
|
|
|
'''Some pages on the tool can only be accessed by managers, also in
|
|
|
|
edit mode.'''
|
2012-05-08 07:49:45 -05:00
|
|
|
if self.user.has_role('Manager'): return True
|
|
|
|
|
2012-07-18 14:58:11 -05:00
|
|
|
def computeConnectedUsers(self):
|
|
|
|
'''Computes a table showing users that are currently connected.'''
|
2013-04-26 19:15:44 -05:00
|
|
|
res = '<table cellpadding="0" cellspacing="0" class="list">' \
|
|
|
|
'<tr><th></th><th>%s</th></tr>' % \
|
|
|
|
self.translate('last_user_access')
|
2012-07-18 14:58:11 -05:00
|
|
|
rows = []
|
2013-09-09 16:14:50 -05:00
|
|
|
for userId, lastAccess in self.o.loggedUsers.items():
|
2012-07-18 14:58:11 -05:00
|
|
|
user = self.search1('User', noSecurity=True, login=userId)
|
|
|
|
if not user: continue # Could have been deleted in the meanwhile
|
|
|
|
fmt = '%s (%s)' % (self.dateFormat, self.hourFormat)
|
|
|
|
access = time.strftime(fmt, time.localtime(lastAccess))
|
|
|
|
rows.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % \
|
|
|
|
(user.o.absolute_url(), user.title,access))
|
|
|
|
return res + '\n'.join(rows) + '</table>'
|
|
|
|
|
2009-11-17 03:05:19 -06:00
|
|
|
def getObject(self, uid):
|
|
|
|
'''Allow to retrieve an object from its unique identifier p_uid.'''
|
|
|
|
return self.o.getObject(uid, appy=True)
|
2009-12-01 13:36:59 -06:00
|
|
|
|
|
|
|
def getDiskFolder(self):
|
|
|
|
'''Returns the disk folder where the Appy application is stored.'''
|
2012-05-08 07:49:45 -05:00
|
|
|
return self.o.config.diskFolder
|
|
|
|
|
|
|
|
def getClass(self, zopeName):
|
|
|
|
'''Gets the Appy class corresponding to technical p_zopeName.'''
|
|
|
|
return self.o.getAppyClass(zopeName)
|
2010-10-14 07:43:56 -05:00
|
|
|
|
2011-01-14 02:06:25 -06:00
|
|
|
def getAvailableLanguages(self):
|
|
|
|
'''Returns the list of available languages for this application.'''
|
|
|
|
return [(t.id, t.title) for t in self.translations]
|
2011-01-18 08:48:55 -06:00
|
|
|
|
|
|
|
def convert(self, fileName, format):
|
|
|
|
'''Launches a UNO-enabled Python interpreter as defined in the self for
|
|
|
|
converting, using OpenOffice in server mode, a file named p_fileName
|
|
|
|
into an output p_format.'''
|
|
|
|
convScript = '%s/pod/converter.py' % os.path.dirname(appy.__file__)
|
|
|
|
cmd = '%s %s "%s" %s -p%d' % (self.unoEnabledPython, convScript,
|
|
|
|
fileName, format, self.openOfficePort)
|
2014-09-01 07:14:32 -05:00
|
|
|
self.log('executing %s...' % cmd)
|
2011-01-18 08:48:55 -06:00
|
|
|
return executeCommand(cmd) # The result can contain an error message
|
2011-09-08 09:33:16 -05:00
|
|
|
|
2013-02-28 16:00:06 -06:00
|
|
|
def sendMail(self, to, subject, body, attachments=None):
|
|
|
|
'''Sends a mail. See doc for appy.gen.mail.sendMail.'''
|
2014-09-18 04:08:29 -05:00
|
|
|
mailConfig = self.o.getProductConfig(True).mail
|
|
|
|
sendMail(mailConfig, to, subject, body, attachments=attachments,
|
|
|
|
log=self.log)
|
2013-02-28 16:00:06 -06:00
|
|
|
|
2014-09-05 10:13:23 -05:00
|
|
|
def formatDate(self, date, format=None, withHour=True, language=None):
|
2014-05-02 05:35:09 -05:00
|
|
|
'''Check doc @ToolMixin::formatDate.'''
|
|
|
|
if not date: return
|
2014-09-05 10:13:23 -05:00
|
|
|
return self.o.formatDate(date, format, withHour, language)
|
2014-05-02 05:35:09 -05:00
|
|
|
|
|
|
|
def getUserName(self, login=None, normalized=False):
|
|
|
|
return self.o.getUserName(login=login, normalized=normalized)
|
|
|
|
|
2012-03-19 11:00:44 -05:00
|
|
|
def refreshCatalog(self, startObject=None):
|
|
|
|
'''Reindex all Appy objects. For some unknown reason, method
|
|
|
|
catalog.refreshCatalog is not able to recatalog Appy objects.'''
|
|
|
|
if not startObject:
|
2012-05-14 10:35:34 -05:00
|
|
|
# This is a global refresh. Clear the catalog completely, and then
|
2012-03-19 11:00:44 -05:00
|
|
|
# reindex all Appy-managed objects, ie those in folders "config"
|
|
|
|
# and "data".
|
|
|
|
# First, clear the catalog.
|
2014-09-01 07:14:32 -05:00
|
|
|
self.log('recomputing the whole catalog...')
|
2012-03-19 11:00:44 -05:00
|
|
|
app = self.o.getParentNode()
|
|
|
|
app.catalog._catalog.clear()
|
|
|
|
nb = 1
|
2012-09-04 11:00:22 -05:00
|
|
|
failed = []
|
2012-03-19 11:00:44 -05:00
|
|
|
for obj in app.config.objectValues():
|
2012-09-04 11:00:22 -05:00
|
|
|
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
|
|
|
nb += subNb
|
|
|
|
failed += subFailed
|
|
|
|
try:
|
|
|
|
app.config.reindex()
|
|
|
|
except:
|
|
|
|
failed.append(app.config)
|
2012-03-19 11:00:44 -05:00
|
|
|
# Then, refresh objects in the "data" folder.
|
|
|
|
for obj in app.data.objectValues():
|
2012-09-04 11:00:22 -05:00
|
|
|
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
|
|
|
nb += subNb
|
|
|
|
failed += subFailed
|
|
|
|
# Re-try to index all objects for which reindexation has failed.
|
|
|
|
for obj in failed: obj.reindex()
|
|
|
|
if failed:
|
|
|
|
failMsg = ' (%d retried)' % len(failed)
|
|
|
|
else:
|
|
|
|
failMsg = ''
|
2014-09-01 07:14:32 -05:00
|
|
|
self.log('%d object(s) reindexed%s.' % (nb, failMsg))
|
2012-03-19 11:00:44 -05:00
|
|
|
else:
|
|
|
|
nb = 1
|
2012-09-04 11:00:22 -05:00
|
|
|
failed = []
|
2012-03-19 11:00:44 -05:00
|
|
|
for obj in startObject.objectValues():
|
2012-09-04 11:00:22 -05:00
|
|
|
subNb, subFailed = self.refreshCatalog(startObject=obj)
|
|
|
|
nb += subNb
|
|
|
|
failed += subFailed
|
|
|
|
try:
|
|
|
|
startObject.reindex()
|
|
|
|
except Exception, e:
|
|
|
|
failed.append(startObject)
|
|
|
|
return nb, failed
|
2014-05-14 08:10:41 -05:00
|
|
|
|
|
|
|
def _login(self, login):
|
|
|
|
'''Performs a login programmatically. Used by the test system.'''
|
|
|
|
self.request.user = self.search1('User', noSecurity=True, login=login)
|
2014-12-17 09:19:45 -06:00
|
|
|
|
|
|
|
def doSynchronizeExternalUsers(self):
|
|
|
|
'''Synchronizes the local User copies with a distant LDAP user base.'''
|
|
|
|
cfg = self.o.getProductConfig(True).ldap
|
|
|
|
if not cfg: raise Exception('LDAP config not found.')
|
|
|
|
counts = cfg.synchronizeUsers(self)
|
|
|
|
msg = 'LDAP users: %d created, %d updated, %d untouched.' % counts
|
|
|
|
return True, msg
|
|
|
|
|
|
|
|
def showSynchronizeUsers(self):
|
|
|
|
'''Show this button only if a LDAP connection exists and is enabled.'''
|
|
|
|
cfg = self.o.getProductConfig(True).ldap
|
|
|
|
if cfg and cfg.enabled: return 'view'
|
2015-01-08 06:18:14 -06:00
|
|
|
|
|
|
|
def mayDelete(self):
|
|
|
|
'''No one can delete the tool.'''
|
|
|
|
return
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|