epok-toolkit 1.8.3__py3-none-any.whl → 1.9.1__py3-none-any.whl

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.

Potentially problematic release.


This version of epok-toolkit might be problematic. Click here for more details.

@@ -1,2 +1,3 @@
1
1
  from .fields import *
2
- from .manager import *
2
+ from .manager import *
3
+ from .response import *
@@ -0,0 +1,57 @@
1
+ from rest_framework.response import Response
2
+ from django.http import HttpResponse
3
+ from typing import Optional
4
+
5
+
6
+ STATUS_MESSAGES = {
7
+ 200: "OK",
8
+ 201: "Created",
9
+ 202: "Accepted",
10
+ 204: "No Content",
11
+ 400: "Bad Request",
12
+ 401: "Unauthorized",
13
+ 403: "Forbidden",
14
+ 404: "Not Found",
15
+ 500: "Internal Server Error",
16
+ }
17
+
18
+
19
+
20
+ def response(data: Optional[dict] = None, status_code: int = 200, message: Optional[str] = None) -> Response:
21
+ success = True if 200 <= status_code < 300 else False
22
+
23
+ if status_code not in STATUS_MESSAGES:
24
+ raise ValueError(f"Invalid status code: {status_code}. Must be one of {list(STATUS_MESSAGES.keys())}.")
25
+
26
+ if status_code == 201 and not data:
27
+ raise ValueError("Data cannot be empty for status code 201 (Created).")
28
+
29
+ if status_code == 204 and data is not None:
30
+ raise ValueError("Data must be None for status code 204 (No Content).")
31
+
32
+ if not message:
33
+ message = STATUS_MESSAGES[status_code]
34
+
35
+ if not data:
36
+ data = {}
37
+
38
+ payload = {
39
+ "status": success,
40
+ "message": message
41
+ }
42
+ if success and data is not None:
43
+ payload["data"] = data
44
+ elif not success:
45
+ payload["error"] = data
46
+ return Response(payload, status=status_code)
47
+
48
+
49
+
50
+ def file_response(file: bytes, filename: str, content_type: str = "application/octet-stream", status_code: int = 200) -> HttpResponse:
51
+ """
52
+ Returns a file response with the given file content, filename, and content type.
53
+ """
54
+ response = HttpResponse(file, status=status_code)
55
+ response["Content-Disposition"] = f'attachment; filename="{filename}"'
56
+ response["Content-Type"] = content_type
57
+ return response
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: epok-toolkit
3
- Version: 1.8.3
3
+ Version: 1.9.1
4
4
  Summary: Una herramienta para la gestión de tareas y procesos en Django con Celery.
5
5
  Author-email: Fernando Leon Franco <fernanlee2131@gmail.com>
6
6
  License: MIT
@@ -12,6 +12,7 @@ Requires-Python: >=3.12.9
12
12
  Description-Content-Type: text/markdown
13
13
  License-File: LICENSE
14
14
  Requires-Dist: Django>=5.0.2
15
+ Requires-Dist: djangorestframework>=3.16.0
15
16
  Requires-Dist: celery[redis]>=5.5.3
16
17
  Requires-Dist: django-celery-beat>=2.6.0
17
18
  Requires-Dist: colorstreak>=0.1.0
@@ -19,5 +20,5 @@ Dynamic: license-file
19
20
 
20
21
  # EPOK Toolkit
21
22
 
22
- This is a modular toolkit for Django projects including messaging, email, and PDF generation components. Built by Fer León.
23
+ Esta libreria contiene utilidades
23
24
 
@@ -3,9 +3,10 @@ epok_toolkit/apps.py,sha256=O3q3CcucJOHjlYIS0VgbKsbtim2hpng_FxpKEG_MlWs,486
3
3
  epok_toolkit/default_settings.py,sha256=hxsRmsAcjk4ar-pRz_X6AI17mJ3192Ljbx-xBuP5rdY,452
4
4
  epok_toolkit/cache/__init__.py,sha256=q1-pMbXk-r80a3woyq01E84Tt6kB-UH5u06XoQROaM0,68
5
5
  epok_toolkit/cache/cacher.py,sha256=R179_Hrlw1k0tsry9EN0zGl4-Of02L-VzE-xqFuXjaU,4107
6
- epok_toolkit/django/__init__.py,sha256=Y4V9RImrdma2A2nAIfsk1fLpamcSbBNZ297db3iv6DI,44
6
+ epok_toolkit/django/__init__.py,sha256=WjNrw4_QGkAwTWa5C1ksTewKDH1l91mekf5Wlfl3F6w,68
7
7
  epok_toolkit/django/fields.py,sha256=-ajP5qx-4bt9Qz9yW48gTlinTxD1xWPKOEkslqx8cSM,1089
8
8
  epok_toolkit/django/manager.py,sha256=nmgTgvT9fbEiltwxGfqZdphNPbWzSGzkLYRhHVfTXZA,1354
9
+ epok_toolkit/django/response.py,sha256=O8OHBaKgUQjBeYLLbgTTs669l_4D6swUgAOwswjc-88,1716
9
10
  epok_toolkit/email/__init__.py,sha256=pyJwysyVoq6DuYAG72fulsKFoOuAfjw3aBH7FhmYGHc,35
10
11
  epok_toolkit/email/email_async.py,sha256=oC0WowWNUpTpXdxo6hJag5gWUaStxI6VBEArEKQxXko,1521
11
12
  epok_toolkit/email/engine.py,sha256=IIifqRI9z76pHdrO5oSSZ25aP5txOTAgrj1JuVVPlMY,2387
@@ -21,8 +22,8 @@ epok_toolkit/pdf/fuentes/Kollektif-Italic.ttf,sha256=1CXPyw43il9u0tQ_7aRzsEaVtg3
21
22
  epok_toolkit/pdf/fuentes/Kollektif.ttf,sha256=7wTLkVVNUm1giLjIZcWRUH5r2r3o0GjdKic4V1A-pNQ,51128
22
23
  epok_toolkit/pdf/plantillas/Ticket_congrats.png,sha256=OSQhVR0j_nLHE6kSJ33BTR-77HM1fNAfJBe2EuX6wVk,157141
23
24
  epok_toolkit/pdf/plantillas/Ticket_congrats2.png,sha256=1RBogBdo-8WSMpD3H73HoLgJtr5EC5oVKfOCIWOxPSo,373605
24
- epok_toolkit-1.8.3.dist-info/licenses/LICENSE,sha256=iLDbGXdLSIOT5OsxzHCvtmxHtonE21GiFlS3LNkug4A,128
25
- epok_toolkit-1.8.3.dist-info/METADATA,sha256=_Z13k2BjbsM_eKB-BhAd5pWrTd00_RsYN9GQ1wfNzEE,786
26
- epok_toolkit-1.8.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
27
- epok_toolkit-1.8.3.dist-info/top_level.txt,sha256=Wo72AqIFcfWwBGM5F5iGFw9PrO3WBnTSprFZIJk_pNg,13
28
- epok_toolkit-1.8.3.dist-info/RECORD,,
25
+ epok_toolkit-1.9.1.dist-info/licenses/LICENSE,sha256=iLDbGXdLSIOT5OsxzHCvtmxHtonE21GiFlS3LNkug4A,128
26
+ epok_toolkit-1.9.1.dist-info/METADATA,sha256=iJiZRipHnAlvc7Z2cINZ5qrECVe_p6M3QnihEQhIEi4,738
27
+ epok_toolkit-1.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
28
+ epok_toolkit-1.9.1.dist-info/top_level.txt,sha256=Wo72AqIFcfWwBGM5F5iGFw9PrO3WBnTSprFZIJk_pNg,13
29
+ epok_toolkit-1.9.1.dist-info/RECORD,,