paperless-ngx-csv-export 1.0.0__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,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: paperless-ngx-csv-export
3
+ Version: 1.0.0
4
+ Summary: CSV export admin action for Paperless-ngx
5
+ License: MIT
6
+ Project-URL: Homepage, https://pypi.org/user/DrTieGM/
7
+ Keywords: paperless-ngx,django,csv,export
8
+ Classifier: Framework :: Django
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+
14
+ # paperless-ngx-csv-export
15
+
16
+ CSV eksporta papildinājums Paperless-ngx sistēmai.
17
+
18
+ ## Instalācija
19
+
20
+ pip install paperless-ngx-csv-export
21
+
22
+ Pievienot docker-compose.env failā:
23
+
24
+ PAPERLESS_APPS=paperless_ngx_csv_export
25
+
26
+ ## Lietošana
27
+
28
+ 1. Atver /admin
29
+ 2. Dodies uz Documents vai Saved Views
30
+ 3. Atzīmē dokumentus/views
31
+ 4. Action dropdown izvēlies "Eksportēt CSV"
32
+ 5. Nospied "Go"
@@ -0,0 +1,19 @@
1
+ # paperless-ngx-csv-export
2
+
3
+ CSV eksporta papildinājums Paperless-ngx sistēmai.
4
+
5
+ ## Instalācija
6
+
7
+ pip install paperless-ngx-csv-export
8
+
9
+ Pievienot docker-compose.env failā:
10
+
11
+ PAPERLESS_APPS=paperless_ngx_csv_export
12
+
13
+ ## Lietošana
14
+
15
+ 1. Atver /admin
16
+ 2. Dodies uz Documents vai Saved Views
17
+ 3. Atzīmē dokumentus/views
18
+ 4. Action dropdown izvēlies "Eksportēt CSV"
19
+ 5. Nospied "Go"
@@ -0,0 +1,163 @@
1
+ import csv
2
+ import io
3
+
4
+ from django.contrib import admin
5
+ from django.http import HttpResponse
6
+ from guardian.admin import GuardedModelAdmin
7
+
8
+ from documents.models import CustomFieldInstance
9
+ from documents.models import Document
10
+ from documents.models import SavedView
11
+ from documents.models import SavedViewFilterRule
12
+
13
+
14
+ def build_csv_response(queryset, filename="paperless_eksports.csv"):
15
+ """
16
+ Izveido CSV failu no dokumentu queryset.
17
+ Iekļauj visus pamata laukus un custom fields.
18
+ Select tipa custom fields tiek pārvērsti no iekšēja ID uz lasāmu nosaukumu.
19
+ Atgriež HttpResponse ar CSV failu lejupielādei.
20
+ """
21
+ output = io.StringIO(newline='')
22
+ writer = csv.writer(output, delimiter='\t', lineterminator='\n')
23
+
24
+ writer.writerow([
25
+ "ID", "Title", "Correspondent", "Document type", "Storage path",
26
+ "Created", "Added", "ASN", "Owner", "Tags",
27
+ "Dokumenta Nr", "Līguma Nr", "EIS Nr", "Organizācija",
28
+ "Datums no", "Datums līdz", "Izbeigšanas datums",
29
+ "Darbinieks", "Summa bez PVN",
30
+ ])
31
+
32
+ for doc in queryset.select_related(
33
+ "correspondent", "document_type", "storage_path", "owner"
34
+ ).prefetch_related("custom_fields__field", "tags"):
35
+
36
+ # Iegūst custom field vērtības kā vārdnīcu {lauka nosaukums: vērtība}
37
+ # Select tipa laukiem pārvērš iekšējo ID uz lasāmu nosaukumu no extra_data
38
+ cf = {}
39
+ for i in doc.custom_fields.select_related("field"):
40
+ value = i.value
41
+ if value is None:
42
+ value = ""
43
+ elif i.field.data_type == "select":
44
+ options = i.field.extra_data.get("select_options", [])
45
+ label = next((o["label"] for o in options if o["id"] == value), value)
46
+ value = label
47
+ cf[i.field.name] = value
48
+
49
+ # Savieno tagus vienā virknē, atdalīti ar komatu
50
+ tags = ", ".join(t.name for t in doc.tags.all()) or ""
51
+
52
+ writer.writerow([
53
+ doc.id,
54
+ doc.title or "",
55
+ doc.correspondent.name if doc.correspondent else "",
56
+ doc.document_type.name if doc.document_type else "",
57
+ doc.storage_path.name if doc.storage_path else "",
58
+ doc.created.strftime("%Y-%m-%d") if doc.created else "",
59
+ doc.added.strftime("%Y-%m-%d") if doc.added else "",
60
+ doc.archive_serial_number or "",
61
+ doc.owner.username if doc.owner else "",
62
+ tags,
63
+ cf.get("Dokumenta Nr", ""),
64
+ cf.get("Līguma Nr", ""),
65
+ cf.get("EIS Nr", ""),
66
+ cf.get("Organizācija", ""),
67
+ cf.get("Datums no", ""),
68
+ cf.get("Datums līdz", ""),
69
+ cf.get("Izbeigšanas datums", ""),
70
+ cf.get("Darbinieks", ""),
71
+ cf.get("Summa bez PVN", ""),
72
+ ])
73
+
74
+ content = output.getvalue().encode("utf-16")
75
+ response = HttpResponse(content, content_type="text/csv; charset=utf-8")
76
+ response["Content-Disposition"] = f'attachment; filename="{filename}"'
77
+ return response
78
+
79
+
80
+ @admin.action(description="Eksportēt CSV")
81
+ def export_documents_csv(modeladmin, request, queryset):
82
+ """
83
+ Django Admin action dokumentu sarakstam.
84
+ Eksportē atzīmētos dokumentus CSV failā.
85
+ """
86
+ return build_csv_response(queryset)
87
+
88
+
89
+ @admin.action(description="Eksportēt CSV (Saved View)")
90
+ def export_saved_view_csv(modeladmin, request, queryset):
91
+ """
92
+ Django Admin action Saved Views sarakstam.
93
+ Katram atzīmētajam saved view iegūst atbilstošos dokumentus
94
+ pēc saglabātajiem filtriem un eksportē tos CSV failā.
95
+ """
96
+ all_docs = Document.global_objects.none()
97
+ for view in queryset:
98
+ filtered = Document.global_objects.all()
99
+ for rule in view.filter_rules.all():
100
+ rt = rule.rule_type
101
+ val = rule.value
102
+ if rt == 3 or rt == 26:
103
+ filtered = filtered.filter(correspondent__id=val)
104
+ elif rt == 4 or rt == 28:
105
+ filtered = filtered.filter(document_type__id=val)
106
+ elif rt == 25 or rt == 30:
107
+ filtered = filtered.filter(storage_path__id=val)
108
+ elif rt == 6 or rt == 22:
109
+ filtered = filtered.filter(tags__id=val)
110
+ elif rt == 0:
111
+ filtered = filtered.filter(title__icontains=val)
112
+ elif rt == 10:
113
+ filtered = filtered.filter(created__year=val)
114
+ elif rt == 11:
115
+ filtered = filtered.filter(created__month=val)
116
+ all_docs = all_docs | filtered
117
+ return build_csv_response(all_docs.distinct(), filename="paperless_saved_view_eksports.csv")
118
+
119
+
120
+ class CustomFieldInstanceInline(admin.TabularInline):
121
+ """
122
+ Inline klase custom field vērtību attēlošanai
123
+ dokumenta rediģēšanas lapā.
124
+ """
125
+ model = CustomFieldInstance
126
+ readonly_fields = ("field",)
127
+ exclude = ()
128
+ extra = 0
129
+ can_delete = False
130
+ verbose_name = "Custom Field"
131
+ verbose_name_plural = "Custom Fields"
132
+
133
+
134
+ class RuleInline(admin.TabularInline):
135
+ """Inline klase saved view filtra noteikumu rediģēšanai."""
136
+ model = SavedViewFilterRule
137
+
138
+
139
+ # Atreģistrē oriģinālās admin klases un reģistrē mūsējās ar papildu funkcijām
140
+ try:
141
+ admin.site.unregister(Document)
142
+ from documents.admin import DocumentAdmin as OriginalDocumentAdmin
143
+
144
+ class DocumentAdmin(OriginalDocumentAdmin):
145
+ """DocumentAdmin ar CSV eksporta action un custom fields inline."""
146
+ actions = [export_documents_csv]
147
+ inlines = [CustomFieldInstanceInline]
148
+
149
+ admin.site.register(Document, DocumentAdmin)
150
+ except admin.sites.NotRegistered:
151
+ pass
152
+
153
+ try:
154
+ admin.site.unregister(SavedView)
155
+ from documents.admin import SavedViewAdmin as OriginalSavedViewAdmin
156
+
157
+ class SavedViewAdmin(OriginalSavedViewAdmin):
158
+ """SavedViewAdmin ar CSV eksporta action."""
159
+ actions = [export_saved_view_csv]
160
+
161
+ admin.site.register(SavedView, SavedViewAdmin)
162
+ except admin.sites.NotRegistered:
163
+ pass
@@ -0,0 +1,14 @@
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class PaperlessNgxCsvExportConfig(AppConfig):
5
+ """Django app konfigurācija CSV eksporta papildinājumam."""
6
+ name = "paperless_ngx_csv_export"
7
+ verbose_name = "Paperless-ngx CSV Export"
8
+
9
+ def ready(self):
10
+ """
11
+ Pēc aplikācijas ielādes pārraksta DocumentAdmin un SavedViewAdmin
12
+ ar mūsu versijām, kas iekļauj CSV eksporta actions.
13
+ """
14
+ from . import admin # noqa: F401
@@ -0,0 +1,32 @@
1
+ Metadata-Version: 2.4
2
+ Name: paperless-ngx-csv-export
3
+ Version: 1.0.0
4
+ Summary: CSV export admin action for Paperless-ngx
5
+ License: MIT
6
+ Project-URL: Homepage, https://pypi.org/user/DrTieGM/
7
+ Keywords: paperless-ngx,django,csv,export
8
+ Classifier: Framework :: Django
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+
14
+ # paperless-ngx-csv-export
15
+
16
+ CSV eksporta papildinājums Paperless-ngx sistēmai.
17
+
18
+ ## Instalācija
19
+
20
+ pip install paperless-ngx-csv-export
21
+
22
+ Pievienot docker-compose.env failā:
23
+
24
+ PAPERLESS_APPS=paperless_ngx_csv_export
25
+
26
+ ## Lietošana
27
+
28
+ 1. Atver /admin
29
+ 2. Dodies uz Documents vai Saved Views
30
+ 3. Atzīmē dokumentus/views
31
+ 4. Action dropdown izvēlies "Eksportēt CSV"
32
+ 5. Nospied "Go"
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ paperless_ngx_csv_export/__init__.py
4
+ paperless_ngx_csv_export/admin.py
5
+ paperless_ngx_csv_export/apps.py
6
+ paperless_ngx_csv_export.egg-info/PKG-INFO
7
+ paperless_ngx_csv_export.egg-info/SOURCES.txt
8
+ paperless_ngx_csv_export.egg-info/dependency_links.txt
9
+ paperless_ngx_csv_export.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ paperless_ngx_csv_export
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "paperless-ngx-csv-export"
7
+ version = "1.0.0"
8
+ description = "CSV export admin action for Paperless-ngx"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ keywords = ["paperless-ngx", "django", "csv", "export"]
13
+ classifiers = [
14
+ "Framework :: Django",
15
+ "Programming Language :: Python :: 3",
16
+ "License :: OSI Approved :: MIT License",
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://pypi.org/user/DrTieGM/"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+