<repo_name>PrayagPanta/Grade-Automation-System<file_sep>/blog/templates/blog/complaint_teacher.html
{% extends "blog/base.html" %}
{% block content %}
  <h2 class="Info2 content-section">You have received following Complaints</h2>
  <br>
  <p class="Info content-section" style="height: 400px; overflow-y: scroll;">
   No Complaints at this moment
  </p>
{% endblock content %}
<file_sep>/course/views.py
from django.shortcuts import render,redirect
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
from django.contrib.auth.models import User
from django.views.generic import ListView,UpdateView
from .models import Marks,Subject,Teaches
from users.models import StudentInfo,TeacherInfo
from django.contrib.auth.decorators import login_required
from .forms import NameForm,AddForm,NameForm2,UpdateForm
import os
#from mlmodel import analyze
# Create your views here.

files = []
@login_required
def newRecord(request):
    if request.method == 'POST':
        form = NameForm(request.POST)
        if form.is_valid():
            SID = form.cleaned_data.get('SID')
            try:
                users = User.objects.get(id=SID)
                if( users.profile.role == 'T'):
                    return render(request,'course/courseDoesNotExist.html')
            except:
                return render(request,'course/courseDoesNotExist.html')
            return redirect(addMarks,SID)
        else:
            return render(request,'course/Error.html')
    else:
        if( request.user.profile.role == 'T'):
            form = NameForm()
            return render(request, 'course/newRecord.html', {'form': form})
        else:
            return render(request,'course/Error.html')

@login_required
def searchRecord(request):
    if request.method == 'POST':
        form = NameForm2(request.POST)
        if form.is_valid():
            sid =  form.cleaned_data.get('SID')
            qno = form.cleaned_data.get('Qno')
        try:
            users = User.objects.get(id=sid)
        except User.DoesNotExist:
            return render(request,'course/courseDoesNotExist.html')
        if( users.profile.role == 'T'):
            return render(request,'course/Error.html')
        return redirect(UpdateMarks,sid,qno,users)
    else:
        if( request.user.profile.role == 'T'):
            form = NameForm2()
            return render(request, 'course/searchRecord.html', {'form': form})
        else:
            return render(request,'course/Error.html')

@login_required
def addMarks(request,SID):
    if request.method == 'POST':
        form = AddForm(request.POST)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.Name = StudentInfo.objects.get(Sid=SID)
            obj.Checker = TeacherInfo.objects.get(Tid=request.user.id)
            obj.Subject = Teaches.objects.get(Name=obj.Checker).Subject
            obj.Question_No = form.cleaned_data.get('Qno')
            obj.save()
            # if else condition to check if there are unmarked questions present
            return render(request,'course/done.html')
        else:
            return render(request,'course/Error.html')
    elif request.method == 'GET':
        form = AddForm()
        Subject = Teaches.objects.get(Name=TeacherInfo.objects.get(Tid=request.user.id) ).Subject
        id = SID
        # if files is empty put each and every content of the directory in the file
        # else
        url = 'media/answersheet/'+str(id)+'/'+str(Subject)
        files = os.listdir(url)
        imgurl="/media/answersheet/"+str(id)+"/"+str(Subject)+"/1.jpg"
        # summary , marks, totalmarks = analyze(imgurl)
        return render(request, 'course/addMarks.html', {'form': form,'imgurl':imgurl,'files':files})
    else:
        pass
@login_required
def UpdateMarks(request,sid,qno,users):
    if request.method == 'GET':
        form = UpdateForm()
        marks = Marks.objects.filter(Question_No=qno,Subject=Teaches.objects.get(Name=TeacherInfo.objects.get(Tid=request.user.id) ).Subject,Name=sid).first()
        return render(request,'course/update.html',{'form': form ,'marks':marks.Marks})
    else:
        form = UpdateForm(request.POST)
        if form.is_valid():
            NewMarks =  form.cleaned_data.get('NewMarks')
            Marks.objects.filter(Question_No=qno,Subject=Teaches.objects.get(Name=TeacherInfo.objects.get(Tid=request.user.id) ).Subject,Name=sid).update(Marks=NewMarks)
            return render(request,'course/done2.html',{'NewMarks': NewMarks})
        else:
            return render(request,'course/Error.html')



#class PostCreateView(LoginRequiredMixin, CreateView):
#    model = Post
#    fields = ['title', 'content']

