Skip to content

Commit

Permalink
feat[ac-1]: implemented logic for updating course instructor
Browse files Browse the repository at this point in the history
  • Loading branch information
grvup authored and ramG-reddy committed Oct 24, 2024
1 parent c0bc007 commit 0c55dfc
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 5 deletions.
15 changes: 13 additions & 2 deletions FusionIIIT/applications/programme_curriculum/filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import django_filters
from django import forms
from .models import Programme, Discipline, Curriculum, Semester, Course, Batch, CourseSlot, PROGRAMME_CATEGORY_CHOICES
from .models import Programme, Discipline, Curriculum, Semester, Course, Batch, CourseSlot, PROGRAMME_CATEGORY_CHOICES,CourseInstructor

class CourseFilter(django_filters.FilterSet):
class Meta:
Expand Down Expand Up @@ -40,4 +40,15 @@ class Meta:
'name' : forms.TextInput(attrs={'placeholder': 'Course/Project Name','max_length': 100,}),
'name' : django_filters.CharFilter(forms.TextInput(attrs={'placeholder': 'Course/Project Name','max_length': 100,})),
'code' : django_filters.CharFilter(forms.TextInput(attrs={'placeholder': 'Version','max_length': 10,})),
}
}

class CourseInstructorFilter(django_filters.FilterSet):
course_id = django_filters.CharFilter(field_name='course_id__code', lookup_expr='icontains', label='Course Code') # Course code filter
instructor_id = django_filters.CharFilter(field_name='instructor_id__id', lookup_expr='icontains', label='Instructor Name') # Assuming 'username' field in related faculty model
batch_id = django_filters.CharFilter(field_name='batch_id__name', lookup_expr='icontains', label='Programme') # Batch name, adjust if necessary
year = django_filters.NumberFilter(field_name='batch_id__year', lookup_expr='exact', label='Year') # Year filter
discipline_acronym = django_filters.CharFilter(field_name='batch_id__discipline__acronym', lookup_expr='icontains', label='Branch') # Discipline acronym filter

class Meta:
model = CourseInstructor
fields = ['course_id', 'instructor_id', 'batch_id', 'year', 'discipline_acronym']
2 changes: 2 additions & 0 deletions FusionIIIT/applications/programme_curriculum/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
path('admin_course/<course_id>/', views.admin_view_a_course, name='admin_view_a_course'),
path('admin_disciplines/', views.admin_view_all_discplines, name='admin_view_all_discplines'),
path('admin_batches/', views.admin_view_all_batches, name='admin_view_all_batches'),
path('admin_instructor/',views.admin_view_all_course_instructor,name='admin_view_all_course_instructor'),

path('admin_add_programme/', views.add_programme_form, name='add_programme_form'),
path('admin_add_discipline/', views.add_discipline_form, name='add_discipline_form'),
Expand All @@ -41,6 +42,7 @@
path('admin_add_batch/', views.add_batch_form, name='add_batch_form'),
path('admin_add_course_instructor/', views.add_course_instructor, name='add_course_instructor'),

path('admin_update_course_instructor/<instructor_id>/', views.update_course_instructor_form, name='update_course_instructor_form'),
path('admin_update_course/<course_id>/', views.update_course_form, name='update_course_form'),
path('admin_edit_curriculum/<curriculum_id>/', views.edit_curriculum_form, name='edit_curriculum_form'),
path('admin_edit_programme/<programme_id>/', views.edit_programme_form, name='edit_programme_form'),
Expand Down
69 changes: 67 additions & 2 deletions FusionIIIT/applications/programme_curriculum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from .models import Programme, Discipline, Curriculum, Semester, Course, Batch, CourseSlot,NewProposalFile,Proposal_Tracking
from .models import Programme, Discipline, Curriculum, Semester, Course, Batch, CourseSlot,NewProposalFile,Proposal_Tracking,CourseInstructor
from .forms import ProgrammeForm, DisciplineForm, CurriculumForm, SemesterForm, CourseForm, BatchForm, CourseSlotForm, ReplicateCurriculumForm,NewCourseProposalFile,CourseProposalTrackingFile, CourseInstructorForm
from .filters import CourseFilter, BatchFilter, CurriculumFilter
from .filters import CourseFilter, BatchFilter, CurriculumFilter,CourseInstructorFilter
from django.db import IntegrityError
from django.utils import timezone

Expand All @@ -17,6 +17,33 @@
from applications.globals.models import (DepartmentInfo, Designation,ExtraInfo, Faculty, HoldsDesignation)
# ------------module-functions---------------#




@login_required(login_url='/accounts/login')
def admin_view_all_course_instructor(request):
# Fetch all records from the CourseInstructor table
course_instructors = CourseInstructor.objects.all()

# Passing the data to the template
context = {
'course_instructors': course_instructors,
}

return render(request, 'programme_curriculum/acad_admin/admin_view_all_course_instructor.html', context)
@login_required(login_url='/accounts/login')
def update_course_instructor_form(request, id):

instructor = get_object_or_404(CourseInstructor, id=id)
course_instructors = CourseInstructor.objects.all()

