djresttoolkit 0.11.0__tar.gz → 0.12.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.
Files changed (45) hide show
  1. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/PKG-INFO +74 -2
  2. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/README.md +73 -1
  3. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/pyproject.toml +1 -1
  4. djresttoolkit-0.12.0/src/djresttoolkit/views/__init__.py +7 -0
  5. djresttoolkit-0.12.0/src/djresttoolkit/views/_api_views/__init__.py +0 -0
  6. djresttoolkit-0.12.0/src/djresttoolkit/views/_api_views/_choice_fields_apiview.py +42 -0
  7. djresttoolkit-0.11.0/src/djresttoolkit/views/__init__.py +0 -3
  8. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/.gitignore +0 -0
  9. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/LICENSE +0 -0
  10. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/demo/staticfiles/admin/img/LICENSE +0 -0
  11. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/__init__.py +0 -0
  12. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/admin.py +0 -0
  13. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/apps.py +0 -0
  14. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/dbseed/__init__.py +0 -0
  15. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/dbseed/models/__init__.py +0 -0
  16. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/dbseed/models/_choice_field.py +0 -0
  17. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/dbseed/models/_gen.py +0 -0
  18. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/dbseed/models/_seed_model.py +0 -0
  19. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/envconfig/__init__.py +0 -0
  20. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/envconfig/_env_settings.py +0 -0
  21. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/mail/__init__.py +0 -0
  22. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/mail/_email_sender.py +0 -0
  23. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/mail/_models.py +0 -0
  24. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/mail/_types.py +0 -0
  25. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/management/__init__.py +0 -0
  26. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/management/commands/__init__.py +0 -0
  27. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/management/commands/dbflush.py +0 -0
  28. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/management/commands/dbseed.py +0 -0
  29. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/middlewares/__init__.py +0 -0
  30. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/middlewares/_response_time_middleware.py +0 -0
  31. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/migrations/__init__.py +0 -0
  32. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/models/__init__.py +0 -0
  33. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/models/mixins/__init__.py +0 -0
  34. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/models/mixins/_model_choice_fields_mixin.py +0 -0
  35. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/py.typed +0 -0
  36. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/renderers/__init__.py +0 -0
  37. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/renderers/_throttle_info_json_renderer.py +0 -0
  38. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/serializers/__init__.py +0 -0
  39. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/serializers/mixins/__init__.py +0 -0
  40. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/serializers/mixins/_absolute_url_file_mixin.py +0 -0
  41. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/serializers/mixins/_bulk_create_mixin.py +0 -0
  42. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/throttling/__init__.py +0 -0
  43. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/throttling/_throttle_inspector.py +0 -0
  44. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/views/_exceptions/__init__.py +0 -0
  45. {djresttoolkit-0.11.0 → djresttoolkit-0.12.0}/src/djresttoolkit/views/_exceptions/_exception_handler.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: djresttoolkit
3
- Version: 0.11.0
3
+ Version: 0.12.0
4
4
  Summary: A collection of Django and DRF utilities to simplify API development.
5
5
  Project-URL: Homepage, https://github.com/shaileshpandit141/djresttoolkit
6
6
  Project-URL: Documentation, https://shaileshpandit141.github.io/djresttoolkit
@@ -622,7 +622,7 @@ A **Django model mixin** to retrieve **choice fields** from a model, designed to
622
622
 
623
623
  #### Model Choice Field Mixin Methods
624
624
 
625
- `get_choices() -> dict[str, dict[str, str]]`
625
+ - `get_choices() -> dict[str, dict[str, str]]`
626
626
 
627
627
  Retrieve the choice fields from the model as a dictionary.
628
628
 
@@ -681,6 +681,78 @@ print(choices)
681
681
  - Returns a ready-to-use dictionary mapping values to labels.
682
682
  - Ideal for DRF serializers, forms, and admin customization.
683
683
 
