-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Aakash Singh <[email protected]>
- Loading branch information
1 parent
0a4b338
commit fa80b2c
Showing
8 changed files
with
93 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,11 @@ jobs: | |
- uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: actions/setup-python@v3 | ||
|
||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.13" | ||
|
||
- uses: pre-commit/[email protected] | ||
with: | ||
extra_args: --color=always --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from rest_framework import serializers | ||
|
||
from care.users.models import PlugConfig | ||
|
||
|
||
class PLugConfigSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = PlugConfig | ||
exclude = ("id",) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.core.cache import cache | ||
from rest_framework.permissions import IsAdminUser | ||
from rest_framework.response import Response | ||
from rest_framework.viewsets import GenericViewSet, ModelViewSet | ||
|
||
from care.users.api.serializers.plug_config import PLugConfigSerializer | ||
from care.users.models import PlugConfig | ||
|
||
|
||
class PlugConfigViewset( | ||
ModelViewSet, | ||
GenericViewSet, | ||
): | ||
lookup_field = "slug" | ||
serializer_class = PLugConfigSerializer | ||
queryset = PlugConfig.objects.all().order_by("slug") | ||
cache_key = "care_plug_viewset_list" | ||
authentication_classes = [] | ||
|
||
def list(self, request, *args, **kwargs): | ||
# Cache data and return | ||
response = cache.get(self.cache_key) | ||
if not response: | ||
serializer = self.get_serializer(self.queryset, many=True) | ||
response = serializer.data | ||
cache.set(self.cache_key, response) | ||
return Response({"configs": [response]}) | ||
|
||
def perform_create(self, serializer): | ||
cache.delete(self.cache_key) | ||
serializer.save() | ||
|
||
def perform_update(self, serializer): | ||
cache.delete(self.cache_key) | ||
serializer.save() | ||
|
||
def perform_destroy(self, instance): | ||
cache.delete(self.cache_key) | ||
instance.delete() | ||
|
||
def get_permissions(self): | ||
if self.action in ["list", "retrieve"]: | ||
return [] | ||
return [IsAdminUser()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Generated by Django 5.1.1 on 2024-10-29 19:34 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0019_rename_doctor_qualification_user_qualification'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='PlugConfig', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('slug', models.CharField(max_length=255, unique=True)), | ||
('meta', models.JSONField(default=dict)), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters