Skip to content

Commit

Permalink
add: script for copying research scholars data
Browse files Browse the repository at this point in the history
  • Loading branch information
SysSn13 committed Jun 21, 2021
1 parent 255c318 commit 2e7f027
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ static/
mechweb.log
secrets.json
.idea/
settings.json
mechweb.code-workspace
Empty file added alumni/templatetags/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion mechweb/automation_scripts/copy_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def get_course(course):



# opne the shell using python manage.py shell and use this script like this:
# open the shell using python manage.py shell and use this script like this:

# from mechweb.automation_scripts.copy_courses import *
# init_program_and_sem()
Expand Down
77 changes: 77 additions & 0 deletions mechweb/automation_scripts/copy_research_scholars.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
from mechweb.models import Academics, Student, StudentBatch, StudentPage, Program, Students

acads = Academics.objects.first()
prog = Program.objects.all().filter(title="Ph.D").first()
if not prog:
prog = Program(title="Ph.D")
acads.add_child(instance=prog)
prog.save()
print("Created new program: Ph.D")

researchScholars = Students.objects.child_of(prog).first()
if not researchScholars:
researchScholars = Students(title="Research Scholors")
prog.add_child(instance=researchScholars)
researchScholars.save()
print("Created students page: Research Scholors")


def get_batch(year):
global researchScholars, StudentBatch
batch = StudentBatch.objects.child_of(researchScholars).filter(enrollment_year=year).first()
if not batch:
batch = StudentBatch(title="{year} Batch".format(year=year), enrollment_year=year)
researchScholars.add_child(instance=batch)
batch.save()
print("Created batch :", batch)
return batch


def copy_student(stud):
global get_batch, Student
date = stud.enrolment_year
# print(year.year)
batch = get_batch(date.year)
if Student.objects.child_of(batch).filter(webmail=stud.email_id).exists():
print("{student} skipped".format(student=stud))
return

def get_title(stud):
name = stud.first_name
if len(stud.middle_name):
name += " " + stud.middle_name
if len(stud.last_name):
name += " " + stud.last_name
return name

new_stud = Student(
title=get_title(stud),
first_name=stud.first_name,
middle_name=stud.middle_name,
last_name=stud.last_name,
webmail=stud.email_id,
roll_no=stud.roll_no,
enrollment_year=stud.enrolment_year,
leaving_year=stud.leaving_year,
is_exchange=stud.is_exchange,
contact_number=stud.contact_number,
hostel_address=stud.hostel_address,
photo=stud.photo,
intro=stud.intro,
body=stud.body,
website=stud.website,
supervisor=stud.faculty_advisor,
)
batch.add_child(instance=new_stud)
new_stud.save()
print(new_stud.title + " added")


students = StudentPage.objects.all()
cnt = 0
for student in students:
if student.get_programme_display() == "Research Scholar":
copy_student(student.specific)
exit()

