Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added notification/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions notification/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions notification/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NotificationConfig(AppConfig):
name = 'notification'
3 changes: 3 additions & 0 deletions notification/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
62 changes: 62 additions & 0 deletions notification/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from textwrap import dedent

from django.utils import timezone

from celery import task
from notifications_plugin.models import NotificationMessage, Notification

from yaksh.models import Course, Quiz, QuestionPaper, AnswerPaper


@task(name='course_deadline_task')
def course_deadline_task():
courses = Course.objects.filter(active=True, is_trial=False)
for course in courses:
if course.is_active_enrollment():
message = dedent("""
The deadline for the course {0} is {1}, please complete
the course if not completed before the deadline.
""".format(course.name, course.end_enroll_time)
)
students = course.students.all()
creator = course.creator
if students:
students_id = students.values_list('id', flat=True)
notification_type = "warning"
nm = NotificationMessage.objects.add_single_message(
creator_id=creator.id, summary='Course Notification',
description=message, msg_type=notification_type
)
Notification.objects.add_bulk_user_notifications(
receiver_ids=students_id, msg_id=nm.id
)


@task(name='quiz_deadline_task')
def quiz_deadline_task():
courses = Course.objects.filter(active=True, is_trial=False)
for course in courses:
students = course.students.all()
students_id = students.values_list('id', flat=True)
creator = course.creator
modules = course.learning_module.all()
for module in modules:
units = module.learning_unit.all()
for unit in units:
if unit.type == 'quiz':
quiz = unit.quiz
if not quiz.is_expired():
message = dedent("""
The deadline for the quiz {0} is {1}, please
complete the quiz if not completed before the
deadline.
""".format(quiz, quiz.end_date_time)
)
notification_type = 'warning'
nm = NotificationMessage.objects.add_single_message(
creator_id=creator.id, summary='Quiz Notification',
description=message, msg_type=notification_type
)
Notification.objects.add_bulk_user_notifications(
receiver_ids=students_id, msg_id=nm.id
)
3 changes: 3 additions & 0 deletions notification/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions notification/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
21 changes: 20 additions & 1 deletion online_test/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.6/ref/settings/
"""
from celery.schedules import crontab
from yaksh.pipeline.settings import AUTH_PIPELINE
import os
from decouple import config
Expand Down Expand Up @@ -51,7 +52,8 @@
'rest_framework',
'api',
'corsheaders',
'rest_framework.authtoken'
'rest_framework.authtoken',
'notification'
)

MIDDLEWARE = (
Expand Down Expand Up @@ -229,6 +231,23 @@
CELERY_BROKER_URL = 'redis://localhost'
CELERY_RESULT_BACKEND = 'django-db'

CELERY_BEAT_SCHEDULE = {
'send-course-deadline-notifications-once-a-week': {
'task': 'course_deadline_task',
'schedule': crontab(
hour='08', minute=43, day_of_week='Friday', day_of_month='*',
month_of_year='*'
),
},
'send-quiz-deadline-notifications-once-a-week': {
'task': 'quiz_deadline_task',
'schedule': crontab(
hour='09', minute=47, day_of_week='Friday', day_of_month='*',
month_of_year='*'
),
}
}

REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
Expand Down