Code Duplication    Length = 41-41 lines in 2 locations

src/bika/lims/browser/publish/reports_listing.py 1 location

@@ 240-280 (lines=41) @@
237
238
        return item
239
240
    def get_recipients(self, ar):
241
        """Return the AR recipients in the same format like the AR Report
242
        expects in the records field `Recipients`
243
        """
244
        plone_utils = api.get_tool("plone_utils")
245
246
        def is_email(email):
247
            if not plone_utils.validateSingleEmailAddress(email):
248
                return False
249
            return True
250
251
        def recipient_from_contact(contact):
252
            if not contact:
253
                return None
254
            email = contact.getEmailAddress()
255
            return {
256
                "UID": api.get_uid(contact),
257
                "Username": contact.getUsername(),
258
                "Fullname": to_utf8(contact.Title()),
259
                "EmailAddress": email,
260
            }
261
262
        def recipient_from_email(email):
263
            if not is_email(email):
264
                return None
265
            return {
266
                "UID": "",
267
                "Username": "",
268
                "Fullname": email,
269
                "EmailAddress": email,
270
            }
271
272
        # Primary Contacts
273
        to = filter(None, [recipient_from_contact(ar.getContact())])
274
        # CC Contacts
275
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
276
        # CC Emails
277
        cc_emails = ar.getCCEmails(as_list=True)
278
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
279
280
        return to + cc + cc_emails
281

src/bika/lims/browser/publish/emailview.py 1 location

@@ 716-756 (lines=41) @@
713
        except (POSKeyError, TypeError):
714
            return None
715
716
    def get_recipients(self, ar):
717
        """Return the AR recipients in the same format like the AR Report
718
        expects in the records field `Recipients`
719
        """
720
        plone_utils = api.get_tool("plone_utils")
721
722
        def is_email(email):
723
            if not plone_utils.validateSingleEmailAddress(email):
724
                return False
725
            return True
726
727
        def recipient_from_contact(contact):
728
            if not contact:
729
                return None
730
            email = contact.getEmailAddress()
731
            return {
732
                "UID": api.get_uid(contact),
733
                "Username": contact.getUsername(),
734
                "Fullname": to_utf8(contact.Title()),
735
                "EmailAddress": email,
736
            }
737
738
        def recipient_from_email(email):
739
            if not is_email(email):
740
                return None
741
            return {
742
                "UID": "",
743
                "Username": "",
744
                "Fullname": email,
745
                "EmailAddress": email,
746
            }
747
748
        # Primary Contacts
749
        to = filter(None, [recipient_from_contact(ar.getContact())])
750
        # CC Contacts
751
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
752
        # CC Emails
753
        cc_emails = ar.getCCEmails(as_list=True)
754
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
755
756
        return to + cc + cc_emails
757
758
    def ajax_recalculate_size(self):
759
        """Recalculate the total size of the selected attachments