Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Remarks and created RemarksField and RemarksWidget #920

Merged
merged 22 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
31b7351
Add RemarksWidget
rockfruit Jul 26, 2018
71540c0
Add RemarksField
rockfruit Jul 26, 2018
22ffa7a
Fixup templates which manually render RemarksWidgets
rockfruit Jul 26, 2018
54418f4
Remove remarks from some templates where it should not be shown
rockfruit Jul 26, 2018
1fb818c
Modify schemas to use RemarksWidget & RemarksField
rockfruit Jul 26, 2018
a5c7922
Merge branch 'master' into remarks
rockfruit Jul 26, 2018
4339613
Update changelog
rockfruit Jul 26, 2018
7962363
Always display history box to allow setting remarks asynchronously
ramonski Jul 26, 2018
4dbe325
Some error handling in the JS logic
ramonski Jul 26, 2018
879f894
Handle traceback on remarks field update
ramonski Jul 26, 2018
9cedaae
ResultsField.get() returns HTML
rockfruit Jul 26, 2018
6446cc8
Revert unrelated changes made in content sources
rockfruit Jul 26, 2018
b7928fd
RemarksWidget: Add some classes to form elements
rockfruit Jul 26, 2018
dc74513
Remove label "history" from RemarksWidget
rockfruit Jul 26, 2018
4709e18
Add remarks formatting directly to RemarksField.get
rockfruit Jul 26, 2018
3022436
Add remarks formatting directly to RemarksField.get (redux)
rockfruit Jul 26, 2018
27b1ed0
Prevent error in getter if RemarksField contains no value
rockfruit Jul 26, 2018
ad04b5d
Remove misleading comment
rockfruit Jul 26, 2018
dde5c1d
Remove authenticator from RemarksWidget template
rockfruit Jul 26, 2018
4c8bf0a
Add get_cooked_remarks to RemarksWidget...
rockfruit Jul 26, 2018
d9c41da
Do not copy remarks when AR is copied to new AR.
rockfruit Jul 26, 2018
ce3c4fe
Update template condition to decide if Remarks field is shown
rockfruit Jul 26, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Changelog
- #906 DateTime Widget does not display the Time
- #909 List of clients cannot sort by Client ID
- #921 Missing interim fields in worksheet/analyses_transposed view
- #920 Refactored Remarks and created RemarksField and RemarksWidget

**Security**

Expand Down
2 changes: 1 addition & 1 deletion bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from zope.publisher.interfaces import IPublishTraverse

AR_CONFIGURATION_STORAGE = "bika.lims.browser.analysisrequest.manage.add"
SKIP_FIELD_ON_COPY = ["Sample"]
SKIP_FIELD_ON_COPY = ["Sample", "Remarks"]


def returns_json(func):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,13 @@

</form>

<tal:hasremarks tal:condition="python:hasattr(context, 'Remarks')">
<p style="margin-top:2em;"/>
<tal:remarks define="
field python:context.Schema()['Remarks'];
errors python:{};">
<p style="margin-top:2em;"/>
<metal:widget use-macro="python:context.widget('Remarks', mode='edit')" />
</tal:remarks>
</tal:hasremarks>
<tal:remarks tal:condition="python:hasattr(context.aq_inner, 'schema') and 'Remarks' in context.schema"
define="checkPermission nocall: context/portal_membership/checkPermission;
mode python:'edit' if checkPermission('Modify portal content', context) else 'view';
field python:context.Schema()['Remarks'];
errors python:{};">
<metal:widget use-macro="python:context.widget('Remarks', mode=mode)"/>
</tal:remarks>

