From 761849297eeccf61277369b4e33cb579389f3a3c Mon Sep 17 00:00:00 2001 From: Gowtham Sai <66207607+gowtham3105@users.noreply.github.com> Date: Fri, 5 Aug 2022 10:50:07 +0530 Subject: [PATCH 1/6] Limit Resumes per student (#136) --- CDC_Backend/APIs/constants.py | 1 + CDC_Backend/APIs/studentViews.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index aeb26b1..faa35d1 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -54,6 +54,7 @@ TIER = 'tier' # To be Configured Properly FOURTH_YEAR = '2019' MAX_OFFERS_PER_STUDENT = 2 +MAX_RESUMES_PER_STUDENT =3 EMAIL_VERIFICATION_TOKEN_TTL = 48 # in hours JNF_TEXT_MAX_CHARACTER_COUNT = 100 JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT = 200 diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index ccb25bf..0fbadd0 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -40,6 +40,9 @@ def addResume(request, id, email, user_type): student = get_object_or_404(Student, id=id) files = request.FILES + if len(student.resumes) >= MAX_RESUMES_PER_STUDENT: + raise PermissionError('Max Number of Resumes limit reached') + file = files['file'] destination_path = STORAGE_DESTINATION_RESUMES + str(student.roll_no) + "/" file_name = saveFile(file, destination_path) @@ -51,6 +54,9 @@ def addResume(request, id, email, user_type): except Http404: return Response({'action': "Upload Resume", 'message': 'Student Not Found'}, status=status.HTTP_404_NOT_FOUND) + except PermissionError: + return Response({'action': "Upload Resume", 'message': 'Max Number of Resumes limit reached'}, + status=status.HTTP_400_BAD_REQUEST) except: if path.exists(destination_path): logger.error("Upload Resume: Error in Saving Resume") From 91794a4174a432321360b7bb043ea8f3140e826d Mon Sep 17 00:00:00 2001 From: Gowtham Sai <66207607+gowtham3105@users.noreply.github.com> Date: Fri, 5 Aug 2022 10:50:29 +0530 Subject: [PATCH 2/6] bug fixes (#137) --- CDC_Backend/APIs/serializers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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: From 081a51c5ed62866af73aefa7140ac9e01e220b1a Mon Sep 17 00:00:00 2001 From: karthik mv Date: Thu, 11 Aug 2022 13:02:26 +0530 Subject: [PATCH 3/6] import export for data models in django admin (#138) * import export for User and Student model * export feature for placement, placementapplication, ppo. --- CDC_Backend/APIs/admin.py | 45 +++++++++++++++++++++++++---- CDC_Backend/CDC_Backend/settings.py | 1 + requirements.txt | 13 ++++++++- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/CDC_Backend/APIs/admin.py b/CDC_Backend/APIs/admin.py index ab52c34..29bfefd 100644 --- a/CDC_Backend/APIs/admin.py +++ b/CDC_Backend/APIs/admin.py @@ -1,13 +1,19 @@ from django.contrib import admin -from simple_history.admin import SimpleHistoryAdmin from django.contrib.admin.templatetags.admin_urls import admin_urlname from django.shortcuts import resolve_url from django.utils.html import format_html from django.utils.safestring import SafeText +from simple_history.admin import SimpleHistoryAdmin +from import_export.admin import ImportExportMixin, ExportMixin +from import_export import resources + from .models import * -admin.site.register(User, SimpleHistoryAdmin) +class UserAdmin(ImportExportMixin, SimpleHistoryAdmin): + pass + +admin.site.register(User,UserAdmin) admin.site.register(Admin, SimpleHistoryAdmin) admin.site.site_header = "CDC Recruitment Portal" @@ -18,8 +24,11 @@ def model_admin_url(obj, name=None) -> str: return format_html('{}', url, name or str(obj)) +class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin): + pass + @admin.register(Student) -class Student(SimpleHistoryAdmin): +class Student(StudentAdmin): list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply') search_fields = ("roll_no", "name", "phone_number") ordering = ("roll_no", "name", "batch", "branch", "phone_number") @@ -36,17 +45,33 @@ class Student(SimpleHistoryAdmin): queryset.update(can_apply=True) self.message_user(request, "Registered the users") +class PlacementResources(resources.ModelResource): + class Meta: + model = Placement + exclude = ('id','changed_by', 'is_company_details_pdf', 'is_description_pdf', + 'is_compensation_details_pdf', 'is_selection_procedure_details_pdf') +class AdminAdmin(ExportMixin, SimpleHistoryAdmin): + resource_class = PlacementResources + @admin.register(Placement) -class Placement(SimpleHistoryAdmin): +class Placement(AdminAdmin): list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC') search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME) ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC') list_filter = ('tier',) +class PlacementApplicationResources(resources.ModelResource): + class Meta: + model = PlacementApplication + exclude = ('id', 'changed_by') + +class PlacementAdmin(ExportMixin, SimpleHistoryAdmin): + resource_class = PlacementApplicationResources + @admin.register(PlacementApplication) -class PlacementApplication(SimpleHistoryAdmin): +class PlacementApplication(PlacementAdmin): list_display = ('id', 'Placement', 'Student', 'selected') search_fields = ('id',) ordering = ('id',) @@ -59,8 +84,16 @@ class PlacementApplication(SimpleHistoryAdmin): return model_admin_url(obj.student) +class PrePlacementResources(resources.ModelResource): + class Meta: + model = PrePlacementOffer + exclude = ('id', 'changed_by') + +class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin): + resource_class = PrePlacementResources + @admin.register(PrePlacementOffer) -class PrePlacementOffer(SimpleHistoryAdmin): +class PrePlacementOffer(PrePlacementOfferAdmin): list_display = ('company', 'Student', 'accepted') search_fields = ('company',) ordering = ('company',) diff --git a/CDC_Backend/CDC_Backend/settings.py b/CDC_Backend/CDC_Backend/settings.py index 22552bf..4211796 100644 --- a/CDC_Backend/CDC_Backend/settings.py +++ b/CDC_Backend/CDC_Backend/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ 'django_db_logger', 'background_task', 'simple_history', + 'import_export', ] MIDDLEWARE = [ diff --git a/requirements.txt b/requirements.txt index 5fbc28b..d6465e1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,8 @@ certifi==2021.10.8 chardet==4.0.0 charset-normalizer==2.0.12 colorama==0.4.4 +defusedxml==0.7.1 +diff-match-patch==20200713 dill==0.3.5.1 dj-database-url==0.5.0 Django==3.2.13 @@ -12,8 +14,10 @@ django-background-tasks==1.2.5 django-compat==1.0.15 django-cors-headers==3.11.0 django-db-logger==0.1.12 +django-import-export==2.8.0 django-simple-history==3.1.1 djangorestframework==3.13.1 +et-xmlfile==1.1.0 google-auth==2.6.6 gunicorn==20.1.0 idna==3.3 @@ -22,7 +26,10 @@ isort==5.10.1 jsonfield==3.1.0 lazy-object-proxy==1.7.1 Markdown==3.3.6 +MarkupPy==1.14 mccabe==0.7.0 +odfpy==1.4.1 +openpyxl==3.0.10 pdfkit==1.0.0 platformdirs==2.5.1 psycopg2-binary==2.9.3 @@ -32,14 +39,18 @@ PyJWT==2.4.0 pylint==2.13.5 python-dotenv==0.20.0 pytz==2022.1 +PyYAML==6.0 requests==2.27.1 rsa==4.8 six==1.16.0 sqlparse==0.4.2 +tablib==3.2.1 toml==0.10.2 tomli==2.0.1 -typing-extensions==4.1.1 +typing_extensions==4.1.1 urllib3==1.26.9 whitenoise==6.0.0 wrapt==1.14.0 +xlrd==2.0.1 +xlwt==1.3.0 zipp==3.8.0 From c929b73c3377fd6cabc8fbc754b26f06796bf7bf Mon Sep 17 00:00:00 2001 From: Karthik JP Date: Sat, 10 Sep 2022 10:45:34 +0530 Subject: [PATCH 4/6] Update README.md --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a4495bb..bae49a2 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ python# CDC - Backend 2. Create a Virtual Environment in the [CDC_Backend](./) folder with this command below
`python -m venv venv` 3. Activate the environment with this command
- `.\venv\Scripts\activate` + `.\venv\Scripts\activate` (for WINDOWS)
+ `source ./venv/bin/activate` (for LINUX) 4. Install the dependencies
`pip install -r requirements.txt ` 5. Ensure that you have the PostgreSQL installed on your machine and is running on PORT **5432**
@@ -17,7 +18,8 @@ python# CDC - Backend ### Running the Application 1. Activate the environment with this command.
- `.\venv\Scripts\activate` + `.\venv\Scripts\activate` (for WINDOWS)
+ `source ./venv/bin/activate` (for LINUX) 2. Start the application by running this command (_Run the command where [manage.py](./CDC_Backend/manage.py) is located_)
` python manage.py runserver` From f9977ae99a3a7ff9ff57243e35156786affb3301 Mon Sep 17 00:00:00 2001 From: karthik Date: Sat, 10 Sep 2022 12:19:19 +0530 Subject: [PATCH 5/6] added doc --- doc/setup/postgres.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 doc/setup/postgres.md diff --git a/doc/setup/postgres.md b/doc/setup/postgres.md new file mode 100644 index 0000000..d3dba5e --- /dev/null +++ b/doc/setup/postgres.md @@ -0,0 +1,16 @@ +typical conf file for pg_hba.conf for dev work. + + +# TYPE DATABASE USER ADDRESS METHOD + +# "local" is for Unix domain socket connections only +local all all md5 +# IPv4 local connections: +host all all 127.0.0.1/32 md5 +# IPv6 local connections: +host all all ::1/128 md5 +# Allow replication connections from localhost, by a user with the +# replication privilege. +local replication all peer +host replication all 127.0.0.1/32 ident +host replication all ::1/128 ident \ No newline at end of file From 61bccc10bd0fb040748e40d0edf8e3c08738f1f8 Mon Sep 17 00:00:00 2001 From: karthik Date: Sat, 10 Sep 2022 12:20:11 +0530 Subject: [PATCH 6/6] deleted dev.env --- dev.env | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 dev.env diff --git a/dev.env b/dev.env deleted file mode 100644 index 8752c76..0000000 --- a/dev.env +++ /dev/null @@ -1,12 +0,0 @@ -HOSTING_URL=http://localhost:8000/ -DEBUG=True -EMAIL=saisurya3127@gmail.com -EMAIL_PASSWORD=deirkdgolaopottv -SECRET_KEY=%2e!&f6(ib^690y48z=)&w6fczhwukzzp@3y*^*7u+7%4s-mie -EMAIL_VERIFICATION_SECRET_KEY=b'<\xa3\xaf&(*|\x0e\xbces\x07P\xf7\xd6\xa9sf\x19$\x96\xb7\x90\x8b\x88\x84\x0e\x191\xde,M\x90\x17(\xf7\nG\x13"\x8d$\x9f&\xb0\xcd\xa4\xaf\xa9\x1b\x15\x02B\x8a\xaf\xff\x0c\x1e\xd5\xb3\x06\xb8\xa6\x9bQ\xa0TR\xe8\x98\x9ae\xe0n}\xcc/[\xdaFz\x18\xfeX\xaf\xbd\xd0\x88\xeal\xe3\xd2\xe3\xb8\x8c\x199{\xf3<\xb0\xc5\xd0\xe7*Rv\xda\xbb \x1d\x85~\xff%>\x1e\xb8\xa7\xbf\xbc\xb2\x06\x86X\xc3\x9f\x13<\x9fd\xea\xb5"\\5&\x01\xa4\x7f=\xa0\x1b\x8bO\x01h\xe8\xfd\x1f\xfe\xba\xbeg\\\xc2\xcb\xc3\xd1~\xff\xd5/9d\xa8\xa7x{\x16\xdb\\\xbb\x08\rI\xcd\x9e7\x8c~\x0f\x1d\x81rXZD\xf0\xf7\x87K\x8f\xfb,\xf4\xf0\xa5\x9e\xde^\xca\xae\x80|9b\x9b\xaaE"\xba\xfb\xdf\x80\xb1\x99\x83e[\xf8\xce&Rq\x99\xdb}\xeeO\xd5\x18\x8d\x0bv\xe7\xab\xf9\xb9{\xb5u\xce\xcf\x90\xa6HE\xc5\x92p\x00\x158\xdf\x1d' -DB_NAME=cdc -DB_USER=postgres -DB_PASSWORD=postgres -DB_HOST=localhost -DB_PORT=5432 -RECAPTCHA_SECRET_KEY=6Lcv-mEfAAAAAOxM3pzPc-9W96yPlkWnn6v41fLl