diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index eb4711c..a5a0a6d 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -8,10 +8,7 @@ from django.utils.safestring import SafeText from .models import * admin.site.register(User) -# admin.site.register(Student) admin.site.register(Admin) -# admin.site.register(Placement) -admin.site.register(PlacementApplication) admin.site.register(PrePlacementOffer) admin.site.site_header = "CDC Recruitment Portal" @@ -38,4 +35,17 @@ class Placement(admin.ModelAdmin): list_filter = ('tier',) +@admin.register(PlacementApplication) +class PlacementApplication(admin.ModelAdmin): + list_display = ('id', 'Placement', 'Student', 'selected') + search_fields = ('id',) + ordering = ('id',) + list_filter = ('selected',) + + def Placement(self, obj): + return model_admin_url(obj.placement) + + def Student(self, obj): + return model_admin_url(obj.student) + diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 845ecef..3183343 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -53,13 +53,15 @@ def markStatus(request, id, email, user_type): def getDashboard(request, id, email, user_type): try: placements = Placement.objects.all().order_by('-created_at') - ongoing = placements.filter(deadline_datetime__gt=datetime.now()) - previous = placements.exclude(deadline_datetime__gt=datetime.now()) + ongoing = placements.filter(deadline_datetime__gt=datetime.now(), offer_accepted__isnull=False) + previous = placements.exclude(deadline_datetime__gt=datetime.now()).filter(offer_accepted__isnull=False) + new = placements.filter(offer_accepted__isnull=True) ongoing = PlacementSerializerForAdmin(ongoing, many=True).data previous = PlacementSerializerForAdmin(previous, many=True).data + new = PlacementSerializerForAdmin(new, many=True).data return Response( - {'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous}, + {'action': "Get Dashboard - Admin", 'message': "Data Found", "ongoing": ongoing, "previous": previous, "new": new}, status=status.HTTP_200_OK) except Http404: return Response({'action': "Get Dashboard - Admin", 'message': 'Student Not Found'}, diff --git a/CDC_Backend/APIs/companyViews.py b/CDC_Backend/APIs/companyViews.py index 7d7d50b..a73b0cf 100644 --- a/CDC_Backend/APIs/companyViews.py +++ b/CDC_Backend/APIs/companyViews.py @@ -193,6 +193,8 @@ def addPlacement(request): # Check if tentative_no_of_offers is integer if data[TENTATIVE_NO_OF_OFFERS].isdigit(): opening.tentative_no_of_offers = int(data[TENTATIVE_NO_OF_OFFERS]) + elif data[TENTATIVE_NO_OF_OFFERS] == 'null': + opening.tentative_no_of_offers = None else: raise ValueError('Tentative No Of Offers must be an integer') diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index d8c9080..b5022b9 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -22,6 +22,9 @@ class Student(models.Model): resumes = ArrayField(models.CharField(null=True, default=None, max_length=100), size=10, default=list, blank=True) cpi = models.DecimalField(decimal_places=2, max_digits=4) + def __str__(self): + return str(self.roll_no) + class Admin(models.Model): id = models.CharField(blank=False, max_length=15, primary_key=True) @@ -81,7 +84,7 @@ class Placement(models.Model): size=TOTAL_BRANCHES, default=list ) - tentative_no_of_offers = models.IntegerField(blank=False, default=1) + tentative_no_of_offers = models.IntegerField(blank=False, default=None, null=True) other_requirements = models.CharField(blank=True, max_length=200, default="") additional_info = ArrayField(models.CharField(blank=True, max_length=200), size=15, default=list, blank=True) email_verified = models.BooleanField(blank=False, default=False) @@ -96,6 +99,9 @@ class Placement(models.Model): return super(Placement, self).save(*args, **kwargs) + def __str__(self): + return self.company_name + " - " + self.id + class PlacementApplication(models.Model): id = models.CharField(blank=False, primary_key=True, max_length=15) placement = models.ForeignKey(Placement, blank=False, on_delete=models.RESTRICT, default=None, null=True) @@ -116,6 +122,9 @@ class PlacementApplication(models.Model): verbose_name_plural = "Placement Applications" unique_together = ('placement_id', 'student_id') + def __str__(self): + return self.placement.company_name + " - " + self.student.name + class PrePlacementOffer(models.Model): id = models.AutoField(primary_key=True) diff --git a/CDC_Backend/APIs/serializers.py b/CDC_Backend/APIs/serializers.py index a7c1228..98608a3 100644 --- a/CDC_Backend/APIs/serializers.py +++ b/CDC_Backend/APIs/serializers.py @@ -154,8 +154,11 @@ class PlacementApplicationSerializer(serializers.ModelSerializer): return data def get_resume_link(self, obj): - link = LINK_TO_STORAGE_RESUME + urllib.parse.quote_plus(obj.id + "/" + obj.resume) - return link + ele = {} + ele['link'] = LINK_TO_STORAGE_RESUME + urllib.parse.quote_plus(obj.id + "/" + obj.resume) + ele['name'] = obj.resume + return ele + class Meta: model = PlacementApplication diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index 79504fc..946e52f 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -44,7 +44,7 @@ def addResume(request, id, email, user_type): files = request.FILES file = files['file'] - destination_path = STORAGE_DESTINATION_RESUMES + id + "/" + destination_path = STORAGE_DESTINATION_RESUMES + str(student.roll_no) + "/" file_name = saveFile(file, destination_path) student.resumes.append(file_name) diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index b35dd17..de58aae 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -1,6 +1,7 @@ import logging import os import random +import re import string import sys from os import path, remove @@ -113,8 +114,10 @@ def saveFile(file, location): prefix = generateRandomString() file_name = prefix + "_" + file.name + file_name = re.sub(r'[\\/:*?"<>|]', '_', file_name) + if not path.isdir(location): - os.mkdir(location) + os.makedirs(location) destination_path = location + str(file_name) if path.exists(destination_path): @@ -123,7 +126,6 @@ def saveFile(file, location): with open(destination_path, 'wb+') as destination: for chunk in file.chunks(): destination.write(chunk) - return file_name diff --git a/CDC_Backend/CDC_Backend/settings.py b/CDC_Backend/CDC_Backend/settings.py index 8219a0f..d524b5b 100644 --- a/CDC_Backend/CDC_Backend/settings.py +++ b/CDC_Backend/CDC_Backend/settings.py @@ -83,23 +83,23 @@ WSGI_APPLICATION = 'CDC_Backend.wsgi.application' # https://docs.djangoproject.com/en/2.2/ref/settings/#databases DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': os.environ.get("DB_NAME"), - 'USER': os.environ.get("DB_USER"), - 'PASSWORD': os.environ.get("DB_PASSWORD"), - 'HOST': os.environ.get("DB_HOST"), - 'PORT': os.environ.get("DB_PORT"), - }, - # 'default': { # 'ENGINE': 'django.db.backends.postgresql_psycopg2', - # 'NAME': 'd84i5cbjig5rrf', - # 'USER': 'hbkullcdjbxuwh', - # 'PASSWORD': '45d990da00e2cc96d7d4e2e5e308d4b07a387883f70c40e090a6252175cb634e', - # 'HOST': 'ec2-54-163-97-228.compute-1.amazonaws.com', - # 'PORT': '5432', - # } + # 'NAME': os.environ.get("DB_NAME"), + # 'USER': os.environ.get("DB_USER"), + # 'PASSWORD': os.environ.get("DB_PASSWORD"), + # 'HOST': os.environ.get("DB_HOST"), + # 'PORT': os.environ.get("DB_PORT"), + # }, + + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'd84i5cbjig5rrf', + 'USER': 'hbkullcdjbxuwh', + 'PASSWORD': '45d990da00e2cc96d7d4e2e5e308d4b07a387883f70c40e090a6252175cb634e', + 'HOST': 'ec2-54-163-97-228.compute-1.amazonaws.com', + 'PORT': '5432', + } } # Password validation