684
+ Here’s a concise **docs entry** for your `ChoiceFieldsAPIView` suitable for `djresttoolkit` documentation:
685
+
686
+ ---
687
+
688
+ ### 11. ChoiceFieldsAPIView — API Reference
689
+
690
+ ```python
691
+ from djresttoolkit.views import ChoiceFieldsAPIView
692
+ ```
693
+
694
+ #### `ChoiceFieldsAPIView`
695
+
696
+ A **generic DRF API view** to return all choices for specified model fields.
697
+
698
+ #### Class Attributes of Choice Fields APIView
699
+
700
+ - `model_class: type[Model] | None` — The Django model to inspect. **Must be set.**
701
+ - `choice_fields: list[str] | None` — List of fields on the model with choices. **Must be set.**
702
+
703
+ ---
704
+
705
+ #### Choice Fields APIView Methods
706
+
707
+ - `get(request: Request) -> Response`
708
+
709
+ Fetches the choices for the configured model fields.
710
+
711
+ - **Returns:**
712
+ - `200 OK` — JSON object containing all choices:
713
+
714
+ ```json
715
+ {
716
+ "choices": {
717
+ "status": {"draft": "Draft", "published": "Published"},
718
+ "category": {"a": "Category A", "b": "Category B"}
719
+ }
720
+ }
721
+ ```
722
+
723
+ - `400 Bad Request` — If any error occurs while retrieving choices.
724
+
725
+ - **Raises:**
726
+ - `AttributeDoesNotExist` — If `model_class` or `choice_fields` is not set.
727
+
728
+ ---
729
+
730
+ ### Example of Choice Fields APIView
731
+
732
+ ```python
733
+ from django.urls import path
734
+ from djresttoolkit.views import ChoiceFieldsAPIView
735
+ from myapp.models import Product
736
+
737
+ class ProductChoiceAPI(ChoiceFieldsAPIView):
738
+ model_class = Product
739
+ choice_fields = ["status", "category"]
740
+
741
+ urlpatterns = [
742
+ path(
743
+ "api/v1/product-choices/",
744
+ ProductChoiceAPI.as_view(),
745
+ name="product-choices"
746
+ ),
747
+ ]
748
+ ```
749
+
750
+ #### Choice Fields APIView Features
751
+
752
+ - Dynamically returns all choices for selected fields in a model.
753
+ - Useful for frontend forms or API consumers that need selectable options.
754
+ - Integrates seamlessly with `ModelChoiceFieldMixin` from `djresttoolkit`.
755
+
684
756
  ## 🛠️ Planned Features
685
757
 
686
758
  - Add more utils
@@ -564,7 +564,7 @@ A **Django model mixin** to retrieve **choice fields** from a model, designed to
564
564
 
565
565
  #### Model Choice Field Mixin Methods
566
566
 
567
- `get_choices() -> dict[str, dict[str, str]]`
567
+ - `get_choices() -> dict[str, dict[str, str]]`
568
568
 
569
569
  Retrieve the choice fields from the model as a dictionary.
570
570
 
@@ -623,6 +623,78 @@ print(choices)
623
623
  - Returns a ready-to-use dictionary mapping values to labels.
624
624
  - Ideal for DRF serializers, forms, and admin customization.
625
625
 
