Code Duplication    Length = 41-41 lines in 2 locations

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

@@ 208-248 (lines=41) @@
205
206
        return item
207
208
    def get_recipients(self, ar):
209
        """Return the AR recipients in the same format like the AR Report
210
        expects in the records field `Recipients`
211
        """
212
        plone_utils = api.get_tool("plone_utils")
213
214
        def is_email(email):
215
            if not plone_utils.validateSingleEmailAddress(email):
216
                return False
217
            return True
218
219
        def recipient_from_contact(contact):
220
            if not contact:
221
                return None
222
            email = contact.getEmailAddress()
223
            return {
224
                "UID": api.get_uid(contact),
225
                "Username": contact.getUsername(),
226
                "Fullname": to_utf8(contact.Title()),
227
                "EmailAddress": email,
228
            }
229
230
        def recipient_from_email(email):
231
            if not is_email(email):
232
                return None
233
            return {
234
                "UID": "",
235
                "Username": "",
236
                "Fullname": email,
237
                "EmailAddress": email,
238
            }
239
240
        # Primary Contacts
241
        to = filter(None, [recipient_from_contact(ar.getContact())])
242
        # CC Contacts
243
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
244
        # CC Emails
245
        cc_emails = map(lambda x: x.strip(), ar.getCCEmails().split(","))
246
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
247
248
        return to + cc + cc_emails
249

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

@@ 695-735 (lines=41) @@
692
        except (POSKeyError, TypeError):
693
            return None
694
695
    def get_recipients(self, ar):
696
        """Return the AR recipients in the same format like the AR Report
697
        expects in the records field `Recipients`
698
        """
699
        plone_utils = api.get_tool("plone_utils")
700
701
        def is_email(email):
702
            if not plone_utils.validateSingleEmailAddress(email):
703
                return False
704
            return True
705
706
        def recipient_from_contact(contact):
707
            if not contact:
708
                return None
709
            email = contact.getEmailAddress()
710
            return {
711
                "UID": api.get_uid(contact),
712
                "Username": contact.getUsername(),
713
                "Fullname": to_utf8(contact.Title()),
714
                "EmailAddress": email,
715
            }
716
717
        def recipient_from_email(email):
718
            if not is_email(email):
719
                return None
720
            return {
721
                "UID": "",
722
                "Username": "",
723
                "Fullname": email,
724
                "EmailAddress": email,
725
            }
726
727
        # Primary Contacts
728
        to = filter(None, [recipient_from_contact(ar.getContact())])
729
        # CC Contacts
730
        cc = filter(None, map(recipient_from_contact, ar.getCCContact()))
731
        # CC Emails
732
        cc_emails = map(lambda x: x.strip(), ar.getCCEmails().split(","))
733
        cc_emails = filter(None, map(recipient_from_email, cc_emails))
734
735
        return to + cc + cc_emails
736
737
    def ajax_recalculate_size(self):
738
        """Recalculate the total size of the selected attachments