added notification for getting points after reading article

This commit is contained in:
abutalib-kiwi
2023-08-25 19:08:15 +05:30
parent 9b6a84c7d1
commit 5b2ab2275e
5 changed files with 18 additions and 8 deletions

View File

@ -47,7 +47,7 @@ from account.utils import custom_response, custom_error_response
from guardian.utils import upload_image_to_alibaba
from .utils import update_positions_based_on_points
from notifications.utils import send_notification
from notifications.constants import REMOVE_JUNIOR
from notifications.constants import REMOVE_JUNIOR, ARTICLE_REWARD_POINTS
from web_admin.models import Article, ArticleSurvey, SurveyOption, ArticleCard
from web_admin.serializers.article_serializer import (ArticleSerializer, ArticleListSerializer,
StartAssessmentSerializer)
@ -666,6 +666,8 @@ class CompleteArticleAPIView(views.APIView):
is_answer_correct=True).aggregate(
total_earn_points=Sum('earn_points'))['total_earn_points']
data = {"total_earn_points":total_earn_points}
send_notification.delay(ARTICLE_REWARD_POINTS, None, None,
request.user.id, {'points': total_earn_points})
return custom_response(SUCCESS_CODE['3042'], data, response_status=status.HTTP_200_OK)
except Exception as e:
return custom_error_response(str(e), response_status=status.HTTP_400_BAD_REQUEST)

View File

@ -17,7 +17,8 @@ IN_PROGRESS_TASK_EXPIRING = 13
TOP_JUNIOR = 14
NEW_ARTICLE_PUBLISHED = 15
REMOVE_JUNIOR = 16
ARTICLE_REWARD_POINTS = 16
REMOVE_JUNIOR = 17
TEST_NOTIFICATION = 99
@ -66,7 +67,7 @@ NOTIFICATION_DICT = {
# as junior send task for approval
TASK_ACTION: {
"title": "Task completion approval!",
"body": "{from_user} completed her task {task_name}."
"body": "{from_user} completed their task {task_name}."
},
# Juniors will receive notification as soon
# as their task is rejected by custodians
@ -105,6 +106,11 @@ NOTIFICATION_DICT = {
"title": "Time to read!",
"body": "A new article has been published."
},
# Juniors will receive notification when they earn points by reading financial Learning
ARTICLE_REWARD_POINTS: {
"title": "Article reward points!",
"body": "You are rewarded with {points} points for reading article and answering questions. "
},
# Juniors will receive notification as soon as their custodians remove them from account
REMOVE_JUNIOR: {
"title": "Disassociate by guardian!",

View File

@ -77,6 +77,7 @@ def get_notification_data(notification_type, from_user_id, from_user_type, to_us
push_data = NOTIFICATION_DICT[notification_type].copy()
notification_data = push_data.copy()
task_name = None
points = extra_data.get('points', None)
if 'task_id' in extra_data:
task = JuniorTask.objects.filter(id=extra_data.get('task_id')).first()
task_name = task.task_name
@ -85,8 +86,9 @@ def get_notification_data(notification_type, from_user_id, from_user_type, to_us
from_user_name, from_user_image, from_user = get_from_user_details(from_user_id, from_user_type)
push_data['body'] = push_data['body'].format(from_user=from_user_name, task_name=task_name)
notification_data['body'] = notification_data['body'].format(from_user=from_user_name, task_name=task_name)
push_data['body'] = push_data['body'].format(from_user=from_user_name, task_name=task_name, points=points)
notification_data['body'] = notification_data['body'].format(from_user=from_user_name,
task_name=task_name, points=points)
notification_data['from_user'] = from_user_name
notification_data['from_user_image'] = from_user_image

View File

@ -36,7 +36,7 @@ class NotificationViewSet(viewsets.GenericViewSet):
paginator = self.pagination_class()
paginated_queryset = paginator.paginate_queryset(queryset, request)
serializer = self.serializer_class(paginated_queryset, many=True)
return custom_response(None, serializer.data)
return custom_response(None, serializer.data, count=queryset.count())
@action(methods=['post'], detail=False, url_path='device', url_name='device', serializer_class=RegisterDevice)
def fcm_registration(self, request):

View File

@ -35,11 +35,11 @@ app.conf.beat_schedule = {
},
'notify_task_expiry': {
'task': 'base.tasks.notify_task_expiry',
'schedule': crontab(minute='5', hour='12'),
'schedule': crontab(minute='0', hour='18'),
},
'notify_top_junior': {
'task': 'base.tasks.notify_top_junior',
'schedule': crontab(minute='*/5',),
'schedule': crontab(minute='0', hour='*/2'),
},
}