Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aditya chopra #57

Open
wants to merge 8 commits into
base: revamp
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -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),
),
]
2 changes: 2 additions & 0 deletions models/resident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions serializers/resident.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Meta:
"is_resident",
"display_picture",
"address",
"address_bhawan",
"registration_date",
"city",
"state",
"country",
Expand Down
10 changes: 10 additions & 0 deletions views/resident.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 = \
Expand Down Expand Up @@ -555,6 +561,8 @@ def download(self, request, hostel__code):
'Degree': [],
'Date of Birth': [],
'Address': [],
'Address Bhawan':[],
'Registration Date':[],
'City': [],
'State': [],
'Country': [],
Expand Down Expand Up @@ -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))
Expand Down
62 changes: 55 additions & 7 deletions views/upload_bhawan_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from calendar import monthrange
import swapper
import csv
import pandas as pd
Expand Down Expand Up @@ -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':[]
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand All @@ -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