mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Merge branch 'development' of https://github.com/Rushilwiz/SkoolOS into development
This commit is contained in:
commit
2315f4ff48
|
@ -1,56 +1,102 @@
|
|||
import os
|
||||
import sys
|
||||
import signal
|
||||
import time
|
||||
import event_processor
|
||||
import sys
|
||||
import os
|
||||
import pyinotify
|
||||
|
||||
|
||||
class SkoolOSDaemon:
|
||||
"""Constructor"""
|
||||
def __init__(self, work_dir='/tmp'):
|
||||
self.work_dir = work_dir
|
||||
self.start_time = None
|
||||
self.end_time = None
|
||||
self.log_file = None
|
||||
def __write_pid_file(self):
|
||||
try:
|
||||
dirName = "/tmp/skooloslogs"
|
||||
# Create log Directory
|
||||
os.mkdir(dirName)
|
||||
except FileExistsError:
|
||||
pass
|
||||
pid = str(os.getpid())
|
||||
file_ = open('/tmp/skoolosdaemonpid', 'w')
|
||||
file_.write(pid)
|
||||
file_.close()
|
||||
def readable_time(self, input_time):
|
||||
return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time))
|
||||
def start(self):
|
||||
self.__write_pid_file()
|
||||
self.start_time = time.time()
|
||||
self.log_file = open('/tmp/skooloslogs/' + str(self.start_time), 'w')
|
||||
self.log_file.write("Start time: \n" + self.readable_time(self.start_time) + "\n\n")
|
||||
sys.stdout = self.log_file
|
||||
event_processor.watch_dir(self.work_dir)
|
||||
def stop(self):
|
||||
event_processor.stop_watching()
|
||||
self.end_time = time.time()
|
||||
self.log_file.write("Stop time: \n" + self.readable_time(self.end_time))
|
||||
self.log_file.write("Total work time: " +
|
||||
time.strftime("%H:%M:%S", time.gmtime(self.end_time - self.start_time)))
|
||||
class EventHandler(pyinotify.ProcessEvent):
|
||||
_methods = [
|
||||
"IN_CREATE",
|
||||
"IN_CLOSE_WRITE",
|
||||
"IN_DELETE",
|
||||
"IN_MOVED_TO",
|
||||
"IN_MOVED_FROM",
|
||||
"IN_OPEN",
|
||||
]
|
||||
|
||||
def process_IN_CREATE(self, event):
|
||||
description = \
|
||||
"Event: Created file\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
def process_IN_CLOSE_WRITE(self, event):
|
||||
description = \
|
||||
"Event: Wrote to a file\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
def process_IN_DELETE(self, event):
|
||||
description = \
|
||||
"Event: Deleted file\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
def process_IN_MOVED_TO(self, event):
|
||||
description = \
|
||||
"Event: Moved a file in\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
def process_IN_MOVED_FROM(self, event):
|
||||
description = \
|
||||
"Event: Moved a file out\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
def process_IN_OPEN(self, event):
|
||||
description = \
|
||||
"Event: Opened file\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
print(description)
|
||||
|
||||
|
||||
logger = None
|
||||
|
||||
def Main():
|
||||
def signal_handler(signum, frame):
|
||||
logger.stop()
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
# signal.signal(signal.SIGTERM, signal_handler)
|
||||
global logger
|
||||
logger = SkoolOSDaemon("/tmp")
|
||||
logger.start()
|
||||
NOTIFIER = None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
Main()
|
||||
def watch_dir(watched_dir="/tmp", logdir="/tmp/skooloslogs"):
|
||||
if not os.path.exists(logdir):
|
||||
os.makedirs(logdir)
|
||||
logfile = open(
|
||||
logdir + "skoolos_" + time.strftime("%m%d%Y-%H%M%S", time.localtime()),
|
||||
'w')
|
||||
sys.stdout = logfile
|
||||
print("Start time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n\n")
|
||||
global NOTIFIER
|
||||
wm = pyinotify.WatchManager()
|
||||
mask = pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE | \
|
||||
pyinotify.IN_MOVED_TO | pyinotify.IN_MOVED_FROM | pyinotify.IN_OPEN
|
||||
NOTIFIER = pyinotify.ThreadedNotifier(wm, EventHandler())
|
||||
NOTIFIER.start()
|
||||
wm.add_watch(watched_dir, mask, rec=True)
|
||||
|
||||
|
||||
def stop_watching():
|
||||
NOTIFIER.stop()
|
||||
print("End time: " +
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime()) + "\n\n")
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
import time
|
||||
import pyinotify
|
||||
|
||||
|
||||
def readable_time(input_time):
|
||||
return time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime(input_time))
|
||||
|
||||
|
||||
class EventProcessor(pyinotify.ProcessEvent):
|
||||
_methods = ["IN_OPEN",
|
||||
"IN_CREATE",
|
||||
"IN_CLOSE_WRITE",
|
||||
"IN_DELETE",
|
||||
"IN_MOVED_TO",
|
||||
"IN_MOVED_FROM",
|
||||
]
|
||||
|
||||
|
||||
def __method_format(method):
|
||||
return {
|
||||
"IN_OPEN":"Opened a file",
|
||||
"IN_CREATE":"Created a file",
|
||||
"IN_CLOSE_WRITE":"Wrote to a file",
|
||||
"IN_DELETE":"Deleted a file",
|
||||
"IN_MOVED_TO":"Moved a file or directory in from elsewhere",
|
||||
"IN_MOVED_FROM":"Moved a file or directory elsewhere",
|
||||
}.get(method, "Unknown event")
|
||||
|
||||
|
||||
def __process_generator(cls, method):
|
||||
def _method_name(self, event):
|
||||
description = "Event description: {}\n" \
|
||||
"Path name: {}\n" \
|
||||
"Event Name: {}\n" \
|
||||
"Timestamp: {}\n".format(__method_format(method),
|
||||
event.pathname,
|
||||
event.maskname,
|
||||
readable_time(time.time())
|
||||
)
|
||||
if "IN_DELETE" in description:
|
||||
description += "WARNING: Unexpected file deletion\n"
|
||||
if "IN_MOVED_TO" in description:
|
||||
description += "WARNING: Unexpected file add to work\n"
|
||||
if "IN_MOVED_FROM" in description:
|
||||
description += "WARNING: Unexpected file moved out of directory\n"
|
||||
print(description)
|
||||
_method_name.__name__ = "process_{}".format(method)
|
||||
setattr(cls, _method_name.__name__, _method_name)
|
||||
|
||||
|
||||
EVENT_NOTIFIER = None
|
||||
|
||||
|
||||
def watch_dir(dir_to_watch):
|
||||
global EVENT_NOTIFIER
|
||||
for method in EventProcessor._methods:
|
||||
__process_generator(EventProcessor, method)
|
||||
watch_manager = pyinotify.WatchManager()
|
||||
EVENT_NOTIFIER = pyinotify.ThreadedNotifier(watch_manager, EventProcessor())
|
||||
watch_manager.add_watch(dir_to_watch, pyinotify.ALL_EVENTS, rec=True)
|
||||
EVENT_NOTIFIER.loop()
|
||||
|
||||
|
||||
def stop_watching():
|
||||
EVENT_NOTIFIER.stop()
|
|
@ -1,52 +0,0 @@
|
|||
import pyinotify
|
||||
|
||||
wm = pyinotify.WatchManager()
|
||||
mask = pyinotify.IN_CREATE | pyinotify.IN_CLOSE_WRITE | pyinotify.IN_DELETE | \
|
||||
pyinotify.IN_MOVED_TO | pyinotify.IN_MOVED_FROM | pyinotify.IN_OPEN
|
||||
|
||||
class EventHandler(pyinotify.ProcessEvent):
|
||||
_methods = ["IN_CREATE",
|
||||
"IN_CLOSE_WRITE",
|
||||
"IN_DELETE",
|
||||
"IN_MOVED_TO",
|
||||
"IN_MOVED_FROM",
|
||||
"IN_OPEN",
|
||||
]
|
||||
def __process_generator(self, event):
|
||||
description = \
|
||||
"Event: {}\n" \
|
||||
"Event Path: {}\n" \
|
||||
"Timestamp: {}\n".format(
|
||||
method,
|
||||
event.pathname,
|
||||
time.strftime("%A, %B %d, %Y %H:%M:%S", time.localtime())
|
||||
)
|
||||
if "IN_DELETE" in description:
|
||||
description += "WARNING: Unexpected file deletion\n"
|
||||
if "IN_MOVED_TO" in description:
|
||||
description += "WARNING: Unexpected file add to work\n"
|
||||
if "IN_MOVED_FROM" in description:
|
||||
description += "WARNING: Unexpected file moved out of directory\n"
|
||||
return description
|
||||
|
||||
def process_IN_CREATE(self, event):
|
||||
self.__process_generator(event)
|
||||
def process_IN_CLOSE_WRITE(self, event):
|
||||
self.__process_generator(event)
|
||||
def process_IN_DELETE(self, event):
|
||||
self.__process_generator(event)
|
||||
def process_IN_MOVED_TO(self, event):
|
||||
self.__process_generator(event)
|
||||
def process_IN_MOVED_FROM(self, event):
|
||||
self.__process_generator(event)
|
||||
def process_IN_OPEN(self, event):
|
||||
self.__process_generator(event)
|
||||
|
||||
|
||||
notifier = pyinotify.ThreadedNotifier(wm, EventHandler())
|
||||
notifier.start()
|
||||
|
||||
wdd = wm.add_watch('/tmp', mask, rec=True)
|
||||
input("Press any key to continue...")
|
||||
|
||||
notifier.stop()
|
|
@ -1,19 +0,0 @@
|
|||
from bgservice import SkoolOSDaemon as sod
|
||||
import threading
|
||||
|
||||
logger = sod()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
line=1
|
||||
print(line)
|
||||
line+=1
|
||||
logger.start()
|
||||
print(line)
|
||||
line+=1
|
||||
input("Enter any key when you are done modifyng the /tmp/ directory")
|
||||
print(line)
|
||||
line+=1
|
||||
logger.stop()
|
||||
print(line)
|
||||
line+=1
|
|
@ -2,7 +2,7 @@ from django.contrib import admin
|
|||
from .models import (
|
||||
DefFiles,
|
||||
Assignment,
|
||||
Classes,
|
||||
Class,
|
||||
Teacher,
|
||||
Student
|
||||
)
|
||||
|
@ -13,4 +13,4 @@ admin.site.register(Teacher)
|
|||
admin.site.register(Student)
|
||||
admin.site.register(DefFiles)
|
||||
admin.site.register(Assignment)
|
||||
admin.site.register(Classes)
|
||||
admin.site.register(Class)
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#
|
||||
# ####################################
|
||||
#
|
||||
# from api.models import Assignment, Student, Classes, Teacher, DefFiles
|
||||
# from api.models import Assignment, Student, Class, Teacher, DefFiles
|
||||
# from datetime import datetime
|
||||
#
|
||||
# f1 = DefFiles(
|
||||
|
@ -76,8 +76,8 @@
|
|||
# A3.files.add(f4)
|
||||
# A3.save()
|
||||
#
|
||||
# #classes
|
||||
# math = Classes(
|
||||
# #Class
|
||||
# math = Class(
|
||||
# name='Math5',
|
||||
#
|
||||
# )
|
||||
|
@ -86,7 +86,7 @@
|
|||
# math.assignments.add(A2)
|
||||
# math.save()
|
||||
#
|
||||
# english = Classes(
|
||||
# english = Class(
|
||||
# name='English',
|
||||
# )
|
||||
# english.save()
|
||||
|
@ -104,8 +104,8 @@
|
|||
# repo="https://github.com/therealraffi/2022rkhondak.git",
|
||||
# )
|
||||
# raffu.save()
|
||||
# raffu.classes.add(math)
|
||||
# raffu.classes.add(english)
|
||||
# raffu.Class.add(math)
|
||||
# raffu.Class.add(english)
|
||||
# raffu.save()
|
||||
#
|
||||
# #teachers
|
||||
|
@ -115,7 +115,7 @@
|
|||
# ion_user="eharris1"
|
||||
# )
|
||||
# ng.save()
|
||||
# ng.classes.add(math)
|
||||
# ng.Class.add(math)
|
||||
# ng.save()
|
||||
#
|
||||
# chao = Teacher(
|
||||
|
@ -124,5 +124,5 @@
|
|||
# ion_user="AKBailey"
|
||||
# )
|
||||
# chao.save()
|
||||
# chao.classes.add(english)
|
||||
# chao.Class.add(english)
|
||||
# chao.save()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-14 19:14
|
||||
# Generated by Django 3.0.7 on 2020-06-14 23:00
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
|
@ -14,6 +14,19 @@ class Migration(migrations.Migration):
|
|||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Class',
|
||||
fields=[
|
||||
('name', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
||||
('description', models.CharField(default='Class Description', max_length=500)),
|
||||
('repo', models.URLField(blank=True, default='')),
|
||||
('path', models.CharField(default='', max_length=100)),
|
||||
('assignments', models.TextField(blank=True, default='')),
|
||||
('default_file', models.CharField(blank=True, default='', max_length=100)),
|
||||
('confirmed', models.TextField(blank=True, default='')),
|
||||
('unconfirmed', models.TextField(blank=True, default='')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DefFiles',
|
||||
fields=[
|
||||
|
@ -28,13 +41,9 @@ class Migration(migrations.Migration):
|
|||
migrations.CreateModel(
|
||||
name='Teacher',
|
||||
fields=[
|
||||
('created', models.DateTimeField(auto_now_add=True)),
|
||||
('first_name', models.CharField(max_length=100)),
|
||||
('last_name', models.CharField(max_length=100)),
|
||||
('classes', models.CharField(blank=True, default='', max_length=100)),
|
||||
('ion_user', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
||||
('git', models.CharField(max_length=100)),
|
||||
('email', models.CharField(blank=True, default='', max_length=100)),
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('git', models.CharField(blank=True, default='', max_length=100)),
|
||||
('classes', models.ManyToManyField(to='api.Class')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
|
@ -42,21 +51,12 @@ class Migration(migrations.Migration):
|
|||
name='Student',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('website', models.CharField(blank=True, default='https://google.com', max_length=150)),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Classes',
|
||||
fields=[
|
||||
('name', models.CharField(max_length=100, primary_key=True, serialize=False)),
|
||||
('grade', models.IntegerField(blank=True, default=0)),
|
||||
('git', models.CharField(blank=True, default='', max_length=100)),
|
||||
('repo', models.URLField(blank=True, default='')),
|
||||
('path', models.CharField(default='', max_length=100)),
|
||||
('teacher', models.CharField(default='', max_length=100)),
|
||||
('assignments', models.TextField(blank=True, default='')),
|
||||
('default_file', models.CharField(blank=True, default='', max_length=100)),
|
||||
('confirmed', models.TextField(blank=True, default='')),
|
||||
('unconfirmed', models.TextField(blank=True, default='')),
|
||||
('classes', models.CharField(blank=True, default='', max_length=100)),
|
||||
('added_to', models.CharField(blank=True, default='', max_length=100)),
|
||||
('completed', models.TextField(blank=True, default='')),
|
||||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-14 20:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='student',
|
||||
name='website',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='added_to',
|
||||
field=models.CharField(blank=True, default='', max_length=100),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='classes',
|
||||
field=models.CharField(blank=True, default='', max_length=100),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='completed',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='git',
|
||||
field=models.CharField(blank=True, default='https://github.com/', max_length=100),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='grade',
|
||||
field=models.IntegerField(blank=True, default=9),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='repo',
|
||||
field=models.URLField(blank=True, default=''),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='student',
|
||||
name='student_id',
|
||||
field=models.IntegerField(blank=True, default=0),
|
||||
),
|
||||
]
|
31
Website/api/migrations/0002_auto_20200615_0046.py
Normal file
31
Website/api/migrations/0002_auto_20200615_0046.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-15 00:46
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='class',
|
||||
name='confirmed',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='class',
|
||||
name='confirmed',
|
||||
field=models.ManyToManyField(blank=True, related_name='confirmed', to='api.Student'),
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='class',
|
||||
name='unconfirmed',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='class',
|
||||
name='unconfirmed',
|
||||
field=models.ManyToManyField(blank=True, related_name='unconfirmed', to='api.Student'),
|
||||
),
|
||||
]
|
|
@ -1,43 +0,0 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-14 20:44
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0002_auto_20200614_2034'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='student',
|
||||
name='student_id',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='teacher',
|
||||
name='created',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='teacher',
|
||||
name='email',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='teacher',
|
||||
name='first_name',
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name='teacher',
|
||||
name='last_name',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='student',
|
||||
name='git',
|
||||
field=models.CharField(blank=True, default='', max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='student',
|
||||
name='grade',
|
||||
field=models.IntegerField(blank=True),
|
||||
),
|
||||
]
|
18
Website/api/migrations/0003_auto_20200615_0233.py
Normal file
18
Website/api/migrations/0003_auto_20200615_0233.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-15 02:33
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0002_auto_20200615_0046'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='teacher',
|
||||
name='classes',
|
||||
field=models.ManyToManyField(blank=True, related_name='teacher', to='api.Class'),
|
||||
),
|
||||
]
|
|
@ -1,18 +0,0 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-14 21:07
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0003_auto_20200614_2044'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='student',
|
||||
name='grade',
|
||||
field=models.IntegerField(blank=True, default=0),
|
||||
),
|
||||
]
|
22
Website/api/migrations/0004_auto_20200615_0255.py
Normal file
22
Website/api/migrations/0004_auto_20200615_0255.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# Generated by Django 3.0.7 on 2020-06-15 02:55
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('api', '0003_auto_20200615_0233'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='teacher',
|
||||
name='classes',
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='class',
|
||||
name='teachers',
|
||||
field=models.ManyToManyField(blank=True, related_name='teachers', to='api.Teacher'),
|
||||
),
|
||||
]
|
|
@ -1,49 +1,49 @@
|
|||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class DefFiles(models.Model):
|
||||
name=models.CharField(max_length=100)
|
||||
path=models.CharField(max_length=100)
|
||||
assignment=models.CharField(max_length=100, default="")
|
||||
classes=models.CharField(max_length=100)
|
||||
teacher=models.CharField(max_length=100)
|
||||
|
||||
class Assignment(models.Model):
|
||||
owner = models.ForeignKey('auth.User', related_name='assignments', on_delete=models.CASCADE)
|
||||
|
||||
name=models.CharField(max_length=100, primary_key=True)
|
||||
due_date=models.DateTimeField()
|
||||
# files = models.ManyToManyField(DefFiles)
|
||||
files=models.CharField(max_length=100, default="", blank=True)
|
||||
path=models.CharField(max_length=100)
|
||||
classes=models.CharField(max_length=100)
|
||||
teacher=models.CharField(max_length=100)
|
||||
def __str__(self):
|
||||
return '%s' % (self.name)
|
||||
|
||||
class Classes(models.Model):
|
||||
class Student(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
grade = models.IntegerField(default=0, blank=True)
|
||||
git=models.CharField(default="", max_length=100, blank=True)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
classes=models.CharField(max_length=100, default="", blank=True)
|
||||
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||
completed=models.TextField(default="", blank=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Student, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
|
||||
class Class(models.Model):
|
||||
name = models.CharField(primary_key=True, max_length=100)
|
||||
description = models.CharField(default="Class Description", max_length=500)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
path=models.CharField(max_length=100, default="")
|
||||
teacher=models.CharField(max_length=100, default="")
|
||||
assignments=models.TextField(default="", blank=True)
|
||||
default_file=models.CharField(max_length=100, default="", blank=True)
|
||||
confirmed=models.TextField(default="", blank=True)
|
||||
unconfirmed=models.TextField(default="", blank=True)
|
||||
confirmed=models.ManyToManyField(Student, blank=True, related_name='confirmed')
|
||||
unconfirmed=models.ManyToManyField(Student, blank=True, related_name='unconfirmed')
|
||||
|
||||
# assignments = models.ManyToManyField(Assignment, default="")
|
||||
# default_file = models.ManyToManyField(DefFiles)
|
||||
def save(self, *args, **kwargs):
|
||||
return super(Classes, self).save(*args, **kwargs)
|
||||
return super(Class, self).save(*args, **kwargs)
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Teacher(models.Model):
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
# classes = models.ManyToManyField(Classes, default="")
|
||||
classes=models.CharField(max_length=100, default="", blank=True)
|
||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||
git=models.CharField(max_length=100)
|
||||
classes=models.ManyToManyField(Class, blank=True, related_name='classes')
|
||||
git=models.CharField(max_length=100, default="", blank=True)
|
||||
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Teacher, self).save(*args, **kwargs)
|
||||
|
@ -58,8 +58,26 @@ class Student(models.Model):
|
|||
added_to=models.CharField(max_length=100, default="", blank=True)
|
||||
completed=models.TextField(default="", blank=True)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Student, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
|
||||
class Assignment(models.Model):
|
||||
owner = models.ForeignKey('auth.User', related_name='assignments', on_delete=models.CASCADE)
|
||||
|
||||
name=models.CharField(max_length=100, primary_key=True)
|
||||
due_date=models.DateTimeField()
|
||||
# files = models.ManyToManyField(DefFiles)
|
||||
files=models.CharField(max_length=100, default="", blank=True)
|
||||
path=models.CharField(max_length=100)
|
||||
classes=models.CharField(max_length=100)
|
||||
teacher=models.CharField(max_length=100)
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
return '%s' % (self.name)
|
||||
|
||||
|
||||
class DefFiles(models.Model):
|
||||
name=models.CharField(max_length=100)
|
||||
path=models.CharField(max_length=100)
|
||||
assignment=models.CharField(max_length=100, default="")
|
||||
classes=models.CharField(max_length=100)
|
||||
teacher=models.CharField(max_length=100)
|
||||
|
|
|
@ -9,8 +9,8 @@ urlpatterns = [
|
|||
path('teachers/<str:pk>/', views.TeacherDetail.as_view()),
|
||||
path('assignments/', views.AssignmentList.as_view()),
|
||||
path('assignments/<str:pk>/', views.AssignmentDetail.as_view()),
|
||||
path('classes/', views.ClassesList.as_view()),
|
||||
path('classes/<str:pk>/', views.ClassesDetail.as_view()),
|
||||
path('classes/', views.ClassList.as_view()),
|
||||
path('classes/<str:pk>/', views.ClassDetail.as_view()),
|
||||
]
|
||||
|
||||
urlpatterns = format_suffix_patterns(urlpatterns)
|
|
@ -1,5 +1,5 @@
|
|||
from .models import Student, Teacher, Classes, Assignment, DefFiles
|
||||
from .serializers import StudentSerializer, TeacherSerializer, ClassesSerializer, AssignmentSerializer, UserSerializer
|
||||
from .models import Student, Teacher, Class, Assignment, DefFiles
|
||||
from .serializers import StudentSerializer, TeacherSerializer, ClassSerializer, AssignmentSerializer, UserSerializer
|
||||
from rest_framework import generics, viewsets, permissions, response, status
|
||||
from django.http import Http404
|
||||
from rest_framework.views import APIView
|
||||
|
@ -14,7 +14,7 @@ from rest_framework.response import Response
|
|||
class UserViewSet(viewsets.ModelViewSet):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
permission_Class = [permissions.IsAuthenticated]
|
||||
|
||||
|
||||
class StudentViewSet(viewsets.ModelViewSet):
|
||||
|
@ -23,7 +23,7 @@ class StudentViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
queryset = Student.objects.all()
|
||||
serializer_class = StudentSerializer
|
||||
permission_classes = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
@ -34,18 +34,18 @@ class TeacherViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
queryset = Teacher.objects.all()
|
||||
serializer_class = TeacherSerializer
|
||||
permission_classes = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
serializer.save(owner=self.request.user)
|
||||
|
||||
class ClassesViewSet(viewsets.ModelViewSet):
|
||||
class ClassViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
API endpoint that allows users to be viewed or edited.
|
||||
"""
|
||||
queryset = Classes.objects.all()
|
||||
serializer_class = ClassesSerializer
|
||||
permission_classes = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
queryset = Class.objects.all()
|
||||
serializer_class = ClassSerializer
|
||||
permission_Class = [permissions.IsAuthenticated, IsOwnerOrReadOnly]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
if(self.request.user.groups.filter(name__in=['teachers']).exists() or self.request.user.is_superuser):
|
||||
|
@ -61,7 +61,7 @@ class AssignmentViewSet(viewsets.ModelViewSet):
|
|||
"""
|
||||
queryset = Assignment.objects.all()
|
||||
serializer_class = AssignmentSerializer
|
||||
permission_classes = [permissions.IsAuthenticated, isTeacher, IsOwnerOrReadOnly]
|
||||
permission_Class = [permissions.IsAuthenticated, isTeacher, IsOwnerOrReadOnly]
|
||||
|
||||
def perform_create(self, serializer):
|
||||
if(self.request.user.groups.filter(name__in=['teachers']).exists() or self.request.user.is_superuser):
|
||||
|
@ -76,4 +76,4 @@ class AssignmentViewSet(viewsets.ModelViewSet):
|
|||
# """
|
||||
# queryset = DefFiles.objects.all()
|
||||
# serializer_class = DefFilesSerializer
|
||||
# permissions_classes = [permissions.IsAuthenticatedOrReadOnly]
|
||||
# permissions_Class = [permissions.IsAuthenticatedOrReadOnly]
|
||||
|
|
|
@ -9,7 +9,7 @@ router = routers.DefaultRouter()
|
|||
router.register(r'students', api_views.StudentViewSet)
|
||||
router.register(r'teachers', api_views.TeacherViewSet)
|
||||
router.register(r'assignments', api_views.AssignmentViewSet)
|
||||
router.register(r'classes', api_views.ClassesViewSet)
|
||||
router.register(r'classes', api_views.ClassViewSet)
|
||||
# router.register(r'files', api_views.DefFilesViewSet)
|
||||
router.register(r'users', api_views.UserViewSet)
|
||||
|
||||
|
|
|
@ -13,22 +13,20 @@ body {
|
|||
color: #333333;
|
||||
margin-top: 5rem;
|
||||
font-family: 'Segoe UI';
|
||||
margin-left: 2.5rem;
|
||||
margin-right: 2.5rem;
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.bg-steel {
|
||||
background: #3cba54;
|
||||
}
|
||||
|
||||
.site-header .navbar-nav .nav-link {
|
||||
color: #cbd5db;
|
||||
color: #e1e1e1;
|
||||
}
|
||||
|
||||
.site-header .navbar-nav .nav-link:hover {
|
||||
|
@ -38,63 +36,3 @@ ul {
|
|||
.site-header .navbar-nav .nav-link.active {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.content-section {
|
||||
background: #ffffff;
|
||||
padding: 10px 20px;
|
||||
border: 1px solid #dddddd;
|
||||
border-radius: 3px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.article-title {
|
||||
color: #444444;
|
||||
}
|
||||
|
||||
a.article-title:hover {
|
||||
color: #428bca;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-content {
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.article-img {
|
||||
height: 65px;
|
||||
width: 65px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.article-metadata {
|
||||
padding-bottom: 1px;
|
||||
margin-bottom: 4px;
|
||||
border-bottom: 1px solid #e3e3e3
|
||||
}
|
||||
|
||||
.article-metadata a:hover {
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.article-svg {
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.account-img {
|
||||
height: 125px;
|
||||
width: 125px;
|
||||
margin-right: 20px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.account-heading {
|
||||
font-size: 2.5rem;
|
||||
}
|
||||
|
||||
.nounderline {
|
||||
text-decoration: none !important;
|
||||
color: black !important;
|
||||
}
|
||||
|
|
BIN
Website/skoolos/static/skoolos/tj_trans.png
Normal file
BIN
Website/skoolos/static/skoolos/tj_trans.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
|
@ -21,8 +21,8 @@
|
|||
<nav class="navbar navbar-expand-md navbar-dark bg-steel fixed-top">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="/docs/4.3/assets/brand/bootstrap-solid.svg" width="30" height="30" class="d-inline-block align-top" alt="">
|
||||
Bootstrap
|
||||
<img src="{% static 'skoolos/tj_trans.png' %}" width="30" height="30" class="d-inline-block align-top" alt="">
|
||||
SkoolOS
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
|
|
|
@ -1,3 +1,15 @@
|
|||
{% extends "skoolos/base.html" %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
{% for class in classes %}
|
||||
<div class="card-columns">
|
||||
<a class="card" href="#" style="text-decoration: none;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ class.name }}</h5>
|
||||
<p class="card-text">{{ class.description }}</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock content %}
|
||||
|
|
|
@ -1,10 +1,24 @@
|
|||
from django.shortcuts import render
|
||||
from django.contrib.auth.decorators import login_required
|
||||
|
||||
from api.models import Student, Teacher
|
||||
|
||||
# Create your views here.
|
||||
|
||||
@login_required()
|
||||
def home (request):
|
||||
try:
|
||||
student = Student.objects.get(user=request.user)
|
||||
return render(request, "skoolos/home.html", {'classes': student.confirmed.all()})
|
||||
except Student.DoesNotExist:
|
||||
pass
|
||||
|
||||
try:
|
||||
teacher = Teacher.objects.get(user=request.user)
|
||||
return render(request, "skoolos/home.html", {'classes': teacher.classes})
|
||||
except Teacher.DoesNotExist:
|
||||
pass
|
||||
|
||||
return render(request, "skoolos/home.html")
|
||||
|
||||
@login_required()
|
||||
|
|
|
@ -145,4 +145,4 @@ def create_account (request):
|
|||
def logout(request):
|
||||
auth_logout(request)
|
||||
messages.success(request, "You've been logged out!")
|
||||
return redirect(request, "/login")
|
||||
return redirect("/login")
|
||||
|
|
Loading…
Reference in New Issue
Block a user