<file_sep># Generated by Django 3.1.6 on 2021-09-05 13:47

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='course',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('code', models.CharField(max_length=10)),
                ('name', models.CharField(max_length=20)),
                ('course_student', models.JSONField()),
            ],
        ),
        migrations.CreateModel(
            name='teacher',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
        migrations.CreateModel(
            name='lecture',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('topic', models.CharField(max_length=20)),
                ('date', models.DateTimeField()),
                ('duration', models.DurationField()),
                ('attendance', models.JSONField()),
                ('lecturer', models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='teacher.teacher')),
                ('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='teacher.course')),
            ],
        ),
        migrations.AddField(
            model_name='course',
            name='course_teacher',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='teacher.teacher'),
        ),
    ]
<file_sep># Generated by Django 3.1.6 on 2021-09-05 17:15

from django.db import migrations, models


class Migration(migrations.Migration):

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

    operations = [
        migrations.RemoveField(
            model_name='lecture',
            name='duration',
        ),
        migrations.AlterField(
            model_name='lecture',
            name='attendance',
            field=models.JSONField(default=list),
        ),
    ]
<file_sep># Generated by Django 3.1.6 on 2021-09-05 15:06

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('student', '0002_auto_20210905_1917'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='student',
            name='rollno',
        ),
    ]
<file_sep>{% extends 'base.html' %}
{% load static %}
{% block title%} Portal {% endblock%}
{% block content%}

<div class="container-fluid">
          {% if lectures %}
          <div class="row">
            <div class="col-md-12">
              <div class="card">
                <div class="card-header card-header-primary">
                  <h4 class="card-title ">Lectures</h4>
                  <p class="card-category"></p>
                </div>
                <div class="card-body">
                  <div class="table-responsive">
                    <table class="table">
                      <thead class=" text-primary">
                        <th>
                          Topic
                        </th>
                        <th>
                          Subject
                        </th>
                        <th>
                          Date
                        </th>
                        <th>
                          Attendance
                        </th>
                      </thead>
                      <tbody>
                        {% for i in lectures %}
                        <tr>
                        <td>{{i.topic}}
                        </td>
                        <td>{{i.subject}}
                        </td>
                        <td>{{i.date}}
                        </td>
                        <td>
                        {% if i.approved is True %}Approved
                        {% else %}
                        <a href="{% url 'teacher:approve' i.topic %}" class="btn btn-primary btn-sm">Give approval
                        </a>
                        {% endif %}
                        </tr>
                      {% endfor %}  
                      </tbody>
                    </table>
                  </div>
                </div>
              </div>
            </div>
            
          </div>
          {% endif %}
         
    
</div>

{% endblock %}
<file_sep>
from django.contrib import admin
from django.urls import path
from . import views

app_name = 'teacher'

urlpatterns = [
    path('', views.TeacherPage.as_view(),name = 'TeacherPage'),
    path('Admin/', views.AdminPage.as_view(),name = 'AdminPage'),
   path('scheduleLec/', views.scheduleLec.as_view(),name = 'scheduleLec'),
   path('markAttend/<str:topic>/', views.markAttend.as_view(),name = 'markAttend'),
    path('attendance/<topic>/', views.attendance.as_view(),name = 'attendance'),
     path('approve/<topic>/', views.approve.as_view(),name = 'approve'),
]
<file_sep>from django.shortcuts import render,redirect
from django.views.generic.base import View
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import Group, User

# Create your views here.
class StudentPage(View):
    def get(self,request,template_name='studentpage.html'):
        return render(request,template_name)<file_sep># Attendance Portal
## User roles:
### Teacher
1. Schedule lecture
2. Mark Attendance
3. View Attendance
### Admin
1. Create course
2. Allocate teacher for the course
3. Enroll students in the course
4. Approve Attendance

Refer demo video file.
<file_sep>from django.db import models
from django.contrib.auth.models import User
from django.db.models.fields.related import ForeignKey
from django.db.models import OneToOneField
# Create your models here.
class student(models.Model):
    user: OneToOneField = models.OneToOneField(User, on_delete=models.CASCADE)
    

    def __str__(self):
        return self.user.first_name+" "+self.user.last_name<file_sep>from django.shortcuts import render,redirect
from django.views.generic.base import View
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import Group, User
from .models import course, lecture, teacher

# Create your views here.
class AdminPage(View):
    def get(self,request,template_name='adminpage.html'):
        message={}
        lectures = lecture.objects.all()
        message['lectures']=lectures
        return render(request,template_name,message)

class TeacherPage(View):
    def get(self,request,template_name='teacherpage.html'):
        message={}
        thisteacher = teacher.objects.filter(user = request.user)
        thisteacher = thisteacher[0]
        lectures = lecture.objects.filter(lecturer = thisteacher)
        message['lectures']=lectures
        return render(request,template_name,message)

