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

liqd / roots / 26235555947

21 May 2026 03:24PM UTC coverage: 40.79% (-39.5%) from 80.274%
26235555947

Pull #112

github

web-flow
Merge 0c04922a1 into fb15f37ba
Pull Request #112: [ST-2214] Add more Information to Sentry Error + Solve absolute Url Bug

9 of 27 new or added lines in 5 files covered. (33.33%)

3614 existing lines in 161 files now uncovered.

3736 of 9159 relevant lines covered (40.79%)

0.41 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