Code Duplication    Length = 41-41 lines in 2 locations

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

@@ 605-645 (lines=41) @@
602
        except (POSKeyError, TypeError):
603
            return None
604
605
    def get_recipients(self, ar):
606
        """Return the AR recipients in the same format like the AR Report
607
        expects in the records field `Recipients`
608
        """
609
        plone_utils = api.get_tool("plone_utils")
610
611
        def is_email(email):
612
            if not plone_utils.validateSingleEmailAddress(email):
613
                return False
614
            return True
615
616
        def recipient_from_contact(contact):
617
            if not contact:
618
                return None
619
            email = contact.getEmailAddress()
620
            return {
621
                "UID": api.get_uid(contact),
622
                "Username": contact.getUsername(),
623
                "Fullname": to_utf8(contact.Title()),
624
                "EmailAddress": email,
625
            }
626
627
        def recipient_from_email(email):
628
            if not is_email(email):
629
                return None
630
            return {
631
                "UID": "",
632
                "Username": "",
633
                "Fullname": email,
634
                "EmailAddress": email,
635
            }
636
637
        # Primary Contacts
638
        to = filter(None, [recipient_from_contact(ar.getContact())])
639
        # CC Contacts
640
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
641
        # CC Emails
642
        cc_emails = map(lambda x: x.strip(), ar.getCCEmails().split(","))
643
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
644
645
        return to + cc + cc_emails
646
647
    def ajax_recalculate_size(self):
648
        """Recalculate the total size of the selected attachments

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

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