%namespace file="/base/fileViews.html" name="fileViews" import="displayFile, displayAudio"/>
<%namespace file="/base/formViews.html" name="formViews" import="formViewLong, formViewForAssociation, displayAssociatedFiles, formViewForMemory"/>
<%namespace file="/base/markup.html" name="markup" import="*"/>
<%namespace file="/base/javascriptDefs.html" name="javascriptDefs" import="*"/>
<%! import re %>
<%def name="collectionViewPaper(collection)">
<%
if collection.elicitor:
author = collection.elicitor
else:
author = collection.enterer
%>
${collection.title}
${author.firstName} ${author.lastName}
entered: ${h.pretty_date(collection.datetimeEntered)}
last modified: ${h.pretty_date(collection.datetimeModified)}
+
${displayCollectionDataAndButtons(collection, True)}
% if collection.contents:
${self.displayContentMin()}
% else:
This Collection has no content
% endif
%def>
<%def name="displayContentMin()">
${h.literal(c.contents)}
%def>
<%def name="displayCollectionDataAndButtons(collection, displayTitle)">
${displayCollectionData(collection, displayTitle)}
${displayCollectionButtons(collection)}
% for file in collection.files:
Associated File ${file.id}: ${file.name} (${h.pretty_filesize(file.size)})
${file.getHTMLRepresentation(collectionID=collection.id)}
% endfor
%def>
<%def name="displayCollectionData(collection, displayTitle)">
ID |
${collection.id} |
% if displayTitle:
title |
${collection.title} |
% endif
type |
${collection.type} |
% if collection.url:
url |
${collection.url} |
% endif
% if collection.description:
description |
${collection.description} |
% endif
% if collection.speaker:
speaker |
${collection.speaker.firstName} ${collection.speaker.lastName} |
% endif
% if collection.source:
source |
${collection.source.authorFirstName} ${collection.source.authorLastName} \
(${collection.source.year}) |
% endif
% if collection.elicitor:
elicitor |
${collection.elicitor.firstName} ${collection.elicitor.lastName} |
% endif
enterer |
${collection.enterer.firstName} ${collection.enterer.lastName} |
% if collection.dateElicited:
date elicited |
${h.pretty_date(collection.dateElicited)} |
% endif
time entered |
${h.pretty_date(collection.datetimeEntered)} |
last updated |
${h.pretty_date(collection.datetimeModified)} |
%def>
<%def name="displayCollectionButtons(collection, viewLongButton=False)">
%def>
<%def name="collectionViewLong(collection, displayTitle=True)">
${self.displayCollectionData(collection, displayTitle)}
${self.displayCollectionButtons(collection)}
% if collection.files:
Associated Files
${displayAssociatedFiles(collection, 'collection')}
% endif
Content
% if collection.contents:
${self.displayContent(collection)}
% else:
This Collection has no content
% endif
%def>
<%def name="collectionViewShort(collection, displayTitle=True)">
${self.displayCollectionData(collection, displayTitle)}
${self.displayCollectionButtons(collection, True)}
%def>
<%def name="collectionViewReallyShort(collection, displayTitle=True)">
<%
URL = url(controller='collection', action='view', id=collection.id)
cTitle = collection.title
if len(cTitle) > 20:
cTitle = u'%s...' % cTitle[:20]
%>
${cTitle}
|
${h.pretty_date(collection.datetimeModified)}
|
${collection.type}
|
%def>
<%def name="displayContent(collection)">
<%
formsDict = dict([(form.id, form) for form in collection.forms])
# Apply Markdown conversion
# contents = h.literal(h.markdown(collection.contents, safe_mode="escape"))
contents = h.literal(h.rst2html(collection.contents))
# Replace "form[X]" with a representation of Form X
patt = re.compile('(form\[([0-9]+)\])')
matches = patt.findall(contents)
if c.collectionViewType == 'columns':
contents = capture(displayFormsAsColumns, matches, formsDict)
else:
contents = capture(displayContentEmbedded, contents, matches, formsDict, c.collectionViewType)
cClass = sClass = lClass = 'buttonLink'
if c.collectionViewType == 'long':
lClass += ' selected'
elif c.collectionViewType == 'short':
sClass += ' selected'
else:
cClass += ' selected'
%>
${javascriptDefs.toggleLabelsJavaScript()}
${javascriptDefs.labelsHidden()}
+
long
short
columns
${h.literal(contents)}
%def>
<%def name="displayFormsAsColumns(matches, formsDict)">
<%
contents = []
for match in matches:
try:
form = formsDict[int(match[1])]
glosses = []
for gloss in form.glosses:
glossLine = gloss.glossGrammaticality + gloss.gloss
glosses.append(glossLine)
glosses = '; '.join(glosses)
line = '%s%s | %s |
' % (form.grammaticality, h.storageToOutputTranslate(form.transcription), glosses)
contents.append(line)
except KeyError:
pass
contents = h.literal('' + '\n'.join(contents) + '
')
%>
${contents}
%def>
<%def name="displayContentEmbedded(contents, matches, formsDict, displayType)">
<%
for match in matches:
contents = contents.replace(match[0], capture(displayForm, formsDict, match[1], displayType))
# Replace "FORMID:X" with an enumeration signifier, e.g., "(1)"
patt = re.compile('FORMID:([0-9]+);')
lines = []
number = 1
formIDToNum = {}
for line in contents.split('\n'):
if patt.match(line.strip()):
formID = int(patt.findall(line)[0])
Url = url(controller='form', action='view', id=formID)
title = 'Click to view Form %s' % formID
anchorStart = '' % (Url, title)
line = '(%s%s
)' % (anchorStart, number)
try:
formIDToNum[formID].append(number)
except KeyError:
formIDToNum[formID] = [number]
number += 1
lines.append(line)
contents = '\n'.join(lines)
patt = re.compile('(ref\[([0-9]+)\])')
matches = patt.findall(contents)
for match in matches:
replacement = ', '.join([str(formID) for formID in formIDToNum[int(match[1])]])
contents = contents.replace(match[0], replacement)
contents = capture(markup.linkToOLDEntitites, contents)
contents = h.literal(contents)
%>
${contents}
%def>
<%def name="displayForm(formsDict, formID, displayType='long')">
<%
try:
form = formsDict[int(formID)]
except KeyError:
form = None
%>
FORMID:${formID};
% if form:
% if displayType == 'long':
${formViewLong(form)}
% else:
${form.grammaticality}${h.storageToOutputTranslate(form.transcription)}
% for gloss in form.glosses:
‘${gloss.glossGrammaticality}${gloss.gloss}’
% endfor
<% OLUFiles = [file for file in form.files if file.utteranceType=='Object Language Utterance'] %>
% for file in OLUFiles:
<% fileReference = url('retrieve', path=file.name) %>
<% displayAudio(file, fileReference) %>
% endfor
% endif
% else:
There is no Form with ID ${formID}
% endif
%def>