#    def form_valid(self, form):
#        form.instance.author = self.request.user
#        return super().form_valid(form)
<file_sep>/course/migrations/0004_auto_20200229_1754.py
# Generated by Django 3.0.1 on 2020-02-29 12:09

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('course', '0003_auto_20200229_1736'),
    ]

    operations = [
        migrations.RenameField(
            model_name='teaches',
            old_name='Subect',
            new_name='Subject',
        ),
    ]
<file_sep>/README.md
# Grade-Automation-System
To run project :
1) python manage.py runserver
2) Delete sqlite database 
3) python manage.py makemigrations 
4) python manage.py migrate
5) python manage.py createsuperuser ( also the teacher)
6) login as superuser to add students,subjects and other relevant details
<file_sep>/users/migrations/0002_auto_20200211_1915.py
# Generated by Django 3.0.1 on 2020-02-11 13:30

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('users', '0001_initial'),
        ('course', '0001_initial'),
    ]

    operations = [
        migrations.AddField(
            model_name='complaint',
            name='Subject',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='course.Subject'),
        ),
        migrations.AddField(
            model_name='complaint',
            name='Tid',
            field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='users.TeacherInfo'),
        ),
    ]
<file_sep>/blog/forms.py
from django import forms


class ComplaintForm(forms.Form):
    Subject = forms.CharField(max_length=100)
    Complaint = forms.CharField(label="Complaint", max_length=100)
    class Meta:
        fields = ['Subject','Complaint']
<file_sep>/users/models.py
from django.db import models
from django.contrib.auth.models import User



class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    image = models.ImageField(default='default.jpg', upload_to='profile_pics')
    roles = [
        ('S', 'Student'),
        ('T', 'Teacher'),
    ]
    role = models.CharField(
        max_length=1,
        choices=roles,
        default='S'
      )

    def __str__(self):
        return self.user.username
    def __unicode__(self):
        return self.user.username

class StudentInfo(models.Model):
    Sid = models.OneToOneField(Profile, primary_key=True,on_delete=models.CASCADE)
    Name = models.CharField(max_length=30)
    School = models.CharField(max_length=80)
    Exam_Center = models.CharField(max_length=80)

    def __str__(self):
        return self.Name


class TeacherInfo(models.Model):
    Tid = models.OneToOneField(Profile, primary_key=True,on_delete=models.CASCADE)
    Name = models.CharField(max_length=30)
    School = models.CharField(max_length=80)

    def __str__(self):
        return self.Name

class Complaint(models.Model):
    Sid = models.OneToOneField(StudentInfo, primary_key=True,on_delete=models.CASCADE)
    Tid = models.OneToOneField(TeacherInfo,on_delete=models.CASCADE)
    Subject = models.OneToOneField('course.Subject',on_delete=models.CASCADE)
    Complaint = models.CharField(max_length=500)
<file_sep>/course/admin.py
from django.contrib import admin
from .models import Subject,Enrolled,Teaches,Marks
# Register your models here.

