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

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