• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

liqd / adhocracy-plus / 25327419454

04 May 2026 03:20PM UTC coverage: 42.415% (-43.8%) from 86.168%
25327419454

Pull #3075

github

web-flow
Merge 06ba30015 into 15731e8ac
Pull Request #3075: [ST-1932] Breadcrumb Navigation

0 of 31 new or added lines in 1 file covered. (0.0%)

3376 existing lines in 150 files now uncovered.

3302 of 7785 relevant lines covered (42.41%)

0.42 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

40.48
/apps/users/fields.py
1
import re
1✔
2

3
from django import forms
1✔
4
from django.core.exceptions import ValidationError
1✔
5
from django.core.validators import EmailValidator
1✔
6
from django.forms import widgets
1✔
7
from django.utils.translation import gettext_lazy as _
1✔
8

9

10
class CommaSeparatedEmailField(forms.Field):
1✔
11
    email_validator = EmailValidator(
1✔
12
        message=_("Please enter correct email addresses, separated by " "commas.")
13
    )
14

15
    widget = widgets.TextInput(
1✔
16
        attrs={"placeholder": "maria@example.com, peter@example.com,…"}
17
    )
18

19
    def to_python(self, value):
1✔
UNCOV
20
        if not value:
×
21
            return []
×
22

UNCOV
23
        emails = []
×
UNCOV
24
        for email in value.split(","):
×
UNCOV
25
            email = email.strip()
×
UNCOV
26
            self.email_validator(email)
×
UNCOV
27
            emails.append(email)
×
28

UNCOV
29
        return emails
×
30

31

32
class EmailFileField(forms.FileField):
1✔
33
    """Extract emails from uploaded text files."""
34

35
    widget = widgets.FileInput
1✔
36
    # Find possible email strings. Emails may be quoted and separated by
37
    # whitespaces, commas, semicolons or < and >.
38
    email_regex = re.compile(r'[^\s;,"\'<]+@[^\s;,"\'>]+\.[a-z]{2,}')
1✔
39
    email_validator = EmailValidator()
1✔
40

41
    def clean(self, data, initial=None):
1✔
UNCOV
42
        file = super().clean(data, initial)
×
UNCOV
43
        return self._extract_emails(file)
×
44

45
    def _extract_emails(self, file):
1✔
UNCOV
46
        if not file:
×
UNCOV
47
            return []
×
48

49
        emails = []
×
50
        for byteline in file:
×
51
            # As it is difficult to guess the correct encoding of a file,
52
            # email addresses are restricted to contain only ascii letters.
53
            # This works for every encoding which is a superset of ascii like
54
            # utf-8 and latin-1. Non ascii chars are simply ignored.
55
            line = byteline.decode("ascii", "ignore")
×
56
            for match in self.email_regex.finditer(line):
×
57
                email = match.group(0)
×
58
                if self.is_valid_email(email):
×
59
                    emails.append(email)
×
60
        return emails
×
61

62
    def is_valid_email(self, email):
1✔
63
        try:
×
64
            self.email_validator(email)
×
65
            return True
×
66
        except ValidationError:
×
67
            return False
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc