File: exceptions.py

package info (click to toggle)
python-django-import-export 4.3.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,300 kB
  • sloc: python: 11,650; makefile: 180; sh: 63; javascript: 50
file content (38 lines) | stat: -rw-r--r-- 1,002 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class ImportExportError(Exception):
    """A generic exception for all others to extend."""

    pass


class FieldError(ImportExportError):
    """Raised when a field encounters an error."""

    pass


class WidgetError(ImportExportError):
    """Raised when there is a misconfiguration with a Widget."""

    pass


class ImportError(ImportExportError):
    def __init__(self, error, number=None, row=None):
        """A wrapper for errors thrown from the import process.

        :param error: The underlying error that occurred.
        :param number: The row number of the row containing the error (if obtainable).
        :param row: The row containing the error (if obtainable).
        """
        self.error = error
        self.number = number
        self.row = row

    def __str__(self):
        s = ""
        if self.number is not None:
            s += f"{self.number}: "
        s += f"{self.error}"
        if self.row is not None:
            s += f" ({self.row})"
        return s