# python manage.py shell < mechweb/automation_scripts/copy_research_scholars.py
4 changes: 2 additions & 2 deletions mechweb/templates/mechweb/alumnus_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ <h4>Roll Number</h4>
{% if page.specific.email_id %}
<li>
<h4>Email ID</h4>
<p>{{ page.specific.email_id|noscrape }}</p>
<p>{{ page.specific.email_id|noscrape|safe }}</p>
{% if page.specific.email_id_2 %}
<p>{{ page.specific.email_id_2|noscrape }}</p>
<p>{{ page.specific.email_id_2|noscrape|safe }}</p>
{% endif %}
</li>
{% endif %}
Expand Down
4 changes: 2 additions & 2 deletions mechweb/templates/mechweb/faculty_home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ <h5>Head of Department</h5>
<li><span>Contact</span> {{ faculty.specific.office_contact_number }}</li>
{% endif %}
{% if faculty.specific.email_id %}
<li><span>Email</span> {{ faculty.specific.email_id|noscrape }}</li>
<li><span>Email</span> {{ faculty.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if faculty.specific.irins_profile_link %}
<li><span>Research Profile:</span><a href="{{ faculty.specific.irins_profile_link }}">IIT Guwahati
Expand Down Expand Up @@ -251,7 +251,7 @@ <h2><a href="{{ faculty.url }}">
<li><span>Contact</span> {{ faculty.specific.office_contact_number }}</li>
{% endif %}
{% if faculty.specific.email_id %}
<li><span>Email</span> {{ faculty.specific.email_id|noscrape }}</li>
<li><span>Email</span> {{ faculty.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if faculty.specific.irins_profile_link %}
<li><span>Research Profile:</span><a href="{{ faculty.specific.irins_profile_link }}">IIT Guwahati
Expand Down
2 changes: 1 addition & 1 deletion mechweb/templates/mechweb/faculty_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ <h4>Home contact Number</h4>
{% endif %} {% if page.specific.email_id %}
<li>
<h4>Mail ID</h4>
<p>{{ page.specific.email_id|noscrape }}</p>
<p>{{ page.specific.email_id|noscrape|safe }}</p>
</li>
{% endif %} {% if page.specific.website %}
<li>
Expand Down
8 changes: 4 additions & 4 deletions mechweb/templates/mechweb/staff_home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h2>{{ staff }}</h2>
<li><span>Office</span>{{ staff.specific.address }}</li>
{% endif %}
{% if staff.specific.email_id %}
<li><span>Email : </span>{{ staff.specific.email_id|noscrape }}</li>
<li><span>Email : </span>{{ staff.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if staff.specific.contact_number %}
<li><span>Contact</span>{{ staff.specific.contact_number }}</li>
Expand Down Expand Up @@ -142,7 +142,7 @@ <h2>{{ staff }}</h2>
<li><span>Office</span>{{ staff.specific.address }}</li>
{% endif %}
{% if staff.specific.email_id %}
<li><span>Email : </span>{{ staff.specific.email_id|noscrape }}</li>
<li><span>Email : </span>{{ staff.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if staff.specific.contact_number %}
<li><span>Contact</span>{{ staff.specific.contact_number }}</li>
Expand Down Expand Up @@ -189,7 +189,7 @@ <h2>{{ staff }}</h2>
<li><span>Office</span>{{ staff.specific.address }}</li>
{% endif %}
{% if staff.specific.email_id %}
<li><span>Email : </span>{{ staff.specific.email_id|noscrape }}</li>
<li><span>Email : </span>{{ staff.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if staff.specific.contact_number %}
<li><span>Contact</span>{{ staff.specific.contact_number }}</li>
Expand Down Expand Up @@ -226,7 +226,7 @@ <h2>{{ staff }}</h2>

<td>{{ forloop.counter }}.</td>
<td>{{ staff.specific.full_name }}</td>
<td> {%if staff.specific.email%}{{staff.specific.email|noscrape}}{%endif%}</td>
<td> {%if staff.specific.email%}{{staff.specific.email|noscrape|safe}}{%endif%}</td>
<td><a href="{{staff.specific.associate_faculty.url}}">{{staff.specific.associate_faculty}}</a>
<td>{{staff.specific.project_title}}</td>

Expand Down
2 changes: 1 addition & 1 deletion mechweb/templates/mechweb/staff_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h4>Joining year</h4>
{% if page.email_id %}
<li>
<h4>Email ID</h4>
<p>{{ page.email_id|noscrape }}</p>
<p>{{ page.email_id|noscrape|safe }}</p>
</li>
{% endif %}

Expand Down
4 changes: 2 additions & 2 deletions mechweb/templates/mechweb/student_batch.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ <h2 class="text-center text-white" > <strong>{{page.title}}</strong></h2>
<td> {{forloop.counter}}</td>
<td>{{ student.specific.first_name }} {{student.specific.middle_name}} {{student.specific.last_name}}</td>
<td>{{student.specific.roll_no}}</td>
<td> {{student.specific.webmail|noscrape}}</td>
<td> {{student.specific.webmail|noscrape|safe}}</td>
<td>
{% if student.specific.supervisor %}
<a href="{{student.specific.supervisor.url}}"> {{student.specific.supervisor}}</a>
Expand Down Expand Up @@ -206,7 +206,7 @@ <h3> {{ student }}</h3>
{% if student.specific.enrollment_year %}
<li> <b>Enrollment year: </b> {{ student.specific.enrollment_year|date:"Y" }}</li>
{% endif %}
<li ><b >Email: </b>{{ student.specific.webmail|noscrape}}</li>
<li ><b >Email: </b>{{ student.specific.webmail|noscrape|safe}}</li>
{% if student.specific.roll_no %}
<li ><b>Registration No.: </b>{{ student.specific.roll_no }}</li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion mechweb/templates/mechweb/student_home_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h2>{{ student }}</h2>
<li><span>Enrollment year</span>{{ student.specific.enrolment_year|date:"Y" }}</li>
{% endif %}
{% if student.specific.email_id %}
<li><span>Email</span>{{ student.specific.email_id|noscrape }}</li>
<li><span>Email</span>{{ student.specific.email_id|noscrape|safe }}</li>
{% endif %}
{% if student.specific.roll_no %}
<li><span>Enrollment NO.</span>{{ student.specific.roll_no }}</li>
Expand Down
4 changes: 2 additions & 2 deletions mechweb/templates/mechweb/student_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ <h4>Roll Number</h4>
{% if page.specific.email_id %}
<li>
<h4>Email ID</h4>
<p>{{ page.specific.email_id|noscrape }}</p>
<p>{{ page.specific.email_id|noscrape|safe }}</p>
{% if page.specific.email_id_2 %}
<p>{{ page.specific.email_id_2|noscrape }}</p>
<p>{{ page.specific.email_id_2|noscrape|safe }}</p>
{% endif %}
</li>
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod-wsgi==4.7.1
oauthlib==3.1.0
openpyxl==3.0.5
Pillow==7.2.0
pkg-resources==0.0.0
#pkg-resources==0.0.0
pycparser==2.20
PyJWT==1.7.1
python3-openid==3.2.0
Expand Down

0 comments on commit 2e7f027

Please sign in to comment.