django-attachment-helpers 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-attachment-helpers
3
+ Version: 0.1.1
4
+ Summary: Generic create and delete helpers for Django attachment models
5
+ Author-email: Hemant Rawal <rawalhemant2059@gmail.com>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: django>=3.2
10
+
11
+ # django-attachment-helpers
12
+
13
+ Generic create and delete helpers for any Django attachment model.
14
+
15
+ ## Install
16
+ pip install django-attachment-helpers
17
+
18
+ ## Usage
19
+
20
+ from attachment_helpers import create_attachments, delete_attachments
21
+
22
+ # Create attachments
23
+ create_attachments(
24
+ model=ReportDoc,
25
+ parent_field="report",
26
+ parent_instance=report_obj,
27
+ titles=["Invoice", "Receipt"],
28
+ docs=[file1, file2],
29
+ )
30
+
31
+ # Delete attachments
32
+ delete_attachments(
33
+ model=ReportDoc,
34
+ parent_field="report",
35
+ parent_instance=report_obj,
36
+ deleted_ids=["1", "2"],
37
+ )
@@ -0,0 +1,27 @@
1
+ # django-attachment-helpers
2
+
3
+ Generic create and delete helpers for any Django attachment model.
4
+
5
+ ## Install
6
+ pip install django-attachment-helpers
7
+
8
+ ## Usage
9
+
10
+ from attachment_helpers import create_attachments, delete_attachments
11
+
12
+ # Create attachments
13
+ create_attachments(
14
+ model=ReportDoc,
15
+ parent_field="report",
16
+ parent_instance=report_obj,
17
+ titles=["Invoice", "Receipt"],
18
+ docs=[file1, file2],
19
+ )
20
+
21
+ # Delete attachments
22
+ delete_attachments(
23
+ model=ReportDoc,
24
+ parent_field="report",
25
+ parent_instance=report_obj,
26
+ deleted_ids=["1", "2"],
27
+ )
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "django-attachment-helpers"
7
+ version = "0.1.1"
8
+ description = "Generic create and delete helpers for Django attachment models"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ authors = [{ name = "Hemant Rawal", email = "rawalhemant2059@gmail.com" }]
12
+ license = "MIT"
13
+ dependencies = [
14
+ "django>=3.2",
15
+ ]
16
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,3 @@
1
+ from .attachments import create_attachments , delete_attachments
2
+
3
+ all = ["create_attachments", "delete_attachments"]
@@ -0,0 +1,52 @@
1
+ from typing import List, Optional, Type
2
+
3
+
4
+ def delete_attachments(model: Type, parent_field: str, parent_instance, deleted_ids: List[str]):
5
+ """
6
+ Generic delete helper for any attachment model.
7
+ """
8
+ if not deleted_ids:
9
+ return
10
+
11
+ filter_kwargs = {
12
+ "id__in": deleted_ids,
13
+ parent_field: parent_instance,
14
+ }
15
+
16
+ return model.objects.filter(**filter_kwargs).delete()
17
+
18
+
19
+ def create_attachments(
20
+ model: Type,
21
+ parent_field: str,
22
+ parent_instance,
23
+ titles: Optional[List[str]] = None,
24
+ docs: Optional[List] = None,
25
+ title_field: str = "title",
26
+ file_field: str = "doc",
27
+ use_bulk: bool = True,
28
+ ):
29
+ """
30
+ Generic create helper for any attachment model.
31
+ """
32
+ titles = titles or []
33
+ docs = docs or []
34
+
35
+ objects = []
36
+
37
+ for title, doc in zip(titles, docs):
38
+ if not title or not doc:
39
+ continue
40
+
41
+ obj_data = {
42
+ parent_field: parent_instance,
43
+ title_field: title.strip(),
44
+ file_field: doc,
45
+ }
46
+
47
+ objects.append(model(**obj_data))
48
+
49
+ if use_bulk:
50
+ return model.objects.bulk_create(objects)
51
+
52
+ return [obj.save() for obj in objects]
@@ -0,0 +1,37 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-attachment-helpers
3
+ Version: 0.1.1
4
+ Summary: Generic create and delete helpers for Django attachment models
5
+ Author-email: Hemant Rawal <rawalhemant2059@gmail.com>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: django>=3.2
10
+
11
+ # django-attachment-helpers
12
+
13
+ Generic create and delete helpers for any Django attachment model.
14
+
15
+ ## Install
16
+ pip install django-attachment-helpers
17
+
18
+ ## Usage
19
+
20
+ from attachment_helpers import create_attachments, delete_attachments
21
+
22
+ # Create attachments
23
+ create_attachments(
24
+ model=ReportDoc,
25
+ parent_field="report",
26
+ parent_instance=report_obj,
27
+ titles=["Invoice", "Receipt"],
28
+ docs=[file1, file2],
29
+ )
30
+
31
+ # Delete attachments
32
+ delete_attachments(
33
+ model=ReportDoc,
34
+ parent_field="report",
35
+ parent_instance=report_obj,
36
+ deleted_ids=["1", "2"],
37
+ )
@@ -0,0 +1,10 @@
1
+ README.md
2
+ pyproject.toml
3
+ src/django_attachment_helpers/__init__.py
4
+ src/django_attachment_helpers/attachments.py
5
+ src/django_attachment_helpers.egg-info/PKG-INFO
6
+ src/django_attachment_helpers.egg-info/SOURCES.txt
7
+ src/django_attachment_helpers.egg-info/dependency_links.txt
8
+ src/django_attachment_helpers.egg-info/requires.txt
9
+ src/django_attachment_helpers.egg-info/top_level.txt
10
+ test/tests_utils.py
@@ -0,0 +1,2 @@
1
+ django_attachment_helpers
2
+ test
File without changes