class scheduleLec(View):
    def get(self,request,template_name='schedule_lec.html'):
        return render(request,template_name)

    def post(self,request,template_name='schedule_lec.html'):
        message={}
        topic = request.POST.get('topic')
        subject = request.POST.get('subject')
        Subject = course.objects.all().filter(code = subject)
        attendance = ["0"]
        date = request.POST.get('date')
        lecturer = teacher.objects.filter(user = request.user)
        try:
            lectureData = lecture(topic=topic,subject=Subject[0],date=date,lecturer=lecturer[0],attendance=attendance)
            lectureData.save()
            message['error']="Lecture scheduled."
        except: 
            message['error']="Something went wrong!"
        return render(request,template_name,message)

class markAttend(View):
    def get(self,request,topic,template_name="mark_attendance.html"):
        message={}
        Lecture = lecture.objects.filter(topic=topic)
        message['lecture']= Lecture[0]
        Course = Lecture[0].subject
        students = Course.course_student
        message['students']= students
        return render(request,template_name,message)

    def post(self,request,topic,template_name="mark_attendance.html"):
        attendance = request.POST.getlist('list')
        lecture.objects.filter(topic=topic).update(attendance=attendance)
        Lecture = lecture.objects.filter(topic=topic)
        print(Lecture)
        print(attendance)
        message={}
        message['lecture']=Lecture
        return render(request,template_name,message)

class attendance(View):

    def get(self,request,topic,template_name="attendance.html"):
        message={}
        Lecture = lecture.objects.filter(topic=topic)
        message['lecture']= Lecture[0]
        Course = Lecture[0].subject
        students = Course.course_student
        message['students']= students
        return render(request,template_name,message)

class approve(View):

    def get(self,request,topic,template_name="approve.html"):
        message={}
        Lecture = lecture.objects.filter(topic=topic)
        message['lecture']= Lecture[0]
        Course = Lecture[0].subject
        students = Course.course_student
        message['students']= students
        return render(request,template_name,message)

    def post(self,request,topic,template_name="approve.html"):
        lecture.objects.filter(topic=topic).update(approved=True)
        return redirect('teacher:AdminPage')<file_sep>from typing import DefaultDict
from django.db import models
from django.db.models import OneToOneField
from django.contrib.auth.models import User
from django.db.models.deletion import CASCADE, DO_NOTHING


# Create your models here.
class teacher(models.Model):
    user: OneToOneField = models.OneToOneField(User, on_delete=models.CASCADE)
    
    def __str__(self):
        return self.user.first_name+" "+self.user.last_name   

class course(models.Model):
    code = models.CharField(max_length=10)
    name = models.CharField(max_length=20)
    course_teacher = models.ForeignKey(teacher, on_delete=CASCADE)
    course_student = models.JSONField(default=list)
    def __str__(self):
        return self.name

class lecture(models.Model):
    topic = models.CharField(max_length=20)
    subject = models.ForeignKey(course, on_delete=CASCADE)
    date = models.DateTimeField()
    attendance = models.JSONField(default=list)
    lecturer = models.ForeignKey(teacher, on_delete=DO_NOTHING)
    approved = models.BooleanField(default=False)
    def __str__(self):
        return self.topic<file_sep>
from django.contrib import admin
from django.urls import path
from . import views

app_name = 'student'

urlpatterns = [
    path('', views.StudentPage.as_view(),name = 'StudentPage'),
   
]
<file_sep># Generated by Django 3.1.6 on 2021-09-05 21:36

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ('teacher', '0002_auto_20210905_2245'),
    ]

    operations = [
        migrations.AddField(
            model_name='lecture',
            name='approved',
            field=models.BooleanField(default=False),
        ),
        migrations.AlterField(
            model_name='course',
            name='course_student',
            field=models.JSONField(default=list),
        ),
    ]
<file_sep>from django.contrib import admin
from .models import course, lecture, teacher
# Register your models here.
admin.site.register(teacher)
admin.site.register(course)
admin.site.register(lecture)<file_sep>from django.shortcuts import render,redirect
from django.views.generic.base import View
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import Group, User

# Create your views here.
class landing(View):
    def get(self, request, template_name='landing.html'):
        return render(request, template_name)

class Login(View):
    def get(self, request, template_name='login.html'):
        return render(request,template_name)

    def post(self, request, template_name='login.html'):
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(username=username,password=<PASSWORD>)
        group = None
        if user is not None:
            if user.is_active:
                login(request, user)
                group = user.groups.all()[0].name
                if group == 'student_group':
                    return redirect('student:StudentPage')
                if group == 'teacher_group':
                    return redirect('teacher:TeacherPage')
                if group == 'admin_group':
                    return redirect('teacher:AdminPage')
                else:
                    return render(request, 'landing.html')
            else:
                return render(request, template_name, {'error_message': 'Your account has been disabled'})
        else:
            return render(request, template_name, {'error_message': 'Invalid Login'})



class Logout(View):
    def get(self, request,template_name="landing.html"):
        logout(request)
        return render(request, 'landing.html')
        