Include Signatures of Analysts in Reports (just like managers)

Hi everyone, I am still quite new to Senaite so my question might seem a bit arrogant.

I am trying to modify reports to include signatures and info of Managers and Analysts. I have tried a few things but they don’t seem to be working. I have explained more about my problem down below. Any response would be highly appreciated!

<div class="w-100">
  <h1 i18n:translate="">Heads of Laboratories</h1>
  <table class="table table-sm table-condensed">
    <tr>
      <tal:manager repeat="manager python:model.analysts">
        <td style="border:none">
        <img tal:condition="manager/Signature"
        tal:attributes="src string:${manager/absolute_url}/Signature" 
        style="height:35px"
         />
          </div>
          <div class="font-weight-bold">
            <span tal:content="manager/Salutation"></span>
            <span tal:condition="manager/Salutation">&nbsp;</span>
            <span tal:content="manager/Fullname"></span>
          </div>
          <div>
            <span tal:content="manager/JobTitle"></span>
          </div>
          <div>
            <span tal:content="manager/DefaultDepartment/title|nothing">
            </span>
          </div>
        </td>
      </tal:manager>
    </tr>
  </table>
</div>


From the code snippet above, the line

<tal:manager repeat="manager python:model.managers">

fetches a list of manager objects successfully, therefore, generating the signature as in the attached screenshot above.

However, trying to replicate the same using:

<tal:manager repeat="manager python:model.analysts">

returns the error below:

Error: analysts

 - Expression: "python:model.analysts"
 - Filename:   ... 0-py2.7.egg/senaite/impress/templates/reports/Default.pt
 - Location:   (line 603: col 41)
 - Source:     ... anager repeat="manager python:model.analysts">
                                          ^^^^^^^^^^^^^^^^^^^^^
...

I also tried using the model.getAnalysts() method and it worked but not as desired:

<tal:manager repeat="manager python:model.getAnalysts()">


It only returns a list of usernames of the analysts linked to this report instead of their user objects from which I can get the fullname, signature etc.

How do I get around this? Do we have a method that would return analysts in the correct format? Or is there a function that can fetch user info using just their username?

I figured it out guys. I documented it in a blog article as well: Senaite Custom Reports - Inserting Analyst Signatures on Analysis Reports

Please feel free to ask any questions or give alternative approaches that worked for you so we can help out others have an easier time working with Senaite.

1 Like

Hi @ramonski and @ronaldm, I’d love to hear what you guys think about this approach. Is there an easier, cleaner or more efficient way?

Hi @wwangwe,

Thanks for writing up your findings in the blog post!

However, it is not recommended to change the code of senaite.core or any of it’s add-ons directly, because you need to manually merge your changes if you update SENAITE.

It would be better to add the code in a custom report controller, as described here:

Besides this, you could think about skipping analysts w/o linked labcontact in your code directly and also avoid the blind try/except, e.g.:


def analysts(self):
    analysts = []
    for analyst in self.getAnalysts():
        user = api.get_user(analyst)
        contact = api.get_user_contact(user, ["LabContact"])
        if contact_info:
            analysts.append({
                "Salutation": contact.getSalutation(),
                "Fullname": contact.getFullname(),
                "JobTitle": contact.getJobTitle(),
                "absolute_url": contact.absolute_url() ,
                ...
            })
    return analysts

Best regards
Ramon

Hello, @ramonski. Thank you for your insight. I’ll go back and make some changes based on your suggestions, and I’ll also update my article.