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

@@ 742-782 (lines=41) @@
739
        except (POSKeyError, TypeError):
740
            return None
741
742
    def get_recipients(self, ar):
743
        """Return the AR recipients in the same format like the AR Report
744
        expects in the records field `Recipients`
745
        """
746
        plone_utils = api.get_tool("plone_utils")
747
748
        def is_email(email):
749
            if not plone_utils.validateSingleEmailAddress(email):
750
                return False
751
            return True
752
753
        def recipient_from_contact(contact):
754
            if not contact:
755
                return None
756
            email = contact.getEmailAddress()
757
            return {
758
                "UID": api.get_uid(contact),
759
                "Username": contact.getUsername(),
760
                "Fullname": to_utf8(contact.Title()),
761
                "EmailAddress": email,
762
            }
763
764
        def recipient_from_email(email):
765
            if not is_email(email):
766
                return None
767
            return {
768
                "UID": "",
769
                "Username": "",
770
                "Fullname": email,
771
                "EmailAddress": email,
772
            }
773
774
        # Primary Contacts
775
        to = filter(None, [recipient_from_contact(ar.getContact())])
776
        # CC Contacts
777
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
778
        # CC Emails
779
        cc_emails = ar.getCCEmails(as_list=True)
780
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
781
782
        return to + cc + cc_emails
783
784
    def ajax_recalculate_size(self):
785
        """Recalculate the total size of the selected attachments