From ed28117a7f30f0f1d444e8bf6a44b2bab53e849b Mon Sep 17 00:00:00 2001 From: jain Date: Mon, 24 Jul 2023 15:10:59 +0530 Subject: [PATCH] bugs and push notification for create task --- base/messages.py | 6 +++++- celerybeat-schedule | Bin 0 -> 16384 bytes guardian/serializers.py | 8 ++++++++ guardian/views.py | 14 ++++++++++++-- junior/views.py | 5 ++++- notifications/constants.py | 5 +++++ 6 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 celerybeat-schedule diff --git a/base/messages.py b/base/messages.py index 38c345d..865a6d6 100644 --- a/base/messages.py +++ b/base/messages.py @@ -75,7 +75,11 @@ ERROR_CODE = { "2042": "Article Card with given id doesn't exist.", "2043": "Article Survey with given id doesn't exist.", "2044": "Task does not exist", - "2045": "Invalid guardian" + "2045": "Invalid guardian", + "2046": "Due date must be future date", + "2047": "Invalid Junior ID ", + "2048": "Choose right file for image", + "2049": "This task is already requested " } """Success message code""" SUCCESS_CODE = { diff --git a/celerybeat-schedule b/celerybeat-schedule new file mode 100644 index 0000000000000000000000000000000000000000..2e805bda3e0039d93c7d85c2524de869889c8544 GIT binary patch literal 16384 zcmeI(J#W)M7zgl6-8RjY^o2kPAR#1>S{STWyo?B`>VPU1Q-sBUWnT_r)m-w}XG9}K z$`rxI%m+Y>h%W#u6CZ$yiH%Qy1b4AhGO!dxB+%cH{anu0aJWqwu7Fc&Mh{~2f4QPP_69i3;*JV}f#c7a>0WcMxLf9o?wJn9bllzBHg9bumMV-A*%~;{ z+{r=wHFK4aiA)dNC=~lrwE~gIP~}~!i17&-YJNwwWh+nQj+w#%r%9ty4~OqSsL}Ru4P;zG>XD4Vw4u9~pvN zbz`xgNU9EL!K2#Y*WkOAAuW1zY)EyFmUh{Ac3C;GjEl6RbQp13-tbK_uuWPS#jCVB zikInl+q^V2JUY>*lhLIrB&WkIrPS>Bj~E2tWV=5P$## PAOHafKmY;|n7Y6ZTU<&y literal 0 HcmV?d00001 diff --git a/guardian/serializers.py b/guardian/serializers.py index a5ad978..a8a2e46 100644 --- a/guardian/serializers.py +++ b/guardian/serializers.py @@ -169,6 +169,14 @@ class TaskSerializer(serializers.ModelSerializer): """Meta info""" model = JuniorTask fields = ['id', 'task_name','task_description','points', 'due_date', 'junior', 'default_image'] + + def validate_due_date(self, value): + """validation on due date""" + if value < datetime.today().date(): + raise serializers.ValidationError({"details": ERROR_CODE['2046'], + "code": 400, "status": "failed", + }) + return value def create(self, validated_data): """create default task image data""" validated_data['guardian'] = Guardian.objects.filter(user=self.context['user']).last() diff --git a/guardian/views.py b/guardian/views.py index a320385..973ac19 100644 --- a/guardian/views.py +++ b/guardian/views.py @@ -30,7 +30,7 @@ from account.utils import custom_response, custom_error_response from base.messages import ERROR_CODE, SUCCESS_CODE from base.constants import NUMBER from .utils import upload_image_to_alibaba -from notifications.constants import REGISTRATION +from notifications.constants import REGISTRATION, TASK_CREATED from notifications.utils import send_notification """ Define APIs """ @@ -119,6 +119,7 @@ class TaskListAPIView(viewsets.ModelViewSet): permission_classes = [IsAuthenticated] pagination_class = PageNumberPagination queryset = JuniorTask.objects.all() + http_method_names = ('get',) def list(self, request, *args, **kwargs): """Create guardian profile""" @@ -146,9 +147,17 @@ class CreateTaskAPIView(viewsets.ModelViewSet): """create task for junior""" serializer_class = TaskSerializer queryset = JuniorTask.objects.all() + http_method_names = ('post', ) def create(self, request, *args, **kwargs): image = request.data['default_image'] + junior = request.data['junior'] + allowed_extensions = ['.jpg', '.jpeg', '.png'] + if not any(extension in str(image) for extension in allowed_extensions): + return custom_error_response(ERROR_CODE['2048'], response_status=status.HTTP_400_BAD_REQUEST) + if not junior.isnumeric(): + """junior value must be integer""" + return custom_error_response(ERROR_CODE['2047'], response_status=status.HTTP_400_BAD_REQUEST) data = request.data if 'https' in str(image): image_data = image @@ -164,6 +173,8 @@ class CreateTaskAPIView(viewsets.ModelViewSet): if serializer.is_valid(): # save serializer serializer.save() + junior_id = Junior.objects.filter(id=junior).last() + send_notification.delay(TASK_CREATED, None, junior_id.auth.id, {}) return custom_response(SUCCESS_CODE['3018'], serializer.data, response_status=status.HTTP_200_OK) return custom_error_response(serializer.errors, response_status=status.HTTP_400_BAD_REQUEST) @@ -172,7 +183,6 @@ class SearchTaskListAPIView(viewsets.ModelViewSet): serializer_class = TaskDetailsSerializer permission_classes = [IsAuthenticated] pagination_class = PageNumberPagination - queryset = JuniorTask.objects.all() def get_queryset(self): """Get the queryset for the view""" diff --git a/junior/views.py b/junior/views.py index a764adf..67f24e9 100644 --- a/junior/views.py +++ b/junior/views.py @@ -256,7 +256,10 @@ class CompleteJuniorTaskAPIView(views.APIView): # fetch junior query task_queryset = JuniorTask.objects.filter(id=task_id, junior__auth__email=self.request.user).last() if task_queryset: - # use RemoveJuniorSerializer serializer + # use CompleteTaskSerializer serializer + if task_queryset.task_status in ['4', '5']: + """Already request send """ + return custom_error_response(ERROR_CODE['2049'], response_status=status.HTTP_400_BAD_REQUEST) serializer = CompleteTaskSerializer(task_queryset, data={'image': image_url}, partial=True) if serializer.is_valid(): # save serializer diff --git a/notifications/constants.py b/notifications/constants.py index b72ed61..25602a8 100644 --- a/notifications/constants.py +++ b/notifications/constants.py @@ -2,6 +2,7 @@ notification constants file """ REGISTRATION = 1 +TASK_CREATED = 2 TEST_NOTIFICATION = 99 NOTIFICATION_DICT = { @@ -9,6 +10,10 @@ NOTIFICATION_DICT = { "title": "Successfully registered!", "body": "You have registered successfully. Now login and complete your profile." }, + TASK_CREATED: { + "title": "Task created!", + "body": "Task created successfully." + }, TEST_NOTIFICATION: { "title": "Test Notification", "body": "This notification is for testing purpose"