diff --git a/migrations/0017_resident_address_bhawan_resident_registration_date_and_more.py b/migrations/0017_resident_address_bhawan_resident_registration_date_and_more.py new file mode 100644 index 0000000..cb5c3a5 --- /dev/null +++ b/migrations/0017_resident_address_bhawan_resident_registration_date_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.1.5 on 2024-08-03 19:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bhawan_app', '0016_auto_20221116_0024'), + ] + + operations = [ + migrations.AddField( + model_name='resident', + name='address_bhawan', + field=models.CharField(default='', max_length=100), + ), + migrations.AddField( + model_name='resident', + name='registration_date', + field=models.DateTimeField(blank=True, null=True), + ), + migrations.AlterField( + model_name='complaint', + name='status', + field=models.CharField(choices=[('res', 'Resolved'), ('pen', 'Pending'), ('unr', 'Unresolved'), ('ipr', 'Inprocess')], default='pen', max_length=10), + ), + ] diff --git a/models/resident.py b/models/resident.py index ffa06ad..2f2dc32 100644 --- a/models/resident.py +++ b/models/resident.py @@ -51,6 +51,8 @@ class Resident(Model): start_date = models.DateTimeField(default=datetime.now) end_date = models.DateTimeField(null=True, blank=True) is_living_in_campus = models.BooleanField(default = True) + address_bhawan = models.CharField(max_length=100,default="") + registration_date=models.DateTimeField(null=True, blank=True) fee_type = models.CharField( max_length=10, choices=statuses.FEE_TYPES, diff --git a/serializers/resident.py b/serializers/resident.py index 1153fa6..cd85ee4 100644 --- a/serializers/resident.py +++ b/serializers/resident.py @@ -73,6 +73,8 @@ class Meta: "is_resident", "display_picture", "address", + "address_bhawan", + "registration_date", "city", "state", "country", diff --git a/views/resident.py b/views/resident.py index 7454a49..a10dc67 100644 --- a/views/resident.py +++ b/views/resident.py @@ -67,6 +67,8 @@ def create(self, request, hostel__code): room_number = data['room_number'] start_date = data['start_date'] fee_type = data['fee_type'] + address_bhawan=data['address_bhawan'] + registration_date=data['registration_date'] except Exception: return Response( "Invalid field values for invalid input", @@ -169,6 +171,8 @@ def create(self, request, hostel__code): mother=mother, is_resident=True, mothers_contact=mothers_contact, + address_bhawan=address_bhawan, + registration_date=registration_date, ) return Response(ResidentSerializer(instance).data) @@ -197,6 +201,8 @@ def retrieve(self, request, hostel__code, pk=None): obj["postal_code"] = None obj["reservation_category"] = None obj["is_living_in_campus"] = False + obj["address_bhawan"]=None + obj["registration_date"]=None try: contact_information = \ @@ -555,6 +561,8 @@ def download(self, request, hostel__code): 'Degree': [], 'Date of Birth': [], 'Address': [], + 'Address Bhawan':[], + 'Registration Date':[], 'City': [], 'State': [], 'Country': [], @@ -588,6 +596,8 @@ def download(self, request, hostel__code): data['Department'].append(department[0]) data['Date of Birth'].append(self.get_date_of_birth(resident)) data['Address'].append(self.get_address(resident)) + data['Address Bhawan'].append(resident.address_bhawan) + data['Registration Date'].append(resident.registration_date) data['City'].append(self.get_city(resident)) data['State'].append(self.get_state(resident)) data['Country'].append(self.get_country(resident)) diff --git a/views/upload_bhawan_data.py b/views/upload_bhawan_data.py index 0ae0c89..62fd448 100644 --- a/views/upload_bhawan_data.py +++ b/views/upload_bhawan_data.py @@ -1,3 +1,4 @@ +from calendar import monthrange import swapper import csv import pandas as pd @@ -58,7 +59,7 @@ def update_data(self, request, hostel__code): else: complete_list = True - ROOM_NA = ['', 'Not Joined', 'Not joined yet', 'NOT ALLOWTED', 'Pending', 'Not Joining yet', 'not joined yet', 'Not Joined Yet'] + ROOM_NA = ['', 'Not Joined', 'Not joined yet', 'NOT ALLOWTED', 'Pending', 'Not Joining yet', 'not joined yet', 'Not Joined Yet', 'Not Allotted'] invalid_data = { 'Student enrollment no': [], 'Error while uploading':[] @@ -91,9 +92,16 @@ def update_data(self, request, hostel__code): in_campus = student_data[11] fee_status = student_data[10] start_date = student_data[12].split('/r/n')[0] + # assumed the column indexes of the following fields(as no where is the csv file handled and the script was working before) + fathers_name = student_data[13] + fathers_phone = student_data[14] + mothers_name = student_data[15] + mothers_phone = student_data[16] + + # gets the student's object and checks if it is a resident of new hostel try: - person = Person.objects.get(student__enrolment_number=student_enrollement_no) - present_residents |= Resident.objects.filter(person=person,hostel=hostel) + student = Person.objects.get(student__enrolment_number=student_enrollement_no) + present_residents |= Resident.objects.filter(person=student,hostel=hostel) except: invalid_data['Student enrollment no'].append(student_enrollement_no) invalid_data['Error while uploading'].append('Student not found') @@ -139,21 +147,60 @@ def update_data(self, request, hostel__code): if not valid_date : invalid_data['Student enrollment no'].append(student_enrollement_no) invalid_data['Error while uploading'].append('Invalid start date format') - continue + try: - Resident.objects.update_or_create( - person = person, + existing = Resident.objects.get(person=student, is_resident=True) + try: + father = existing.father + if(fathers_name is not None): + father.full_name = fathers_name + father.save() + # else: + # father.delete() + # father = None + except: + if(fathers_name is not None): + father = Person.objects.create( + full_name = fathers_name + ) + else: + father = None + try: + mother = existing.mother + if(mothers_name is not None): + mother.full_name = mothers_name + mother.save() + # else: + # mother.delete() + # mother = None + except: + if(mothers_name is not None): + mother = Person.objects.create( + full_name = mothers_name + ) + else: + mother = None + + + r = Resident.objects.update_or_create( + person = student, + hostel = hostel, is_resident = True, defaults = { - 'person': person, + 'person': student, 'room_number': room_no, 'hostel': hostel, 'is_living_in_campus': is_living_in_campus, 'fee_type': fee_type, 'start_date': start_date_format, + 'father': father, + 'fathers_contact' : fathers_phone, + 'mother': mother, + 'mothers_contact' : mothers_phone, } ) + except Exception as e: invalid_data['Student enrollment no'].append(student_enrollement_no) invalid_data['Error while uploading'].append('Unable to update data') @@ -180,3 +227,4 @@ def update_data(self, request, hostel__code): response['Content-Disposition'] = 'attachment; filename=' + file_name df.to_csv(path_or_buf=response, index=False) return response + \ No newline at end of file