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

saritasa-nest / django-import-export-extensions / 6955835944

22 Nov 2023 10:14AM UTC coverage: 78.478% (+0.4%) from 78.121%
6955835944

Pull #25

github

web-flow
Merge 82e75b45f into a3aa8ce29
Pull Request #25: Add force-import feature

57 of 70 new or added lines in 8 files covered. (81.43%)

12 existing lines in 1 file now uncovered.

1134 of 1445 relevant lines covered (78.48%)

9.41 hits per line

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

52.0
/import_export_extensions/admin/model_admins/mixins.py
1
import typing
12✔
2

3
from django.contrib.contenttypes.models import ContentType
12✔
4
from django.core.handlers.wsgi import WSGIRequest
12✔
5
from django.utils.module_loading import import_string
12✔
6
from django.utils.translation import gettext_lazy as _
12✔
7

8
from ... import models
12✔
9

10

11
class BaseImportExportJobAdminMixin:
12✔
12
    """Mixin provides common methods for ImportJob and ExportJob admins."""
13

14
    def has_add_permission(
12✔
15
        self,
16
        request: WSGIRequest,
17
        *args,
18
        **kwargs,
19
    ) -> bool:
20
        """Import/Export Jobs should not be created using this interface."""
21
        return False
12✔
22

23
    def has_delete_permission(
12✔
24
        self,
25
        request: WSGIRequest,
26
        *args,
27
        **kwargs,
28
    ) -> bool:
29
        """Import/Export Jobs should not be deleted using this interface.
30

31
        Instead, admins must cancel jobs.
32

33
        """
34
        return False
12✔
35

36
    def _model(self, obj: models.ImportJob) -> str:
12✔
37
        """Add `model` field of import/export job."""
38
        try:
×
39
            resource_class = import_string(obj.resource_path)
×
40
            model = resource_class.Meta.model._meta.verbose_name_plural
×
41
        # In case resource has no Meta or model we need to catch AttributeError
42
        except (ImportError, AttributeError):
×
43
            model = _("Unknown")
×
44
        return model
×
45

46
    def get_from_content_type(
12✔
47
        self,
48
        obj: typing.Union[models.ImportJob, models.ExportJob],
49
    ) -> typing.Union[ContentType, None]:
50
        """Shortcut to get object from content_type."""
51
        content_type = obj.resource_kwargs.get("content_type")
×
52
        obj_id = obj.resource_kwargs.get("object_id")
×
53

54
        if content_type and obj_id:
×
55
            content_type = ContentType.objects.get(id=content_type)
×
56
            return content_type.model_class().objects.filter(id=obj_id).first()
×
57
        return None
×
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

© 2025 Coveralls, Inc