diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 2b27a9b..fe7da63 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -194,7 +194,7 @@ def addPlacement(request): '%d-%m-%Y').date() # Only Allowing Fourth Year for Placement - opening.allowed_batch = [FOURTH_YEAR, ] + opening.allowed_batch = [2017, 2018, 2019, 2020, 2021] # Check if allowed_branch are valid if data[ALLOWED_BRANCH] is None: raise ValueError('Allowed Branch cannot be empty') diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 4b31276..d3cd9ac 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -34,6 +34,11 @@ TIERS = [ ['6', 'Tier 6'] ] +DEGREE_CHOICES = [ + ['bTech', 'B.Tech'], + ['ms/phd', 'MS/ PhD'], +] + TOTAL_BRANCHES = 4 # Total No of Branches TOTAL_BATCHES = 4 # Total No of Batches diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index 1a92d10..5003428 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -6,6 +6,9 @@ from simple_history.models import HistoricalRecords from .constants import * +# from .utils import * + + class User(models.Model): email = models.EmailField(primary_key=True, blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT) id = models.CharField(blank=False, max_length=25, db_index=True) @@ -30,6 +33,7 @@ class Student(models.Model): cpi = models.DecimalField(decimal_places=2, max_digits=4) can_apply = models.BooleanField(default=True, verbose_name='Registered') changed_by = models.ForeignKey(User, blank=True, on_delete=models.RESTRICT, default=None, null=True) + degree = models.CharField(choices=DEGREE_CHOICES, blank=False, max_length=10, default=DEGREE_CHOICES[0][0]) history = HistoricalRecords(user_model=User) def __str__(self): @@ -47,6 +51,25 @@ class Student(models.Model): self.changed_by = None + +class Admin(models.Model): + id = models.CharField(blank=False, max_length=15, primary_key=True) + name = models.CharField(blank=False, max_length=JNF_TEXT_MAX_CHARACTER_COUNT) + changed_by = models.ForeignKey(User, blank=True, on_delete=models.RESTRICT, default=None, null=True) + history = HistoricalRecords(user_model=User) + + @property + def _history_user(self): + return self.changed_by + + @_history_user.setter + def _history_user(self, value): + if isinstance(value, User): + self.changed_by = value + else: + self.changed_by = None + + def two_day_after_today(): return timezone.now() + timezone.timedelta(days=2) diff --git a/CDC_Backend/APIs/serializers.py b/CDC_Backend/APIs/serializers.py index f7cc868..1447d6d 100644 --- a/CDC_Backend/APIs/serializers.py +++ b/CDC_Backend/APIs/serializers.py @@ -162,7 +162,7 @@ class PlacementApplicationSerializer(serializers.ModelSerializer): return data def get_resume_link(self, obj): - ele = {'link': LINK_TO_STORAGE_RESUME + urllib.parse.quote(obj.id + "/" + obj.resume), 'name': obj.resume} + ele = {'link': LINK_TO_STORAGE_RESUME + urllib.parse.quote(str(obj.student.roll_no) + "/" + obj.resume), 'name': obj.resume} return ele class Meta: diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index d4f6204..50bfe9e 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -180,6 +180,9 @@ def PlacementApplicationConditions(student, placement): if int(i.placement.tier) < int(placement.tier): return False, "Can't apply for this tier" + if student.degree != 'bTech' and not placement.rs_eligible: + raise PermissionError("Can't apply for this placement") + return True, "Conditions Satisfied" except PermissionError as e: @@ -325,4 +328,3 @@ def send_opening_notifications(placement_id): except: logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info())) return False - diff --git a/CDC_Backend/CDC_Backend/settings.py b/CDC_Backend/CDC_Backend/settings.py index 373c6fb..c5ce582 100644 --- a/CDC_Backend/CDC_Backend/settings.py +++ b/CDC_Backend/CDC_Backend/settings.py @@ -15,7 +15,6 @@ import os from dotenv import load_dotenv load_dotenv("../dev.env") -# import django_heroku # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -55,6 +54,7 @@ MIDDLEWARE = [ 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', + 'corsheaders.middleware.CorsPostCsrfMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', @@ -145,15 +145,14 @@ STATICFILES_DIR = ( os.path.join(BASE_DIR, 'static'), ) -CORS_ORIGIN_ALLOW_ALL = True +CORS_ORIGIN_ALLOW_ALL = False CORS_ORIGIN_WHITELIST = [ + "https://cdc.iitdh.ac.in", "http://localhost:3000", - "http://127.0.0.1:3000", - "http://localhost:8000", - "http://127.0.0.1:8000" + "https://localhost:3000" ] - -CSRF_TRUSTED_ORIGINS = [] +CORS_REPLACE_HTTPS_REFERER = True +CSRF_TRUSTED_ORIGINS = [ "https://cdc.iitdh.ac.in", "http://cdc.iitdh.ac.in"] # EMAIL_BACKEND = 'django.core.mail.backends.filebased.EmailBackend' EMAIL_FILE_PATH = './emails' diff --git a/CDC_Backend/CDC_Backend/wsgi.py b/CDC_Backend/CDC_Backend/wsgi.py index 057007a..0537202 100644 --- a/CDC_Backend/CDC_Backend/wsgi.py +++ b/CDC_Backend/CDC_Backend/wsgi.py @@ -6,7 +6,6 @@ It exposes the WSGI callable as a module-level variable named ``application``. For more information on this file, see https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ """ - import os from django.core.wsgi import get_wsgi_application diff --git a/CDC_Backend/run_prod.sh b/CDC_Backend/run_prod.sh new file mode 100644 index 0000000..3ad9b30 --- /dev/null +++ b/CDC_Backend/run_prod.sh @@ -0,0 +1 @@ +gunicorn --certfile=/home/cdc/Desktop/1f9476e3959ebe60.crt --keyfile=/home/cdc/Desktop/star_iitdh_key.key --bind localhost:8000 CDC_Backend.wsgi --access-logfile access.log --error-logfile error.log & diff --git a/CDC_Backend/templates/company_jnf_response.html b/CDC_Backend/templates/company_jnf_response.html index 3e3419f..33484c1 100644 --- a/CDC_Backend/templates/company_jnf_response.html +++ b/CDC_Backend/templates/company_jnf_response.html @@ -44,7 +44,7 @@ {% for item in value.details %}
  • {% if 'link' in value.type and value.link %} - {{ item|slice:"16:"}} + {{ item|slice:"16:" }} {% elif 'link' in value.type %} {{ item }} {% else %} diff --git a/Email_service_README.md b/Email_service_README.md new file mode 100644 index 0000000..26f134e --- /dev/null +++ b/Email_service_README.md @@ -0,0 +1,13 @@ +we have defined a service for running the `start_email_service.sh` file continusouly on the server. Use the following commands for doing anything to the email + service. + +## Enable the Service +`sudo systemctl enable cdc-email-sender.service` + +## Start the Service +`sudo systemctl start cdc-email-sender.service` + +## Check Status of the Service +`sudo systemctl status cdc-email-sender.service` + +Any Doubts contact Gowtham Sai - 190010036 diff --git a/start_email_service.sh b/start_email_service.sh new file mode 100755 index 0000000..048b305 --- /dev/null +++ b/start_email_service.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +source /home/cdc/Desktop/CDC_Web_Portal_Backend/cdc-placement-website-backend/venv/bin/activate + +cd /home/cdc/Desktop/CDC_Web_Portal_Backend/cdc-placement-website-backend/CDC_Backend + +python manage.py process_tasks