59 translate = request.localizer.translate |
61 translate = request.localizer.translate |
60 workflow = IWorkflow(context) |
62 workflow = IWorkflow(context) |
61 versions = IWorkflowVersions(context) |
63 versions = IWorkflowVersions(context) |
62 state = IWorkflowState(context) |
64 state = IWorkflowState(context) |
63 self.version_id = state.version_id |
65 self.version_id = state.version_id |
|
66 # init state format |
|
67 state_format = translate(_("{state} by {principal}")) |
|
68 if state.state_urgency: |
|
69 state_format = state_format.replace('{state}', |
|
70 '{state} <i class="fa fa-fw fa-exclamation-triangle txt-color-red"></i>'); |
|
71 state_class = 'text-danger' # if state.state in workflow.update_states else 'txt-color-text' |
|
72 state_format = state_format.replace('{state}', |
|
73 '<span class="{0}">{{state}}</span>'.format(state_class)) |
|
74 # init principal format |
|
75 # principal_class = 'text-danger' if state.state_principal != owner else 'txt-color-text' |
|
76 principal_class = 'text-danger' \ |
|
77 if state.state in (workflow.update_states | workflow.waiting_states) \ |
|
78 else 'txt-color-text' |
|
79 state_format = state_format.replace('{principal}', |
|
80 '<span class="{0}">{{principal}}</span>'.format(principal_class)) |
|
81 # get state label |
64 state_label = request.registry.queryAdapter(workflow, IWorkflowStateLabel, name=state.state) |
82 state_label = request.registry.queryAdapter(workflow, IWorkflowStateLabel, name=state.state) |
65 if state_label is None: |
83 if state_label is None: |
66 state_label = request.registry.queryAdapter(workflow, IWorkflowStateLabel) |
84 state_label = request.registry.queryAdapter(workflow, IWorkflowStateLabel) |
67 if state_label is None: |
85 if state_label is None: |
68 self.state = translate(_("{state} by {{principal}}")).format( |
86 self.state = state_format.format(state=translate(workflow.get_state_label(state.state)), |
69 state=translate(workflow.get_state_label(state.state))) |
87 principal=security.get_principal(state.state_principal).title) |
70 else: |
88 else: |
71 self.state = state_label.get_label(context, request, format=False) |
89 self.state = state_format.format(state=state_label.get_label(context, request, format=False), |
72 principal_class = 'text-danger' if state.state_principal != owner else 'txt-color-text' |
90 principal=security.get_principal(state.state_principal).title) |
73 self.state = self.state.replace('{principal}', |
|
74 '<span class="{0}">{{principal}}</span>'.format(principal_class)) |
|
75 state_class = 'text-danger' if state.state in workflow.update_states else None |
|
76 if state_class: |
|
77 self.state = '<span class="{state_class}">{state}</span>'.format(state_class=state_class, |
|
78 state=self.state) |
|
79 self.state = self.state.format(principal=security.get_principal(state.state_principal).title) |
|
80 self.state_date = translate(_("since {date}")).format(date=format_datetime(state.state_date, request=request)) |
91 self.state_date = translate(_("since {date}")).format(date=format_datetime(state.state_date, request=request)) |
81 if state.state not in workflow.update_states and versions.has_version(workflow.update_states): |
92 has_update_state = versions.has_version(workflow.update_states) |
|
93 if (state.state not in workflow.update_states and has_update_state) or \ |
|
94 (state.state in workflow.retired_states and has_update_state): |
82 target = sorted(versions.get_versions(workflow.update_states), |
95 target = sorted(versions.get_versions(workflow.update_states), |
83 key=lambda x: IWorkflowState(x).version_id, |
96 key=lambda x: IWorkflowState(x).version_id)[-1] |
84 reverse=True)[-1] |
|
85 self.version_link = { |
97 self.version_link = { |
86 'css_class': 'text-danger', |
98 'css_class': 'text-danger', |
87 'href': absolute_url(target, request, 'admin.html'), |
99 'href': absolute_url(target, request, 'admin.html'), |
88 'title': translate(_("access new version")) |
100 'title': translate(_("access new version")) |
89 } |
101 } |
90 elif state.state not in workflow.published_states and versions.has_version(workflow.published_states): |
102 elif state.state not in workflow.published_states and versions.has_version(workflow.published_states): |
91 target = sorted(versions.get_versions(workflow.published_states), |
103 target = sorted(versions.get_versions(workflow.published_states), |
92 key=lambda x: IWorkflowState(x).version_id, |
104 key=lambda x: IWorkflowState(x).version_id, |
93 reverse=True)[-1] |
105 reverse=True)[-1] |
94 self.version_link = { |
106 self.version_link = { |
95 'css_class': 'txt-color-text', |
107 'css_class': 'text-danger', |
96 'href': absolute_url(target, request, 'admin.html'), |
108 'href': absolute_url(target, request, 'admin.html'), |
97 'title': translate(_("access published version")) |
109 'title': translate(_("access published version")) |
98 } |
110 } |
99 else: |
111 else: |
100 self.version_link = None |
112 self.version_link = None |