PageRenderTime 66ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 1ms

/modules/bibformat/lib/bibformat_templates.py

https://github.com/lbjay/cds-invenio
Python | 1933 lines | 1871 code | 32 blank | 30 comment | 20 complexity | 893d69c6836b620345f0957a5d13be30 MD5 | raw file
Possible License(s): GPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. # -*- coding: utf-8 -*-
  2. ##
  3. ## This file is part of CDS Invenio.
  4. ## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
  5. ##
  6. ## CDS Invenio is free software; you can redistribute it and/or
  7. ## modify it under the terms of the GNU General Public License as
  8. ## published by the Free Software Foundation; either version 2 of the
  9. ## License, or (at your option) any later version.
  10. ##
  11. ## CDS Invenio is distributed in the hope that it will be useful, but
  12. ## WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ## General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
  18. ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  19. """HTML Templates for BibFormat administration"""
  20. __revision__ = "$Id$"
  21. # non Invenio imports
  22. import cgi
  23. # Invenio imports
  24. from invenio.messages import gettext_set_language
  25. from invenio.config import CFG_SITE_URL, CFG_SITE_SECURE_URL
  26. from invenio.messages import language_list_long
  27. from invenio.config import CFG_PATH_PHP
  28. MAX_MAPPINGS = 100 #show max this number of mappings on one page
  29. class Template:
  30. """Templating class, refer to bibformat.py for examples of call"""
  31. def tmpl_admin_index(self, ln, warnings, is_admin):
  32. """
  33. Returns the main BibFormat admin page.
  34. @param ln: language
  35. @param warnings: a list of warnings to display at top of page. None if no warning
  36. @param is_admin: indicate if user is authorized to use BibFormat
  37. @return: main BibFormat admin page
  38. """
  39. _ = gettext_set_language(ln) # load the right message language
  40. out = ''
  41. if warnings:
  42. out += '''
  43. <table width="66%%" class="errorbox" style="margin-left: auto; margin-right: auto;">
  44. <tr>
  45. <th class="errorboxheader">
  46. %(warnings)s
  47. </th>
  48. </tr>
  49. </table>
  50. ''' % {'warnings': '<br/>'.join(warnings)}
  51. out += '''
  52. <p>
  53. This is where you can edit the formatting styles available for the records. '''
  54. if not is_admin:
  55. out += '''You need to
  56. <a href="%(siteurl)s/youraccount/login?referer=%(siteurl)s/admin/bibformat/bibformatadmin.py">login</a> to enter.
  57. ''' % {'siteurl':CFG_SITE_URL}
  58. out += '''
  59. </p>
  60. <dl>
  61. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_templates_manage?ln=%(ln)s">Manage Format Templates</a></dt>
  62. <dd>Define how to format a record.</dd>
  63. </dl>
  64. <dl>
  65. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/output_formats_manage?ln=%(ln)s">Manage Output Formats</a></dt>
  66. <dd>Define which template is applied to which record for a given output.</dd>
  67. </dl>
  68. <br/>
  69. <dl>
  70. <dt><a href="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%(ln)s">Format Elements Documentation</a></dt>
  71. <dd>Documentation of the format elements to be used inside format templates.</dd>
  72. </dl>
  73. <dl>
  74. <dt><a href="%(siteurl)s/help/admin/bibformat-admin-guide">BibFormat Admin Guide</a></dt>
  75. <dd>Documentation about BibFormat administration</dd>
  76. </dl>
  77. '''% {'siteurl':CFG_SITE_URL, 'ln':ln}
  78. if CFG_PATH_PHP:
  79. #Show PHP admin only if PHP is enabled
  80. out += '''
  81. <br/><br/><br/><br/>
  82. <div style="background-color:rgb(204, 204, 204);">
  83. <h2><span style="color:rgb(204, 0, 0);">Old</span>
  84. BibFormat admin interface (in gray box)</h2>
  85. <em>
  86. <p>The BibFormat admin interface enables you to specify how the
  87. bibliographic data is presented to the end user in the search
  88. interface and search results pages. For example, you may specify that
  89. titles should be printed in bold font, the abstract in small italic,
  90. etc. Moreover, the BibFormat is not only a simple bibliographic data
  91. <em>output formatter</em>, but also an automated <em>link
  92. constructor</em>. For example, from the information on journal name
  93. and pages, it may automatically create links to publisher's site based
  94. on some configuration rules.
  95. <h2>Configuring BibFormat</h2>
  96. <p>By default, a simple HTML format based on the most common fields
  97. (title, author, abstract, keywords, fulltext link, etc) is defined.
  98. You certainly want to define your own ouput formats in case you have a
  99. specific metadata structure.
  100. <p>Here is a short guide of what you can configure:
  101. <blockquote>
  102. <dl>
  103. <dt><a href="BEH_display.php">Behaviours</a>
  104. <dd>Define one or more output BibFormat behaviours. These are then
  105. passed as parameters to the BibFormat modules while executing
  106. formatting.
  107. <br /><em>Example:</em> You can tell BibFormat that is has to enrich the
  108. incoming metadata file by the created format, or that it only has to
  109. print the format out.
  110. <dt><a href="OAIER_display.php">Extraction Rules</a>
  111. <dd>Define how the metadata tags from input are mapped into internal
  112. BibFormat variable names. The variable names can afterwards be used
  113. in formatting and linking rules.
  114. <br /><em>Example:</em> You can tell that <code>100 $a</code> field
  115. should be mapped into <code>$100.a</code> internal variable that you
  116. could use later.
  117. <dt><a href="LINK_display.php">Link Rules</a>
  118. <dd>Define rules for automated creation of URI links from mapped
  119. internal variables.
  120. <br /><em>Example:</em> You can tell a rule how to create a link to
  121. People database out of the <code>$100.a</code> internal variable
  122. repesenting author's name. (The <code>$100.a</code> variable was mapped
  123. in the previous step, see the Extraction Rules.)
  124. <dt><a href="LINK_FORMAT_display.php">File Formats</a>
  125. <dd>Define file format types based on file extensions. This will be
  126. used when proposing various fulltext services.
  127. <br /><em>Example:</em> You can tell that <code>*.pdf</code> files will
  128. be treated as PDF files.
  129. <dt><a href="UDF_display.php">User Defined Functions (UDFs)</a>
  130. <dd>Define your own functions that you can reuse when creating your
  131. own output formats. This enables you to do complex formatting without
  132. ever touching the BibFormat core code.
  133. <br /><em>Example:</em> You can define a function how to match and
  134. extract email addresses out of a text file.
  135. <dt><a href="FORMAT_display.php">Formats</a>
  136. <dd>Define the output formats, i.e. how to create the output out of
  137. internal BibFormat variables that were extracted in a previous step.
  138. This is the functionality you would want to configure most of the
  139. time. It may reuse formats, user defined functions, knowledge bases,
  140. etc.
  141. <br /><em>Example:</em> You can tell that authors should be printed in
  142. italic, that if there are more than 10 authors only the first three
  143. should be printed, etc.
  144. <dt><a href="KB_display.php">Knowledge Bases (KBs)</a>
  145. <dd>Define one or more knowledge bases that enables you to transform
  146. various forms of input data values into the unique standard form on
  147. the output.
  148. <br /><em>Example:</em> You can tell that <em>Phys Rev D</em> and
  149. <em>Physical Review D</em> are both the same journal and that these
  150. names should be standardized to <em>Phys Rev : D</em>.
  151. <dt><a href="test.php">Execution Test</a>
  152. <dd>Enables you to test your formats on your sample data file. Useful
  153. when debugging newly created formats.
  154. </dl>
  155. </blockquote>
  156. <p>To learn more on BibFormat configuration, you can consult the <a
  157. href="guide.html">BibFormat Admin Guide</a>.</small>
  158. <h2>Running BibFormat</h2>
  159. <h3>From the Web interface</h3>
  160. <p>
  161. Run <a href="BIBREFORMAT_display.php">Reformat Records</a> tool.
  162. This tool permits you to update stored formats for bibliographic records.
  163. <br />
  164. It should normally be used after configuring BibFormat's
  165. <a href="BEH_display.php">Behaviours</a> and
  166. <a href="FORMAT_display.php">Formats</a>.
  167. When these are ready, you can choose to rebuild formats for selected
  168. collections or you can manually enter a search query and the web interface
  169. will accomplish all necessary formatting steps.
  170. <br />
  171. <i>Example:</i> You can request Photo collections to have their HTML
  172. brief formats rebuilt, or you can reformat all the records written by Ellis.
  173. <h3>From the command-line interface</h3>
  174. <p>Consider having an XML MARC data file that is to be uploaded into
  175. the CDS Invenio. (For example, it might have been harvested from other
  176. sources and processed via <a href="../bibconvert/">BibConvert</a>.)
  177. Having configured BibFormat and its default output type behaviour, you
  178. would then run this file throught BibFormat as follows:
  179. <blockquote>
  180. <pre>
  181. $ bibformat < /tmp/sample.xml > /tmp/sample_with_fmt.xml
  182. <pre>
  183. </blockquote>
  184. that would create default HTML formats and would "enrich" the input
  185. XML data file by this format. (You would then continue the upload
  186. procedure by calling successively <a
  187. href="../bibupload/">BibUpload</a> and <a
  188. href="../bibindex/">BibIndex</a>.)
  189. <p>Now consider a different situation. You would like to add a new
  190. possible format, say "HTML portfolio" and "HTML captions" in order to
  191. nicely format multiple photographs in one page. Let us suppose that
  192. these two formats are called <code>hp</code> and <code>hc</code> and
  193. are already loaded in the <code>collection_format</code> table.
  194. (TODO: describe how this is done via WebAdmin.) You would then
  195. proceed as follows: firstly, you would prepare the corresponding <a
  196. href="BEH_display.php">output behaviours</a> called <code>HP</code>
  197. and <code>HC</code> (TODO: note the uppercase!) that would not enrich
  198. the input file but that would produce an XML file with only
  199. <code>001</code> and <code>FMT</code> tags. (This is in order not to
  200. update the bibliographic information but the formats only.) You would
  201. also prepare corresponding <a href="FORMAT_display.php">formats</a>
  202. at the same time. Secondly, you would launch the formatting as
  203. follows:
  204. <blockquote>
  205. <pre>
  206. $ bibformat otype=HP,HC < /tmp/sample.xml > /tmp/sample_fmts_only.xml
  207. <pre>
  208. </blockquote>
  209. that should give you an XML file containing only 001 and FMT tags.
  210. Finally, you would upload the formats:
  211. <blockquote>
  212. <pre>
  213. $ bibupload < /tmp/sample_fmts_only.xml
  214. <pre>
  215. </blockquote>
  216. and that's it. The new formats should now appear in <a
  217. href="%(siteurl)s">WebSearch</a>.
  218. </em>
  219. </div>
  220. ''' % {'siteurl':CFG_SITE_URL, 'ln':ln}
  221. return out
  222. def tmpl_admin_format_template_show_attributes(self, ln, name, description, filename, editable,
  223. all_templates=[], new=False):
  224. """
  225. Returns a page to change format template name and description
  226. If template is new, offer a way to create a duplicate from an
  227. existing template
  228. @param ln: language
  229. @param name: the name of the format
  230. @param description: the description of the format
  231. @param filename: the filename of the template
  232. @param editable: True if we let user edit, else False
  233. @param all_templates: a list of tuples (filename, name) of all other templates
  234. @param new: if True, the format template has just been added (is new)
  235. @return: editor for 'format'
  236. """
  237. _ = gettext_set_language(ln) # load the right message language
  238. out = ""
  239. out += '''
  240. <table class="admin_wvar" cellspacing="0">
  241. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  242. <tr>
  243. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a></small>&nbsp;</td>
  244. <td>1.&nbsp;<small><a href="format_template_show?ln=%(ln)s&amp;bft=%(filename)s">%(template_editor)s</a></small>&nbsp;</td>
  245. <td>2.&nbsp;<small>%(modify_template_attributes)s</small>&nbsp;</td>
  246. <td>3.&nbsp;<small><a href="format_template_show_dependencies?ln=%(ln)s&amp;bft=%(filename)s">%(check_dependencies)s</a></small>&nbsp;</td>
  247. </tr>
  248. </table><br/>
  249. ''' % {'ln':ln,
  250. 'menu':_("Menu"),
  251. 'filename':filename,
  252. 'close_editor': _("Close Editor"),
  253. 'modify_template_attributes': _("Modify Template Attributes"),
  254. 'template_editor': _("Template Editor"),
  255. 'check_dependencies': _("Check Dependencies")
  256. }
  257. disabled = ""
  258. readonly = ""
  259. if not editable:
  260. disabled = 'disabled="disabled"'
  261. readonly = 'readonly="readonly"'
  262. out += '''
  263. <form action="format_template_update_attributes?ln=%(ln)s&amp;bft=%(filename)s" method="POST">
  264. ''' % {'ln':ln,
  265. 'filename':filename}
  266. if new:
  267. #Offer the possibility to make a duplicate of existing format template code
  268. out += '''
  269. <table><tr>
  270. <th class="adminheaderleft">Make a copy of format template:&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#addFormatTemplate">?</a>]</th>
  271. </tr>
  272. <tr>
  273. <td><select tabindex="1" name="duplicate" id="duplicate" %(readonly)s>
  274. <option value="">None (Blank Page)</option>
  275. <option value="" disabled="disabled">-------------</option>
  276. ''' % {'siteurl': CFG_SITE_URL,
  277. 'readonly':readonly}
  278. for (o_filename, o_name) in all_templates:
  279. out += '''<option value="%(template_filename)s">%(template_name)s</option>''' % {'template_name':o_name,
  280. 'template_filename': o_filename}
  281. out += ''' </select>
  282. </td></tr></table>'''
  283. out += '''
  284. <table><tr>
  285. <th colspan="2" class="adminheaderleft">%(name)s attributes&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#attrsFormatTemplate">?</a>]</th>
  286. </tr>
  287. <tr>
  288. <td class="admintdright">
  289. <input type="hidden" name="key" value="%(name)s"/>
  290. <label for="name">%(name_label)s</label>:&nbsp;</td>
  291. <td><input tabindex="2" name="name" type="text" id="name" size="25" value="%(name)s" %(readonly)s/>
  292. <input type="hidden" value="%(filename)s"/>
  293. </td>
  294. </tr>
  295. ''' % {"name": name,
  296. 'ln':ln,
  297. 'filename':filename,
  298. 'disabled':disabled,
  299. 'readonly':readonly,
  300. 'name_label': _("Name"),
  301. 'siteurl':CFG_SITE_URL
  302. }
  303. out += '''
  304. <tr>
  305. <td class="admintdright" valign="top"><label for="description">%(description_label)s</label>:&nbsp;</td>
  306. <td><textarea tabindex="3" name="description" id="description" rows="4" cols="25" %(readonly)s>%(description)s</textarea> </td>
  307. </tr>
  308. <tr>
  309. <td>&nbsp;</td>
  310. <td align="right"><input tabindex="6" class="adminbutton" type="submit" value="%(update_format_attributes)s" %(disabled)s/></td>
  311. </tr>
  312. </table></form>
  313. ''' % {"description": description,
  314. 'ln':ln,
  315. 'filename':filename,
  316. 'disabled':disabled,
  317. 'readonly':readonly,
  318. 'description_label': _("Description"),
  319. 'update_format_attributes': _("Update Format Attributes"),
  320. 'siteurl':CFG_SITE_URL
  321. }
  322. return out
  323. def tmpl_admin_format_template_show_dependencies(self, ln, name, filename, output_formats, format_elements, tags):
  324. """
  325. Shows the dependencies (on elements) of the given format.
  326. @param name: the name of the template
  327. @param filename: the filename of the template
  328. @param format_elements: the elements (and list of tags in each element) this template depends on
  329. @param output_formats: the output format that depend on this template
  330. @param tags: the tags that are called by format elements this template depends on.
  331. """
  332. _ = gettext_set_language(ln) # load the right message language
  333. out = '''
  334. <table class="admin_wvar" cellspacing="0">
  335. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  336. <tr>
  337. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a>&nbsp;</small></td>
  338. <td>1.&nbsp;<small><a href="format_template_show?ln=%(ln)s&amp;bft=%(filename)s">%(template_editor)s</a></small>&nbsp;</td>
  339. <td>2.&nbsp;<small><a href="format_template_show_attributes?ln=%(ln)s&amp;bft=%(filename)s">%(modify_template_attributes)s</a></small>&nbsp;</td>
  340. <td>3.&nbsp;<small>%(check_dependencies)s</small>&nbsp;</td>
  341. </tr>
  342. </table>
  343. <table width="90%%" class="admin_wvar" cellspacing="0"><tr>
  344. <th class="adminheaderleft">Output Formats that use %(name)s</th>
  345. <th class="adminheaderleft">Format Elements used by %(name)s*</th>
  346. <th class="adminheaderleft">All Tags Called*</th>
  347. </tr>
  348. <tr>
  349. <td valign="top">&nbsp;<br/>
  350. ''' % {'ln':ln,
  351. 'filename':filename,
  352. 'menu': _("Menu"),
  353. 'close_editor': _("Close Editor"),
  354. 'modify_template_attributes': _("Modify Template Attributes"),
  355. 'template_editor': _("Template Editor"),
  356. 'check_dependencies': _("Check Dependencies"),
  357. 'name': name }
  358. #Print output formats
  359. if len(output_formats) == 0:
  360. out += '<p align="center"><i>No output format uses this format template.</i></p>'
  361. for output_format in output_formats:
  362. name = output_format['names']['generic']
  363. filename = output_format['filename']
  364. out += ''' <a href="output_format_show?ln=%(ln)s&amp;bfo=%(filename)s">%(name)s</a>''' % {'filename':filename,
  365. 'name':name,
  366. 'ln':ln}
  367. if len(output_format['tags']) > 0:
  368. out += "("+", ".join(output_format['tags'])+")"
  369. out += "<br/>"
  370. #Print format elements (and tags)
  371. out += '</td><td valign="top">&nbsp;<br/>'
  372. if len(format_elements) == 0:
  373. out += '<p align="center"><i>This format template uses no format element.</i></p>'
  374. for format_element in format_elements:
  375. name = format_element['name']
  376. out += ''' <a href="format_elements_doc?ln=%(ln)s#%(anchor)s">%(name)s</a>''' % {'name':"bfe_"+name.lower(),
  377. 'anchor':name.upper(),
  378. 'ln':ln}
  379. if len(format_element['tags']) > 0:
  380. out += "("+", ".join(format_element['tags'])+")"
  381. out += "<br/>"
  382. #Print tags
  383. out += '</td><td valign="top">&nbsp;<br/>'
  384. if len(tags) == 0:
  385. out += '<p align="center"><i>This format template uses no tag.</i></p>'
  386. for tag in tags:
  387. out += '''%(tag)s<br/>''' % { 'tag':tag}
  388. out += '''
  389. </td>
  390. </tr>
  391. </table>
  392. <b>*Note</b>: Some tags linked with this format template might not be shown. Check manually.
  393. '''
  394. return out
  395. def tmpl_admin_format_template_show(self, ln, name, description, code, filename, ln_for_preview, pattern_for_preview, editable, content_type_for_preview, content_types):
  396. """
  397. Returns the editor for format templates. Edit 'format'
  398. @param ln: language
  399. @param format: the format to edit
  400. @param filename: the filename of the template
  401. @param ln_for_preview: the language for the preview (for bfo)
  402. @param pattern_for_preview: the search pattern to be used for the preview (for bfo)
  403. @param editable: True if we let user edit, else False
  404. @param code: the code of the template of the editor
  405. @return: editor for 'format'
  406. """
  407. _ = gettext_set_language(ln) # load the right message language
  408. out = ""
  409. # If xsl, hide some options in the menu
  410. nb_menu_options = 4
  411. if filename.endswith('.xsl'):
  412. nb_menu_options = 2
  413. out += '''
  414. <style type="text/css">
  415. <!--
  416. .ed_button {
  417. font-size: x-small;
  418. }
  419. -->
  420. </style>
  421. <script src="%(siteurl)s/admin/bibformat/js_quicktags.js" type="text/javascript"></script>
  422. <script type="text/javascript">
  423. /* Ask user confirmation before leaving page */
  424. var user_must_confirm_before_leaving_page = false;
  425. window.onbeforeunload = confirmExit;
  426. function confirmExit() {
  427. if (user_must_confirm_before_leaving_page)
  428. return "%(leave_editor_message)s";
  429. }
  430. function getByID( id ) {
  431. if (document.getElementById)
  432. var returnVar = document.getElementById(id);
  433. else if (document.all)
  434. var returnVar = document.all[id];
  435. else if (document.layers)
  436. var returnVar = document.layers[id];
  437. return returnVar;
  438. }
  439. window.onresize= resizeViews;
  440. window.onload= prepareLayout;
  441. function prepareLayout(){
  442. resizeViews();
  443. }
  444. function resizeViews(){
  445. var myWidth = 0, myHeight = 0;
  446. if( typeof( window.innerWidth ) == 'number' ) {
  447. //Non-IE
  448. myWidth = window.innerWidth;
  449. myHeight = window.innerHeight;
  450. } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  451. //IE 6+ in 'standards compliant mode'
  452. myWidth = document.documentElement.clientWidth;
  453. myHeight = document.documentElement.clientHeight;
  454. } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  455. //IE 4 compatible
  456. myWidth = document.body.clientWidth;
  457. myHeight = document.body.clientHeight;
  458. }
  459. if (myHeight <= 400) {
  460. getByID("code").style.height=10;
  461. getByID("previewiframe").style.height=10;
  462. } else{
  463. getByID("code").style.height=((myHeight-400)/2);
  464. getByID("previewiframe").style.height=((myHeight-400)/2);
  465. }
  466. getByID("previewiframe").style.height=200;
  467. // Resize documentation
  468. var height = document.documentElement.clientHeight;
  469. height -= getByID('shortDocFrame').offsetTop
  470. //height -= 20;
  471. getByID('shortDocFrame').style.height = height +"px";
  472. }
  473. </script>
  474. <table class="admin_wvar" cellspacing="0">
  475. <tr><th colspan="%(nb_menu_options)s" class="adminheaderleft">%(menu)s</th></tr>
  476. <tr>
  477. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(close_editor)s</a></small>&nbsp;</td>
  478. <td>1.&nbsp;<small>%(template_editor)s</small>&nbsp;</td>
  479. ''' % {'ln': ln, 'filename': filename,
  480. 'menu': _("Menu"),
  481. 'label_show_doc': _("Show Documentation"),
  482. 'label_hide_doc': _("Hide Documentation"),
  483. 'close_editor': _("Close Editor"),
  484. 'modify_template_attributes': _("Modify Template Attributes"),
  485. 'template_editor': _("Template Editor"),
  486. 'check_dependencies': _("Check Dependencies"),
  487. 'nb_menu_options': nb_menu_options,
  488. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL,
  489. 'leave_editor_message': _('Your modifications will not be saved.').replace('"', '\\"')
  490. }
  491. if not filename.endswith('.xsl'):
  492. out +='''<td>2.&nbsp;<small><a href="format_template_show_attributes?ln=%(ln)s&amp;bft=%(filename)s">%(modify_template_attributes)s</a></small>&nbsp;</td>
  493. <td>3.&nbsp;<small><a href="format_template_show_dependencies?ln=%(ln)s&amp;bft=%(filename)s">%(check_dependencies)s</a></small>&nbsp;</td>
  494. ''' % {'ln': ln, 'filename': filename,
  495. 'menu': _("Menu"),
  496. 'label_show_doc': _("Show Documentation"),
  497. 'label_hide_doc': _("Hide Documentation"),
  498. 'close_editor': _("Close Editor"),
  499. 'modify_template_attributes': _("Modify Template Attributes"),
  500. 'template_editor': _("Template Editor"),
  501. 'check_dependencies': _("Check Dependencies"),
  502. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL
  503. }
  504. out +='''
  505. </tr>
  506. </table>
  507. <script type="text/javascript">
  508. function toggle_doc_visibility(){
  509. var doc = document.getElementById('docTable');
  510. var link = document.getElementById('docLink');
  511. if (doc.style.display=='none'){
  512. doc.style.display = '';
  513. link.innerHTML = "%(label_hide_doc)s"
  514. } else {
  515. doc.style.display = 'none';
  516. link.innerHTML = "%(label_show_doc)s"
  517. }
  518. }
  519. </script>
  520. ''' % {'ln': ln, 'filename': filename,
  521. 'menu': _("Menu"),
  522. 'label_show_doc': _("Show Documentation"),
  523. 'label_hide_doc': _("Hide Documentation"),
  524. 'close_editor': _("Close Editor"),
  525. 'modify_template_attributes': _("Modify Template Attributes"),
  526. 'template_editor': _("Template Editor"),
  527. 'check_dependencies': _("Check Dependencies"),
  528. 'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL
  529. }
  530. disabled = ""
  531. readonly = ""
  532. toolbar = """<script type="text/javascript">edToolbar('%s/admin/bibformat/bibformatadmin.py/format_elements_doc?ln=%s');</script>""" % (CFG_SITE_URL, ln)
  533. if not editable:
  534. disabled = 'disabled="disabled"'
  535. readonly = 'readonly="readonly"'
  536. toolbar = ''
  537. #First column: template code and preview
  538. out += '''
  539. <table width="90%%" cellspacing="5">
  540. <tr>
  541. <td valign="top">
  542. <form action="format_template_show_preview_or_save?ln=%(ln)s&amp;bft=%(filename)s" method="POST" target="previewiframe">
  543. <table width="100%%" id="mainTable"><tr>
  544. <th class="adminheaderleft"><div style="float:left;">Format template code</div>
  545. <div style="float:right;">
  546. <a id="docLink" href="#" onclick="toggle_doc_visibility()">%(label_hide_doc)s</a>
  547. </div>
  548. </th>
  549. </tr>
  550. <tr><td colspan="2" id="codetd">
  551. %(toolbar)s
  552. <textarea name="code" id="code" rows="25" %(readonly)s
  553. style="width:100%%" onchange="user_must_confirm_before_leaving_page=true;">%(code)s</textarea>
  554. <script type="text/javascript">var edCanvas = document.getElementById('code');</script>
  555. </td></tr>
  556. <tr><td align="right" valign="top">
  557. <input type="submit" class="adminbutton" name="save_action" value="Save Changes" onclick="user_must_confirm_before_leaving_page=false;" %(disabled)s/>
  558. </td>
  559. </tr>
  560. </table>
  561. <table width="100%%">
  562. <tr><th class="adminheaderleft">
  563. Preview
  564. </th>
  565. </tr>
  566. <tr><td align="right" valign="top" style="font-size: small;">
  567. <nobr>
  568. <label for="content_type_for_preview">Content-type (MIME):</label> <select id="content_type_for_preview" name="content_type_for_preview" style="font-size: x-small;">
  569. ''' % {'ln':ln,
  570. 'siteurl':CFG_SITE_URL,
  571. 'filename':filename,
  572. 'label_hide_doc':_("Hide Documentation"),
  573. 'code':code,
  574. 'readonly':readonly,
  575. 'disabled':disabled,
  576. 'toolbar':toolbar}
  577. for content_type in content_types:
  578. if content_type == content_type_for_preview:
  579. out += '''<option value="%(content_type)s" selected="selected">%(content_type)s</option>''' % {'content_type':content_type}
  580. else:
  581. out += '''<option value="%(content_type)s">%(content_type)s</option>''' % {'content_type':content_type}
  582. out += '''
  583. </select></nobr>
  584. <nobr><label for="ln_for_preview">Language:</label> <select id="ln_for_preview" name="ln_for_preview" style="font-size: x-small;">
  585. '''
  586. for lang in language_list_long():
  587. if lang[0] == ln_for_preview:
  588. out += '''<option value="%(ln)s" selected="selected">%(language)s</option>''' % {'ln':lang[0],
  589. 'language':lang[1]}
  590. else:
  591. out += '''<option value="%(ln)s">%(language)s</option>''' % {'ln':lang[0], 'language':lang[1]}
  592. out += '''
  593. </select></nobr>
  594. &nbsp;
  595. <nobr><label for="pattern_for_preview">Search Pattern: </label><input type="text" value="%(pattern_for_preview)s" size="8" name="pattern_for_preview" id="pattern_for_preview" style="font-size: x-small;"/></nobr>&nbsp;
  596. <input type="submit" class="adminbutton" name="preview_action" value="Reload Preview"/>
  597. </td>
  598. </tr>
  599. <tr><td>
  600. <iframe src ="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_template_show_preview_or_save?ln=%(ln)s&amp;ln_for_preview=%(ln_for_preview)s&amp;pattern_for_preview=%(pattern_for_preview)s&amp;bft=%(filename)s" name="previewiframe" id="previewiframe" width="100%%" height="400"></iframe>
  601. </td></tr>
  602. </table>
  603. </form>
  604. </td>
  605. ''' % {'code':code, 'ln':ln,
  606. 'siteurl':CFG_SITE_URL, 'filename':filename,
  607. 'ln_for_preview':ln_for_preview,
  608. 'pattern_for_preview':pattern_for_preview
  609. }
  610. #Second column Print documentation
  611. out += '''
  612. <td valign="top" id="docTable">
  613. <table width="100%%"><tr>
  614. <th class="adminheaderleft">Elements Documentation</th>
  615. </tr>
  616. </table>
  617. <table width="100%%"><tr>
  618. <td class="admintdright">
  619. <form action="format_template_show_short_doc?ln=%(ln)s" method="POST" target="shortDocFrame">
  620. <nobr><label for="search_doc_pattern">Search for:&nbsp;</label><input type="text" size="15" name="search_doc_pattern" id="search_doc_pattern" value=""/> <input type="submit" class="adminbutton" name="search_in_doc" value="Search" /></nobr>
  621. </form>
  622. </td>
  623. </tr>
  624. </table>
  625. <iframe name="shortDocFrame" id="shortDocFrame" src ="%(siteurl)s/admin/bibformat/bibformatadmin.py/format_template_show_short_doc?ln=%(ln)s" height="90%%" width="98%%"></iframe>
  626. </td>
  627. </tr>
  628. </table>
  629. ''' % {'siteurl':CFG_SITE_URL, 'ln':ln}
  630. return out
  631. def tmpl_admin_format_template_show_short_doc(self, ln, format_elements):
  632. """
  633. Prints the format element documentation in a condensed way to display
  634. inside format template editor.
  635. This page is different from others: it is displayed inside a <iframe>
  636. tag in template tmpl_admin_format_template_show.
  637. @param ln: language
  638. @param format_elements: a list of format elements structures as returned by get_format_elements
  639. """
  640. out = '''
  641. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  642. <html>
  643. <head>
  644. <title>BibFormat Short Documentation of Format Elements</title>
  645. <link rel="stylesheet" href="%(siteurl)s/img/invenio.css">
  646. <script src="%(siteurl)s/admin/bibformat/js_quicktags.js" type="text/javascript"></script>
  647. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  648. </head>
  649. <body>
  650. <script type="text/javascript">
  651. function toggle_visibility(element, show, r,g,b){
  652. var children = element.childNodes
  653. var child
  654. for(x=0; x<children.length; x++){
  655. if (children[x].id == 'params'){
  656. child = children[x]
  657. }
  658. }
  659. if (show=='show'){
  660. element.style.background='rgb(201, 218, 255)'
  661. element.style.cursor='pointer'
  662. child.style.display=''
  663. } else {
  664. element.style.background="rgb("+r+","+g+","+b+")"
  665. child.style.display='none'
  666. }
  667. }
  668. ///// FROM JS QuickTags ///////
  669. // Copyright (c) 2002-2005 Alex King
  670. // http://www.alexking.org/
  671. //
  672. // Licensed under the LGPL license
  673. // http://www.gnu.org/copyleft/lesser.html
  674. function insertAtCursor(myField, myValue) {
  675. //IE support
  676. if (document.selection) {
  677. myField.focus();
  678. sel = document.selection.createRange();
  679. sel.text = myValue;
  680. }
  681. //MOZILLA/NETSCAPE support
  682. else if (myField.selectionStart || myField.selectionStart == '0') {
  683. var startPos = myField.selectionStart;
  684. var endPos = myField.selectionEnd;
  685. myField.value = myField.value.substring(0, startPos)
  686. + myValue
  687. + myField.value.substring(endPos, myField.value.length);
  688. } else {
  689. myField.value += myValue;
  690. }
  691. }
  692. ///// END FROM JS QuickTags /////
  693. function insert_my_code_into_container(code){
  694. var codeArea = parent.document.getElementById("code");
  695. if (codeArea.readOnly == false){
  696. //var clean_code = code.replace(=#,'="');
  697. //clean_code = clean_code.replace(# ,'" ');
  698. insertAtCursor(codeArea, code);
  699. }
  700. }
  701. </script>
  702. ''' % {'siteurl': CFG_SITE_SECURE_URL or CFG_SITE_URL}
  703. if len(format_elements) == 0:
  704. out += '''
  705. <em>No format elements found</em>
  706. '''
  707. else:
  708. line = 0
  709. #Print elements doc
  710. for format_element in format_elements:
  711. format_attributes = format_element['attrs']
  712. row_content = ""
  713. name = format_attributes['name']
  714. description = format_attributes['description']
  715. params = [x['name'] + '=\u0022'+str(x['default'])+'\u0022' for x in format_attributes['params']]
  716. builtin_params = [x['name'] + '=\u0022'+str(x['default'])+'\u0022' for x in format_attributes['builtin_params']]
  717. code = "<BFE_" + name + ' ' + ' '.join(builtin_params)+ ' ' + ' '.join(params) +"/>"
  718. if line % 2:
  719. row_content += '''<div onmouseover="toggle_visibility(this, 'show', 235, 247, 255);"
  720. onmouseout="toggle_visibility(this, 'hide', 235, 247, 255);"
  721. style="background-color: rgb(235, 247, 255);"
  722. onclick="insert_my_code_into_container('%s')"
  723. ><hr/>''' % code
  724. else:
  725. row_content += '''<div onmouseover="toggle_visibility(this, 'show', 255, 255, 255);"
  726. onmouseout="toggle_visibility(this, 'hide', 255, 255, 255);"
  727. onclick="insert_my_code_into_container('%s')"
  728. >''' % code
  729. params_names = ""
  730. for param in format_attributes['params']:
  731. params_names += "<b>"+param['name'] +'</b> '
  732. row_content += '''
  733. <code> <b>&lt;BFE_%(name)s/&gt;</b><br/></code>
  734. <small>%(description)s.</small>
  735. <div id="params" style="display:none;">
  736. <ul>
  737. ''' % {'params_names':params_names, 'name':name, 'description':description}
  738. for param in format_attributes['params']:
  739. row_content += '''
  740. <li><small><b>%(name)s</b>:&nbsp;%(description)s</small></li>
  741. ''' % {'name':param['name'],
  742. 'description':param['description']}
  743. for param in format_attributes['builtin_params']:
  744. row_content += '''
  745. <li><small><b>%(name)s</b>:&nbsp;%(description)s</small></li>
  746. ''' % {'name':param['name'],
  747. 'description':param['description']}
  748. row_content += '</ul></div>'
  749. if line % 2:
  750. row_content += '''<hr/></div>'''
  751. else:
  752. row_content += '</div>'
  753. line += 1
  754. out += row_content
  755. out += '''</body></html>'''
  756. return out
  757. def tmpl_admin_format_templates_management(self, ln, formats):
  758. """
  759. Returns the management console for formats. Includes list of formats and
  760. associated administration tools.
  761. @param ln: language
  762. @param formats: a list of dictionaries with formats attributes
  763. @return: format management console as html
  764. """
  765. _ = gettext_set_language(ln) # load the right message language
  766. #top of the page and table header
  767. out = '''
  768. <table class="admin_wvar" cellspacing="0">
  769. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  770. <tr>
  771. <td>0.&nbsp;<small>%(manage_format_templates)s</small>&nbsp;</td>
  772. <td>1.&nbsp;<small><a href="output_formats_manage?ln=%(ln)s">%(manage_output_formats)s</a>&nbsp;</td>
  773. <td>2.&nbsp;<small><a href="format_elements_doc?ln=%(ln)s">%(format_elements_documentation)s</a></small>&nbsp;</td>
  774. </tr>
  775. </table>
  776. <p>From here you can create, edit or delete formats templates.
  777. Have a look at the <a href="format_elements_doc?ln=%(ln)s">format elements documentation</a> to
  778. learn which elements you can use in your templates.</p>
  779. <table class="admin_wvar" width="95%%" cellspacing="0">
  780. <tr>
  781. <th class="adminheaderleft" >&nbsp;</th>
  782. <th class="adminheaderleft" >%(name)s</th>
  783. <th class="adminheaderleft" >%(description)s</th>
  784. <th class="adminheaderleft" >%(status)s</th>
  785. <th class="adminheaderleft" >%(last_modification_date)s</th>
  786. <th class="adminheadercenter" >%(action)s&nbsp;&nbsp;&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#formatTemplates">?</a>]</th>
  787. </tr>
  788. ''' % {'name':_("Name"),
  789. 'description':_("Description"),
  790. 'menu': _("Menu"),
  791. 'status':_("Status"),
  792. 'last_modification_date':_("Last Modification Date"),
  793. 'action':_("Action"),
  794. 'ln':ln,
  795. 'manage_output_formats':_("Manage Output Formats"),
  796. 'manage_format_templates':_("Manage Format Templates"),
  797. 'format_elements_documentation':_("Format Elements Documentation"),
  798. 'siteurl':CFG_SITE_URL}
  799. #table content: formats names, description and buttons
  800. if len(formats) == 0:
  801. out += '''<tr>
  802. <td colspan="6" class="admintd" align="center"><em>No format</em></td>
  803. </tr>'''
  804. else:
  805. line = 0
  806. for attrs in formats:
  807. filename = attrs['filename']
  808. if filename == "":
  809. filename = "&nbsp;"
  810. name = attrs['name']
  811. if name == "":
  812. name = "&nbsp;"
  813. description = attrs['description']
  814. if description == "":
  815. description = "&nbsp;"
  816. last_mod_date = attrs['last_mod_date']
  817. status = attrs['status']
  818. disabled = ""
  819. if not attrs['editable']:
  820. disabled = 'disabled="disabled"'
  821. style = 'style="vertical-align: middle;'
  822. if line % 2:
  823. style = 'style="vertical-align: middle;background-color: rgb(235, 247, 255);'
  824. line += 1
  825. row_content = '''<tr>
  826. <td class="admintdright" %(style)s">&nbsp;</td>
  827. <td class="admintdleft" %(style)s white-space: nowrap;"><a href="format_template_show?bft=%(filename)s&amp;ln=%(ln)s">%(name)s</a></td>
  828. <td class="admintdleft" %(style)s" >%(description)s</td>
  829. <td class="admintdleft" %(style)s white-space: nowrap;" >%(status)s</td>
  830. <td class="admintdleft" %(style)s white-space: nowrap;" >%(last_mod_date)s</td>
  831. <td class="admintd" %(style)s white-space: nowrap;">
  832. <form method="post" action="format_template_delete?ln=%(ln)s&amp;bft=%(filename)s">
  833. <input class="adminbutton" type="submit" value="%(delete)s" %(disabled)s/>
  834. </form>
  835. </td>
  836. </tr>
  837. ''' % {'filename':filename,
  838. 'name':name,
  839. 'description':description,
  840. 'ln':ln,
  841. 'style':style,
  842. 'disabled':disabled,
  843. 'last_mod_date':last_mod_date,
  844. 'status':status,
  845. 'delete':_("Delete")
  846. }
  847. out += row_content
  848. #table footer, buttons and bottom of the page
  849. out += '''
  850. <tr>
  851. <td align="left" colspan="3">
  852. <form action="format_templates_manage?ln=%(ln)s">
  853. <input type="hidden" name="checking" value="1"></input>
  854. <input class="adminbutton" type="submit" value="%(extensive_checking)s"/>
  855. </form>
  856. </td>
  857. <td align="right" colspan="3">
  858. <form action="format_template_add?ln=%(ln)s">
  859. <input class="adminbutton" type="submit" value="%(add_format_template)s"/>
  860. </form>
  861. </td>
  862. </tr>
  863. </table>
  864. ''' % {'ln':ln,
  865. 'add_format_template':_("Add New Format Template"),
  866. 'extensive_checking':_("Check Format Templates Extensively")}
  867. return out
  868. def tmpl_admin_output_formats_management(self, ln, output_formats):
  869. """
  870. Returns the main management console for formats. Includes list of formats and
  871. associated administration tools.
  872. @param ln: language
  873. @param output_formats: a list of output formats
  874. @return: main management console as html
  875. """
  876. _ = gettext_set_language(ln) # load the right message language
  877. #top of the page and table header
  878. out = '''
  879. <table class="admin_wvar" cellspacing="0">
  880. <tr><th colspan="4" class="adminheaderleft">%(menu)s</th></tr>
  881. <tr>
  882. <td>0.&nbsp;<small><a href="format_templates_manage?ln=%(ln)s">%(manage_format_templates)s</a></small>&nbsp;</td>
  883. <td>1.&nbsp;<small>%(manage_output_formats)s</small>&nbsp;</td>
  884. <td>2.&nbsp;<small><a href="format_elements_doc?ln=%(ln)s">%(format_elements_documentation)s</a></small>&nbsp;</td>
  885. </tr>
  886. </table>
  887. <p>From here you can add, edit or delete output formats available for collections. Output formats define which template to use. <br/>To edit templates go to the <a href="format_templates_manage?ln=%(ln)s">template administration page</a>.</p>
  888. <table class="admin_wvar" width="95%%" cellspacing="0">
  889. <tr>
  890. <th class="adminheaderleft" >&nbsp;</th>
  891. <th class="adminheaderleft" ><a href="output_formats_manage?ln=%(ln)s&amp;sortby=code">%(code)s</a></th>
  892. <th class="adminheaderleft" ><a href="output_formats_manage?ln=%(ln)s&amp;sortby=name">%(name)s</a></th>
  893. <th class="adminheaderleft" >%(description)s</th>
  894. <th class="adminheaderleft" >%(status)s</th>
  895. <th class="adminheaderleft" >%(last_modification_date)s</th>
  896. <th class="adminheadercenter" >%(action)s&nbsp;&nbsp;&nbsp;[<a href="%(siteurl)s/help/admin/bibformat-admin-guide#outputFormats">?</a>]</th>
  897. </tr>
  898. ''' % {'code':_("Code"),
  899. 'name':_("Name"),
  900. 'description':_("Description"),
  901. 'status':_("Status"),
  902. 'last_modification_date':_("Last Modification Date"),
  903. 'action':_("Action"),
  904. 'ln':ln,
  905. 'manage_output_formats':_("Manage Output Formats"),
  906. 'manage_format_templates':_("Manage Format Templates"),
  907. 'format_elements_documentation':_("Format Elements Documentation"),
  908. 'menu': _("Menu"),
  909. 'siteurl':CFG_SITE_URL}
  910. #table content: formats names, description and buttons
  911. if len(output_formats) == 0:
  912. out += '''<tr>
  913. <td colspan="5" class="admintd" align="center"><em>No format</em></td>
  914. </tr>'''
  915. else:
  916. line = 0
  917. for output_format in output_formats:
  918. format_attributes = output_format['attrs']
  919. name = format_attributes['names']['generic']
  920. if name == "":
  921. name = "&nbsp;"
  922. description = format_attributes['description']
  923. if description == "":
  924. description = "&nbsp;"
  925. code = format_attributes['code']
  926. if code == "":
  927. code = "&nbsp;"
  928. last_mod_date = output_format['last_mod_date']
  929. status = output_format['status']
  930. disabled = ""
  931. if not output_format['editable']:
  932. disabled = 'disabled="disabled"'
  933. style = "vertical-align: middle;"
  934. if line % 2:
  935. style = 'vertical-align: middle; background-color: rgb(235, 247, 255);'
  936. line += 1
  937. row_content = '''<tr>
  938. <td class="admintdright" style="%(style)s">&nbsp;</td>
  939. <td class="admintdleft" style="white-space: nowrap; %(style)s">
  940. <a href="output_format_show?bfo=%(code)s">%(code)s</a>
  941. </td>
  942. <td class="admintdleft" style="white-space: nowrap; %(style)s">
  943. <a href="output_format_show?bfo=%(code)s">%(name)s</a>
  944. </td>
  945. <td class="admintdleft"style="%(style)s" >
  946. %(description)s
  947. </td>
  948. <td class="admintd" style="white-space: nowrap; %(style)s" >%(status)s</td>
  949. <td class="admintdleft" style="white-space: nowrap;%(style)s" >%(last_mod_date)s</td>
  950. <td class="admintd" style="white-space: nowrap; %(style)s">
  951. <form method="POST" action="output_format_delete?ln=%(ln)s&amp;bfo=%(code)s">
  952. <input class="adminbutton" type="submit" value="Delete" %(disabled)s />
  953. </form>
  954. </td>
  955. </tr>
  956. ''' % {'style':style,
  957. 'code':code,
  958. 'description':description,
  959. 'name':name,
  960. 'ln':ln,
  961. 'disabled':disabled,
  962. 'last_mod_date':last_mod_date,
  963. 'status':status}
  964. out += row_content
  965. #table footer, buttons and bottom of the page
  966. out += '''
  967. <tr>
  968. <td align="right" colspan="7">
  969. <form method="GET" action="output_format_add?ln=%(ln)s">
  970. <input class="adminbutton" type="submit" value="%(add_output_format)s"/>
  971. </form>
  972. </td>
  973. </tr>
  974. </table>
  975. ''' % {'ln':ln,
  976. 'add_output_format':_("Add New Output Format")}
  977. return out
  978. def tmpl_admin_output_format_show(self, ln, code, name, rules, default, format_templates, editable):
  979. """
  980. Returns the content of an output format
  981. rules is an ordered list of dict (sorted by evaluation order),
  982. with keys 'field', 'value' and 'template'
  983. IMPORTANT: we display rules evaluation index starting at 1 in

Large files files are truncated, but you can click here to view the full file