|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
|
|
3
|
|
|
from bika.lims import api |
|
4
|
|
|
from bika.lims.browser import ulocalized_time |
|
5
|
|
|
from plone.app.layout.viewlets import ViewletBase |
|
6
|
|
|
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class SampleDispatchedViewlet(ViewletBase): |
|
10
|
|
|
"""Print a viewlet showing the WF history comment |
|
11
|
|
|
""" |
|
12
|
|
|
template = ViewPageTemplateFile("templates/sample_dispatched_viewlet.pt") |
|
13
|
|
|
|
|
14
|
|
|
def __init__(self, context, request, view, manager=None): |
|
15
|
|
|
super(SampleDispatchedViewlet, self).__init__( |
|
16
|
|
|
context, request, view, manager=manager) |
|
17
|
|
|
self.context = context |
|
18
|
|
|
self.request = request |
|
19
|
|
|
self.view = view |
|
20
|
|
|
|
|
21
|
|
|
def is_dispatched(self): |
|
22
|
|
|
"""Returns whether the current sample is dispatched |
|
23
|
|
|
""" |
|
24
|
|
|
return api.get_review_status(self.context) == "dispatched" |
|
25
|
|
|
|
|
26
|
|
|
def get_state_info(self): |
|
27
|
|
|
"""Returns the WF state information |
|
28
|
|
|
""" |
|
29
|
|
|
history = api.get_review_history(self.context) |
|
30
|
|
|
entry = len(history) and history[0] or {} |
|
31
|
|
|
actor = entry.get("actor") |
|
32
|
|
|
user = api.user.get_user(actor) |
|
33
|
|
|
if user: |
|
34
|
|
|
actor = user.getProperty("fullname", actor) |
|
35
|
|
|
date = entry.get("time") |
|
36
|
|
|
comments = entry.get("comments", "") |
|
37
|
|
|
|
|
38
|
|
|
return { |
|
39
|
|
|
"actor": actor, |
|
40
|
|
|
"date": self.ulocalized_time(date, long_format=1), |
|
41
|
|
|
"comments": api.safe_unicode(comments), |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
def index(self): |
|
45
|
|
|
if self.is_dispatched(): |
|
46
|
|
|
return "" |
|
47
|
|
|
return self.template() |
|
48
|
|
|
|
|
49
|
|
|
def ulocalized_time(self, time, long_format=None, time_only=None): |
|
50
|
|
|
return ulocalized_time(time, long_format, time_only, |
|
51
|
|
|
context=self.context, request=self.request) |
|
52
|
|
|
|