diff --git a/.DS_Store b/.DS_Store index 4808ac2..b4c80e4 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/CDC_Backend/.DS_Store b/CDC_Backend/.DS_Store index e1c3358..7f94099 100644 Binary files a/CDC_Backend/.DS_Store and b/CDC_Backend/.DS_Store differ diff --git a/CDC_Backend/APIs/companyUrls.py b/CDC_Backend/APIs/companyUrls.py index 4db1c55..e09de52 100644 --- a/CDC_Backend/APIs/companyUrls.py +++ b/CDC_Backend/APIs/companyUrls.py @@ -5,4 +5,5 @@ from . import companyViews urlpatterns = [ path('addPlacement/', companyViews.addPlacement, name="Add Placement"), path('verifyEmail/', companyViews.verifyEmail, name="Verify Email"), + path('getAutoFillJnf/', companyViews.autoFillJnf, name="Auto FIll JNF"), ] diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 77d228e..ec01f0a 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -1,6 +1,7 @@ from rest_framework.decorators import api_view from .utils import * +from .serializers import * logger = logging.getLogger('db') @@ -283,7 +284,8 @@ def verifyEmail(request): "opening_type": PLACEMENT, "company_name": opening.company_name, } - sendEmail([opening.email, CDC_MAIl_ADDRESS], COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), data, + sendEmail([opening.email, CDC_MAIl_ADDRESS], + COMPANY_OPENING_SUBMITTED_TEMPLATE_SUBJECT.format(id=opening.id), data, COMPANY_OPENING_SUBMITTED_TEMPLATE, attachment_jnf_respone) return Response({'action': "Verify Email", 'message': "Email Verified Successfully"}, @@ -298,3 +300,23 @@ def verifyEmail(request): logger.warning("Verify Email: " + str(sys.exc_info())) return Response({'action': "Verify Email", 'message': "Something went wrong"}, status=status.HTTP_400_BAD_REQUEST) + + +@api_view(['GET']) +@precheck([PLACEMENT_ID]) +def autoFillJnf(request): + try: + data = request.GET + placement_id = data.get(PLACEMENT_ID) + opening = get_object_or_404(Placement, id=placement_id) + serializer = AutofillSerializers(opening) + return Response({'action': "Get AutoFill", 'message': 'Data Found', 'placement_data': serializer.data}, + status=status.HTTP_200_OK) + except Http404: + return Response({'action': "Get AutoFill", 'message': 'Placement Not Found'}, + status=status.HTTP_404_NOT_FOUND) + except Exception as e: + traceback_str = traceback.format_exc() + logger.warning("Get AutoFill: " + traceback_str) + return Response({'action': "Get AutoFill", 'message': "Something went wrong"}, + status=status.HTTP_400_BAD_REQUEST) diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 5696feb..bf5b7e8 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -90,6 +90,7 @@ FIELD = "field" STATUS_ACCEPTING_APPLICATIONS = "Accepting Applications" PLACEMENT = "Placement" +PLACEMENT_ID = "placement_id" COMPANY_NAME = "company_name" ADDRESS = "address" @@ -158,7 +159,7 @@ STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT = 'CDC - Application Submitted - STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT = 'CDC - Application Updated - {company_name}' COMPANY_EMAIl_VERIFICATION_TEMPLATE_SUBJECT = 'Email Verification - Career Development Cell, IIT Dharwad' NOTIFY_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Placement Opportunity at {company_name}' - +REMINDER_STUDENTS_OPENING_TEMPLATE_SUBJECT = 'Reminder - Placement Opportunity at {company_name}' STUDENT_APPLICATION_SUBMITTED_TEMPLATE = 'student_application_submitted.html' COMPANY_OPENING_SUBMITTED_TEMPLATE = 'company_opening_submitted.html' STUDENT_APPLICATION_STATUS_SELECTED_TEMPLATE = 'student_application_status_selected.html' @@ -167,7 +168,7 @@ STUDENT_APPLICATION_UPDATED_TEMPLATE = 'student_application_updated.html' COMPANY_EMAIL_VERIFICATION_TEMPLATE = 'company_email_verification.html' COMPANY_JNF_RESPONSE_TEMPLATE = 'company_jnf_response.html' NOTIFY_STUDENTS_OPENING_TEMPLATE = 'notify_students_new_opening.html' - +REMINDER_STUDENTS_OPENING_TEMPLATE = 'students_opening_reminder.html' APPLICATION_CSV_COL_NAMES = ['Applied At', 'Roll No.', 'Name', 'Email', 'Phone Number', 'Branch', 'Batch', 'CPI', 'Resume', 'Selected', ] diff --git a/CDC_Backend/APIs/serializers.py b/CDC_Backend/APIs/serializers.py index ad7d9f7..19d94bc 100644 --- a/CDC_Backend/APIs/serializers.py +++ b/CDC_Backend/APIs/serializers.py @@ -188,4 +188,11 @@ class PlacementApplicationSerializerForAdmin(serializers.ModelSerializer): class ContributorSerializer(serializers.ModelSerializer): class Meta: - model = Contributor \ No newline at end of file + model = Contributor + + + +class AutofillSerializers(serializers.ModelSerializer): + class Meta: + model = Placement + fields = '__all__' \ No newline at end of file diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index be57175..3d64768 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -285,7 +285,7 @@ def opening_description_table_html(opening): else: # if isinstance(opening, QueryDict): details = opening keys = list(details.keys()) - newdetails = {} + newdetails = {"ID": opening.id} for key in keys: if isinstance(details[key], list): details[key] = {"details": details[key], "type": ["list"]} diff --git a/CDC_Backend/CDC_Backend/settings.py b/CDC_Backend/CDC_Backend/settings.py index 2447ee0..7df7fc3 100644 --- a/CDC_Backend/CDC_Backend/settings.py +++ b/CDC_Backend/CDC_Backend/settings.py @@ -30,7 +30,7 @@ DEBUG = os.environ.get('DEBUG') == "True" ALLOWED_HOSTS = ['cdc.iitdh.ac.in', 'localhost'] -ADMINS = [('Gowtham Sai', '190010036@iitdh.ac.in'), ('Karthik Mv', '200010030@iitdh.ac.in')] +ADMINS = [ ('Karthik Mv', '200010030@iitdh.ac.in')] # Application definition INSTALLED_APPS = [ @@ -47,7 +47,7 @@ INSTALLED_APPS = [ 'background_task', 'simple_history', 'import_export', - "django_extensions" + 'django_extensions' ] MIDDLEWARE = [ diff --git a/CDC_Backend/scripts/send_reminder_mails.py b/CDC_Backend/scripts/send_reminder_mails.py new file mode 100644 index 0000000..0048c34 --- /dev/null +++ b/CDC_Backend/scripts/send_reminder_mails.py @@ -0,0 +1,63 @@ +from APIs.models import Placement, Student, PlacementApplication, User +from APIs.utils import sendEmail, PlacementApplicationConditions +from APIs.constants import * +from django.shortcuts import get_object_or_404 +from django.utils import timezone +import time +import pytz + +REPEAT_AFTER = 10 * 60 + + +def send_reminder_mails(): + placements = Placement.objects.all() + students = Student.objects.all() + + for placement in placements.iterator(): + print("Processing placement: ", placement) + # if placement is approved and email is verified + if not (placement.offer_accepted and placement.email_verified): + continue + + # if placement is not expired + if placement.deadline_datetime < timezone.now(): + continue + + # send the reminder mail if the deadline is within 24 hours +- ReapetAfter + if timezone.now() - timezone.timedelta( + seconds=REPEAT_AFTER) <= placement.deadline_datetime - timezone.timedelta(days=1) < timezone.now() + \ + timezone.timedelta(seconds=REPEAT_AFTER): + for student in students: + try: + # if Application not found then send email + if not PlacementApplication.objects.filter(placement=placement, student=student).exists(): + if student.branch in placement.allowed_branch: + if student.degree == 'bTech' or placement.rs_eligible is True: + if PlacementApplicationConditions(student, placement)[0]: + student_user = get_object_or_404(User, id=student.id) + # change timezone to IST + deadline_datetime = placement.deadline_datetime.astimezone(pytz.timezone('Asia/Kolkata')) + data = { + "company_name": placement.company_name, + "opening_type": 'Placement', + "deadline": deadline_datetime.strftime("%A, %-d %B %Y, %-I:%M %p"), + "link": PLACEMENT_OPENING_URL.format(id=placement.id) + } + print("Sending mail to " + student_user.email, "placement id: ", placement.id) + sendEmail(student_user.email, + REMINDER_STUDENTS_OPENING_TEMPLATE_SUBJECT.format( + company_name=placement.company_name), + data, REMINDER_STUDENTS_OPENING_TEMPLATE) + + except Exception as e: + print(e) + continue + + +def run(): + while True: + print("Sleeping for", REPEAT_AFTER, "seconds") + time.sleep(REPEAT_AFTER) + print("Running send_reminder_mails()") + send_reminder_mails() + diff --git a/CDC_Backend/templates/students_opening_reminder.html b/CDC_Backend/templates/students_opening_reminder.html index 4541089..dd0b9d2 100644 --- a/CDC_Backend/templates/students_opening_reminder.html +++ b/CDC_Backend/templates/students_opening_reminder.html @@ -45,7 +45,7 @@
- Gentle reminder for the same. + Gentle reminder to fill out the application form. Interested students can apply before {{ deadline }} in the CDC-webportal.
diff --git a/README.md b/README.md index bae49a2..1c41ba8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ python# CDC - Backend ### Setup 1. Download the Repository to your local machine