admin.site.register(Subject)
admin.site.register(Enrolled)
admin.site.register(Teaches)
admin.site.register(Marks)
<file_sep>/course/templates/course/addMarks.html
{% extends "blog/base2.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block extra_head %}
    <link rel="stylesheet" type="text/css" href="{% static 'course/style.css' %}">
{% endblock %}
{% block side %}
<div class="cont">
  <div class="point"><h3>Estimated Marks  <br> 19/20 </h3> </div>
  <div class="keyword"><h4>Answer Keywords</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div>
</div>
<form method="POST">
    {% csrf_token %}
    <fieldset class="form-group conta">
        <center><legend class="keyword"><h4>Enter the marks for student</h4></legend></center>
          {{ form|crispy }}
    </fieldset>
    <div class="form-group">
        <button class="btn" type="submit">Next question</button>
    </div>
</form>
{% endblock side %}
{% block content %}
<div class="content-section">
    <form method="POST">
        {% csrf_token %}
        <fieldset class="form-group conta">
            <h3 class="border-bottom mb-4" > Answer 1</h3>
            <div class="summary"><h4>Summary of the Answer</h4><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.{{ files }}</p></div>
            <img src="{{ imgurl }}">
        </fieldset>
    </form>
</div>
{% endblock content %}
<file_sep>/course/models.py
from django.db import models


class Subject(models.Model):
    Name = models.CharField(max_length=100)
    Question_Paper = models.ImageField(default='default.jpg', upload_to='profile_pics')
    Number_Of_Questions = models.IntegerField(default=0)
    def __str__(self):
        return self.Name

class Enrolled(models.Model):
    Name = models.OneToOneField('users.StudentInfo',primary_key = True,on_delete=models.CASCADE)
    Subect =models.OneToOneField(Subject,on_delete=models.CASCADE)

    def __str__(self):
        return self.Name.Name

class Teaches(models.Model):
    Name = models.OneToOneField('users.TeacherInfo',primary_key = True,on_delete=models.CASCADE)
    Subject =models.OneToOneField(Subject,on_delete=models.CASCADE)

    def __str__(self):
        return self.Name.Name

class Marks(models.Model):
    Name = models.ForeignKey('users.StudentInfo',on_delete=models.CASCADE)
    Checker = models.ForeignKey('users.TeacherInfo',on_delete=models.CASCADE)
    Subject = models.ForeignKey(Subject,on_delete=models.CASCADE)
    Question_No = models.CharField(max_length=4)
    Marks = models.IntegerField()

    def __str__(self):
        return self.Name.Name
<file_sep>/course/urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('newRecord/', views.newRecord, name='new-Record'),
    path('searchRecord/', views.searchRecord, name='search-Record'),
    path('addMarks/<int:SID>/',views.addMarks,name='add-Marks'),
    path('searchRecord/UpdateMarks/<str:sid>/<str:qno>/<str:users>/',views.UpdateMarks,name='update-Marks'),
]
<file_sep>/users/admin.py
from django.contrib import admin
from .models import Profile,StudentInfo,TeacherInfo,Complaint
from django.contrib.auth.models import User


admin.site.register(Profile)
admin.site.register(StudentInfo)
admin.site.register(TeacherInfo)
admin.site.register(Complaint)
#admin.site.register(CorrectsAnsof)
<file_sep>/users/forms.py
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import UserCreationForm


class UserRegisterForm(UserCreationForm):
    email = forms.EmailField()
    role = forms.ChoiceField( choices=(('S','S') , ('T','T') ) )
    class Meta:
        model = User
        fields = ['username','email','role','<PASSWORD>1', '<PASSWORD>']

class PasswordForm(forms.Form):
    OldPassword = forms.CharField(label="Old Password", max_length=100)
    NewPassword = forms.CharField(label="New Password",max_length=100)
    NewPassword2 = forms.CharField(label="Re-type New Password",max_length=100)
    class Meta:
        fields = ['OldPassword','NewPassword','NewPassword2']
<file_sep>/blog/views.py
from django.shortcuts import render
from django.views.generic import ListView,DetailView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Post
from course.models import Enrolled
from django.contrib.auth.decorators import login_required
from .forms import ComplaintForm

@login_required
def home(request):
    if( request.user.profile.role == 'S'):
        return render(request, 'blog/student.html',{'title':'Home Page'})
    else:
        return render(request, 'blog/teacher.html',{'title':'Home Page'})

@login_required
def about(request):
    return render(request, 'blog/about.html', {'title': 'About'})

@login_required
def comp(request):
    return render(request,'blog/complaint_teacher.html')
@login_required
def compS(request):
    if request.method == 'GET':
        form = ComplaintForm()
        return render(request,'blog/complaint_student.html',{'form': form})
    else:
        return render(request,'blog/Noresults.html')

#class ViewEnrollment(ListView,LoginRequiredMixin):
    #model =  Enrolled
<file_sep>/course/migrations/0003_auto_20200229_1736.py
# Generated by Django 3.0.1 on 2020-02-29 11:51

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    dependencies = [
        ('users', '0002_auto_20200211_1915'),
        ('course', '0002_subject_number_of_questions'),
    ]

    operations = [
        migrations.AddField(
            model_name='marks',
            name='id',
            field=models.AutoField(auto_created=True, default=1, primary_key=True, serialize=False, verbose_name='ID'),
            preserve_default=False,
        ),
        migrations.AlterField(
            model_name='marks',
            name='Name',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.StudentInfo'),
        ),
    ]
