Crew replication, etc.

This commit is contained in:
Kumi 2022-09-26 14:27:52 +00:00
parent 37c10284f1
commit 82fa6d445e
Signed by: kumi
GPG key ID: ECBCC9082395383F
13 changed files with 182 additions and 13 deletions

0
core/helpers/__init__.py Normal file
View file

0
core/helpers/adonis.py Normal file
View file

5
core/helpers/uploads.py Normal file
View file

@ -0,0 +1,5 @@
import uuid
def get_upload_path(instance, filename):
return f"{str(uuid.uuid4)}/{filename}"

View file

@ -0,0 +1,16 @@
# Generated by Django 4.1.1 on 2022-09-22 14:58
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('core', '0008_vesselalias'),
]
operations = [
migrations.DeleteModel(
name='VesselAlias',
),
]

View file

@ -0,0 +1,63 @@
# Generated by Django 4.1.1 on 2022-09-22 15:22
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0009_delete_vesselalias'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.IntegerField(primary_key=True, serialize=False)),
('title', models.CharField(max_length=256)),
('shortcode', models.CharField(max_length=64)),
],
),
migrations.CreateModel(
name='CrewMember',
fields=[
('pin', models.IntegerField(primary_key=True, serialize=False)),
('first_name', models.CharField(max_length=256)),
('last_name', models.CharField(max_length=256)),
('email', models.EmailField(max_length=254)),
('dob', models.DateField()),
],
),
migrations.CreateModel(
name='Moodle',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=64)),
('url', models.URLField()),
('monitor', models.BooleanField(default=True)),
('backup', models.BooleanField(default=False)),
('vessel', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.vessel')),
],
),
migrations.CreateModel(
name='MoodleDatabase',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('host', models.CharField(max_length=256)),
('username', models.CharField(max_length=256)),
('password', models.CharField(max_length=256)),
('database', models.CharField(default='moodle', max_length=256)),
('instance', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='core.moodle')),
],
),
migrations.CreateModel(
name='CourseAssignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.course')),
('crew', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.crewmember')),
('instance', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='core.moodle')),
],
),
]

View file

@ -0,0 +1,36 @@
# Generated by Django 4.1.1 on 2022-09-22 15:43
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0010_course_crewmember_moodle_moodledatabase_and_more'),
]
operations = [
migrations.CreateModel(
name='MoodlePlugin',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128)),
('section', models.CharField(max_length=16)),
('current_version', models.IntegerField()),
],
),
migrations.AddField(
model_name='replicationtarget',
name='monitor',
field=models.BooleanField(default=True),
),
migrations.CreateModel(
name='CourseAssignmentLog',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('assignment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.courseassignment')),
('instance', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.moodle')),
],
),
]

View file

@ -1,3 +1,6 @@
from .auth import User, OTPSession
from .vessel import Vessel
from .replication import ReplicationFile, ReplicationFileLog, ReplicationSource, ReplicationTarget
from .course import Course
from .crew import CrewMember
from .moodle import Moodle, MoodleDatabase

View file

@ -1,3 +1,6 @@
from django.db import models
class Course(models.Model):
id = models.IntegerField(primary_key=True)
title = models.CharField(max_length=256)

View file

@ -1,7 +1,7 @@
from django.db import models
from django.utils import timezone
from .course import Course
from .vessel import Vessel
from ..helpers.uploads import get_upload_path
class CrewMember(models.Model):
@ -11,8 +11,14 @@ class CrewMember(models.Model):
email = models.EmailField()
dob = models.DateField()
profile_picture = models.ImageField(upload_to=get_upload_path)
class CourseAssignment(models.Model):
crew = models.ForeignKey(CrewMember, models.CASCADE)
course = models.ForeignKey(Course, models.CASCADE)
vessel = models.ForeignKey(Vessel, models.CASCADE, null=True)
expiry = models.DateTimeField(null=True, blank=True)
@classmethod
def get_or_import(cls, pin):
try:
found = cls.objects.get(pin=pin)
if found.expiry and found.expiry < timezone.now():
pass

41
core/models/moodle.py Normal file
View file

@ -0,0 +1,41 @@
from django.db import models
from django import forms
from .vessel import Vessel
from .crew import CrewMember
from .course import Course
class Moodle(models.Model):
vessel = models.OneToOneField(Vessel, models.CASCADE)
name = models.CharField(max_length=Vessel.name.field.max_length)
url = models.URLField()
monitor = models.BooleanField(default=True)
backup = models.BooleanField(default=False)
class MoodleDatabase(models.Model):
instance = models.OneToOneField(Moodle, models.CASCADE)
host = models.CharField(max_length=256)
username = models.CharField(max_length=256)
password = models.CharField(max_length=256)
database = models.CharField(max_length=256, default="moodle")
class MoodlePlugin(models.Model):
name = models.CharField(max_length=128)
section = models.CharField(max_length=16)
current_version = models.IntegerField()
class CourseAssignment(models.Model):
crew = models.ForeignKey(CrewMember, models.CASCADE)
course = models.ForeignKey(Course, models.CASCADE)
instance = models.ForeignKey(Moodle, models.CASCADE, null=True)
class CourseAssignmentLog(models.Model):
assignment = models.ForeignKey(CourseAssignment, models.CASCADE)
instance = models.ForeignKey(Moodle, models.CASCADE)
timestamp = models.DateTimeField(auto_now_add=True)

View file

@ -26,6 +26,7 @@ class ReplicationTarget(models.Model):
name = models.CharField(max_length=128)
address = models.CharField(max_length=256)
username = models.CharField(max_length=64, default=getuser(), null=True, blank=True)
monitor = models.BooleanField(default=True)
def to_vessel(self, dbclass=None) -> Vessel:
return Vessel(name, address, username, dbclass=ContentMonsterDatabase)

View file

@ -50,8 +50,3 @@ class Vessel(models.Model):
pass
return ship
class VesselAlias(models.Model):
vessel = models.ForeignKey(Vessel, models.CASCADE)
alias = models.CharField(max_length=64)