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

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

11 Sep 2023 07:22AM UTC coverage: 77.914% (-0.2%) from 78.1%
6143239757

push

github

web-flow
Merge pull request #14 from saritasa-nest/extend-documentation

13 of 19 new or added lines in 5 files covered. (68.42%)

6 existing lines in 2 files now uncovered.

1083 of 1390 relevant lines covered (77.91%)

9.34 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