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

Conversation

rockfruit
Copy link
Contributor

Description of the issue/feature this PR addresses

Remarks added during AR-Add (or perhaps other places) are modified with the widget's process_form, which can easily be mistakenly bypassed, resulting in entries without proper information being stored.

Current behavior before PR

Remarks entered in AR-Add form were saved without date/username header.

Desired behavior after PR is merged

  • Fields now use RemarksField and RemarksWidget.

  • Remarks entered in AR-Add or in portal_factory are stored correctly, Unless you do it on purpose, it should not be so easy to accidentally bypass the field's setter.

  • Where widget is rendered manually in custom templates, use View/Modify portal content permission check to decide if widget is displayed in edit/view mode.

  • Remarks field is editable in AR-Add XXX should this be on? I like them there, not sure if it's the right default.

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@rockfruit rockfruit requested a review from ramonski July 24, 2018 18:21
@rockfruit rockfruit added the Cleanup 🧹 Code cleanup and refactoring label Jul 24, 2018
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the changes that do not belong to this PR. PEP8 is ok, but changing code structures introduces too much potential for side-effects. Please also don't forget the time of the Reviewer looking at your code ...

In code try to not repeat yourself. If you find yourself writing multiple times the same structure, you should write a method/function for it.

The rest looks good, but please finish the requested changes first tomorrow in the morning with high priority. I really want these changes in as soon as possible;)

* Submit the value to the field setter via /@@API/update.
*
###
widget = $(".ArchetypesRemarksWidget[data-uid='#{uid}']")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't repeat yourself;) Make a separate method for this and handle the case when the field is not found

append_only=True,
),
),
RemarksField('Remarks',
Copy link
Contributor

@ramonski ramonski Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either put the name of the field in the next line (like the fields above) or put it in the same line as the opening brace. But not both styles mixed in one file please.

else:
delta = valid_to - today

delta = valid_to - today
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually does not belong to this PR

allowed_types=('AnalysisRequest',),
relationship='AnalysisRequestInvoice',
),
ReferenceField(
'SupplyOrder',
required=1,
vocabulary_display_path_bound=sys.maxsize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither do these changes belong here. Actually I have no idea what these attributes are doing, why did you remove them?

@@ -828,7 +910,7 @@ def getLastARNumber(self):
ar_ids = sorted([AR.id for AR in ARs if AR.id.startswith(prefix)])
try:
last_ar_number = int(ar_ids[-1].split("-R")[-1])
except:
except (IndexError, TypeError, ValueError):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually nice, but you might introduce with that cosmetic change unexpected errors.
E.g. if ar_ids[-1] returns None you will get an AttributeError here.

Try to keep the focus more on the task to do please.

return list()

layout = self.getLayout()
slots = list()

for pos in layout:
if type != ALL_ANALYSES_TYPES and pos['type'] != type:
if typ != ALL_ANALYSES_TYPES and pos['type'] != typ:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are introducing too much changes in this PR...

@@ -1535,12 +1546,11 @@ def copy_src_fields_to_dst(src, dst):
new_ws_analyses = []
old_ws_analyses = []
for analysis in analyses:
position = analysis_positions[analysis.UID()]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch, but does not belong to this PR. Please remove that and make a new one. Same for the type vs typ

*
* @returns {string} portal url
###
return window.portal_url
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use this method:

  get_portal_url: =>
    ###
     * Return the portal url (calculated in code)
    ###
    url = $("input[name=portal_url]").val()
    return url or window.portal_url


deferred = $.Deferred()
options =
url: window.portal_url + "/@@API/update"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @get_portal_url() instead of window.portal_url please

@rockfruit rockfruit removed PR: Rework-requested Cleanup 🧹 Code cleanup and refactoring labels Jul 26, 2018
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puh, that one was harder than expected. Thanks Campbell!

@ramonski ramonski added Improvement 🔧 Cleanup 🧹 Code cleanup and refactoring labels Jul 26, 2018
@ramonski ramonski merged commit 7fc0c8a into senaite:master Jul 26, 2018
ramonski added a commit that referenced this pull request Jul 27, 2018
@ramonski ramonski mentioned this pull request Jul 27, 2018
xispa pushed a commit that referenced this pull request Jul 27, 2018
xispa added a commit to senaite/senaite.health that referenced this pull request Sep 17, 2018
This was because of senaite/senaite.core#920

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFPlone.FactoryTool, line 478, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 32, in _call
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 237, in _exec
  Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
  Module Products.PageTemplates.PageTemplate, line 87, in pt_render
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 158, in render
  Module chameleon.zpt.template, line 297, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module 338b44bf2274717b61b2323795a9c98f.py, line 1101, in render
  Module 338b44bf2274717b61b2323795a9c98f.py, line 911, in render_master
  Module 69e91da7ad509eec74265fa5c1df1777.py, line 1465, in render_master
  Module 69e91da7ad509eec74265fa5c1df1777.py, line 645, in render_content
  Module 338b44bf2274717b61b2323795a9c98f.py, line 901, in __fill_main
  Module 338b44bf2274717b61b2323795a9c98f.py, line 153, in render_main
  Module 5f0aa4601784b64af4844c8766340a88.py, line 414, in render_body
  Module Products.Archetypes.BaseObject, line 276, in widget
  Module Products.Archetypes.Renderer, line 26, in render
  Module Products.Archetypes.generator.widget, line 147, in __call__
AttributeError: Macro bika_widgets/remarks does not exist for <Patient at patient.2018-09-17.1793646232>
xispa added a commit to senaite/senaite.health that referenced this pull request Sep 17, 2018
This was because of senaite/senaite.core#920

Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFPlone.FactoryTool, line 478, in __call__
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module Products.CMFFormController.FSControllerPageTemplate, line 91, in __call__
  Module Products.CMFFormController.BaseControllerPageTemplate, line 32, in _call
  Module Shared.DC.Scripts.Bindings, line 322, in __call__
  Module Shared.DC.Scripts.Bindings, line 359, in _bindAndExec
  Module Products.CMFCore.FSPageTemplate, line 237, in _exec
  Module Products.CMFCore.FSPageTemplate, line 177, in pt_render
  Module Products.PageTemplates.PageTemplate, line 87, in pt_render
  Module zope.pagetemplate.pagetemplate, line 132, in pt_render
  Module five.pt.engine, line 98, in __call__
  Module z3c.pt.pagetemplate, line 158, in render
  Module chameleon.zpt.template, line 297, in render
  Module chameleon.template, line 191, in render
  Module chameleon.template, line 171, in render
  Module 338b44bf2274717b61b2323795a9c98f.py, line 1101, in render
  Module 338b44bf2274717b61b2323795a9c98f.py, line 911, in render_master
  Module 69e91da7ad509eec74265fa5c1df1777.py, line 1465, in render_master
  Module 69e91da7ad509eec74265fa5c1df1777.py, line 645, in render_content
  Module 338b44bf2274717b61b2323795a9c98f.py, line 901, in __fill_main
  Module 338b44bf2274717b61b2323795a9c98f.py, line 153, in render_main
  Module 5f0aa4601784b64af4844c8766340a88.py, line 414, in render_body
  Module Products.Archetypes.BaseObject, line 276, in widget
  Module Products.Archetypes.Renderer, line 26, in render
  Module Products.Archetypes.generator.widget, line 147, in __call__
AttributeError: Macro bika_widgets/remarks does not exist for <Patient at patient.2018-09-17.1793646232>
@rockfruit rockfruit deleted the remarks branch October 19, 2021 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup 🧹 Code cleanup and refactoring Improvement 🔧
Development

Successfully merging this pull request may close these issues.

2 participants