Skip to content

Commit 5718fb0

Browse files
committed
Added get_sessions_for + Merged session info viewlet into a single collapsible
1 parent 9c16952 commit 5718fb0

File tree

4 files changed

+34
-38
lines changed

4 files changed

+34
-38
lines changed

src/imio/esign/browser/templates/macros.pt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<tr metal:define-macro="signers" i18n:domain="imio.esign">
4141
<td class="table_widget_label"><label i18n:translate="">Signers</label></td>
4242
<td class="table_widget_value">
43-
<table class="no-border no-style-table listing context_viewlet_signers_table"
43+
<table id="context_viewlet_signers_table" class="no-border no-style-table listing"
4444
tal:define="signers python:session.get('signers', [])">
4545
<thead>
4646
<tr>

src/imio/esign/browser/templates/session_info.pt

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,19 @@
44
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
55
lang="en"
66
i18n:domain="imio.esign">
7-
<div class="faceted-session-info"
8-
tal:condition="python: view.available()"
9-
tal:define="session_id python: str(view.session.get('id', ''))">
10-
<div tal:attributes="id string:session-info-${session_id};
11-
onclick string:toggleDetails('collapsible-session-info-${session_id}', toggle_parent_active=true);
12-
class python: view.collapsible_css_default()">
7+
<div class="faceted-session-info" tal:condition="python: view.available()">
8+
<div id="session-info"
9+
onclick="toggleDetails('collapsible-session-info', toggle_parent_active=true);"
10+
tal:attributes="class python: view.collapsible_css_default()">
1311
<span i18n:translate="">Session information (<img i18n:name="icon_url" tal:attributes="src string:${view/portal_url}/++resource++imio.esign/parapheo.svg" /> Parapheo)</span>
1412
</div>
15-
<div tal:attributes="id string:collapsible-session-info-${session_id};
16-
class python: view.collapsible_content_css_default()">
13+
<div id="collapsible-session-info"
14+
tal:attributes="class python: view.collapsible_content_css_default()">
1715
<div class="collapsible-inner-content session-info-container"
18-
tal:define="template python: context.unrestrictedTraverse('@@esign-macros').index;
19-
session python: view.session">
16+
tal:repeat="session python:view.sessions"
17+
tal:define="template python: context.unrestrictedTraverse('@@esign-macros').index">
2018
<div class="session-info-column">
21-
<table class="no-style-table table-view-widgets">
19+
<table id="context_viewlet_session_table" class="no-style-table table-view-widgets">
2220
<tbody>
2321
<tal:block tal:repeat="macro_name python:view.get_table_rows(1)">
2422
<metal:render_cell use-macro="python: template.macros[macro_name]" />
@@ -28,15 +26,15 @@
2826
</div>
2927

3028
<div class="session-info-column">
31-
<table class="no-style-table table-view-widgets">
29+
<table id="context_viewlet_session_table" class="no-style-table table-view-widgets">
3230
<tbody>
3331
<tal:block tal:repeat="macro_name python:view.get_table_rows(2)">
3432
<metal:render_cell use-macro="python: template.macros[macro_name]" />
3533
</tal:block>
3634
</tbody>
3735
</table>
3836
</div>
39-
<script>$('table.context_viewlet_signers_table').each(setoddeven);</script>
37+
<script>$('table#context_viewlet_signers_table').each(setoddeven);</script>
4038
</div>
4139
</div>
4240
</div>

src/imio/esign/browser/views.py

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from imio.esign.config import get_registry_signing_users_email_content
1313
from imio.esign.utils import create_external_session
1414
from imio.esign.utils import get_session_annotation
15+
from imio.esign.utils import get_sessions_for
1516
from imio.esign.utils import get_state_description
1617
from imio.esign.utils import remove_session
1718
from imio.helpers.content import uuidToObject
@@ -261,34 +262,14 @@ def available(self):
261262
@property
262263
def sessions(self):
263264
"""Return all sessions that contain files from this context."""
264-
annot = get_session_annotation()
265-
result = []
266-
seen = set()
267-
for f_uid in annot["c_uids"].get(self.context.UID(), []):
268-
session_id = annot["uids"].get(f_uid)
269-
if session_id is not None and session_id not in seen:
270-
seen.add(session_id)
271-
session = dict(annot["sessions"].get(session_id, {}))
272-
session["id"] = session_id
273-
result.append(session)
274-
return result
275-
276-
@property
277-
def session(self):
278-
"""Current session during render loop; also used by base template."""
279-
return getattr(self, "_current_session", None) or {}
265+
return get_sessions_for(self.context.UID())
280266

281267
def render(self):
282268
"""Render viewlet once per session linked to this context."""
283269
sessions = self.sessions
284-
if not sessions:
285-
return ""
286-
parts = []
287-
for s in sessions:
288-
self._current_session = s
289-
parts.append(self.index())
290-
self._current_session = None
291-
return "\n".join(parts)
270+
if sessions:
271+
return self.index()
272+
return ""
292273

293274

294275
@implementer(IPublishTraverse)

src/imio/esign/utils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
from copy import deepcopy
23
from datetime import datetime
34
from datetime import timedelta
45
from imio.esign import _tr as _
@@ -516,3 +517,19 @@ def get_state_description(state):
516517
'returned': u'The session is finished and signed documents are on the way back to the application.',
517518
'finalized': u'The session is finished and signed documents have been sent back to the application.',
518519
}.get(state, "")
520+
521+
522+
def get_sessions_for(context_uid, readonly=True):
523+
"""Returns a list of all sessions involving the provided context_uid"""
524+
annot = get_session_annotation()
525+
result = []
526+
seen = set()
527+
for f_uid in annot["c_uids"].get(context_uid, []):
528+
session_id = annot["uids"].get(f_uid)
529+
if session_id is not None and session_id not in seen:
530+
seen.add(session_id)
531+
session = annot["sessions"][session_id]
532+
result.append(session)
533+
if readonly:
534+
return deepcopy(result)
535+
return result

0 commit comments

Comments
 (0)