<file_sep>/users/migrations/0001_initial.py
# Generated by Django 3.0.1 on 2020-02-11 13:30

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Profile',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('image', models.ImageField(default='default.jpg', upload_to='profile_pics')),
                ('role', models.CharField(choices=[('S', 'Student'), ('T', 'Teacher')], default='S', max_length=1)),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='StudentInfo',
            fields=[
                ('Sid', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.Profile')),
                ('Name', models.CharField(max_length=30)),
                ('School', models.CharField(max_length=80)),
                ('Exam_Center', models.CharField(max_length=80)),
            ],
        ),
        migrations.CreateModel(
            name='TeacherInfo',
            fields=[
                ('Tid', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.Profile')),
                ('Name', models.CharField(max_length=30)),
                ('School', models.CharField(max_length=80)),
            ],
        ),
        migrations.CreateModel(
            name='Complaint',
            fields=[
                ('Sid', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.StudentInfo')),
                ('Complaint', models.CharField(max_length=500)),
            ],
        ),
    ]
<file_sep>/course/templates/course/update.html
{% extends "blog/base2.html" %}
{% load static %}
{% load crispy_forms_tags %}
{% block extra_head %}
    <link rel="stylesheet" type="text/css" href="{% static 'course/style.css' %}">
{% endblock %}
{% block side %}
<div class="cont">
  <div class="point"><h3>Previous Marks  <br> {{ marks }} /20 </h3> </div>
  <div class="keyword"><h4>Answer Keywords</h4> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> </div>
</div>
<form method="POST">
    {% csrf_token %}
    <fieldset class="form-group conta">
        <center><legend class="keyword"><h4>Enter the marks for student</h4></legend></center>
          {{ form|crispy }}
    </fieldset>
    <div class="form-group">
        <button class="btn" type="submit">Update</button><!--https://stackoverflow.com/questions/25345392/how-to-add-url-parameters-to-django-template-url-tag-->
        <a class="btn" href="{% url 'search-Record' %}">Retain Previous</a>
    </div>
</form>
{% endblock side %}
{% block content %}
<div class="content-section">
    <form method="POST">
        {% csrf_token %}
        <fieldset class="form-group conta">
            <h3 class="border-bottom mb-4" > Answer 1</h3>
            <div class="summary"><h4>Summary of the Answer</h4><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p></div>
            <img src="/media/answersheet/answer.jpg">
        </fieldset>
    </form>
</div>
{% endblock content %}
<file_sep>/course/forms.py
from django import forms
from .models import Marks

class NameForm(forms.Form):
    SID = forms.CharField(label="Student's ID", max_length=100)

class NameForm2(forms.Form):
    SID = forms.CharField(label="Student's ID", max_length=100)
    Qno = forms.CharField(label="Question Number",max_length=4)

class UpdateForm(forms.Form):
    NewMarks = forms.IntegerField(label="Enter the Updated Mark")


class AddForm(forms.ModelForm):
    Qno = forms.CharField(label="Enter the question number for the answer",max_length=4)
    Marks = forms.IntegerField(label="Enter the Marks")

    class Meta:
        model = Marks
        fields = ['Qno', 'Marks']
<file_sep>/blog/urls.py
from django.urls import path
from . import views

urlpatterns = [
    path('', views.home, name='blog-home'),
    path('about/', views.about, name='blog-about'),
    path('complaints/',views.comp,name='comp'),
    path('compS/',views.compS,name='compS')
]
<file_sep>/course/migrations/0001_initial.py
# Generated by Django 3.0.1 on 2020-02-11 13:30

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('users', '0001_initial'),
    ]

    operations = [
        migrations.CreateModel(
            name='Subject',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('Name', models.CharField(max_length=100)),
                ('Question_Paper', models.ImageField(default='default.jpg', upload_to='profile_pics')),
            ],
        ),
        migrations.CreateModel(
            name='Teaches',
            fields=[
                ('Name', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.TeacherInfo')),
                ('Subect', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='course.Subject')),
            ],
        ),
        migrations.CreateModel(
            name='Marks',
            fields=[
                ('Name', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.StudentInfo')),
                ('Question_No', models.CharField(max_length=4)),
                ('Marks', models.IntegerField()),
                ('Checker', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='users.TeacherInfo')),
                ('Subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='course.Subject')),
            ],
        ),
        migrations.CreateModel(
            name='Enrolled',
            fields=[
                ('Name', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, primary_key=True, serialize=False, to='users.StudentInfo')),
                ('Subect', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='course.Subject')),
            ],
        ),
    ]