# Passing the data to the template
context = {
'course_instructors': course_instructors,
}
# Handle the update logic here
return render(request, 'programme_curriculum/acad_admin/admin_view_all_course_instructor.html', context)

@login_required(login_url='/accounts/login')
def programme_curriculum(request):
"""
Expand Down Expand Up @@ -1635,4 +1662,42 @@ def add_course_instructor(request):
form = CourseInstructorForm()

return render(request, 'programme_curriculum/acad_admin/add_course_instructor.html', {'form': form})
return HttpResponseRedirect('/programme_curriculum/')

@login_required(login_url='/accounts/login')
def admin_view_all_course_instructor(request):
if request.session.get('currentDesignationSelected') == "acadadmin":
course_instructors = CourseInstructor.objects.all()

# Apply filtering
course_instructor_filter = CourseInstructorFilter(request.GET, queryset=course_instructors)
filtered_course_instructors = course_instructor_filter.qs

return render(request, 'programme_curriculum/acad_admin/admin_view_all_course_instructor.html', {
'course_instructors': filtered_course_instructors,
'courseinstructorfilter': course_instructor_filter
})

return HttpResponseRedirect('/programme_curriculum/')

@login_required(login_url='/accounts/login')
def update_course_instructor_form(request, instructor_id):

if request.session.get('currentDesignationSelected') == "acadadmin":
# Retrieve the CourseInstructor object or return 404 if not found
course_instructor = get_object_or_404(CourseInstructor, id=instructor_id)

if request.method == 'POST':
# Bind the form to the POST data for validation and save
form = CourseInstructorForm(request.POST, instance=course_instructor)
if form.is_valid():
form.save() # Save the updated data to the database
return redirect('/programme_curriculum/') # Redirect after successful update
else:
# Create the form with existing data (pre-populated)
form = CourseInstructorForm(instance=course_instructor)

return render(request, 'programme_curriculum/acad_admin/add_course_instructor.html', {'form': form, 'instructor': course_instructor})

# Redirect to the main page if the user is not 'acadadmin'
return HttpResponseRedirect('/programme_curriculum/')
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{% extends 'programme_curriculum/acad_admin/common.html' %}
{% block content %}
<div class="ui top attached tabular large menu">
<a class="item active" data-tab="afirst">Course Instructors</a>
</div>
<div class="ui bottom attached tab segment active" data-tab="afirst">
<div class="content">
<div class="description" style="overflow: auto; max-height: 495px">
<table class="ui celled medium table"
style="text-align: center;
margin: auto;">
<thead>
<tr style="font-size: medium;
background-color: whitesmoke;">
<td><h4>Course Code</h4></td>
<td><h4>Course Name</h4></td>
<td><h4>Course Version</h4></td>
<td><h4>Instructor</h4></td>
<td><h4>Batch</h4></td>
<td><h4>Year</h4></td>
<td></td>
</tr>
</thead>
<tbody>
{% for instructor in course_instructors %}
<tr>
<td><a href="{% url 'programme_curriculum:admin_view_a_course' instructor.course_id.id %}">{{ instructor.course_id.code }}</a></td>
<td>{{ instructor.course_id.name }}</td>
<td>{{ instructor.course_id.version }}</td>
<td>{{ instructor.instructor_id.id }}</td>
<td>{{ instructor.batch_id.name }}&nbsp;&nbsp;&nbsp;{{ instructor.batch_id.discipline.acronym }}</td>
<td>{{ instructor.batch_id.year }}</td>
<td class="collapsing">
<a class="tiny ui positive animated button" tabindex="0"
href="{% url 'programme_curriculum:update_course_instructor_form' instructor.id %}"
type="Submit" name="Submit">
<div class="visible content">EDIT</div>
<div class="hidden content">
<i class="edit icon"></i>
</div>
</a>
</td>
</tr>
{% empty %}
<tr>
<td colspan="6">No Course Instructors Available</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{% endblock %}

{% block rightcontent %}
<br>
<br>
<div class="ui center aligned segment">
<div class="description" style="overflow: auto; height: 400px">
<a class="fluid ui large primary animated button" tabindex="0"
href="{% url 'programme_curriculum:add_course_instructor' %}"
type="Submit" name="Submit">
<div class="visible content">ADD COURSE INSTRUCTOR</div>
<div class="hidden content">
<i class="add icon"></i>
</div>
</a>
<div class="ui horizontal divider">FILTER SEARCH</div>
<form class="ui small form" method="get">
{{ courseinstructorfilter.form }}
<br>
<button class="ui tiny basic primary button" type="Submit" name="Submit">
<i class="search icon"></i>
Search
</button>
</form>
</div>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<a class="item" href="{% url 'programme_curriculum:admin_view_all_courses' %}">Courses
<i class="right floated chevron right icon"></i>
</a>
<a class="item" href="{% url 'programme_curriculum:add_course_instructor' %}">Add Course Instructor
<a class="item" href="{% url 'programme_curriculum:admin_view_all_course_instructor' %}">Course Instructor
<i class="right floated chevron right icon"></i>
</a>
</div>
Expand Down

0 comments on commit 0c55dfc

Please sign in to comment.