Professional Documents
Culture Documents
Hari Document
Hari Document
Hari Document
Submitted by
HARIHARAN K
(RegNo:20BSC114)
ASSISTANT PROFESSOR
(Autonomous)
(Affiliated to Bharathiar University)
fulfilment of the requirement. for the award of the Bachelor of Science in Computer Science
is a record original work done by HARIHARAN (Reg no:20BSC114) and this project work
has not formed the basics for the award of any degree are similar title to any candidate of any
university.
SYSTEM ” is a record of original work done by me during 2022-2023, under the supervision
Computer Science, Hindusthan College of Arts & Science, Coimbatore and this project work
has not formed the basis of award of any Degree similar title to any candidate of any
university.
Date: (HARIHARAN K)
ACKNOWLEDGEMENT
ACKNOWLEDGEMENT
Director Mrs. T. SARASWATHI KANNAIYAN, who was a very example in my life for
achieving goals.
I Sincerely express my profound, thanks to our respected Professor & Head of the
discussion constant support and timely valuable guidance and encouragement during my
project work.
My sincere thanks to our class tutor and project coordinator Mrs. A. KIRUTHIKA
(Ph.D) Department of Computer Science. who took keen interest in my work and put me on
the right path, through his valuable suggestions and timely help in each stage of my project.
All above I thank GOD and My Parent for all his blessings.
ABSTRACT
ABSTRACT
organizations, and companies to conduct exams and assessments over the internet. This
system offers a variety of features to help automate the examination process, including
The system typically starts with an administrator who sets up the exam, adds questions to the
question bank, and sets the rules for the exam. Once the exam is ready, students or candidates
can log in to the system and take the exam. The system usually offers multiple types of
questions, such as multiple choice, true/false, short answer, and essay questions.
The online examination system has several advantages over traditional paper-based exams. It
saves time and resources, as there is no need to print or distribute paper copies of the exam. It
also eliminates the possibility of cheating or fraud, as the system can monitor the student's
Moreover, it provides immediate feedback to students, allowing them to see their scores and
learn from their mistakes. The system can also generate reports and analytics, helping
instructors and administrators to evaluate the performance of students and identify areas for
improvement.
TABLE OF CONTENTS
TABLE OF CONTENTS
INTRODUCTION
1 1.1 ABOUT THE PROJECT 1
1.2 SCOPE
1.3 OBJECTIVES
The Online Examination System is a digital platform designed to simplify the examination
process and provide a user-friendly interface for students, professors, and admins. This
system is developed using various programming languages such as Python, Django, CSS,
HTML, and JavaScript. The purpose of this documentation is to describe the scope,
1.2 Scope
institutions, where it can be used for conducting online exams for various subjects. The system
is designed to provide a hassle-free way of evaluating students, making the examination process
simplified, and allowing exams to be taken from anywhere and at any time. The system's scope
is vast, covering different types of exams such as multiple-choice, short-answer, and essay-type
questions, which can be scheduled and managed by the admin. The system aims to provide a
1.3 OBJECTIVES
The primary objective of the Online Examination System is to simplify the examination
process and provide a user-friendly interface for students, professors, and admins. The
system aims to provide a secure environment for exams and ensure the authenticity of results.
The platform also aims to reduce the workload of teachers and minimize paper wastage. The
system intends to provide an efficient method of conducting online exams that can be
1
Features:
The Online Examination System contains an admin side from where a user can take and
manage exams easily. The admin plays an essential role in the management of this system. In
this project, there is a separate interface for students, professors, and admins. The features of
1. Secure login system for students, professors, and admins: The platform provides a
secure login system for students, professors, and admins, ensuring that only
2. Exam scheduling and management: The system provides an option to schedule exams
and set time limits for each exam, making it a time-based examination.
3. Various types of exams: The system supports various types of exams such as
4. Instant result display: The system allows instant result display after the completion of
5. Exam feedback for students: The platform provides feedback to students on their
7. Minimal paper wastage: The system reduces paper wastage as all exams are
conducted online.
2
SYSTEM ANALYSIS AND FEASIBILITY STUDY
3
2. SYSTEM ANALYSIS AND FEASIBILITY STUDY
The traditional method of conducting exams involves a lot of paperwork, is time-consuming, and is
prone to errors. It is also challenging to conduct exams in remote locations, and the authenticity of
the results is questionable. Hence, there is a need for a digital platform that can simplify the
examination process, provide a secure environment, and ensure the authenticity of results.
The existing system for conducting exams involves the use of paper-based exams, which are
time-consuming, require physical presence, and are prone to errors. The traditional method
also lacks the flexibility to conduct exams from remote locations, making it difficult for
students in different regions to appear for exams. The use of paper-based exams also leads to
a lot of paper wastage and makes the process of result management cumbersome. The
authenticity of the results is also questionable, as the exams are not always conducted under
secure conditions.
The proposed Online Examination System is a digital platform designed to simplify the examination
process, provide a secure environment, and ensure the authenticity of results. The system is designed
to provide a hassle-free way of evaluating students, making the examination process simplified, and
allowing exams to be taken from anywhere and at any time. The platform provides a secure login
4
system for students, professors, and admins, ensuring that only authorized users can access the
system.
Advantages
2. Secure Environment: The platform provides a secure environment for exams, ensuring
3. Anytime, Anywhere Access: The system allows exams to be taken from anywhere
4. Reduced Paper Wastage: The system reduces paper wastage as all exams are
conducted online.
conduct a feasibility study to determine if the system is viable and feasible. The feasibility
study will analyze the technical, economic, and operational aspects of the proposed system
and determine if the system is worth investing in. Here is a breakdown of the feasibility
study:
5
Technical Feasibility:
The technical feasibility of the proposed system will analyze if the system can be developed
using the available technology and resources. It will consider the availability of hardware,
software, and technical expertise required to develop the system. In this case, the system is
developed using Python, Django, CSS, HTML, and JavaScript. These technologies are
readily available, and the necessary technical expertise can be obtained. Therefore, the
Economic Feasibility:
The economic feasibility of the proposed system will analyze if the system is financially
viable. It will consider the cost of developing the system, the benefits it offers, and the return
on investment (ROI). The development cost of the proposed system will include the cost of
hardware, software, technical expertise, and other expenses. However, the benefits of the
proposed system include reduced paper wastage, efficient result management, and improved
student feedback, among others. The ROI of the proposed system will be determined by
comparing the development cost with the benefits offered by the system. If the ROI is
Operational Feasibility:
The operational feasibility of the proposed system will analyse if the system can be integrated
into the existing operations of the organization. It will consider the ease of use, training
required, and compatibility with existing systems. In this case, the proposed system is
designed to integrate into the existing operations of the organization. It is user-friendly, and
the necessary training can be provided. The system is also compatible with existing systems.
6
SYSTEM SPECIFICATION
7
3. SYSTEM SPECIFICATION
Monitor : VGA/SVGA
Keyboard : Logitech
8
SOFTWARE DESCRIPTION
HTML
HTML tutorial or HTML 5 tutorial provides basic and advanced concepts of HTML. Our
HTML tutorial is developed for beginners and professionals. In our tutorial, every topic is given
step-by-step so that you can learn it in a very easy way. If you are new in learning HTML, then
you can learn HTML from basic to a professional level and after learning HTML with
CSS and JavaScript you will be able to create your own interactive and dynamic website. But
o HTML is used to create web pages and web applications. o HTML is widely
used language on the web. o We can create a static website by HTML only.
language.
Applications of HTML
As mentioned before, HTML is one of the most widely used languages over the web. I'm
• Web pages development - HTML is used to create pages which are rendered over the
web. Almost every page of the web is having html tags in it to render its details in
browser.
9
• Internet Navigation - HTML provides tags which are used to navigate from one page
• Responsive UI - HTML pages now-a-days works well on all platform, mobile, tabs,
• Offline support HTML pages once loaded can be made available offline on the
• Game development- HTML5 has native support for rich experience and is now
CSS
CSS tutorial or CSS 3 tutorial provides basic and advanced concepts of CSS
technology. Our CSS tutorial is developed for beginners and professionals. The major points
o CSS stands for Cascading Style Sheet. o CSS is used to design HTML tags.
o HTML, CSS, and JavaScript are used for web designing. It helps web designers to
10
Before CSS, tags like font, color, background style, element alignments, border and size had to
be repeated on every web page. This was a very long process. For example: If you are
developing a large website where fonts and color information are added on every single page,
it will be become a long and expensive process. CSS was created to solve this problem. It was
a W3C recommendation.
CSS style definitions are saved in external CSS files, so it is possible to change the entire
CSS provides more detailed attributes than plain HTML to define the look and feel of the
website.
Django
on MVT (Model View Template) design pattern. The Django is very demanding due to its rapid
development feature. It takes less time to build application after collecting client requirement.
This framework uses a famous tag line: The web framework for perfectionists with
deadlines.
By using Django, we can build web applications in very less time. Django is designed in such
a manner that it handles much of configure things automatically, so we can focus on application
development only.
11
Popularity
Django is widely accepted and used by various well-known sites such as:
• Mozilla
• Disqus
• Bitbucket
Features of Django
• Rapid Development
• Secure
• Scalable
• Fully loaded
• Versatile
• Open Source
I. Rapid Development
Django was designed with the intention to make a framework which takes less time to build
web application. The project implementation phase is a very time taken but Django creates it
rapidly.
12
II. Secure
Django takes security seriously and helps developers to avoid many common security
mistakes, such as SQL injection, cross-site scripting, cross-site request forgery etc. Its user
authentication system provides a secure way to manage user accounts and passwords.
III. Scalable
Django is scalable in nature and has ability to switch from small quickly and flexibly to large
Django includes various helping task modules and libraries which can be used to handle
common Web development tasks. Django takes care of user authentication, content
V. Versatile
domains. Now a days, Companies are using Django to build various types of applications like
content management systems, social networks sites or scientific computing platforms etc.
13
VI. Open Source
can be downloaded with source code from the public repository. Open source reduces the total
Django is a one of the most popular web frameworks. It has widely supportive community
Database: MongoDB
Database
Database is a physical container for collections. Each database gets its own set of files on the
Collection
collection exists within a single database. Collections do not enforce a schema. Documents
within a collection can have different fields. Typically, all documents in a collection are of
14
Document
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema
means that documents in the same collection do not need to have the same set of fields or
structure, and common fields in a collection's documents may hold different types of data.
holds different documents. Number of fields, content and size of the document
• No complex joins.
• Tuning.
• Uses internal memory for storing the (windowed) working set, enabling faster
access of data.
documents.
• Big Data
• Data Hub
system. It helps to identify and define the functional and non-functional requirements of the
system, as well as the user needs and expectations. Here are some key requirements that
Functional requirements:
16
• Automatic grading and result calculation
Non-functional requirements:
User requirements:
17
SYSTEM DESIGN AND DEVELOPMENT PROCESS
18
4. SYSTEM DESIGN AND DEVELOPMENT PROCESS
19
4.2 Input Design
The input design of the Online Examination System is an essential aspect of the system's
usability and effectiveness. The input design determines how the user interacts with the
system and how the system processes the user's input. The input design must be intuitive,
efficient, and user-friendly to enhance the user experience. Here are some aspects of the input
1. Login Page: The user will input their credentials, such as username and password, on
the login page to access the system. The login page should be secure and userfriendly.
2. Registration Page: The registration page is where new users can register to use the
system. The registration form should be simple and straightforward, requiring only
essential information.
3. Exam Creation Page: The exam creation page is where the admin can create new
exams. The page should be intuitive and easy to use, allowing the admin to add
4. Exam Taking Interface: The exam taking interface is where students take exams. The
interface should be easy to navigate, and the questions should be presented clearly and
concisely.
20
4.3 Output Design
The output design of the Online Examination System determines how the system presents
information to the user. The output design must be clear, concise, and user-friendly to
enhance the user experience. Here are some aspects of the output design of the Online
Examination System:
1. Exam Results: After completing an exam, the system should present the results to the
student. The results should be presented clearly, showing the student's score and any
2. Exam Reports: The system should generate reports of the exams taken by students.
The reports should be easy to understand, providing insights into the performance of
the students.
3. User Management: The system should provide an interface for managing user
accounts. The interface should be easy to use, allowing the admin to add or remove
users as necessary.
4. System Alerts: The system should generate alerts for important events, such as new
exam creation or exam deadline reminders. The alerts should be clear and concise,
21
TESTING AND IMPLEMENTATION PHASE
22
5. TESTING AND IMPLEMENTATION PHASE
After the source code has been completed, documented as related data structures.
Completed the project must undergo testing and validation where there is subtitle and definite
The project developer treads lightly, designing and execution test that will demonstrates
that the program works rather than uncovering errors, unfortunately errors will be present and
if the project developer doesn’t find them, the user will find out.
The project developer is always responsible for testing the individual units i.e. modules
of the program. In many cases developer also conducts integration testing i.e. the testing step
This project has undergone the following testing procedures to ensure its correctness.
• UNIT TESTING
• INTEGRATION TESTING
• VALIDATION TESTING
23
UNIT TESTING
In unit testing, we must test the programs making up the system. For this reason, Unit testing
sometimes called as Program testing. The software units in a system are the modules and
routines that are assembled and integrated to perform a specific function, Unit testing first on
This enables us to detect errors in coding and logic that are contained with the module
alone. The testing was carried out during programming stage itself.
In these testing procedures the project is given to the customer to test whether all requirements
have been fulfilled and after the user is fully satisfied. The project is perfectly ready. If the user
makes request for any change and if they found any errors those all errors must be taken into
INTEGRATION TESTING
Integration testing is a systematic technique for constructing the program structure. While
at the same time conducting tests to uncover errors associated with interfacing. The objective
is to take unit tested modules and build a program structure that has been dictated by design.
In this integration testing it done using the main module and based on the type of
integration testing the subordinate tables and other criteria along with their path, is replaced
one at a time with actual modules. In the project, after integrating the modules such as purchase
and sales, they are tested with their integration in purchase returns and sales return.
24
VALIDATION TESTING
It is said that validation is successful when the software functions in a systematic manner
that can be reasonably accepted by the customers. This type of testing is very important because
it is the only way to check whether the requirements given by user have been completely
fulfilled. The input given to various forms are validated effectively. The validated input is given
Implementation is the stage where the theoretical design is turned into a working system. The
most crucial stage in achieving a new successful system and in giving confidence on the new
system for the users that it will work efficiently and effectively. The system can be implemented
only after thorough testing is done and if it is found to work according to the specification. It
involves careful planning, investigation of the current system and its constraints on
implementation, design of methods to achieve the changeover and an evaluation of change over
methods apart from planning. Two major tasks of preparing the implementation are education
and training of the users and testing of the system. The more complex the system being
implemented, the more involved will be the systems analysis and design effort required just for
hardware and software acquisition is carried out. The system may require some software to be
developed. Implementation is the final and important phase. The new system has been
implemented successfully is found to be working in the perfect working order it has satisfied
the users and now the users have switched to the new system from the manual system.
25
CONCLUSION
26
6. CONCLUSION
hassle-free way. The entire examination process is simplified, and exams can be taken from
anywhere, anytime. The system is developed using Python, Django, CSS, HTML, and
JavaScript. The project contains an admin side from where a user can take and manage exams
easily. The admin plays an important role in the management of this system. The system also
The input design and output design of the system are essential to ensure the system's usability
and effectiveness. The input design should be intuitive, efficient, and user-friendly, while the
27
SCOPE FOR FUTURE ENHANCEMENT
28
7. SCOPE FOR FUTURE ENHANCEMENT
The Online Examination System has a wide range of applications in the education sector. It
can be used by schools, colleges, universities, and other educational institutions. Here are
some future scope and enhancements that can be made to the system:
1. Integration with Learning Management Systems (LMS): The system can be integrated
experience.
2. Gamification of Exams: The system can include gamification elements to make the
3. AI-based Monitoring: The system can use AI-based monitoring to prevent cheating
4. Integration with E-Learning Platforms: The system can be integrated with existing E-
5. Mobile Application: The system can be developed into a mobile application, making
29
BIBLIOGRPAHY
30
8.BIBLIOGRAPHY
Textbook Reference:
Website Reference:
• https://www.w3schools.com/mongodb/ •
https://www.mongodb.com/docs/
• https://docs.djangoproject.com/en/4.2/
• https://www.w3schools.com/html/
• https://www.w3schools.com/css/
• https://www.w3schools.com/js/
31
APPENDICES
32
9. Appendices
Screenshots
33
B) Sample Code
@login_required(login_url='faculty-login')
def view_exams_prof(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = ExamForm(prof_user)
if request.method == 'POST' and permissions:
form = ExamForm(prof_user,request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof
exam.save()
form.save_m2m()
return redirect('view_exams')
34
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/mainexam.html', {
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def add_question_paper(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = QPForm(prof_user)
if request.method == 'POST' and permissions:
form = QPForm(prof_user,request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof_user
exam.save()
form.save_m2m()
return redirect('faculty-add_question_paper')
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/addquestionpaper.html', {
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def add_questions(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = QForm()
if request.method == 'POST' and permissions:
form = QForm(request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof_user
exam.save()
form.save_m2m()
return redirect('faculty-addquestions')
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/addquestions.html', {
35
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def view_previousexams_prof(request):
prof = request.user
student = 0
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/previousexam.html', {
'exams': exams,'prof': prof
})
@login_required(login_url='login')
def student_view_previous(request):
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
list_un.append(exam)
return render(request,'exam/previousstudent.html',{
'exams':list_un,
'completed':list_of_completed
})
@login_required(login_url='faculty-login')
def view_students_prof(request):
students = User.objects.filter(groups__name = "Student")
student_name = []
student_completed = []
count = 0
dicts = {}
examn = Exam_Model.objects.filter(professor=request.user)
for student in students:
student_name.append(student.username)
count = 0
for exam in examn:
if StuExam_DB.objects.filter(student=student,examname=exam.name,completed=1).exists():
count += 1
else:
count += 0
student_completed.append(count)
i=0
for x in student_name:
dicts[x] = student_completed[i]
i+=1
36
return render(request, 'exam/viewstudents.html', {
'students':dicts
})
@login_required(login_url='faculty-login')
def view_results_prof(request):
students = User.objects.filter(groups__name = "Student")
dicts = {}
prof = request.user
professor = User.objects.get(username=prof.username)
examn = Exam_Model.objects.filter(professor=professor)
for exam in examn:
if StuExam_DB.objects.filter(examname=exam.name,completed=1).exists():
students_filter = StuExam_DB.objects.filter(examname=exam.name,completed=1)
for student in students_filter:
key = str(student.student) + " " + str(student.examname) + " " +
str(student.qpaper.qPaperTitle)
dicts[key] = student.score
return render(request, 'exam/resultsstudent.html', {
'students':dicts
})
@login_required(login_url='login')
def view_exams_student(request):
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
list_un.append(exam)
return render(request,'exam/mainexamstudent.html',{
'exams':list_un,
'completed':list_of_completed
})
@login_required(login_url='login')
def view_students_attendance(request):
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
list_un.append(exam)
return render(request,'exam/attendance.html',{
37
'exams':list_un,
'completed':list_of_completed
})
def convert(seconds):
min, sec = divmod(seconds, 60)
hour, min = divmod(min, 60)
min += hour*60
return "%02d:%02d" % (min, sec)
@login_required(login_url='login')
def appear_exam(request,id):
student = request.user
if request.method == 'GET':
exam = Exam_Model.objects.get(pk=id)
time_delta = exam.end_time - exam.start_time
time = convert(time_delta.seconds)
time = time.split(":")
mins = time[0]
secs = time[1]
context = {
"exam":exam,
"question_list":exam.question_paper.questions.all(),
"secs":secs,
"mins":mins
}
return render(request,'exam/giveExam.html',context)
if request.method == 'POST' :
student = User.objects.get(username=request.user.username)
paper = request.POST['paper']
examMain = Exam_Model.objects.get(name = paper)
stuExam = StuExam_DB.objects.get_or_create(examname=paper, student=student,qpaper =
examMain.question_paper)[0]
qPaper = examMain.question_paper
stuExam.qpaper = qPaper
qPaperQuestionsList = examMain.question_paper.questions.all()
for ques in qPaperQuestionsList:
student_question = Stu_Question(student=student,question=ques.question,
optionA=ques.optionA, optionB=ques.optionB,optionC=ques.optionC, optionD=ques.optionD,
answer=ques.answer)
student_question.save()
stuExam.questions.add(student_question)
stuExam.save()
stuExam.completed = 1
stuExam.save()
examQuestionsList =
StuExam_DB.objects.filter(student=request.user,examname=paper,qpaper=examMain.question_pap
er,questions__student = request.user)[0]
#examQuestionsList = stuExam.questions.all()
38
examScore = 0
list_i = examMain.question_paper.questions.all()
queslist = examQuestionsList.questions.all()
i=0
for j in range(list_i.count()):
ques = queslist[j]
max_m = list_i[i].max_marks
ans = request.POST.get(ques.question, False)
if not ans:
ans = "E"
ques.choice = ans
ques.save()
if ans.lower() == ques.answer.lower() or ans == ques.answer:
examScore = examScore + max_m
i+=1
stuExam.score = examScore
stuExam.save()
stu = StuExam_DB.objects.filter(student=request.user,examname=examMain.name)
results = StuResults_DB.objects.get_or_create(student=request.user)[0]
results.exams.add(stu[0])
results.save()
return redirect('view_exams_student')
@login_required(login_url='login')
def result(request,id):
student = request.user
exam = Exam_Model.objects.get(pk=id)
score =
StuExam_DB.objects.get(student=student,examname=exam.name,qpaper=exam.question_paper).sc
ore
return render(request,'exam/result.html',{'exam':exam,"score":score}
@login_required(login_url='login')
def index(request):
exists = StudentPreferenceModel.objects.filter(user=request.user).exists()
student_preference = None
if request.method == 'GET':
var = "On"
if exists:
var="Off"
student_preference = StudentPreferenceModel.objects.get(user=request.user)
39
if student_preference.sendEmailOnLogin == True:
var = "On"
return
render(request,'studentPreferences/pref.html',{'student_preference':student_preference,'email_pre
f_value':var})
if request.method == 'POST':
if exists:
student_preference = StudentPreferenceModel.objects.get(user=request.user)
var = "Off"
pref = request.POST['email_pref']
if exists:
student_preference.sendEmailOnLogin = pref
student_preference.save()
else:
var = "On"
StudentPreferenceModel.objects.create(user = request.user, sendEmailOnLogin=pref)
student_preference = StudentPreferenceModel.objects.filter(user=request.user)
if pref == 'True':
var = "On"
return
render(request,'studentPreferences/pref.html',{'student_preference':student_preference,'email_pre
f_value':var})
@login_required(login_url='login')
def change_password(request):
if request.method == 'POST':
form = PasswordChangeForm(request.user, request.POST)
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user)
messages.success(request, 'Your password was successfully updated!')
return redirect('login')
else:
messages.error(request, 'Please correct the error below.')
else:
form = PasswordChangeForm(request.user)
return render(request, 'studentPreferences/change_password.html', {
'form': form
})
@login_required(login_url='faculty-login')
def view_exams_prof(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = ExamForm(prof_user)
if request.method == 'POST' and permissions:
form = ExamForm(prof_user,request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof
exam.save()
form.save_m2m()
return redirect('view_exams')
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/mainexam.html', {
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def add_question_paper(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = QPForm(prof_user)
if request.method == 'POST' and permissions:
form = QPForm(prof_user,request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof_user
exam.save()
form.save_m2m()
return redirect('faculty-add_question_paper')
41
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/addquestionpaper.html', {
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def add_questions(request):
prof = request.user
prof_user = User.objects.get(username=prof)
permissions = False
if prof:
permissions = has_group(prof,"Professor")
if permissions:
new_Form = QForm()
if request.method == 'POST' and permissions:
form = QForm(request.POST)
if form.is_valid():
exam = form.save(commit=False)
exam.professor = prof_user
exam.save()
form.save_m2m()
return redirect('faculty-addquestions')
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/addquestions.html', {
'exams': exams, 'examform': new_Form, 'prof': prof,
})
else:
return redirect('view_exams_student')
@login_required(login_url='faculty-login')
def view_previousexams_prof(request):
prof = request.user
student = 0
exams = Exam_Model.objects.filter(professor=prof)
return render(request, 'exam/previousexam.html', {
'exams': exams,'prof': prof
})
@login_required(login_url='login')
def student_view_previous(request):
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
42
list_un.append(exam)
return render(request,'exam/previousstudent.html',{
'exams':list_un,
'completed':list_of_completed
})
@login_required(login_url='faculty-login')
def view_students_prof(request):
students = User.objects.filter(groups__name = "Student")
student_name = []
student_completed = []
count = 0
dicts = {}
examn = Exam_Model.objects.filter(professor=request.user)
for student in students:
student_name.append(student.username)
count = 0
for exam in examn:
if StuExam_DB.objects.filter(student=student,examname=exam.name,completed=1).exists():
count += 1
else:
count += 0
student_completed.append(count)
i=0
for x in student_name:
dicts[x] = student_completed[i]
i+=1
return render(request, 'exam/viewstudents.html', {
'students':dicts
})
@login_required(login_url='faculty-login')
def view_results_prof(request):
students = User.objects.filter(groups__name = "Student")
dicts = {}
prof = request.user
professor = User.objects.get(username=prof.username)
examn = Exam_Model.objects.filter(professor=professor)
for exam in examn:
if StuExam_DB.objects.filter(examname=exam.name,completed=1).exists():
students_filter = StuExam_DB.objects.filter(examname=exam.name,completed=1)
for student in students_filter:
key = str(student.student) + " " + str(student.examname) + " " +
str(student.qpaper.qPaperTitle)
dicts[key] = student.score
return render(request, 'exam/resultsstudent.html', {
'students':dicts
})
@login_required(login_url='login')
def view_exams_student(request):
43
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
list_un.append(exam)
return render(request,'exam/mainexamstudent.html',{
'exams':list_un,
'completed':list_of_completed
})
@login_required(login_url='login')
def view_students_attendance(request):
exams = Exam_Model.objects.all()
list_of_completed = []
list_un = []
for exam in exams:
if StuExam_DB.objects.filter(examname=exam.name ,student=request.user).exists():
if StuExam_DB.objects.get(examname=exam.name,student=request.user).completed == 1:
list_of_completed.append(exam)
else:
list_un.append(exam)
return render(request,'exam/attendance.html',{
'exams':list_un,
'completed':list_of_completed
})
def convert(seconds):
min, sec = divmod(seconds, 60)
hour, min = divmod(min, 60)
min += hour*60
return "%02d:%02d" % (min, sec)
@login_required(login_url='login')
def appear_exam(request,id):
student = request.user
if request.method == 'GET':
exam = Exam_Model.objects.get(pk=id)
time_delta = exam.end_time - exam.start_time
time = convert(time_delta.seconds)
time = time.split(":")
mins = time[0]
secs = time[1]
context = {
"exam":exam,
"question_list":exam.question_paper.questions.all(),
"secs":secs,
44
"mins":mins
}
return render(request,'exam/giveExam.html',context)
if request.method == 'POST' :
student = User.objects.get(username=request.user.username)
paper = request.POST['paper']
examMain = Exam_Model.objects.get(name = paper)
stuExam = StuExam_DB.objects.get_or_create(examname=paper, student=student,qpaper =
examMain.question_paper)[0]
qPaper = examMain.question_paper
stuExam.qpaper = qPaper
qPaperQuestionsList = examMain.question_paper.questions.all()
for ques in qPaperQuestionsList:
student_question = Stu_Question(student=student,question=ques.question,
optionA=ques.optionA, optionB=ques.optionB,optionC=ques.optionC, optionD=ques.optionD,
answer=ques.answer)
student_question.save()
stuExam.questions.add(student_question)
stuExam.save()
stuExam.completed = 1
stuExam.save()
examQuestionsList =
StuExam_DB.objects.filter(student=request.user,examname=paper,qpaper=examMain.question_pap
er,questions__student = request.user)[0]
#examQuestionsList = stuExam.questions.all()
examScore = 0
list_i = examMain.question_paper.questions.all()
queslist = examQuestionsList.questions.all()
i=0
for j in range(list_i.count()):
ques = queslist[j]
max_m = list_i[i].max_marks
ans = request.POST.get(ques.question, False)
if not ans:
ans = "E"
ques.choice = ans
ques.save()
if ans.lower() == ques.answer.lower() or ans == ques.answer:
examScore = examScore + max_m
i+=1
stuExam.score = examScore
stuExam.save()
stu = StuExam_DB.objects.filter(student=request.user,examname=examMain.name)
results = StuResults_DB.objects.get_or_create(student=request.user)[0]
results.exams.add(stu[0])
results.save()
return redirect('view_exams_student')
45
@login_required(login_url='login')
def result(request,id):
student = request.user
exam = Exam_Model.objects.get(pk=id)
score =
StuExam_DB.objects.get(student=student,examname=exam.name,qpaper=exam.question_paper).sc
ore
return render(request,'exam/result.html',{'exam':exam,"score":score})
@login_required(login_url='faculty-login')
def index(request):
return render(request,'faculty/index.html')
class Register(View):
def get(self,request):
faculty_form = FacultyForm()
faculty_info_form = FacultyInfoForm()
return
render(request,'faculty/register.html',{'faculty_form':faculty_form,'faculty_info_form':faculty_info_f
orm})
def post(self,request):
faculty_form = FacultyForm(data=request.POST)
faculty_info_form = FacultyInfoForm(data=request.POST)
email = request.POST['email']
domain = get_current_site(request).domain
email_subject = 'Activate your Exam Portal Faculty account'
46
email_body = "Hi. Please contact the admin team of "+domain+". To register yourself as a
professor."+ ".\n\n You are receiving this message because you registered on " + domain +". If you
didn't register please contact support team on " + domain
fromEmail = 'noreply@exam.com'
email = EmailMessage(
email_subject,
email_body,
fromEmail,
[email],
)
student_info = faculty_info_form.save(commit=False)
student_info.user = faculty
if 'picture' in request.FILES:
student_info.picture = request.FILES['picture']
student_info.save()
messages.success(request,"Registered Succesfully. Check Email for confirmation")
EmailThread(email).start()
return redirect('faculty-login')
else:
print(faculty_form.errors,faculty_info_form.errors)
return
render(request,'faculty/register.html',{'faculty_form':faculty_form,'faculty_info_form':faculty_info_f
orm})
class LoginView(View):
def get(self,request):
return render(request,'faculty/login.html')
def post(self,request):
username = request.POST['username']
password = request.POST['password']
has_grp = False
if username and password:
user = auth.authenticate(username=username,password=password)
exis = User.objects.filter(username=username).exists()
if exis:
user_ch = User.objects.get(username=username)
has_grp = has_group(user_ch,"Professor")
if user and user.is_active and exis and has_grp:
auth.login(request,user)
messages.success(request,"Welcome, "+ user.username + ". You are
now logged in.")
return redirect('faculty-index')
elif not has_grp and exis:
messages.error(request,'You dont have permssions to login as faculty.
If You think this is a mistake please contact admin')
return render(request,'faculty/login.html')
else:
messages.error(request,'Invalid credentials')
return render(request,'faculty/login.html')
47
messages.error(request,'Please fill all fields')
return render(request,'faculty/login.html')
class LogoutView(View):
def post(self,request):
auth.logout(request)
messages.success(request,'Logged Out')
return redirect('faculty-login')
48