mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
jira-15 dashboard API
This commit is contained in:
@ -87,7 +87,7 @@ class ChangePasswordSerializer(serializers.Serializer):
|
|||||||
if self.context.password not in ('', None):
|
if self.context.password not in ('', None):
|
||||||
if user.check_password(value):
|
if user.check_password(value):
|
||||||
return value
|
return value
|
||||||
raise serializers.ValidationError({"details":ERROR_CODE['2015']})
|
raise serializers.ValidationError(ERROR_CODE['2015'])
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
new_password = validated_data.pop('new_password')
|
new_password = validated_data.pop('new_password')
|
||||||
current_password = validated_data.pop('current_password')
|
current_password = validated_data.pop('current_password')
|
||||||
|
@ -81,7 +81,7 @@ SUCCESS_CODE = {
|
|||||||
"3015": "Verification code sent on your email.",
|
"3015": "Verification code sent on your email.",
|
||||||
"3016": "Send otp on your Email successfully",
|
"3016": "Send otp on your Email successfully",
|
||||||
"3017": "Profile image update successfully",
|
"3017": "Profile image update successfully",
|
||||||
"3018": "Created task successfully"
|
"3018": "Task created successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
STATUS_CODE_ERROR = {
|
STATUS_CODE_ERROR = {
|
||||||
|
@ -16,7 +16,7 @@ class GuardianAdmin(admin.ModelAdmin):
|
|||||||
@admin.register(JuniorTask)
|
@admin.register(JuniorTask)
|
||||||
class TaskAdmin(admin.ModelAdmin):
|
class TaskAdmin(admin.ModelAdmin):
|
||||||
"""Junior Admin"""
|
"""Junior Admin"""
|
||||||
list_display = ['task_name', 'task_status', 'junior', 'points']
|
list_display = ['id', 'task_name', 'task_status', 'junior', 'due_date', 'points', 'created_at', 'updated_at']
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Return email id"""
|
"""Return email id"""
|
||||||
|
18
guardian/migrations/0012_alter_juniortask_default_image.py
Normal file
18
guardian/migrations/0012_alter_juniortask_default_image.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-06 05:12
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('guardian', '0011_juniortask_default_image_juniortask_is_approved_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='juniortask',
|
||||||
|
name='default_image',
|
||||||
|
field=models.URLField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
]
|
18
guardian/migrations/0013_alter_guardian_image.py
Normal file
18
guardian/migrations/0013_alter_guardian_image.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 4.2.2 on 2023-07-06 06:40
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('guardian', '0012_alter_juniortask_default_image'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='guardian',
|
||||||
|
name='image',
|
||||||
|
field=models.URLField(blank=True, default=None, null=True),
|
||||||
|
),
|
||||||
|
]
|
@ -16,7 +16,7 @@ class Guardian(models.Model):
|
|||||||
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
phone = models.CharField(max_length=31, null=True, blank=True, default=None)
|
||||||
country_name = models.CharField(max_length=100, null=True, blank=True, default=None)
|
country_name = models.CharField(max_length=100, null=True, blank=True, default=None)
|
||||||
"""Image info"""
|
"""Image info"""
|
||||||
image = models.ImageField(null=True, blank=True, default=None)
|
image = models.URLField(null=True, blank=True, default=None)
|
||||||
"""Personal info"""
|
"""Personal info"""
|
||||||
family_name = models.CharField(max_length=50, null=True, blank=True, default=None)
|
family_name = models.CharField(max_length=50, null=True, blank=True, default=None)
|
||||||
gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None)
|
gender = models.CharField(choices=GENDERS, max_length=15, null=True, blank=True, default=None)
|
||||||
@ -50,7 +50,7 @@ class JuniorTask(models.Model):
|
|||||||
task_description = models.CharField(max_length=500)
|
task_description = models.CharField(max_length=500)
|
||||||
points = models.IntegerField(default=TASK_POINTS)
|
points = models.IntegerField(default=TASK_POINTS)
|
||||||
due_date = models.DateField(auto_now_add=False, null=True, blank=True)
|
due_date = models.DateField(auto_now_add=False, null=True, blank=True)
|
||||||
default_image = models.ImageField(null=True, blank=True, default=None)
|
default_image = models.URLField(null=True, blank=True, default=None)
|
||||||
image = models.URLField(null=True, blank=True, default=None)
|
image = models.URLField(null=True, blank=True, default=None)
|
||||||
junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='junior', verbose_name='Junior')
|
junior = models.ForeignKey(Junior, on_delete=models.CASCADE, related_name='junior', verbose_name='Junior')
|
||||||
task_status = models.CharField(choices=TASK_STATUS, max_length=15, default=PENDING)
|
task_status = models.CharField(choices=TASK_STATUS, max_length=15, default=PENDING)
|
||||||
|
@ -129,9 +129,9 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
|
|||||||
if image:
|
if image:
|
||||||
filename = f"images/{image.name}"
|
filename = f"images/{image.name}"
|
||||||
image_url = upload_image_to_alibaba(image, filename)
|
image_url = upload_image_to_alibaba(image, filename)
|
||||||
print("image_url=====>",image_url)
|
print("image_url=====>",image_url,'===>',type(image_url))
|
||||||
guardian.image = image_url
|
guardian.image = image_url
|
||||||
print("guardian.image=====>", guardian.image)
|
print("guardian.image=====>", guardian.image,'===>',type(guardian.image))
|
||||||
guardian.save()
|
guardian.save()
|
||||||
return guardian
|
return guardian
|
||||||
|
|
||||||
@ -146,13 +146,11 @@ class CreateGuardianSerializer(serializers.ModelSerializer):
|
|||||||
class TaskSerializer(serializers.ModelSerializer):
|
class TaskSerializer(serializers.ModelSerializer):
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = JuniorTask
|
model = JuniorTask
|
||||||
fields = ['task_name','task_description','points', 'due_date', 'junior', 'image']
|
fields = ['task_name','task_description','points', 'due_date', 'junior', 'default_image']
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
validated_data['guardian'] = Guardian.objects.filter(user=self.context['user']).last()
|
validated_data['guardian'] = Guardian.objects.filter(user=self.context['user']).last()
|
||||||
images = self.context['image']
|
images = self.context['image']
|
||||||
validated_data['image'] = images
|
validated_data['default_image'] = images
|
||||||
print("images===>",images)
|
|
||||||
print("validated_data===>",validated_data)
|
|
||||||
# if 'http' in str(images):
|
# if 'http' in str(images):
|
||||||
# validated_data['image'] = images
|
# validated_data['image'] = images
|
||||||
# else:
|
# else:
|
||||||
@ -192,8 +190,8 @@ class TaskDetailsSerializer(serializers.ModelSerializer):
|
|||||||
junior = JuniorDetailSerializer()
|
junior = JuniorDetailSerializer()
|
||||||
class Meta(object):
|
class Meta(object):
|
||||||
model = JuniorTask
|
model = JuniorTask
|
||||||
fields = ['id', 'guardian', 'task_name', 'task_description', 'points', 'due_date', 'image','junior',
|
fields = ['id', 'guardian', 'task_name', 'task_description', 'points', 'due_date','default_image', 'image',
|
||||||
'task_status', 'is_active']
|
'junior', 'task_status', 'is_active', 'created_at','updated_at']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,5 +10,9 @@ def upload_image_to_alibaba(image, filename):
|
|||||||
bucket = oss2.Bucket(auth, settings.ALIYUN_OSS_ENDPOINT, settings.ALIYUN_OSS_BUCKET_NAME)
|
bucket = oss2.Bucket(auth, settings.ALIYUN_OSS_ENDPOINT, settings.ALIYUN_OSS_BUCKET_NAME)
|
||||||
# Upload the temporary file to Alibaba OSS
|
# Upload the temporary file to Alibaba OSS
|
||||||
bucket.put_object_from_file(filename, temp_file.name)
|
bucket.put_object_from_file(filename, temp_file.name)
|
||||||
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{filename}"
|
print("filename====>",filename,'===>',type(filename))
|
||||||
|
new_filename = filename.replace(' ', '%20')
|
||||||
|
print()
|
||||||
|
print("filename====>", filename, '===>', type(filename))
|
||||||
|
return f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{new_filename}"
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"""Third party Django app"""
|
"""Third party Django app"""
|
||||||
from rest_framework.permissions import IsAuthenticated
|
from rest_framework.permissions import IsAuthenticated
|
||||||
from rest_framework import viewsets, status
|
from rest_framework import viewsets, status
|
||||||
|
from rest_framework.pagination import PageNumberPagination
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
"""Import Django app"""
|
"""Import Django app"""
|
||||||
from .serializers import (UserSerializer, CreateGuardianSerializer, TaskSerializer, TaskDetailsSerializer,
|
from .serializers import (UserSerializer, CreateGuardianSerializer, TaskSerializer, TaskDetailsSerializer,
|
||||||
@ -64,35 +65,34 @@ class AllTaskListAPIView(viewsets.ModelViewSet):
|
|||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
"""Create guardian profile"""
|
"""Create guardian profile"""
|
||||||
queryset = JuniorTask.objects.filter(guardian__user=request.user)
|
queryset = JuniorTask.objects.filter(guardian__user=request.user)
|
||||||
print("queryset==>",queryset)
|
|
||||||
serializer = TaskDetailsSerializer(queryset, many=True)
|
serializer = TaskDetailsSerializer(queryset, many=True)
|
||||||
print("serializer.data===>",serializer.data)
|
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class TaskListAPIView(viewsets.ModelViewSet):
|
class TaskListAPIView(viewsets.ModelViewSet):
|
||||||
"""Update guardian profile"""
|
"""Update guardian profile"""
|
||||||
serializer_class = TaskDetailsSerializer
|
serializer_class = TaskDetailsSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
pagination_class = PageNumberPagination
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
"""Create guardian profile"""
|
"""Create guardian profile"""
|
||||||
print("request.GET.get(status)==>",self.request.GET.get('status'))
|
|
||||||
status_value = self.request.GET.get('status')
|
status_value = self.request.GET.get('status')
|
||||||
if status_value == 0:
|
if status_value == 0:
|
||||||
queryset = JuniorTask.objects.filter(guardian__user=request.user)
|
queryset = JuniorTask.objects.filter(guardian__user=request.user).order_by('created_at')
|
||||||
else:
|
else:
|
||||||
queryset = JuniorTask.objects.filter(guardian__user=request.user,
|
queryset = JuniorTask.objects.filter(guardian__user=request.user,
|
||||||
task_status=status_value)
|
task_status=status_value).order_by('due_date','created_at')
|
||||||
print("queryset==>",queryset)
|
paginator = self.pagination_class()
|
||||||
serializer = TaskDetailsSerializer(queryset, many=True)
|
paginated_queryset = paginator.paginate_queryset(queryset, request)
|
||||||
print("serializer.data===>",serializer.data)
|
serializer = TaskDetailsSerializer(paginated_queryset, many=True)
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
class CreateTaskAPIView(viewsets.ModelViewSet):
|
class CreateTaskAPIView(viewsets.ModelViewSet):
|
||||||
"""create task for junior"""
|
"""create task for junior"""
|
||||||
serializer_class = TaskSerializer
|
serializer_class = TaskSerializer
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
image = request.data['image']
|
image = request.data['default_image']
|
||||||
data = request.data
|
data = request.data
|
||||||
if 'https' in str(image):
|
if 'https' in str(image):
|
||||||
image_data = image
|
image_data = image
|
||||||
@ -100,7 +100,7 @@ class CreateTaskAPIView(viewsets.ModelViewSet):
|
|||||||
filename = f"images/{image}"
|
filename = f"images/{image}"
|
||||||
image_url = upload_image_to_alibaba(image, filename)
|
image_url = upload_image_to_alibaba(image, filename)
|
||||||
image_data = image_url
|
image_data = image_url
|
||||||
data.pop('image')
|
data.pop('default_image')
|
||||||
serializer = TaskSerializer(context={"user":request.user, "image":image_data}, data=data)
|
serializer = TaskSerializer(context={"user":request.user, "image":image_data}, data=data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
serializer.save()
|
serializer.save()
|
||||||
@ -112,21 +112,17 @@ class SearchTaskListAPIView(viewsets.ModelViewSet):
|
|||||||
"""Update guardian profile"""
|
"""Update guardian profile"""
|
||||||
serializer_class = TaskDetailsSerializer
|
serializer_class = TaskDetailsSerializer
|
||||||
permission_classes = [IsAuthenticated]
|
permission_classes = [IsAuthenticated]
|
||||||
|
pagination_class = PageNumberPagination
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
"""Create guardian profile"""
|
"""Create guardian profile"""
|
||||||
due_date = self.request.GET.get('due_date')
|
title = self.request.GET.get('title')
|
||||||
print("request.GET.get(status)==>",self.request.GET.get('status'))
|
if title:
|
||||||
if self.request.GET.get('status'):
|
queryset = JuniorTask.objects.filter(guardian__user=request.user, task_name__icontains=title)\
|
||||||
queryset = JuniorTask.objects.filter(guardian__user=request.user,
|
.order_by('due_date','created_at')
|
||||||
task_status=self.request.GET.get('status')).order_by('due_date')
|
paginator = self.pagination_class()
|
||||||
if due_date:
|
paginated_queryset = paginator.paginate_queryset(queryset, request)
|
||||||
queryset = JuniorTask.objects.filter(guardian__user=request.user,
|
serializer = TaskDetailsSerializer(paginated_queryset, many=True)
|
||||||
due_date=due_date).order_by('due_date').order_by('created_at')
|
|
||||||
|
|
||||||
print("queryset==>",queryset)
|
|
||||||
serializer = TaskDetailsSerializer(queryset, many=True)
|
|
||||||
# print("serializer.data===>",serializer.data)
|
|
||||||
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(None, serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
@ -144,11 +140,10 @@ class TopJuniorListAPIView(viewsets.ModelViewSet):
|
|||||||
|
|
||||||
junior_ids = [item['junior'] for item in junior_ids_with_total_points]
|
junior_ids = [item['junior'] for item in junior_ids_with_total_points]
|
||||||
|
|
||||||
juniors = Junior.objects.filter(id__in=junior_ids) \
|
juniors = Junior.objects.filter(id__in=junior_ids)
|
||||||
.annotate(max_points=Max('junior_task__points')) \
|
|
||||||
.order_by('-max_points', 'id')
|
|
||||||
|
|
||||||
serializer = self.get_serializer(juniors, many=True, context={'junior_ids_with_total_points': junior_ids_with_total_points})
|
serializer = self.get_serializer(juniors, many=True, context={'junior_ids_with_total_points':
|
||||||
|
junior_ids_with_total_points})
|
||||||
return custom_response(serializer.data, response_status=status.HTTP_200_OK)
|
return custom_response(serializer.data, response_status=status.HTTP_200_OK)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -92,8 +92,9 @@ REST_FRAMEWORK = {
|
|||||||
'DEFAULT_AUTHENTICATION_CLASSES': [
|
'DEFAULT_AUTHENTICATION_CLASSES': [
|
||||||
# 'rest_framework.authentication.SessionAuthentication',
|
# 'rest_framework.authentication.SessionAuthentication',
|
||||||
'rest_framework.authentication.BasicAuthentication',
|
'rest_framework.authentication.BasicAuthentication',
|
||||||
'rest_framework_simplejwt.authentication.JWTAuthentication',
|
'rest_framework_simplejwt.authentication.JWTAuthentication',],
|
||||||
]
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
||||||
|
'PAGE_SIZE': 5, # Set the default pagination size
|
||||||
}
|
}
|
||||||
SIMPLE_JWT = {
|
SIMPLE_JWT = {
|
||||||
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=50),
|
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=50),
|
||||||
|
Reference in New Issue
Block a user