626
+ Here’s a concise **docs entry** for your `ChoiceFieldsAPIView` suitable for `djresttoolkit` documentation:
627
+
628
+ ---
629
+
630
+ ### 11. ChoiceFieldsAPIView — API Reference
631
+
632
+ ```python
633
+ from djresttoolkit.views import ChoiceFieldsAPIView
634
+ ```
635
+
636
+ #### `ChoiceFieldsAPIView`
637
+
638
+ A **generic DRF API view** to return all choices for specified model fields.
639
+
640
+ #### Class Attributes of Choice Fields APIView
641
+
642
+ - `model_class: type[Model] | None` — The Django model to inspect. **Must be set.**
643
+ - `choice_fields: list[str] | None` — List of fields on the model with choices. **Must be set.**
644
+
645
+ ---
646
+
647
+ #### Choice Fields APIView Methods
648
+
649
+ - `get(request: Request) -> Response`
650
+
651
+ Fetches the choices for the configured model fields.
652
+
653
+ - **Returns:**
654
+ - `200 OK` — JSON object containing all choices:
655
+
656
+ ```json
657
+ {
658
+ "choices": {
659
+ "status": {"draft": "Draft", "published": "Published"},
660
+ "category": {"a": "Category A", "b": "Category B"}
661
+ }
662
+ }
663
+ ```
664
+
665
+ - `400 Bad Request` — If any error occurs while retrieving choices.
666
+
667
+ - **Raises:**
668
+ - `AttributeDoesNotExist` — If `model_class` or `choice_fields` is not set.
669
+
670
+ ---
671
+
672
+ ### Example of Choice Fields APIView
673
+
674
+ ```python
675
+ from django.urls import path
676
+ from djresttoolkit.views import ChoiceFieldsAPIView
677
+ from myapp.models import Product
678
+
679
+ class ProductChoiceAPI(ChoiceFieldsAPIView):
680
+ model_class = Product
681
+ choice_fields = ["status", "category"]
682
+
683
+ urlpatterns = [
684
+ path(
685
+ "api/v1/product-choices/",
686
+ ProductChoiceAPI.as_view(),
687
+ name="product-choices"
688
+ ),
689
+ ]
690
+ ```
691
+
692
+ #### Choice Fields APIView Features
693
+
694
+ - Dynamically returns all choices for selected fields in a model.
695
+ - Useful for frontend forms or API consumers that need selectable options.
696
+ - Integrates seamlessly with `ModelChoiceFieldMixin` from `djresttoolkit`.
697
+
626
698
  ## 🛠️ Planned Features
627
699
 
628
700
  - Add more utils
@@ -4,7 +4,7 @@
4
4
 
5
5
  [project]
6
6
  name = "djresttoolkit"
7
- version = "0.11.0"
7
+ version = "0.12.0"
8
8
  description = "A collection of Django and DRF utilities to simplify API development."
9
9
  readme = { file = "README.md", content-type = "text/markdown" }
10
10
  license = { file = "LICENSE" }
@@ -0,0 +1,7 @@
1
+ from ._exceptions import exception_handler
2
+ from ._api_views._choice_fields_apiview import ChoiceFieldsAPIView
3
+
4
+ __all__ = [
5
+ "exception_handler",
6
+ "ChoiceFieldsAPIView",
7
+ ]
@@ -0,0 +1,42 @@
1
+ # views.py
2
+ from rest_framework.views import APIView
3
+ from rest_framework.response import Response
4
+ from rest_framework.request import Request
5
+ from rest_framework import status
6
+ from djresttoolkit.models.mixins import ModelChoiceFieldMixin, AttributeDoesNotExist
7
+ from django.db.models import Model
8
+
9
+
10
+ class ChoiceFieldsAPIView(APIView):
11
+ """
12
+ Generic API view to return choice fields from a model.
13
+ """
14
+
15
+ model_class: type[Model] | None = None
16
+ choice_fields: list[str] | None = None
17
+
18
+ def get(self, request: Request) -> Response:
19
+ """
20
+ Return a JSON response with all choices for the specified fields.
21
+ """
22
+ if not self.model_class or not self.choice_fields:
23
+ raise AttributeDoesNotExist(
24
+ "model_class and choice_fields must be set.",
25
+ )
26
+
27
+ # Dynamically create a mixin instance
28
+ class DynamicChoiceMixin(ModelChoiceFieldMixin):
29
+ model = self.model_class
30
+ choice_fields = self.choice_fields
31
+
32
+ try:
33
+ choices = DynamicChoiceMixin.get_choices()
34
+ return Response(
35
+ {"choices": choices},
36
+ status=status.HTTP_200_OK,
37
+ )
38
+ except Exception:
39
+ return Response(
40
+ {"detail": "An error occurred while retrieving choices."},
41
+ status=status.HTTP_400_BAD_REQUEST,
42
+ )
@@ -1,3 +0,0 @@
1
- from ._exceptions import exception_handler
2
-
3
- __all__ = ["exception_handler"]
File without changes