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
|
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
|
|
|
|
|
|
|
# Some error messages ----------------------------------------------------------
|
|
|
|
WRONG_FILE_TUPLE = 'This is not the way to set a file. You can specify a ' \
|
|
|
|
'2-tuple (fileName, fileContent) or a 3-tuple (fileName, fileContent, ' \
|
|
|
|
'mimeType).'
|
2011-02-16 06:43:58 -06:00
|
|
|
FREEZE_ERROR = 'Error while trying to freeze a "%s" file in POD field ' \
|
|
|
|
'"%s" (%s).'
|
|
|
|
FREEZE_FATAL_ERROR = 'A server error occurred. Please contact the system ' \
|
|
|
|
'administrator.'
|
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.'''
|
|
|
|
|
2013-06-27 04:57:39 -05:00
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Navigation-related PXs
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Icon for hiding/showing details below the title.
|
|
|
|
pxShowDetails = Px('''
|
2013-07-15 04:23:29 -05:00
|
|
|
<img if="ztool.subTitleIsUsed(className) and (field.name == 'title')"
|
2013-07-20 12:56:17 -05:00
|
|
|
class="clickable" src=":url('toggleDetails')"
|
2013-07-15 06:39:05 -05:00
|
|
|
onclick="toggleSubTitles()"/>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
# Displays up/down arrows in a table header column for sorting a given
|
2013-07-15 04:23:29 -05:00
|
|
|
# column. Requires variables "sortable", 'filterable' and 'field'.
|
|
|
|
pxSortAndFilter = Px('''<x>
|
|
|
|
<x if="sortable">
|
|
|
|
<img if="(sortKey != field.name) or (sortOrder == 'desc')"
|
|
|
|
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
|
|
|
|
(q(field.name), q('asc'), q(filterKey)))"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('sortDown.gif')" class="clickable"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
<img if="(sortKey != field.name) or (sortOrder == 'asc')"
|
2013-07-15 06:39:05 -05:00
|
|
|
onclick=":navBaseCall.replace('**v**', '0,%s,%s,%s' % \
|
2013-07-15 04:23:29 -05:00
|
|
|
(q(field.name), q('desc'), q(filterKey)))"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('sortUp.gif')" class="clickable"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
</x>
|
|
|
|
<x if="filterable">
|
|
|
|
<input type="text" size="7" id=":'%s_%s' % (ajaxHookId, field.name)"
|
|
|
|
value=":filterKey == field.name and filterValue or ''"/>
|
2013-07-15 06:39:05 -05:00
|
|
|
<img onclick=":navBaseCall.replace('**v**', '0, %s,%s,%s' % \
|
2013-07-15 04:23:29 -05:00
|
|
|
(q(sortKey), q(sortOrder), q(field.name)))"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('funnel')" class="clickable"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
</x></x>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
# Buttons for navigating among a list of elements: next,back,first,last...
|
|
|
|
pxAppyNavigate = Px('''
|
|
|
|
<div if="totalNumber > batchSize" align=":dright">
|
|
|
|
<table class="listNavigate"
|
|
|
|
var="mustSortAndFilter=ajaxHookId == 'queryResult';
|
|
|
|
sortAndFilter=mustSortAndFilter and \
|
2013-07-15 04:23:29 -05:00
|
|
|
',%s,%s,%s' % (q(sortKey),q(sortOrder),q(filterKey)) or ''">
|
2013-06-27 04:57:39 -05:00
|
|
|
<tr valign="middle">
|
|
|
|
<!-- Go to the first page -->
|
|
|
|
<td if="(startNumber != 0) and (startNumber != batchSize)"><img
|
2013-07-20 12:56:17 -05:00
|
|
|
class="clickable" src=":url('arrowLeftDouble')"
|
2013-06-27 04:57:39 -05:00
|
|
|
title=":_('goto_first')"
|
|
|
|
onClick=":navBaseCall.replace('**v**', '0'+sortAndFilter)"/></td>
|
|
|
|
|
|
|
|
<!-- Go to the previous page -->
|
|
|
|
<td var="sNumber=startNumber - batchSize" if="startNumber != 0"><img
|
2013-07-20 12:56:17 -05:00
|
|
|
class="clickable" src=":url('arrowLeftSimple')"
|
2013-06-27 04:57:39 -05:00
|
|
|
title=":_('goto_previous')"
|
|
|
|
onClick="navBaseCall.replace('**v**', \
|
|
|
|
str(sNumber)+sortAndFilter)"/></td>
|
|
|
|
|
|
|
|
<!-- Explain which elements are currently shown -->
|
|
|
|
<td class="discreet">
|
2013-07-20 12:56:17 -05:00
|
|
|
<x>:startNumber + 1</x><img src=":url('to')"/>
|
2013-07-23 03:29:39 -05:00
|
|
|
<x>:startNumber + batchNumber</x> <b>//</b>
|
2013-06-27 04:57:39 -05:00
|
|
|
<x>:totalNumber</x> </td>
|
|
|
|
|
|
|
|
<!-- Go to the next page -->
|
|
|
|
<td var="sNumber=startNumber + batchSize"
|
2013-07-15 06:39:05 -05:00
|
|
|
if="sNumber < totalNumber"><img class="clickable"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowRightSimple')" title=":_('goto_next')"
|
2013-06-27 04:57:39 -05:00
|
|
|
onClick=":navBaseCall.replace('**v**', \
|
|
|
|
str(sNumber)+sortAndFilter)"/></td>
|
|
|
|
|
|
|
|
<!-- Go to the last page -->
|
|
|
|
<td var="lastPageIsIncomplete=totalNumber % batchSize;
|
|
|
|
nbOfCompletePages=totalNumber/batchSize;
|
|
|
|
nbOfCountedPages=lastPageIsIncomplete and \
|
|
|
|
nbOfCompletePages or nbOfCompletePages-1;
|
|
|
|
sNumber= nbOfCountedPages * batchSize"
|
|
|
|
if="(startNumber != sNumber) and \
|
2013-07-15 06:39:05 -05:00
|
|
|
(startNumber != sNumber-batchSize)"><img class="clickable"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowRightDouble')" title=":_('goto_last')"
|
2013-06-27 04:57:39 -05:00
|
|
|
onClick="navBaseCall.replace('**v**', \
|
|
|
|
str(sNumber)+sortAndFilter)"/></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</div>''')
|
|
|
|
|
|
|
|
# Buttons for going to next/previous elements if this one is among bunch of
|
|
|
|
# referenced or searched objects. currentNumber starts with 1.
|
|
|
|
pxObjectNavigate = Px('''
|
2013-07-15 04:23:29 -05:00
|
|
|
<div if="req.get('nav', None)"
|
|
|
|
var2="navInfo=ztool.getNavigationInfo();
|
2013-06-27 04:57:39 -05:00
|
|
|
currentNumber=navInfo['currentNumber'];
|
|
|
|
totalNumber=navInfo['totalNumber'];
|
|
|
|
firstUrl=navInfo['firstUrl'];
|
|
|
|
previousUrl=navInfo['previousUrl'];
|
|
|
|
nextUrl=navInfo['nextUrl'];
|
|
|
|
lastUrl=navInfo['lastUrl'];
|
|
|
|
sourceUrl=navInfo['sourceUrl'];
|
|
|
|
backText=navInfo['backText']">
|
|
|
|
|
|
|
|
<!-- Go to the source URL (search or referred object) -->
|
|
|
|
<a if="sourceUrl" href=":sourceUrl"><img
|
|
|
|
var="gotoSource=_('goto_source');
|
|
|
|
goBack=backText and ('%s - %s' % (backText, gotoSource)) \
|
|
|
|
or gotoSource"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('gotoSource')" title=":goBack"/></a>
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
<!-- Go to the first page -->
|
|
|
|
<a if="firstUrl" href=":firstUrl"><img title=":_('goto_first')"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowLeftDouble')"/></a>
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
<!-- Go to the previous page -->
|
|
|
|
<a if="previousUrl" href=":previousUrl"><img title=":_('goto_previous')"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowLeftSimple')"/></a>
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
<!-- Explain which element is currently shown -->
|
|
|
|
<span class="discreet">
|
|
|
|
<x>:currentNumber</x> <b>//</b>
|
|
|
|
<x>:totalNumber</x>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<!-- Go to the next page -->
|
|
|
|
<a if="nextUrl" href=":nextUrl"><img title=":_('goto_next')"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowRightSimple')"/></a>
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
<!-- Go to the last page -->
|
|
|
|
<a if="lastUrl" href=":lastUrl"><img title=":_('goto_last')"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('arrowRightDouble')"/></a>
|
2013-07-15 04:23:29 -05:00
|
|
|
</div>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
pxNavigationStrip = Px('''
|
|
|
|
<table width="100%" class="navigate">
|
|
|
|
<tr>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Breadcrumb -->
|
2013-07-23 03:29:39 -05:00
|
|
|
<td var="breadcrumb=zobj.getBreadCrumb()" class="breadcrumb">
|
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 -->
|
|
|
|
<span if="nb == len(breadcrumb)-1">:bc['title']</span>
|
|
|
|
<!-- Display a link for parent objects -->
|
|
|
|
<a if="nb != len(breadcrumb)-1" href=":bc['url']">:bc['title']</a>
|
2013-06-27 04:57:39 -05:00
|
|
|
</x>
|
|
|
|
</td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Object navigation -->
|
|
|
|
<td align=":dright">:self.pxObjectNavigate</td>
|
2013-06-27 04:57:39 -05:00
|
|
|
</tr>
|
|
|
|
</table>''')
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# PXs for graphical elements shown on every page
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
# Global elements included in every page.
|
2013-07-15 04:23:29 -05:00
|
|
|
pxPagePrologue = Px('''<x>
|
|
|
|
<!-- Include type-specific CSS and JS. -->
|
|
|
|
<x if="cssJs">
|
|
|
|
<link for="cssFile in cssJs['css']" rel="stylesheet" type="text/css"
|
2013-07-20 12:56:17 -05:00
|
|
|
href=":url(cssFile)"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
<script for="jsFile in cssJs['js']" type="text/javascript"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url(jsFile)"></script></x>
|
2013-07-15 04:23:29 -05:00
|
|
|
|
|
|
|
<!-- Javascript messages -->
|
|
|
|
<script type="text/javascript">:ztool.getJavascriptMessages()</script>
|
|
|
|
|
|
|
|
<!-- Global form for deleting an object -->
|
|
|
|
<form id="deleteForm" method="post" action="do">
|
|
|
|
<input type="hidden" name="action" value="Delete"/>
|
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
</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>
|
|
|
|
<!-- Global form for unlinking an object -->
|
|
|
|
<form id="unlinkForm" method="post" action="do">
|
|
|
|
<input type="hidden" name="action" value="Unlink"/>
|
|
|
|
<input type="hidden" name="sourceUid"/>
|
|
|
|
<input type="hidden" name="fieldName"/>
|
|
|
|
<input type="hidden" name="targetUid"/>
|
|
|
|
</form>
|
|
|
|
<!-- 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>
|
|
|
|
<!-- Global form for generating a document from a pod template -->
|
|
|
|
<form id="podTemplateForm" name="podTemplateForm" method="post"
|
|
|
|
action=":ztool.absolute_url() + '/generateDocument'">
|
|
|
|
<input type="hidden" name="objectUid"/>
|
|
|
|
<input type="hidden" name="fieldName"/>
|
|
|
|
<input type="hidden" name="podFormat"/>
|
|
|
|
<input type="hidden" name="askAction"/>
|
|
|
|
<input type="hidden" name="queryData"/>
|
|
|
|
<input type="hidden" name="customParams"/>
|
|
|
|
</form>
|
|
|
|
</x>''')
|
2013-06-27 04:57:39 -05:00
|
|
|
|
|
|
|
pxPageBottom = Px('''
|
|
|
|
<script type="text/javascript">initSlaves();</script>''')
|
2013-06-26 10:06:06 -05:00
|
|
|
|
|
|
|
pxPortlet = Px('''
|
|
|
|
<x var="toolUrl=tool.url;
|
|
|
|
queryUrl='%s/ui/query' % toolUrl;
|
|
|
|
currentSearch=req.get('search', None);
|
|
|
|
currentClass=req.get('className', None);
|
|
|
|
currentPage=req['PATH_INFO'].rsplit('/',1)[-1];
|
|
|
|
rootClasses=ztool.getRootClasses();
|
2013-07-23 03:29:39 -05:00
|
|
|
phases=zobj and zobj.getAppyPhases() or None">
|
2013-06-26 10:06:06 -05:00
|
|
|
|
2013-07-15 04:23:29 -05:00
|
|
|
<table class="portletContent"
|
2013-07-23 03:29:39 -05:00
|
|
|
if="zobj and phases and zobj.mayNavigate()"
|
2013-07-15 04:23:29 -05:00
|
|
|
var2="singlePhase=phases and (len(phases) == 1);
|
2013-06-28 08:00:02 -05:00
|
|
|
page=req.get('page', '');
|
2013-07-23 03:29:39 -05:00
|
|
|
mayEdit=zobj.mayEdit()">
|
2013-07-15 04:23:29 -05:00
|
|
|
<x for="phase in phases">:phase['px']</x>
|
|
|
|
</table>
|
2013-06-26 10:06:06 -05:00
|
|
|
|
|
|
|
<!-- One section for every searchable root class -->
|
|
|
|
<x for="rootClass in [rc for rc in rootClasses \
|
2013-06-27 04:57:39 -05:00
|
|
|
if ztool.userMaySearch(rc)]">
|
2013-06-26 10:06:06 -05:00
|
|
|
|
|
|
|
<!-- A separator if required -->
|
|
|
|
<div class="portletSep" var="nb=loop.rootClass.nb"
|
|
|
|
if="(nb != 0) or ((nb == 0) and phases)"></div>
|
|
|
|
|
|
|
|
<!-- Section title (link triggers the default search) -->
|
|
|
|
<div class="portletContent"
|
|
|
|
var="searchInfo=ztool.getGroupedSearches(rootClass)">
|
|
|
|
<div class="portletTitle">
|
|
|
|
<a var="queryParam=searchInfo['default'] and \
|
|
|
|
searchInfo['default']['name'] or ''"
|
|
|
|
href=":'%s?className=%s&search=%s' % \
|
|
|
|
(queryUrl,rootClass,queryParam)"
|
|
|
|
class=":(not currentSearch and (currentClass==rootClass) and \
|
|
|
|
(currentPage=='query')) and \
|
|
|
|
'portletCurrent' or ''">::_(rootClass + '_plural')</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Actions -->
|
|
|
|
<x var="addPermission='%s: Add %s' % (appName, rootClass);
|
|
|
|
userMayAdd=user.has_permission(addPermission, appFolder);
|
|
|
|
createMeans=ztool.getCreateMeans(rootClass)">
|
|
|
|
|
|
|
|
<!-- Create a new object from a web form -->
|
|
|
|
<input type="button" class="button"
|
|
|
|
if="userMayAdd and ('form' in createMeans)"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonAdd', bg=True)" value=":_('query_create')"
|
2013-07-23 03:29:39 -05:00
|
|
|
onclick=":'goto(%s)' % \
|
|
|
|
q('%s/do?action=Create&className=%s' % \
|
2013-07-15 04:23:29 -05:00
|
|
|
(toolUrl, rootClass))"/>
|
2013-06-26 10:06:06 -05:00
|
|
|
|
|
|
|
<!-- Create object(s) by importing data -->
|
|
|
|
<input type="button" class="button"
|
|
|
|
if="userMayAdd and ('import' in createMeans)"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonImport', bg=True)" value=":_('query_import')"
|
2013-07-23 03:29:39 -05:00
|
|
|
onclick=":'goto(%s)' % \
|
|
|
|
q('%s/ui/import?className=%s' % (toolUrl, rootClass))"/>
|
2013-06-26 10:06:06 -05:00
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- Searches -->
|
|
|
|
<x if="ztool.advancedSearchEnabledFor(rootClass)">
|
|
|
|
|
|
|
|
<!-- Live search -->
|
2013-07-20 12:56:17 -05:00
|
|
|
<form action=":'%s/do' % toolUrl">
|
2013-06-26 10:06:06 -05:00
|
|
|
<input type="hidden" name="action" value="SearchObjects"/>
|
|
|
|
<input type="hidden" name="className" value=":rootClass"/>
|
|
|
|
<table cellpadding="0" cellspacing="0">
|
|
|
|
<tr valign="bottom">
|
|
|
|
<td><input type="text" size="14" name="w_SearchableText"
|
|
|
|
class="inputSearch"/></td>
|
2013-07-15 04:23:29 -05:00
|
|
|
<td>
|
2013-07-20 12:56:17 -05:00
|
|
|
<input type="image" class="clickable" src=":url('search.gif')"
|
2013-07-15 04:23:29 -05:00
|
|
|
title=":_('search_button')"/></td>
|
2013-06-26 10:06:06 -05:00
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<!-- Advanced search -->
|
|
|
|
<div var="highlighted=(currentClass == rootClass) and \
|
|
|
|
(currentPage == 'search')"
|
2013-06-27 04:57:39 -05:00
|
|
|
class=":highlighted and 'portletSearch portletCurrent' or \
|
2013-06-26 10:06:06 -05:00
|
|
|
'portletSearch'"
|
|
|
|
align=":dright">
|
|
|
|
<a var="text=_('search_title')" style="font-size: 88%"
|
|
|
|
href=":'%s/ui/search?className=%s' % (toolUrl, rootClass)"
|
|
|
|
title=":text"><x>:text</x>...</a>
|
|
|
|
</div>
|
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- Predefined searches -->
|
|
|
|
<x for="widget in searchInfo['searches']">
|
2013-07-15 04:23:29 -05:00
|
|
|
<x if="widget['type']=='group'">:widget['px']</x>
|
|
|
|
<x if="widget['type']!='group'" var2="search=widget">:search['px']</x>
|
2013-06-26 10:06:06 -05:00
|
|
|
</x>
|
|
|
|
</div>
|
|
|
|
</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</x>''')
|
2013-06-26 10:06:06 -05:00
|
|
|
|
2013-06-28 08:00:02 -05:00
|
|
|
# The message that is shown when a user triggers an action.
|
2013-06-26 10:06:06 -05:00
|
|
|
pxMessage = Px('''
|
2013-07-15 04:23:29 -05:00
|
|
|
<div var="messages=ztool.consumeMessages()" if="messages" class="message">
|
|
|
|
<!-- The icon for closing the message -->
|
2013-07-20 12:56:17 -05:00
|
|
|
<img src=":url('close')" align=":dright" class="clickable"
|
2013-07-15 04:23:29 -05:00
|
|
|
onclick="this.parentNode.style.display='none'"/>
|
|
|
|
<!-- The message content -->
|
|
|
|
<x>::messages</x>
|
|
|
|
</div>''')
|
2013-06-26 10:06:06 -05:00
|
|
|
|
2013-06-28 08:00:02 -05:00
|
|
|
# The page footer.
|
2013-06-26 10:06:06 -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>
|
2013-06-27 04:57:39 -05:00
|
|
|
</table>''')
|
2013-06-26 10:06:06 -05:00
|
|
|
|
2013-06-28 08:00:02 -05:00
|
|
|
# Hook for defining a PX that proposes additional links, after the links
|
|
|
|
# corresponding to top-level pages.
|
|
|
|
pxLinks = ''
|
|
|
|
|
|
|
|
# Hook for defining a PX that proposes additional icons after standard
|
|
|
|
# icons in the user strip.
|
|
|
|
pxIcons = ''
|
|
|
|
|
|
|
|
# The template PX for all pages.
|
2013-06-25 05:04:23 -05:00
|
|
|
pxTemplate = Px('''
|
2013-06-25 16:22:33 -05:00
|
|
|
<html var="tool=self.tool; ztool=tool.o; user=tool.user;
|
|
|
|
isAnon=ztool.userIsAnon(); 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;
|
|
|
|
req=ztool.REQUEST; resp=req.RESPONSE;
|
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();
|
2013-07-23 03:29:39 -05:00
|
|
|
zobj=ztool.getPublishedObject(layoutType) or \
|
|
|
|
ztool.getHomeObject();
|
|
|
|
obj = zobj and zobj.appy() or None;
|
|
|
|
showPortlet=ztool.showPortlet(zobj, layoutType);
|
2013-06-25 16:22:33 -05:00
|
|
|
dir=ztool.getLanguageDirection(lang);
|
2013-07-24 08:53:19 -05:00
|
|
|
discreetLogin=ztool.getProductConfig(True).discreetLogin;
|
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"/>
|
|
|
|
<x for="name in ztool.getGlobalCssJs()">
|
|
|
|
<link if="name.endswith('.css') and \
|
|
|
|
not ((dir == 'ltr') and (name == 'appyrtl.css'))"
|
2013-07-20 12:56:17 -05:00
|
|
|
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>
|
2013-06-25 05:04:23 -05:00
|
|
|
<body>
|
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>
|
|
|
|
|
|
|
|
<!-- Grey background shown when popups are shown -->
|
|
|
|
<div id="grey" class="grey"></div>
|
|
|
|
|
|
|
|
<!-- 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>
|
|
|
|
|
|
|
|
<!-- 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>
|
|
|
|
|
|
|
|
<table class="main" align="center" cellpadding="0">
|
2013-06-26 06:44:31 -05:00
|
|
|
<tr class="top">
|
|
|
|
<!-- Top banner -->
|
|
|
|
<td var="bannerName=(dir == 'ltr') and 'banner' or 'bannerrtl'"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('%s.jpg' % bannerName, bg=True)">
|
2013-06-26 06:44:31 -05:00
|
|
|
|
|
|
|
<!-- Top links -->
|
|
|
|
<div style="margin-top: 4px" align=":dright">
|
|
|
|
<!-- Icon "home" -->
|
2013-07-20 12:56:17 -05:00
|
|
|
<a class="pageLink" href="/" title=": _('app_home')">
|
|
|
|
<img src=":url('home.gif')" style="margin-right: 3px"/>
|
2013-06-26 06:44:31 -05:00
|
|
|
</a>
|
2013-06-28 08:00:02 -05:00
|
|
|
|
|
|
|
<!-- Additional links -->
|
|
|
|
<x>:self.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 -->
|
|
|
|
<a if="isAnon and 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 -->
|
2013-07-15 04:23:29 -05:00
|
|
|
<select if="ztool.showLanguageSelector()"
|
|
|
|
var2="languages=ztool.getLanguages();
|
|
|
|
defaultLanguage=languages[0]"
|
|
|
|
class="pageLink" onchange="switchLanguage(this)">
|
|
|
|
<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 -->
|
|
|
|
<tr valign="top">
|
|
|
|
<td><div style="position: relative">:self.pxMessage</div></td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<!-- The user strip -->
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<table class="userStrip" width="100%">
|
|
|
|
<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"/>
|
|
|
|
<!-- Login fields, directly shown or not (depends on
|
|
|
|
discreetLogin) -->
|
|
|
|
<span id="loginFields" name="loginFields"
|
|
|
|
style=":discreetLogin and 'display:none' or 'display:block'">
|
|
|
|
<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 -->
|
|
|
|
<x>:self.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>
|
|
|
|
<td class="userStripText" var="userInfo=ztool.getUserLine()"
|
|
|
|
align=":dright">
|
|
|
|
<span>:userInfo[0]</span>
|
2013-07-15 04:23:29 -05:00
|
|
|
<a if="userInfo[1]"
|
2013-07-20 12:56:17 -05:00
|
|
|
href=":userInfo[1]"><img src=":url('edit')"/></a>
|
2013-06-26 10:06:06 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
|
|
|
|
<!-- The navigation strip -->
|
2013-07-23 03:29:39 -05:00
|
|
|
<tr if="zobj and showPortlet and (layoutType != 'edit')">
|
2013-06-27 04:57:39 -05:00
|
|
|
<td>:self.pxNavigationStrip</td>
|
2013-06-26 10:06:06 -05:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>
|
|
|
|
<table width="100%" cellpadding="0" cellspacing="0">
|
|
|
|
<tr valign="top">
|
|
|
|
<!-- The portlet -->
|
2013-06-28 08:00:02 -05:00
|
|
|
<td if="showPortlet" class="portlet">:self.pxPortlet</td>
|
2013-06-26 10:06:06 -05:00
|
|
|
<!-- Page content -->
|
|
|
|
<td class="content">:content</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<!-- Footer -->
|
|
|
|
<tr><td>:self.pxFooter</td></tr>
|
|
|
|
</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
|
|
|
|
# --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# This PX displays an object's history.
|
|
|
|
pxObjectHistory = Px('''
|
|
|
|
<x var="startNumber=req.get'startNumber', 0);
|
|
|
|
startNumber=int(startNumber);
|
|
|
|
batchSize=int(req.get('maxPerPage', 5));
|
2013-07-23 03:29:39 -05:00
|
|
|
historyInfo=zobj.getHistory(startNumber,batchSize=batchSize)"
|
2013-07-15 04:23:29 -05:00
|
|
|
if="historyInfo['events']"
|
|
|
|
var2="objs=historyInfo['events'];
|
|
|
|
totalNumber=historyInfo['totalNumber'];
|
|
|
|
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 -->
|
|
|
|
<x>:self.pxAppyNavigate</x>
|
|
|
|
<!-- 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"
|
|
|
|
var2="odd=loop.event.odd;
|
|
|
|
rhComments=event.get('comments', None);
|
|
|
|
state=event.get('review_state', None);
|
|
|
|
action=event['action'];
|
|
|
|
isDataChange=action == '_datachange_'"
|
|
|
|
class="odd and 'even' or 'odd'" valign="top">
|
|
|
|
<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)' % \
|
2013-07-23 03:29:39 -05:00
|
|
|
(q(zobj.UID()), 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>
|
|
|
|
<td>:ztool.formatDate(event['time'], withHour=True)"></td>
|
|
|
|
<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. -->
|
|
|
|
<table class="appyChanges" width="100%">
|
|
|
|
<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"
|
2013-07-23 03:29:39 -05:00
|
|
|
var2="appyType=zobj.getAppyType(change[0], asDict=True)">
|
2013-07-15 04:23:29 -05:00
|
|
|
<td>::_(appyType['labelId'])</td>
|
|
|
|
<td>::change[1][0]</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</x>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
# Displays an object's transitions(s).
|
|
|
|
pxTransitions = Px('''
|
2013-07-15 04:23:29 -05:00
|
|
|
<form var="transitions=targetObj.getAppyTransitions()" if="transitions"
|
|
|
|
var2="formId='trigger_%s' % targetObj.UID()" method="post"
|
|
|
|
id=":formId" action=":targetObj.absolute_url() + '/do'">
|
|
|
|
<input type="hidden" name="action" value="Trigger"/>
|
|
|
|
<input type="hidden" name="workflow_action"/>
|
|
|
|
<table>
|
|
|
|
<tr valign="middle">
|
|
|
|
<!-- Input field for storing comment -->
|
|
|
|
<textarea id="comment" name="comment" cols="30" rows="3"
|
|
|
|
style="display:none"></textarea>
|
|
|
|
<!-- Buttons for triggering transitions -->
|
|
|
|
<td align=":dright" for="transition in transitions">
|
|
|
|
<!-- Real button -->
|
|
|
|
<input type="button" class="button" if="transition['may_trigger']"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonTransition', bg=True)"
|
2013-07-15 04:23:29 -05:00
|
|
|
title=":transition['title']"
|
|
|
|
value=":ztool.truncateValue(transition['title'])"
|
|
|
|
onclick=":'triggerTransition(%s,%s,%s)' % (q(formId), \
|
|
|
|
q(transition['name']), q(transition['confirm']))"/>
|
|
|
|
|
|
|
|
<!-- Fake button, explaining why the transition can't be triggered -->
|
|
|
|
<input type="button" class="button" if="not transition['may_trigger']"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonFake', bg=True) + ';cursor: help'"
|
2013-07-15 04:23:29 -05:00
|
|
|
value=":ztool.truncateValue(transition['title'])"
|
|
|
|
title=":'%s: %s' % (transition['title'], \
|
|
|
|
transition['reason'])"/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
</form>''')
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
# Displays header information about an object: title, workflow-related info,
|
|
|
|
# history...
|
|
|
|
pxObjectHeader = 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);
|
|
|
|
historyExpanded=req.get('appyHistory','collapsed') == 'expanded';
|
2013-07-23 03:29:39 -05:00
|
|
|
creator=zobj.Creator()">
|
2013-06-27 10:40:01 -05:00
|
|
|
<table width="100%" class="summary">
|
|
|
|
<tr>
|
|
|
|
<td colspan="2" class="by">
|
|
|
|
<!-- Plus/minus icon for accessing history -->
|
|
|
|
<x if="hasHistory">
|
2013-07-15 06:39:05 -05:00
|
|
|
<img class="clickable" onclick="toggleCookie('appyHistory')"
|
2013-07-20 12:56:17 -05:00
|
|
|
src="historyExpanded and url('collapse.gif') or url('expand.gif')"
|
2013-07-15 04:23:29 -05:00
|
|
|
align=":dleft" id="appyHistory_img"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
<x>:_('object_history')</x> ||
|
|
|
|
</x>
|
|
|
|
|
|
|
|
<!-- Creator and last modification date -->
|
2013-07-15 04:23:29 -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-06-27 10:40:01 -05:00
|
|
|
<x>:ztool.formatDate(creationDate, withHour=True)></x>
|
|
|
|
<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">
|
|
|
|
<span id="appyHistory"
|
|
|
|
style=":historyExpanded and 'display:block' or 'display:none')">
|
2013-07-23 03:29:39 -05:00
|
|
|
<div var="ajaxHookId=zobj.UID() + '_history'" id=":ajaxHookId">
|
2013-07-15 04:23:29 -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
|
|
|
|
# transitions.
|
|
|
|
pxObjectButtons = Px('''
|
|
|
|
<table cellpadding="2" cellspacing="0" style="margin-top: 7px"
|
2013-07-23 03:29:39 -05:00
|
|
|
var="previousPage=zobj.getPreviousPage(phaseInfo, page)[0];
|
|
|
|
nextPage=zobj.getNextPage(phaseInfo, page)[0];
|
2013-06-27 10:40:01 -05:00
|
|
|
isEdit=layoutType == 'edit';
|
|
|
|
pageInfo=phaseInfo['pagesInfo'][page]">
|
|
|
|
<tr>
|
|
|
|
<!-- Previous -->
|
|
|
|
<td if="previousPage and pageInfo['showPrevious']">
|
|
|
|
<!-- Button on the edit page -->
|
|
|
|
<x if="isEdit">
|
|
|
|
<input type="button" class="button" value=":_('page_previous')"
|
|
|
|
onClick="submitAppyForm('previous')"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonPrevious', bg=True)"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
<input type="hidden" name="previousPage" value=":previousPage"/>
|
|
|
|
</x>
|
|
|
|
<!-- Button on the view page -->
|
2013-07-15 04:23:29 -05:00
|
|
|
<input if="not isEdit" type="button" class="button"
|
|
|
|
value=":_('page_previous')"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonPrevious', bg=True)"
|
2013-07-23 03:29:39 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(page=previousPage))"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Save -->
|
|
|
|
<td if="isEdit and pageInfo['showSave']">
|
|
|
|
<input type="button" class="button" onClick="submitAppyForm('save')"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url(buttonSave', bg=True)" value=":_('object_save')"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Cancel -->
|
|
|
|
<td if="isEdit and pageInfo['showCancel']">
|
|
|
|
<input type="button" class="button" onClick="submitAppyForm('cancel')"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonCancel', bg=True)" value=":_('object_cancel')"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
</td>
|
|
|
|
|
2013-07-15 04:23:29 -05:00
|
|
|
<td if="not isEdit"
|
2013-07-23 03:29:39 -05:00
|
|
|
var2="locked=zobj.isLocked(user, page);
|
|
|
|
editable=pageInfo['showOnEdit'] and zobj.mayEdit()">
|
2013-06-27 10:40:01 -05:00
|
|
|
|
2013-07-15 04:23:29 -05:00
|
|
|
<!-- Edit -->
|
|
|
|
<input type="button" class="button" if="editable and not locked"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonEdit', bg=True)" value=":_('object_edit')"
|
2013-07-23 03:29:39 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(mode='edit', page=page))"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
|
|
|
|
<!-- Locked -->
|
|
|
|
<a if="editable and locked">
|
|
|
|
<img style="cursor: help"
|
|
|
|
var="lockDate=tool.formatDate(locked[1]);
|
|
|
|
lockMap={'user':tool.getUserName(locked[0]),'date':lockDate};
|
|
|
|
lockMsg=_('page_locked', mapping=lockMap)"
|
2013-07-20 12:56:17 -05:00
|
|
|
src=":url('lockedBig')" title=":lockMsg"/></a>
|
2013-07-15 04:23:29 -05:00
|
|
|
</td>
|
2013-06-27 10:40:01 -05:00
|
|
|
|
|
|
|
<!-- Next -->
|
|
|
|
<td if="nextPage and pageInfo['showNext']">
|
|
|
|
<!-- Button on the edit page -->
|
|
|
|
<x if="isEdit">
|
|
|
|
<input type="button" class="button" onClick="submitAppyForm('next')"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonNext', bg=True)" value=":_('page_next')"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
<input type="hidden" name="nextPage" value=":nextPage"/>
|
|
|
|
</x>
|
|
|
|
<!-- Button on the view page -->
|
2013-07-15 04:23:29 -05:00
|
|
|
<input if="not isEdit" type="button" class="button"
|
2013-07-20 12:56:17 -05:00
|
|
|
style=":url('buttonNext', bg=True)" value=":_('page_next')"
|
2013-07-23 03:29:39 -05:00
|
|
|
onclick=":'goto(%s)' % q(zobj.getUrl(page=nextPage))"/>
|
2013-06-27 10:40:01 -05:00
|
|
|
</td>
|
|
|
|
|
|
|
|
<!-- Workflow transitions -->
|
2013-07-23 03:29:39 -05:00
|
|
|
<td var="targetObj=zobj"
|
2013-06-27 10:40:01 -05:00
|
|
|
if="targetObj.showTransitions(layoutType)">:self.pxTransitions</td>
|
|
|
|
|
|
|
|
<!-- Refresh -->
|
2013-07-23 03:29:39 -05:00
|
|
|
<td if="zobj.isDebug()">
|
|
|
|
<a href="zobj.getUrl(mode=layoutType, page=page, refresh='yes')">
|
2013-07-20 12:56:17 -05:00
|
|
|
<img title="Refresh" style="vertical-align:top" src=":url('refresh')"/>
|
2013-07-15 04:23:29 -05:00
|
|
|
</a>
|
2013-06-27 10:40:01 -05:00
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</table>''')
|
|
|
|
|
2013-06-27 04:57:39 -05:00
|
|
|
pxLayoutedObject = Px('''<p>Layouted object</p>''')
|
|
|
|
pxView = Px('''
|
2013-07-23 03:29:39 -05:00
|
|
|
<x var="x=zobj.allows('View', 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);
|
|
|
|
phaseInfo=zobj.getAppyPhases(currentOnly=True, layoutType='view');
|
2013-06-27 04:57:39 -05:00
|
|
|
phase=phaseInfo['name'];
|
|
|
|
cssJs={};
|
2013-07-23 03:29:39 -05:00
|
|
|
page=req.get('page',None) or zobj.getDefaultViewPage();
|
|
|
|
x=zobj.removeMyLock(user, page);
|
|
|
|
groupedWidgets=zobj.getGroupedAppyTypes(layoutType, page, \
|
2013-06-27 04:57:39 -05:00
|
|
|
cssJs=cssJs)">
|
|
|
|
<x>:self.pxPagePrologue</x>
|
|
|
|
<x var="tagId='pageLayout'">:self.pxLayoutedObject</x>
|
|
|
|
<x>:self.pxPageBottom</x>
|
|
|
|
</x>''', template=pxTemplate, hook='content')
|
|
|
|
|
|
|
|
pxEdit = Px('''
|
2013-07-23 03:29:39 -05:00
|
|
|
<x var="x=zobj.allows('Modify portal content', raiseError=True);
|
2013-06-27 04:57:39 -05:00
|
|
|
errors=req.get('errors', None) or {};
|
2013-07-23 03:29:39 -05:00
|
|
|
layout=zobj.getPageLayout(layoutType);
|
2013-06-27 04:57:39 -05:00
|
|
|
cssJs={};
|
2013-07-23 03:29:39 -05:00
|
|
|
phaseInfo=zobj.getAppyPhases(currentOnly=True, \
|
|
|
|
layoutType=layoutType);
|
2013-06-27 04:57:39 -05:00
|
|
|
phase=phaseInfo['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-07-23 03:29:39 -05:00
|
|
|
groupedWidgets=zobj.getGroupedAppyTypes(layoutType, page, \
|
|
|
|
cssJs=cssJs)">
|
2013-06-27 04:57:39 -05:00
|
|
|
<x>:self.pxPagePrologue</x>
|
|
|
|
<!-- Warn the user that the form should be left via buttons -->
|
2013-07-15 04:23:29 -05:00
|
|
|
<script type="text/javascript"><![CDATA[
|
2013-06-27 04:57:39 -05:00
|
|
|
window.onbeforeunload = function(e){
|
|
|
|
theForm = document.getElementById('appyForm');
|
|
|
|
if (theForm.button.value == "") {
|
|
|
|
var e = e || window.event;
|
|
|
|
if (e) {e.returnValue = warn_leave_form;}
|
|
|
|
return warn_leave_form;
|
|
|
|
}
|
2013-07-15 04:23:29 -05:00
|
|
|
}]]>
|
2013-06-27 04:57:39 -05:00
|
|
|
</script>
|
|
|
|
<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=""/>
|
|
|
|
<input type="hidden" name="page" value=":page"/>
|
|
|
|
<input type="hidden" name="nav" value=":req.get('nav', None)"/>
|
|
|
|
<input type="hidden" name="confirmed" value="False"/>
|
|
|
|
<x var="tagId='pageLayout'">:self.pxLayoutedObject</x>
|
2013-06-27 04:57:39 -05:00
|
|
|
</form>
|
|
|
|
<script type="text/javascript"
|
2013-07-15 04:23:29 -05:00
|
|
|
if="confirmMsg">:'askConfirm(%s,%s,%s)' % \
|
|
|
|
(q('script'), q('postConfirmedEditForm()'), q(confirmMsg))</script>
|
2013-06-27 04:57:39 -05:00
|
|
|
<x>:self.pxPageBottom</x>
|
|
|
|
</x>''', template=pxTemplate, hook='content')
|
2013-06-25 05:04:23 -05:00
|
|
|
|
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
|
|
|
|
classmethods m_getWorkflow and m_getCreators below. Scanning base
|
|
|
|
classes in reverse order allows user-defined elements to override
|
|
|
|
default Appy elements.'''
|
|
|
|
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
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getCreators(klass, cfg):
|
|
|
|
'''Returns the roles that are allowed to create instances of p_klass.
|
|
|
|
p_cfg is the product config that holds the default value.'''
|
|
|
|
res = klass._getParentAttr('creators')
|
|
|
|
# Return default creators if no creators was found.
|
2013-07-24 08:53:19 -05:00
|
|
|
if not res: res = cfg.appConfig.defaultCreators
|
2012-06-02 07:36:49 -05:00
|
|
|
return res
|
|
|
|
|
2012-09-04 11:00:22 -05:00
|
|
|
@classmethod
|
|
|
|
def getIndexes(klass, includeDefaults=True):
|
|
|
|
'''Returns a dict whose keys are the names of the indexes that are
|
|
|
|
applicable to instances of this class, and whose values are the
|
|
|
|
(Zope) types of those indexes.'''
|
|
|
|
# Start with the standard indexes applicable for any Appy class.
|
|
|
|
if includeDefaults:
|
|
|
|
res = defaultIndexes.copy()
|
|
|
|
else:
|
|
|
|
res = {}
|
|
|
|
# Add the indexed fields found on this class
|
|
|
|
for field in klass.__fields__:
|
|
|
|
if not field.indexed or (field.name == 'title'): continue
|
|
|
|
n = field.name
|
|
|
|
indexName = 'get%s%s' % (n[0].upper(), n[1:])
|
|
|
|
res[indexName] = field.getIndexType()
|
|
|
|
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):
|
2009-07-10 08:01:50 -05:00
|
|
|
appyType = self.o.getAppyType(name)
|
2010-08-05 11:23:17 -05:00
|
|
|
if not appyType:
|
2009-07-10 08:01:50 -05:00
|
|
|
raise 'Attribute "%s" does not exist.' % name
|
2010-11-26 10:30:46 -06:00
|
|
|
appyType.store(self.o, value)
|
|
|
|
|
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
|
|
|
|
elif name == 'uid': return self.o.UID()
|
|
|
|
elif name == 'klass': return self.__class__.__bases__[-1]
|
2013-06-07 04:32:23 -05:00
|
|
|
elif name == 'created': return self.o.created
|
|
|
|
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())
|
2011-09-06 18:33:09 -05:00
|
|
|
elif name == 'history':
|
|
|
|
o = self.o
|
|
|
|
key = o.workflow_history.keys()[0]
|
|
|
|
return o.workflow_history[key]
|
|
|
|
elif name == 'user':
|
2011-11-25 11:01:20 -06:00
|
|
|
return self.o.getUser()
|
2011-11-28 15:50:01 -06:00
|
|
|
elif name == 'appyUser':
|
2013-05-17 08:00:31 -05:00
|
|
|
user = self.search1('User', noSecurity=True,
|
2012-05-05 10:04:19 -05:00
|
|
|
login=self.o.getUser().getId())
|
2013-05-17 08:00:31 -05:00
|
|
|
if user: return user
|
|
|
|
if self.o.getUser().getUserName() == 'System Processes':
|
|
|
|
return self.search1('User', noSecurity=True, login='admin')
|
2013-05-17 10:11:22 -05:00
|
|
|
return
|
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()
|
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)
|
2011-09-06 18:33:09 -05:00
|
|
|
# If we got an Appy type, return the value of this type 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):
|
2010-11-26 10:30:46 -06:00
|
|
|
return '<%s appyobj at %s>' % (self.klass.__name__, id(self))
|
|
|
|
|
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)
|
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)
|
|
|
|
return field.isEmptyValue(getattr(obj, name))
|
|
|
|
return True
|
2011-02-17 11:13:42 -06:00
|
|
|
|
2011-10-04 13:12:58 -05:00
|
|
|
def link(self, fieldName, obj):
|
2011-01-19 13:51:43 -06:00
|
|
|
'''This method links p_obj (which can be a list of objects) to this one
|
2011-10-04 13:12:58 -05:00
|
|
|
through reference field p_fieldName.'''
|
|
|
|
return self.getField(fieldName).linkObject(self.o, obj)
|
2011-01-19 13:51:43 -06:00
|
|
|
|
2011-10-04 13:12:58 -05:00
|
|
|
def unlink(self, fieldName, obj):
|
2011-01-19 13:51:43 -06:00
|
|
|
'''This method unlinks p_obj (which can be a list of objects) from this
|
2011-10-04 13:12:58 -05:00
|
|
|
one through reference field p_fieldName.'''
|
|
|
|
return self.getField(fieldName).unlinkObject(self.o, obj)
|
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
|
|
|
|
objects ("title", by default).'''
|
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
|
2013-03-10 10:31:49 -05:00
|
|
|
# refs is a PersistentList: param "key" is not available. So perform the
|
|
|
|
# sort on the real list and then indicate that the persistent list has
|
|
|
|
# changed (the ZODB way).
|
|
|
|
refs.data.sort(key=lambda x: getattr(tool.getObject(x), sortKey),
|
|
|
|
reverse=reverse)
|
|
|
|
refs._p_changed = 1
|
2009-10-27 08:48:04 -05:00
|
|
|
|
2012-06-02 07:36:49 -05:00
|
|
|
def create(self, fieldNameOrClass, noSecurity=False, **kwargs):
|
2011-11-25 11:01:20 -06:00
|
|
|
'''If p_fieldNameOrClass is the name of a field, this method allows to
|
2009-07-10 08:01:50 -05:00
|
|
|
create an object and link it to the current one (self) through
|
|
|
|
reference field named p_fieldName.
|
|
|
|
If p_fieldNameOrClass is a class from the gen-application, it must
|
|
|
|
correspond to a root class and this method allows to create a
|
|
|
|
root object in the application folder.'''
|
|
|
|
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
|
2010-09-02 09:16:08 -05:00
|
|
|
appyType = self.o.getAppyType(fieldName)
|
2011-11-25 11:01:20 -06:00
|
|
|
portalType = tool.getPortalType(appyType.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-10-25 15:42:08 -05:00
|
|
|
# Determine if object must be created from external data
|
|
|
|
externalData = None
|
|
|
|
if kwargs.has_key('_data'):
|
|
|
|
externalData = kwargs['_data']
|
|
|
|
del kwargs['_data']
|
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.
|
|
|
|
appyType.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():
|
2011-01-28 07:36:30 -06:00
|
|
|
setattr(appyObj, attrName, attrValue)
|
2009-07-10 08:01:50 -05:00
|
|
|
if isField:
|
|
|
|
# Link the object to this one
|
2011-11-25 11:01:20 -06:00
|
|
|
appyType.linkObject(self.o, zopeObj)
|
|
|
|
zopeObj._appy_managePermissions()
|
2009-07-10 08:01:50 -05:00
|
|
|
# Call custom initialization
|
2009-11-20 13:17:06 -06:00
|
|
|
if externalData: param = externalData
|
|
|
|
else: param = True
|
|
|
|
if hasattr(appyObj, 'onEdit'): appyObj.onEdit(param)
|
2011-11-25 11:01:20 -06:00
|
|
|
zopeObj.reindex()
|
2009-06-29 07:06:01 -05:00
|
|
|
return appyObj
|
|
|
|
|
2011-02-16 06:43:58 -06:00
|
|
|
def freeze(self, fieldName, doAction=False):
|
|
|
|
'''This method freezes a POD document. TODO: allow to freeze Computed
|
|
|
|
fields.'''
|
|
|
|
rq = self.request
|
|
|
|
field = self.o.getAppyType(fieldName)
|
|
|
|
if field.type != 'Pod': raise 'Cannot freeze non-Pod field.'
|
|
|
|
# Perform the related action if required.
|
|
|
|
if doAction: self.request.set('askAction', True)
|
|
|
|
# Set the freeze format
|
|
|
|
rq.set('podFormat', field.freezeFormat)
|
|
|
|
# Generate the document.
|
|
|
|
doc = field.getValue(self.o)
|
|
|
|
if isinstance(doc, basestring):
|
|
|
|
self.log(FREEZE_ERROR % (field.freezeFormat, field.name, doc),
|
|
|
|
type='error')
|
|
|
|
if field.freezeFormat == 'odt': raise FREEZE_FATAL_ERROR
|
|
|
|
self.log('Trying to freeze the ODT version...')
|
|
|
|
# Try to freeze the ODT version of the document, which does not
|
|
|
|
# require to call OpenOffice/LibreOffice, so the risk of error is
|
|
|
|
# smaller.
|
|
|
|
self.request.set('podFormat', 'odt')
|
|
|
|
doc = field.getValue(self.o)
|
|
|
|
if isinstance(doc, basestring):
|
|
|
|
self.log(FREEZE_ERROR % ('odt', field.name, doc), type='error')
|
|
|
|
raise FREEZE_FATAL_ERROR
|
|
|
|
field.store(self.o, doc)
|
|
|
|
|
|
|
|
def unFreeze(self, fieldName):
|
|
|
|
'''This method un freezes a POD document. TODO: allow to unfreeze
|
|
|
|
Computed fields.'''
|
|
|
|
rq = self.request
|
|
|
|
field = self.o.getAppyType(fieldName)
|
|
|
|
if field.type != 'Pod': raise 'Cannot unFreeze non-Pod field.'
|
|
|
|
field.store(self.o, None)
|
|
|
|
|
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
|
|
|
|
2011-07-26 15:15:04 -05:00
|
|
|
def do(self, transition, comment='', doAction=True, doNotify=True,
|
2012-07-23 08:24:44 -05:00
|
|
|
doHistory=True, noSecurity=False):
|
2009-06-29 07:06:01 -05:00
|
|
|
'''This method allows to trigger on p_self a workflow p_transition
|
2011-07-26 15:15:04 -05:00
|
|
|
programmatically. See doc in self.o.do.'''
|
2011-11-25 11:01:20 -06:00
|
|
|
return self.o.trigger(transition, comment, doAction=doAction,
|
2012-07-23 08:24:44 -05:00
|
|
|
doNotify=doNotify, doHistory=doHistory,
|
|
|
|
doSay=False, 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
|
|
|
|
2010-02-22 08:28:20 -06:00
|
|
|
def search(self, klass, sortBy='', 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
|
|
|
|
field (declared with indexed=True); every param in p_fields must
|
|
|
|
take the name of an indexed field and take a possible value of this
|
2009-11-24 15:41:42 -06:00
|
|
|
field. You can optionally specify a maximum number of results in
|
2010-01-12 14:15:14 -06:00
|
|
|
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
|
|
|
|
search = Search('customSearch', sortBy=sortBy, **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)
|
2009-11-06 04:33:56 -06:00
|
|
|
return [o.appy() for o in res['objects']]
|
|
|
|
|
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,
|
|
|
|
noSecurity=noSecurity)
|
2009-11-24 15:41:42 -06:00
|
|
|
if res: return res._len # It is a LazyMap instance
|
|
|
|
else: return 0
|
|
|
|
|
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:
|
|
|
|
# Get names of indexes from field names.
|
|
|
|
indexes = [Search.getIndexName(name) for name in fields]
|
|
|
|
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:
|
|
|
|
at = getOsTempFolder() + '/' + self.o.UID() + '.xml'
|
|
|
|
# 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
|
|
|
|
|
|
|
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)
|
2009-06-29 07:06:01 -05:00
|
|
|
# ------------------------------------------------------------------------------
|