mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-16 18:36:18 +00:00
conflict has been resolved
This commit is contained in:
@ -39,8 +39,9 @@ class CustomMiddleware(object):
|
||||
# Code to be executed after the view is called
|
||||
device_id = request.META.get('HTTP_DEVICE_ID')
|
||||
user_type = request.META.get('HTTP_USER_TYPE')
|
||||
api_endpoint = request.path
|
||||
if request.user.is_authenticated:
|
||||
"""device details"""
|
||||
# device details
|
||||
device_details = UserDeviceDetails.objects.filter(user=request.user, device_id=device_id).last()
|
||||
if user_type and str(user_type) == str(NUMBER['one']):
|
||||
junior = Junior.objects.filter(auth=request.user, is_active=False).last()
|
||||
@ -52,7 +53,7 @@ class CustomMiddleware(object):
|
||||
if guardian:
|
||||
custom_error = custom_error_response(ERROR_CODE['2075'], response_status=status.HTTP_404_NOT_FOUND)
|
||||
response = custom_response(custom_error)
|
||||
if device_id and not device_details:
|
||||
if device_id and not device_details and api_endpoint != '/api/v1/user/login/':
|
||||
custom_error = custom_error_response(ERROR_CODE['2037'], response_status=status.HTTP_404_NOT_FOUND)
|
||||
response = custom_response(custom_error)
|
||||
return response
|
||||
|
@ -159,10 +159,12 @@ def user_device_details(user, device_id):
|
||||
device_id: string
|
||||
return
|
||||
"""
|
||||
device_details, created = UserDeviceDetails.objects.get_or_create(user=user)
|
||||
device_details, created = UserDeviceDetails.objects.get_or_create(user__id=user)
|
||||
if device_details:
|
||||
device_details.device_id = device_id
|
||||
device_details.save()
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def send_support_email(name, sender, subject, message):
|
||||
|
@ -337,7 +337,11 @@ class UserLogin(viewsets.ViewSet):
|
||||
response_status=status.HTTP_401_UNAUTHORIZED
|
||||
)
|
||||
# storing device id in using celery task so the time would be reduced
|
||||
user_device_details.delay(user, device_id)
|
||||
# user_device_details.delay(user.id, device_id)
|
||||
device_details, created = UserDeviceDetails.objects.get_or_create(user=user)
|
||||
if device_details:
|
||||
device_details.device_id = device_id
|
||||
device_details.save()
|
||||
return custom_response(SUCCESS_CODE['3003'], serializer, response_status=status.HTTP_200_OK)
|
||||
else:
|
||||
return custom_error_response(ERROR_CODE["2002"], response_status=status.HTTP_401_UNAUTHORIZED)
|
||||
@ -465,7 +469,7 @@ class ReSendEmailOtp(viewsets.ModelViewSet):
|
||||
def create(self, request, *args, **kwargs):
|
||||
otp = generate_otp()
|
||||
if User.objects.filter(email=request.data['email']):
|
||||
expiry = OTP_EXPIRY
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
email_data, created = UserEmailOtp.objects.get_or_create(email=request.data['email'])
|
||||
if created:
|
||||
email_data.expired_at = expiry
|
||||
|
@ -251,7 +251,7 @@ class GuardianDetailSerializer(serializers.ModelSerializer):
|
||||
"""Meta info"""
|
||||
model = Guardian
|
||||
fields = ['id', 'email', 'first_name', 'last_name', 'country_code', 'phone', 'gender', 'dob',
|
||||
'guardian_code','is_active', 'is_complete_profile', 'created_at', 'image', 'is_deleted'
|
||||
'guardian_code','is_active', 'is_complete_profile', 'created_at', 'image', 'is_deleted',
|
||||
'updated_at']
|
||||
class TaskDetailsSerializer(serializers.ModelSerializer):
|
||||
"""Task detail serializer"""
|
||||
|
@ -43,10 +43,33 @@ def upload_image_to_alibaba(image, filename):
|
||||
# Save the image object to a temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
"""write image in temporary file"""
|
||||
if type(image) == bytes:
|
||||
temp_file.write(image)
|
||||
else:
|
||||
temp_file.write(image.read())
|
||||
return upload_file_to_alibaba(temp_file, filename)
|
||||
|
||||
|
||||
def upload_base64_image_to_alibaba(image, filename):
|
||||
"""
|
||||
upload image on oss alibaba bucket
|
||||
"""
|
||||
# Save the image object to a temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
# write image in temporary file
|
||||
temp_file.write(image)
|
||||
return upload_file_to_alibaba(temp_file, filename)
|
||||
|
||||
|
||||
def upload_excel_file_to_alibaba(response, filename):
|
||||
"""
|
||||
upload excel file on oss alibaba bucket
|
||||
"""
|
||||
# Save the image object to a temporary file
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
# write image in temporary file
|
||||
temp_file.write(response.content)
|
||||
return upload_file_to_alibaba(temp_file, filename)
|
||||
|
||||
|
||||
def upload_file_to_alibaba(temp_file, filename):
|
||||
"""auth of bucket"""
|
||||
auth = oss2.Auth(settings.ALIYUN_OSS_ACCESS_KEY_ID, settings.ALIYUN_OSS_ACCESS_KEY_SECRET)
|
||||
"""fetch bucket details"""
|
||||
|
@ -66,7 +66,7 @@ class SignupViewset(viewsets.ModelViewSet):
|
||||
"""Generate otp"""
|
||||
otp = generate_otp()
|
||||
# expire otp after 1 day
|
||||
expiry = OTP_EXPIRY
|
||||
expiry = timezone.now() + timezone.timedelta(days=1)
|
||||
# create user email otp object
|
||||
UserEmailOtp.objects.create(email=request.data['email'], otp=otp,
|
||||
user_type=str(request.data['user_type']), expired_at=expiry)
|
||||
@ -262,7 +262,7 @@ class ApproveJuniorAPIView(viewsets.ViewSet):
|
||||
guardian = Guardian.objects.filter(user__email=self.request.user).last()
|
||||
# fetch junior query
|
||||
junior_queryset = Junior.objects.filter(id=self.request.data.get('junior_id')).last()
|
||||
if junior_queryset and junior_queryset.is_deleted:
|
||||
if junior_queryset and (junior_queryset.is_deleted or not junior_queryset.is_active):
|
||||
return custom_error_response(ERROR_CODE['2073'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
# action 1 is use for approve and 2 for reject
|
||||
if request.data['action'] == '1':
|
||||
@ -297,7 +297,7 @@ class ApproveTaskAPIView(viewsets.ViewSet):
|
||||
task_queryset = JuniorTask.objects.filter(id=self.request.data.get('task_id'),
|
||||
guardian=guardian,
|
||||
junior=self.request.data.get('junior_id')).last()
|
||||
if task_queryset and task_queryset.junior.is_deleted:
|
||||
if task_queryset and (task_queryset.junior.is_deleted or not task_queryset.junior.is_active):
|
||||
return custom_error_response(ERROR_CODE['2072'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
# use ApproveJuniorSerializer serializer
|
||||
serializer = ApproveTaskSerializer(context={"guardian_code": guardian.guardian_code,
|
||||
|
@ -339,7 +339,7 @@ class CompleteJuniorTaskAPIView(views.APIView):
|
||||
task_queryset = JuniorTask.objects.filter(id=task_id, junior__auth__email=self.request.user
|
||||
).select_related('guardian', 'junior').last()
|
||||
if task_queryset:
|
||||
if task_queryset.junior.is_deleted:
|
||||
if task_queryset.junior.is_deleted or not task_queryset.junior.is_active:
|
||||
return custom_error_response(ERROR_CODE['2074'], response_status=status.HTTP_400_BAD_REQUEST)
|
||||
# use CompleteTaskSerializer serializer
|
||||
if task_queryset.task_status in [str(NUMBER['four']), str(NUMBER['five'])]:
|
||||
|
@ -56,9 +56,9 @@ class NotificationViewSet(viewsets.GenericViewSet):
|
||||
to send test notification
|
||||
:return:
|
||||
"""
|
||||
send_notification_to_guardian(TEST_NOTIFICATION, None, request.auth.payload['user_id'],
|
||||
send_notification_to_guardian.delay(TEST_NOTIFICATION, None, request.auth.payload['user_id'],
|
||||
{'task_id': None})
|
||||
send_notification_to_junior(TEST_NOTIFICATION, request.auth.payload['user_id'], None,
|
||||
send_notification_to_junior.delay(TEST_NOTIFICATION, None, request.auth.payload['user_id'],
|
||||
{'task_id': None})
|
||||
return custom_response(SUCCESS_CODE["3000"])
|
||||
|
||||
|
@ -4,7 +4,7 @@ web_utils file
|
||||
import base64
|
||||
|
||||
from base.constants import ARTICLE_CARD_IMAGE_FOLDER
|
||||
from guardian.utils import upload_image_to_alibaba
|
||||
from guardian.utils import upload_image_to_alibaba, upload_base64_image_to_alibaba
|
||||
|
||||
|
||||
def pop_id(data):
|
||||
@ -32,7 +32,7 @@ def get_image_url(data):
|
||||
image_name = data.pop('image_name') if 'image_name' in data else f"{data['title']}.jpg"
|
||||
filename = f"{ARTICLE_CARD_IMAGE_FOLDER}/{image_name}"
|
||||
# upload image on ali baba
|
||||
image_url = upload_image_to_alibaba(base64_image, filename)
|
||||
image_url = upload_base64_image_to_alibaba(base64_image, filename)
|
||||
return image_url
|
||||
elif 'image' in data and data['image'] is not None:
|
||||
image = data.pop('image')
|
||||
|
@ -28,6 +28,7 @@ from django.http import HttpResponse
|
||||
from account.utils import custom_response
|
||||
from base.constants import PENDING, IN_PROGRESS, REJECTED, REQUESTED, COMPLETED, EXPIRED, DATE_FORMAT, TASK_STATUS
|
||||
from guardian.models import JuniorTask
|
||||
from guardian.utils import upload_excel_file_to_alibaba
|
||||
from junior.models import JuniorPoints
|
||||
from web_admin.pagination import CustomPageNumberPagination
|
||||
from web_admin.permission import AdminPermission
|
||||
@ -251,18 +252,6 @@ class AnalyticsViewSet(GenericViewSet):
|
||||
buffer.close()
|
||||
|
||||
filename = f"{'analytics'}/{'ZOD_Bank_Analytics.xlsx'}"
|
||||
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
||||
"""write image in temporary file"""
|
||||
temp_file.write(response.content)
|
||||
"""auth of bucket"""
|
||||
auth = oss2.Auth(settings.ALIYUN_OSS_ACCESS_KEY_ID, settings.ALIYUN_OSS_ACCESS_KEY_SECRET)
|
||||
"""fetch bucket details"""
|
||||
bucket = oss2.Bucket(auth, settings.ALIYUN_OSS_ENDPOINT, settings.ALIYUN_OSS_BUCKET_NAME)
|
||||
# Upload the temporary file to Alibaba OSS
|
||||
bucket.put_object_from_file(filename, temp_file.name)
|
||||
"""create perfect url for image"""
|
||||
new_filename = filename.replace(' ', '%20')
|
||||
link = f"https://{settings.ALIYUN_OSS_BUCKET_NAME}.{settings.ALIYUN_OSS_ENDPOINT}/{new_filename}"
|
||||
print(link)
|
||||
return custom_response(None, link)
|
||||
file_link = upload_excel_file_to_alibaba(response, filename)
|
||||
return custom_response(None, file_link)
|
||||
|
||||
|
@ -44,9 +44,20 @@ class ArticleViewSet(GenericViewSet, mixins.CreateModelMixin, mixins.UpdateModel
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
article create api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:param request: { "title": "string", "description": "string",
|
||||
"article_cards": [
|
||||
{ "title": "string",
|
||||
"description": "string",
|
||||
"image_name": "string",
|
||||
"image_url": "string"
|
||||
} ],
|
||||
"article_survey": [
|
||||
{ "question": "string",
|
||||
"options": [
|
||||
{ "option": "string",
|
||||
"is_answer": true }
|
||||
] }
|
||||
] }
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@ -57,9 +68,24 @@ class ArticleViewSet(GenericViewSet, mixins.CreateModelMixin, mixins.UpdateModel
|
||||
def update(self, request, *args, **kwargs):
|
||||
"""
|
||||
article update api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:param request: article_id,
|
||||
{ "title": "string", "description": "string",
|
||||
"article_cards": [
|
||||
{ "id": 0,
|
||||
"title": "string",
|
||||
"description": "string",
|
||||
"image_name": "string",
|
||||
"image_url": "string"
|
||||
} ],
|
||||
"article_survey": [
|
||||
{ "id": 0,
|
||||
"question": "string",
|
||||
"options": [
|
||||
{ "id": 0,
|
||||
"option": "string",
|
||||
"is_answer": true
|
||||
} ]
|
||||
} ] }
|
||||
:return: success message
|
||||
"""
|
||||
article = self.get_object()
|
||||
@ -72,8 +98,6 @@ class ArticleViewSet(GenericViewSet, mixins.CreateModelMixin, mixins.UpdateModel
|
||||
"""
|
||||
article list api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:return: list of article
|
||||
"""
|
||||
queryset = self.get_queryset()
|
||||
@ -86,9 +110,7 @@ class ArticleViewSet(GenericViewSet, mixins.CreateModelMixin, mixins.UpdateModel
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
"""
|
||||
article detail api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:param request: article_id
|
||||
:return: article detail data
|
||||
"""
|
||||
queryset = self.get_object()
|
||||
@ -98,9 +120,7 @@ class ArticleViewSet(GenericViewSet, mixins.CreateModelMixin, mixins.UpdateModel
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
"""
|
||||
article delete (soft delete) api method
|
||||
:param request:
|
||||
:param args:
|
||||
:param kwargs:
|
||||
:param request: article_id
|
||||
:return: success message
|
||||
"""
|
||||
article = self.get_object()
|
||||
@ -177,7 +197,10 @@ class DefaultArticleCardImagesViewSet(GenericViewSet, mixins.CreateModelMixin, m
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""
|
||||
api method to upload default article card images
|
||||
:param request:
|
||||
:param request: {
|
||||
"image_name": "string",
|
||||
"image": "image_file"
|
||||
}
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
|
@ -27,6 +27,7 @@ class ForgotAndResetPasswordViewSet(GenericViewSet):
|
||||
def admin_otp(self, request):
|
||||
"""
|
||||
api method to send otp
|
||||
:param request: {"email": "string"}
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@ -40,6 +41,7 @@ class ForgotAndResetPasswordViewSet(GenericViewSet):
|
||||
def admin_verify_otp(self, request):
|
||||
"""
|
||||
api method to verify otp
|
||||
:param request: {"email": "string", "otp": "otp"}
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
@ -52,6 +54,7 @@ class ForgotAndResetPasswordViewSet(GenericViewSet):
|
||||
def admin_create_password(self, request):
|
||||
"""
|
||||
api method to create new password
|
||||
:param request: {"email": "string", "new_password": "string", "confirm_password": "string"}
|
||||
:return: success message
|
||||
"""
|
||||
serializer = self.serializer_class(data=request.data)
|
||||
|
Reference in New Issue
Block a user