<tal:rejection define="
field python:context.Schema()['RejectionReasons'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,15 @@

</form>

<tal:remarks define="
field python:context.Schema()['Remarks'];
errors python:{};">
<p style="margin-top:2em;"/>
<metal:widget use-macro="python:context.widget('Remarks', mode='edit')" />
</tal:remarks>

<tal:rejection define="
<tal:remarks tal:condition="python:hasattr(context.aq_inner, 'schema') and 'Remarks' in context.schema"
tal:define="checkPermission nocall: context/portal_membership/checkPermission;
mode python:'edit' if checkPermission('Modify portal content', context) else 'view';
field python:context.Schema()['Remarks'];
errors python:{};">
<metal:widget use-macro="python:context.widget('Remarks', mode=mode)"/>
</tal:remarks>

<tal:rejection define="
field python:context.Schema()['RejectionReasons'];
widget python:field.widget;
errors python:{};">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@
<span tal:replace="structure python: table[1]"/>
</tal:tables>

<tal:remarks define="
field python:context.Schema()['Remarks'];
errors python:{};">
<p style="margin-top:2em;"/>
<metal:widget use-macro="python:context.widget('Remarks', mode='edit')" />
<tal:remarks tal:condition="python:hasattr(context.aq_inner, 'schema') and 'Remarks' in context.schema"
tal:define="checkPermission nocall: context/portal_membership/checkPermission;
mode python:'edit' if checkPermission('Modify portal content', context) else 'view';
field python:context.Schema()['Remarks'];
errors python:{};">
<metal:widget use-macro="python:context.widget('Remarks', mode=mode)"/>
</tal:remarks>

<tal:rejection define="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@
<tal:parts replace="structure view/riview"/>


<tal:remarks define="
field python:context.Schema()['Remarks'];
errors python:{};">
<p style="margin-top:2em;"/>
<metal:widget use-macro="python:context.widget('Remarks', mode='edit')" />
<tal:remarks tal:condition="python:hasattr(context.aq_inner, 'schema') and 'Remarks' in context.schema"
tal:define="checkPermission nocall: context/portal_membership/checkPermission;
mode python:'edit' if checkPermission('Modify portal content', context) else 'view';
field python:context.Schema()['Remarks'];
errors python:{};">
<metal:widget use-macro="python:context.widget('Remarks', mode=mode)"/>
</tal:remarks>

</metal:content-core>
</metal:content-core>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@
<div id="folderlisting-main-table"
tal:content="structure view/contents_table"/>

<!-- Remarks -->
<tal:hasremarks tal:condition="python:hasattr(context, 'Remarks')">
<tal:remarks define="field python:context.Schema()['Remarks'];
errors python:{};">
<metal:widget use-macro="python:context.widget('Remarks', mode='edit')" />
</tal:remarks>
</tal:hasremarks>

</metal:content-core>

</body>
Expand Down
1 change: 0 additions & 1 deletion bika/lims/browser/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<include file="manufacturer.zcml"/>
<include file="menu.zcml"/>
<include file="method.zcml"/>
<include file="remarks.zcml"/>
<include file="referenceanalysis.zcml"/>
<include file="referencesample.zcml"/>
<include file="pricelist.zcml"/>
Expand Down
73 changes: 73 additions & 0 deletions bika/lims/browser/fields/remarksfield.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
#
# This file is part of SENAITE.CORE
#
# Copyright 2018 by it's authors.
# Some rights reserved. See LICENSE.rst, CONTRIBUTORS.rst.

from AccessControl import ClassSecurityInfo
from AccessControl import getSecurityManager
from DateTime import DateTime
from Products.Archetypes.Field import ObjectField
from Products.Archetypes.Registry import registerField
from bika.lims.browser.widgets import RemarksWidget
from bika.lims.interfaces import IRemarksField
from zope.interface import implements


class RemarksField(ObjectField):
"""A field that stores remarks. The value submitted to the setter
will always be appended to the actual value of the field.
A divider will be included with extra information about the text.
"""

_properties = ObjectField._properties.copy()
_properties.update({
'type': 'remarks',
'widget': RemarksWidget,
'default': '',
})

implements(IRemarksField)

security = ClassSecurityInfo()

security.declarePrivate('set')

def set(self, instance, value, **kwargs):
"""Adds the value to the existing text stored in the field,
along with a small divider showing username and date of this entry.
"""
if not value:
return
value = value.strip()
date = DateTime().rfc822()
user = getSecurityManager().getUser()
username = user.getUserName()
divider = "=== {} ({})".format(date, username)
existing_remarks = instance.getRawRemarks()
remarks = '\n'.join([divider, value, existing_remarks])
return ObjectField.set(self, instance, remarks)

def get_cooked_remarks(self, instance):
text = self.get(instance)
if not text:
return ""
return text.replace('\n', '<br/>')

def get(self, instance, **kwargs):
"""Returns raw field value.
"""
return self.getRaw(instance, **kwargs)

def getRaw(self, instance, **kwargs):
"""Returns raw field value (possible wrapped in BaseUnit)
"""
value = ObjectField.get(self, instance, **kwargs)
# getattr(instance, "Remarks") returns a BaseUnit
if callable(value):
value = value()
return value


registerField(RemarksField, title='Remarks', description='')
4 changes: 4 additions & 0 deletions bika/lims/browser/js/bika.lims.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ window.bika.lims.controllers = {
".portaltype-reportfolder":
['ReportFolderView'],

// If RemarksWidget is in use on this page,
// load RemarksWIdgetview
".ArchetypesRemarksWidget": ["RemarksWidgetView"],

// Add here your view-controller/s assignment

};
Expand Down
2 changes: 1 addition & 1 deletion bika/lims/browser/js/bika.lims.site.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
config: {
closeOnEsc: false,
onLoad: function() {
this.getOverlay().find('#archetypes-fieldname-Remarks').remove();
this.getOverlay().find('.ArchetypesRemarksWidget').remove();
},
onClose: function() {}
}
Expand Down
2 changes: 1 addition & 1 deletion bika/lims/browser/js/coffee/bika.lims.site.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class window.SiteView
closeOnEsc: false
onLoad: ->
# manually remove remarks
@getOverlay().find('#archetypes-fieldname-Remarks').remove()
@getOverlay().find('.ArchetypesRemarksWidget').remove()
return
onClose: ->
# here is where we'd populate the form controls, if we cared to.
Expand Down
Loading