Commit 6409bf74 authored by LiniEisha's avatar LiniEisha

IT17098960 is committing from IT17100908 user's branch.

parent f55f532c
from django.contrib import admin
from .models import Student, Attendance
admin.site.register(Student)
admin.site.register(Attendance)
# Register your models here.
from django.http import HttpResponse, JsonResponse
from django.views.decorators.csrf import csrf_exempt
from rest_framework.parsers import JSONParser
from .models import Student, Subject, Attendance
from .serializers import StudentSerializer, SubjectSerializer, AttendanceSerializer, FileSerializer
from rest_framework.decorators import api_view
from rest_framework.response import Response
from rest_framework import status
from rest_framework.views import APIView
from rest_framework.parsers import MultiPartParser, FormParser
from rest_framework.views import *
class StudentAPIView(APIView):
def get(self, request):
students = Student.objects.all()
serializer = StudentSerializer(students, many=True)
return Response(serializer.data)
def post(self, request):
serializer = StudentSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class StudentDetails(APIView):
def get_object(self, pk):
try:
return Student.objects.get(studentId=pk)
except Student.DoesNotExist:
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
def get(self, request, pk):
student = self.get_object(pk)
serializer = StudentSerializer(student)
return Response(serializer.data)
def put(self, request, pk):
student = self.get_object(pk)
serializer = StudentSerializer(student, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def delete(self, request, pk):
student = self.get_object(pk)
student.delete(student)
return HttpResponse(status=status.HTTP_204_NO_CONTENT)
@api_view(['GET', 'POST'])
def student_list(request):
if request.method == 'GET':
students = Student.objects.all()
serializer = StudentSerializer(students, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = StudentSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@api_view(['GEt', 'PUT', 'DELETE'])
def student_detail(request, pk):
try:
student = Student.objects.get(studentId=pk)
except Student.DoesNotExist:
return HttpResponse(status=status.HTTP_404_NOT_FOUND)
if request.method == 'GET':
serializer = StudentSerializer(student)
return Response(serializer.data)
elif request.method == 'PUT':
serializer = StudentSerializer(student, data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'DELETE':
student.delete()
return HttpResponse(status=status.HTTP_204_NO_CONTENT)
@api_view(['GET', 'POST'])
def subject_list(request):
if request.method == 'GET':
subjects = Subject.objects.all()
serializer = SubjectSerializer(subjects, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = SubjectSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
@csrf_exempt
def subject_detail (request, pk):
try:
subject = Subject.objects.get(subjectId=pk)
except subject.DoesNotExist:
return HttpResponse(status=404)
if request.method == 'GET':
serializer = SubjectSerializer(subject)
return JsonResponse(serializer.data)
elif request.method == 'PUT':
data = JSONParser().parse(request)
serializer = SubjectSerializer(subject, data=data)
if serializer.is_valid():
serializer.save()
return JsonResponse(serializer.data)
return JsonResponse(serializer.errors, status=400)
elif request.method == 'DELETE':
subject.delete()
return HttpResponse(status=204)
@api_view(['GET', 'POST'])
def attendance_list(request):
if request.method == 'GET':
attendance = Attendance.objects.all()
serializer = AttendanceSerializer(attendance, many=True)
return Response(serializer.data)
elif request.method == 'POST':
serializer = AttendanceSerializer(data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_201_CREATED)
return JsonResponse(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
class FileView(APIView):
# parser_classes = (MultiPartParser, FormParser)
def post(self, request, *args, **kwargs):
file_serializer = FileSerializer(data=request.data)
if file_serializer.is_valid():
file_serializer.save()
return Response(file_serializer.data, status=status.HTTP_201_CREATED)
else:
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
# Generated by Django 2.2.12 on 2020-09-23 11:08
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('FirstApp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='File',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('file', models.FileField(upload_to='')),
('remark', models.CharField(max_length=20)),
('timestamp', models.DateTimeField(auto_now_add=True)),
],
),
migrations.CreateModel(
name='Student',
fields=[
('studentId', models.CharField(max_length=10, primary_key=True, serialize=False)),
('studentFirstName', models.CharField(max_length=100)),
('studentLastName', models.CharField(max_length=100)),
('password', models.CharField(max_length=100)),
('year', models.CharField(max_length=100)),
('semester', models.CharField(max_length=100)),
('batch', models.CharField(max_length=100)),
('faculty', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Lecture',
fields=[
('lectureID', models.CharField(max_length=10, primary_key=True, serialize=False)),
('startTime', models.DateField()),
('endTime', models.DateField()),
('day', models.CharField(max_length=20)),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='FirstApp.Subject')),
],
),
migrations.CreateModel(
name='Attendance',
fields=[
('attendanceID', models.CharField(max_length=10, primary_key=True, serialize=False)),
('date', models.DateField()),
('attendance', models.BooleanField()),
('feedback', models.CharField(blank=True, max_length=50, null=True)),
('student', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='AttendanceApp.Student')),
('subject', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='FirstApp.Subject')),
],
),
]
# from django.db import models
from djongo import models
from FirstApp.MongoModels import Subject
class Student(models.Model):
studentId = models.CharField(primary_key=True, max_length=10)
studentFirstName = models.CharField(max_length=100)
studentLastName = models.CharField(max_length=100)
password = models.CharField(max_length=100)
year = models.CharField(max_length=100)
semester = models.CharField(max_length=100)
batch = models.CharField(max_length=100)
faculty = models.CharField(max_length=100)
def __str__(self):
return self.studentId
# class Subject(models.Model):
# subjectId = models.CharField(primary_key=True, max_length=10)
# subjectName = models.CharField(max_length=100)
# LecturerInCharge = models.CharField(max_length=100)
#
# def __str__(self):
# return self.subjectId
class Attendance(models.Model):
attendanceID = models.CharField(primary_key=True, max_length=10)
student = models.ForeignKey(Student, on_delete=models.CASCADE)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
date = models.DateField()
attendance = models.BooleanField()
feedback = models.CharField(max_length=50, null=True, blank=True)
def __str__(self):
return self.attendanceID
class File(models.Model):
file = models.FileField(blank=False, null=False)
remark = models.CharField(max_length=20)
timestamp = models.DateTimeField(auto_now_add=True)
class Lecture(models.Model):
lectureID = models.CharField(primary_key=True, max_length=10)
subject = models.ForeignKey(Subject, on_delete=models.CASCADE)
startTime = models.DateField()
endTime = models.DateField()
day = models.CharField(max_length=20)
from django.db import models
# Create your models here.
from rest_framework import serializers
from FirstApp.serializers import SubjectSerializer
from .models import Student, Subject, Attendance, File
class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = '__all__'
#
# class SubjectSerializer(serializers.ModelSerializer):
# class Meta:
# model = Subject
# fields = '__all__'
class AttendanceSerializer(serializers.ModelSerializer):
subject = SubjectSerializer()
class Meta:
model = Attendance
fields = '__all__'
class FileSerializer(serializers.ModelSerializer):
class Meta():
model = File
fields = ('file', 'remark', 'timestamp')
from django.urls import path, re_path, include
from django.urls import path
from .api import student_list, student_detail, subject_list, subject_detail, attendance_list, StudentAPIView, StudentDetails
from django.conf.urls import url
from . import views
from .api import FileView
urlpatterns = [
path('', views.first)
path('students/', student_list),
path('students/<str:pk>', student_detail),
path('subjects/', subject_list),
path('subjects/<str:pk>', subject_detail),
path('attendance/', attendance_list),
path('student/', StudentAPIView.as_view()),
# class based
path('student/', StudentAPIView.as_view()),
path('student/<str:pk>', StudentDetails.as_view()),
url(r'^upload/$', FileView.as_view(), name='file-upload')
]
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def first(request):
return HttpResponse('<h1>Hello Attendance App</h1>')
# Generated by Django 2.2.12 on 2020-09-22 18:21
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('FirstApp', '0001_initial'),
('LectureSummarizingApp', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='LectureAudioNoiseRemoved',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('lecture_audio_id', models.CharField(max_length=10)),
('lecturer_date', models.DateField()),
('lecture_audio_name', models.CharField(max_length=50)),
('lecture_audio_length', models.DurationField()),
('lecturer', models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='FirstApp.Lecturer')),
('subject', models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='FirstApp.Subject')),
],
),
]
# Generated by Django 2.2.12 on 2020-09-22 18:32
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('LectureSummarizingApp', '0002_lectureaudionoiseremoved'),
]
operations = [
migrations.RenameField(
model_name='lectureaudionoiseremoved',
old_name='lecture_audio_id',
new_name='lecture_audio_noise_removed_id',
),
]
# Generated by Django 2.2.12 on 2020-09-23 04:34
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('LectureSummarizingApp', '0003_auto_20200923_0002'),
]
operations = [
migrations.RemoveField(
model_name='lectureaudionoiseremoved',
name='lecturer',
),
migrations.RemoveField(
model_name='lectureaudionoiseremoved',
name='subject',
),
migrations.AddField(
model_name='lectureaudionoiseremoved',
name='lecture_audio_id',
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.CASCADE, to='LectureSummarizingApp.LectureAudio'),
),
migrations.CreateModel(
name='LectureSpeechToText',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('lecture_speech_to_text_id', models.CharField(max_length=10)),
('audio_original_text', models.TextField()),
('lecture_audio_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='LectureSummarizingApp.LectureAudio')),
],
),
migrations.CreateModel(
name='LectureNotices',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('lecture_notice_id', models.CharField(max_length=10)),
('notice_text', models.TextField()),
('lecture_audio_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='LectureSummarizingApp.LectureAudio')),
],
),
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment