git methods

This commit is contained in:
Raffu Khondaker 2020-06-07 10:44:57 -04:00
parent e2997a6652
commit a12185aa2e
28 changed files with 304 additions and 588 deletions

View File

@ -1,38 +0,0 @@
import subprocess
import os
#students
def initialize(repo, subject):
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output = process.communicate()
dirname = repo[repo.rindex('/')+1:repo.index(".git")]
os.rename(dirname, subject)
#print(output)
#Teachers
#make student repo by student id
def addStudent(stid, teacher):
os.mkdir(stid)
os.chdir(os.getcwd() + "/" + stid)
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
def addStudents(filename):
print(filename)
def addAsignment(name):
print(name)
def updateAssignment(name):
print(name)
def comment(filename, text):
print(text)
initialize("https://github.com/therealraffi/1579460.git", "Math1")

95
CLI/s-git.py Normal file
View File

@ -0,0 +1,95 @@
import subprocess
import os
import requests
#git clone student directory ==> <student-id>/classes/assignments
def initStudent(ion_user):
#check if git has already been initialized
if(os.path.exists(str(ion_user) +"/" + ".git")):
print("Already synced to: " + str(ion_user))
return
#get student repo from API
URL = "http://127.0.0.1:8000/students/" + ion_user + "/"
r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr'))
if(r.status_code == 200):
data = r.json()
repo = data['repo']
classes = data['classes']
print(data)
#git clone repo
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
# make classes directory
for c in classes:
cpath = str(ion_user) + "/" + c['name']
if(os.path.exists(cpath)):
print(cpath + " already exists...")
else:
os.mkdir(str(ion_user) + "/" + c['name'])
#make assignments directory
for a in c['assignments']:
path = str(ion_user) + "/" + c['name'] + "/" + a['name']
print(path)
if(os.path.exists("/" +path)):
print(path + " already exists...")
else:
os.mkdir(str(ion_user) + "/" + c['name'] + "/" + a['name'])
#push to remote repo
os.chdir(ion_user)
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
elif(r.status_code == 404):
print("Make new account!")
elif(r.status_code == 403):
print("Invalid username/password")
else:
print(r.status_code)
#Teachers
#make student repo by student id
def addStudent(stid, teacher):
os.mkdir(stid)
os.chdir(os.getcwd() + "/" + stid)
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
def addStudents(filename):
print(filename)
def addAsignment(name):
print(name)
def updateAssignment(name):
print(name)
def comment(filename, text):
print(text)
initStudent("2022rkhondak")
os.chdir("2022rkhondak")
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()
process = subprocess.Popen(['git', 'push', '-u', 'origin','master'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.wait()

67
CLI/t-git.py Normal file
View File

@ -0,0 +1,67 @@
import subprocess
import os
import requests
#git clone student directory ==> <student-id>/classes/assignments
def initTeacher(student_id):
#check if git has already been initialized
if(os.path.exists(str(student_id) +"/" + ".git")):
print("Already synced to: " + str(student_id))
return
#get student repo from API
URL = "http://127.0.0.1:8000/students/" + str(student_id) + "/"
r = requests.get(url = URL, auth=('student','_$YFE#34.9_37jr'))
data = r.json()
repo = data['repo']
classes = data['classes']
print(classes)
#git clone repo
process = subprocess.Popen(['git', 'clone', repo], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
#make classes directory
for c in classes:
cpath = str(student_id) + "/" + c['name']
if(os.path.exists(cpath)):
print(cpath + " already exists...")
else:
os.mkdir(str(student_id) + "/" + c['name'])
#make assignments directory
for a in c['assignments']:
path = str(student_id) + "/" + c['name'] + "/" + a['name']
print(path)
if(os.path.exists("/" +path)):
print(path + " already exists...")
else:
os.mkdir(str(student_id) + "/" + c['name'] + "/" + a['name'])
#Teachers
#make student repo by student id
def addStudent(stid, teacher):
os.mkdir(stid)
os.chdir(os.getcwd() + "/" + stid)
process = subprocess.Popen(['git', 'init'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'add', '.'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
process = subprocess.Popen(['git', 'commit', '-m', "First Commit"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
process.communicate()
def addStudents(filename):
print(filename)
def addAsignment(name):
print(name)
def updateAssignment(name):
print(name)
def comment(filename, text):
print(text)
initStudent(1579460)

View File

@ -1,38 +1,63 @@
from api.models import Assignment, Student, Classes, Teacher
from api.models import Assignment, Student, Classes, Teacher, DefFiles
from datetime import datetime
#students
raffu = Student(
first_name = "Raffu",
last_name = "Khondaker",
student_id = 1579460,
webmail = "2022rkhondak@tjhsst.edu",
grade = 10,
f1 = DefFiles(
name="instructions.txt"
)
raffu.save()
#teachers
ng = Teacher(
first_name = "Kim",
last_name = "Ng",
f1.save()
f2 = DefFiles(
name="instructions.txt"
)
ng.save()
chao = Teacher(
first_name = "Susie",
last_name = "Lebryk-Chao",
f2.save()
f3 = DefFiles(
name="sample.txt"
)
f3.save()
f4 = DefFiles(
name="rubric.txt"
)
f4.save()
chao.save()
a1 = Assignment.objects.get(pk=1)
a1.files.add(f1)
a1.save()
a2 = Assignment.objects.get(pk=2)
a2.files.add(f2)
a2.save()
a3 = Assignment.objects.get(pk=3)
a3.files.add(f3)
a3.files.add(f4)
a3.save()
####################################
from api.models import Assignment, Student, Classes, Teacher, DefFiles
from datetime import datetime
f1 = DefFiles(
name="instructions.txt"
)
f1.save()
f2 = DefFiles(
name="instructions.txt"
)
f2.save()
f3 = DefFiles(
name="sample.txt"
)
f3.save()
f4 = DefFiles(
name="rubric.txt"
)
f4.save()
#Assignments
A1 = Assignment(
name='Week1_HW',
due_date=datetime.now(),
)
A1.save()
A1.files.add(f1)
A1.save()
A2 = Assignment(
name='Week2_HW',
@ -40,55 +65,16 @@ A2 = Assignment(
)
A2.save()
A2.files.add(f2)
A2.save()
A3 = Assignment(
name='Journal1',
due_date=datetime.now(),
)
A3.save()
#classes
C1 = Classes(
name='Math5',
)
C1.save()
C2 = Classes(
name='English',
)
C2.save()
C2.teachers = chao
C2.students.add(raffu)
C2.save()
C1.teachers = ng
C1.students.add(raffu)
C1.save()
################################################################################################################
from api.models import Assignment, Student, Classes, Teacher
from datetime import datetime
A1 = Assignment(
name='Week1_HW',
due_date=datetime.now(),
)
A1.save()
A2 = Assignment(
name='Week2_HW',
due_date=datetime.now(),
)
A2.save()
A3 = Assignment(
name='Journal1',
due_date=datetime.now(),
)
A3.files.add(f3)
A3.files.add(f4)
A3.save()
#classes
@ -113,8 +99,10 @@ raffu = Student(
first_name = "Raffu",
last_name = "Khondaker",
student_id = 1579460,
ion_user="2022rkhondak",
webmail = "2022rkhondak@tjhsst.edu",
grade = 10,
repo="https://github.com/therealraffi/2022rkhondak.git",
)
raffu.save()
raffu.classes.add(math)
@ -123,16 +111,18 @@ raffu.save()
#teachers
ng = Teacher(
first_name = "Kim",
last_name = "Ng",
first_name = "Errin",
last_name = "Harris",
ion_user="eharris1"
)
ng.save()
ng.classes.add(math)
ng.save()
chao = Teacher(
first_name = "Susie",
last_name = "Lebryk-Chao",
first_name = "Abagail",
last_name = "Bailey",
ion_user="AKBailey"
)
chao.save()
chao.classes.add(english)

View File

@ -1,7 +1,6 @@
# Generated by Django 3.0.7 on 2020-06-06 17:44
# Generated by Django 3.0.7 on 2020-06-07 07:45
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
@ -12,50 +11,58 @@ class Migration(migrations.Migration):
]
operations = [
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('due_date', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Classes',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField()),
('name', models.CharField(max_length=100)),
('assignments', models.ManyToManyField(default='', to='api.Assignment')),
],
),
migrations.CreateModel(
name='DefFiles',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Teacher',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField()),
('created', models.DateTimeField(auto_now_add=True)),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
('git', models.URLField(default='')),
('classes', models.ManyToManyField(default='', to='api.Classes')),
],
),
migrations.CreateModel(
name='Student',
fields=[
('url', models.URLField()),
('created', models.DateTimeField(auto_now_add=True)),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('student_id', models.IntegerField(primary_key=True, serialize=False)),
('student_id', models.IntegerField()),
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
('webmail', models.EmailField(blank=True, max_length=254)),
('grade', models.IntegerField()),
('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')),
('git', models.URLField()),
('repo', models.URLField(default='')),
('classes', models.ManyToManyField(default='', to='api.Classes')),
],
),
migrations.AddField(
model_name='classes',
name='teachers',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'),
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('url', models.URLField()),
('name', models.CharField(max_length=100)),
('due_date', models.DateTimeField()),
('classes', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Classes')),
('students', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api.Student')),
],
model_name='assignment',
name='files',
field=models.ManyToManyField(default='instructions.txt', to='api.DefFiles'),
),
]

View File

@ -1,24 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='classes',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
migrations.AlterField(
model_name='assignment',
name='students',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-06-07 07:51
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='files',
field=models.ManyToManyField(to='api.DefFiles'),
),
]

View File

@ -1,26 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:17
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0002_auto_20200606_1810'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='classes',
field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
preserve_default=False,
),
migrations.AlterField(
model_name='assignment',
name='students',
field=models.ForeignKey(blank=True, default='', on_delete=django.db.models.deletion.CASCADE, to='api.Student'),
preserve_default=False,
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0003_auto_20200606_1817'),
]
operations = [
migrations.AddField(
model_name='student',
name='webmail',
field=models.EmailField(blank=True, max_length=254),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0004_student_webmail'),
]
operations = [
migrations.AlterField(
model_name='student',
name='classes',
field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
]

View File

@ -1,24 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0005_auto_20200606_1822'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='classes',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
migrations.AlterField(
model_name='assignment',
name='students',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'),
),
]

View File

@ -1,21 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0006_auto_20200606_1824'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='classes',
),
migrations.RemoveField(
model_name='assignment',
name='students',
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:39
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0007_auto_20200606_1825'),
]
operations = [
migrations.AlterField(
model_name='classes',
name='teachers',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'),
),
]

View File

@ -1,28 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 18:59
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0008_auto_20200606_1839'),
]
operations = [
migrations.RemoveField(
model_name='classes',
name='teachers',
),
migrations.AddField(
model_name='student',
name='assignments',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'),
),
migrations.AlterField(
model_name='student',
name='classes',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
]

View File

@ -1,40 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 19:10
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0009_auto_20200606_1859'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='url',
),
migrations.RemoveField(
model_name='classes',
name='url',
),
migrations.RemoveField(
model_name='student',
name='url',
),
migrations.RemoveField(
model_name='teacher',
name='url',
),
migrations.AddField(
model_name='teacher',
name='classes',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
migrations.AddField(
model_name='teacher',
name='students',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 19:16
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0010_auto_20200606_1910'),
]
operations = [
migrations.AddField(
model_name='classes',
name='assignments',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'),
),
]

View File

@ -1,17 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 19:47
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('api', '0011_classes_assignments'),
]
operations = [
migrations.RemoveField(
model_name='student',
name='assignments',
),
]

View File

@ -1,27 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 20:04
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0012_remove_student_assignments'),
]
operations = [
migrations.RemoveField(
model_name='classes',
name='assignments',
),
migrations.RemoveField(
model_name='teacher',
name='students',
),
migrations.AddField(
model_name='assignment',
name='classes',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Classes'),
),
]

View File

@ -1,32 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 20:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0013_auto_20200606_2004'),
]
operations = [
migrations.RemoveField(
model_name='student',
name='classes',
),
migrations.RemoveField(
model_name='teacher',
name='classes',
),
migrations.AddField(
model_name='classes',
name='students',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Student'),
),
migrations.AddField(
model_name='classes',
name='teachers',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'),
),
]

View File

@ -1,32 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 20:23
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0014_auto_20200606_2005'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='classes',
),
migrations.RemoveField(
model_name='classes',
name='teachers',
),
migrations.AddField(
model_name='assignment',
name='students',
field=models.ManyToManyField(default='', through='api.Classes', to='api.Student'),
),
migrations.AddField(
model_name='classes',
name='assignments',
field=models.ForeignKey(default='', on_delete=django.db.models.deletion.CASCADE, to='api.Assignment'),
),
]

View File

@ -1,19 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 20:24
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('api', '0015_auto_20200606_2023'),
]
operations = [
migrations.AddField(
model_name='classes',
name='teachers',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api.Teacher'),
),
]

View File

@ -1,35 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 21:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0016_classes_teachers'),
]
operations = [
migrations.RemoveField(
model_name='assignment',
name='students',
),
migrations.RemoveField(
model_name='classes',
name='assignments',
),
migrations.AddField(
model_name='classes',
name='assignments',
field=models.ManyToManyField(default='', to='api.Assignment'),
),
migrations.RemoveField(
model_name='classes',
name='students',
),
migrations.AddField(
model_name='classes',
name='students',
field=models.ManyToManyField(null=True, to='api.Student'),
),
]

View File

@ -1,18 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 21:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0017_auto_20200606_2101'),
]
operations = [
migrations.AlterField(
model_name='classes',
name='students',
field=models.ManyToManyField(default='', to='api.Student'),
),
]

View File

@ -1,31 +0,0 @@
# Generated by Django 3.0.7 on 2020-06-06 21:26
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0018_auto_20200606_2107'),
]
operations = [
migrations.RemoveField(
model_name='classes',
name='students',
),
migrations.RemoveField(
model_name='classes',
name='teachers',
),
migrations.AddField(
model_name='student',
name='classes',
field=models.ManyToManyField(default='', to='api.Classes'),
),
migrations.AddField(
model_name='teacher',
name='classes',
field=models.ManyToManyField(default='', to='api.Classes'),
),
]

View File

@ -1,8 +1,12 @@
from django.db import models
class DefFiles(models.Model):
name=models.CharField(max_length=100)
class Assignment(models.Model):
name=models.CharField(max_length=100)
due_date=models.DateTimeField()
files = models.ManyToManyField(DefFiles, default="")
def __str__(self):
return '%s' % (self.name)
@ -17,15 +21,21 @@ class Teacher(models.Model):
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
classes = models.ManyToManyField(Classes, default="")
ion_user=models.CharField(primary_key=True, max_length=100)
git = models.URLField(default="")
class Student(models.Model):
created = models.DateTimeField(auto_now_add=True)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
student_id = models.IntegerField(primary_key=True)
student_id = models.IntegerField()
ion_user=models.CharField(primary_key=True, max_length=100)
webmail = models.EmailField(blank=True)
grade = models.IntegerField()
git = models.URLField()
classes = models.ManyToManyField(Classes, default="")
repo = models.URLField(default="")
def save(self, *args, **kwargs):
return super(Student, self).save(*args, **kwargs)

View File

@ -1,12 +1,19 @@
from django.contrib.auth.models import User, Group
from .models import Student, Teacher, Classes, Assignment
from .models import Student, Teacher, Classes, Assignment, DefFiles
from rest_framework import serializers, permissions
class DefFilesSerializer(serializers.HyperlinkedModelSerializer):
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
class Meta:
model = DefFiles
fields = ['name']
class AssignmentSerializer(serializers.HyperlinkedModelSerializer):
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
files = DefFilesSerializer(many=True, read_only=True,allow_null=True)
class Meta:
model = Assignment
fields = ['name', 'due_date', 'url']
fields = ['name', 'due_date', 'url', 'files']
class ClassesSerializer(serializers.HyperlinkedModelSerializer):
assignments = AssignmentSerializer(many=True, read_only=True,allow_null=True)
@ -18,12 +25,12 @@ class StudentSerializer(serializers.HyperlinkedModelSerializer):
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
class Meta:
model = Student
fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes']
fields = ['url', 'first_name', 'last_name', 'grade','webmail','student_id','classes', 'git','repo','ion_user']
class TeacherSerializer(serializers.ModelSerializer):
classes = ClassesSerializer(many=True, read_only=True,allow_null=True)
class Meta:
model = Teacher
fields = ['url', 'first_name', 'last_name', 'classes']
fields = ['url', 'first_name', 'last_name', 'classes','git','ion_user']

View File

@ -1,5 +1,5 @@
from .models import Student, Teacher, Classes, Assignment
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer
from .models import Student, Teacher, Classes, Assignment, DefFiles
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, DefFilesSerializer
from rest_framework import generics, viewsets, permissions
class StudentViewSet(viewsets.ModelViewSet):
@ -33,7 +33,14 @@ class AssignmentViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
permissions_classes = [permissions.IsAdminUser]
queryset = Assignment.objects.all()
serializer_class = AssignmentSerializer
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
class DefFilesViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
"""
queryset = DefFiles.objects.all()
serializer_class = DefFilesSerializer
permissions_classes = [permissions.IsAuthenticatedOrReadOnly]

View File

@ -9,6 +9,8 @@ router.register(r'students', views.StudentViewSet)
router.register(r'teachers', views.TeacherViewSet)
router.register(r'assignments', views.AssignmentViewSet)
router.register(r'classes', views.ClassesViewSet)
router.register(r'files', views.DefFilesViewSet)
# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.