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

@@ 760-800 (lines=41) @@
757
        except (POSKeyError, TypeError):
758
            return None
759
760
    def get_recipients(self, ar):
761
        """Return the AR recipients in the same format like the AR Report
762
        expects in the records field `Recipients`
763
        """
764
        plone_utils = api.get_tool("plone_utils")
765
766
        def is_email(email):
767
            if not plone_utils.validateSingleEmailAddress(email):
768
                return False
769
            return True
770
771
        def recipient_from_contact(contact):
772
            if not contact:
773
                return None
774
            email = contact.getEmailAddress()
775
            return {
776
                "UID": api.get_uid(contact),
777
                "Username": contact.getUsername(),
778
                "Fullname": to_utf8(contact.Title()),
779
                "EmailAddress": email,
780
            }
781
782
        def recipient_from_email(email):
783
            if not is_email(email):
784
                return None
785
            return {
786
                "UID": "",
787
                "Username": "",
788
                "Fullname": email,
789
                "EmailAddress": email,
790
            }
791
792
        # Primary Contacts
793
        to = filter(None, [recipient_from_contact(ar.getContact())])
794
        # CC Contacts
795
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
796
        # CC Emails
797
        cc_emails = ar.getCCEmails(as_list=True)
798
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
799
800
        return to + cc + cc_emails
801
802
    def ajax_recalculate_size(self):
803
        """Recalculate the total size of the selected attachments