Merge branch 'development' of https://github.com/Rushilwiz/SkoolOS into development

This commit is contained in:
Raffu Khondaker 2020-06-15 20:33:11 -04:00
commit ecaa0faf39
4 changed files with 18 additions and 5 deletions

View File

@ -1,5 +1,6 @@
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
import secrets
@ -12,7 +13,6 @@ class Student(models.Model):
classes=models.CharField(max_length=100, default="", blank=True) classes=models.CharField(max_length=100, default="", blank=True)
added_to=models.CharField(max_length=100, default="", blank=True) added_to=models.CharField(max_length=100, default="", blank=True)
completed=models.TextField(default="", blank=True) completed=models.TextField(default="", blank=True)
ion_user=models.CharField(primary_key=True, max_length=100)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(Student, self).save(*args, **kwargs) super(Student, self).save(*args, **kwargs)
@ -37,6 +37,7 @@ class Class(models.Model):
owner = models.ForeignKey('auth.User', related_name='classes', on_delete=models.CASCADE) owner = models.ForeignKey('auth.User', related_name='classes', on_delete=models.CASCADE)
teacher = models.CharField(max_length=100) teacher = models.CharField(max_length=100)
name = models.CharField(primary_key=True, max_length=100) name = models.CharField(primary_key=True, max_length=100)
id = models.CharField(max_length=8, blank=True, null=True)
description = models.CharField(default="Class Description", max_length=500) description = models.CharField(default="Class Description", max_length=500)
repo=models.URLField(default="", blank=True) repo=models.URLField(default="", blank=True)
path=models.CharField(max_length=100, default="") path=models.CharField(max_length=100, default="")
@ -48,6 +49,12 @@ class Class(models.Model):
# assignments = models.ManyToManyField(Assignment, default="") # assignments = models.ManyToManyField(Assignment, default="")
# default_file = models.ManyToManyField(DefFiles) # default_file = models.ManyToManyField(DefFiles)
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
id = self.id
if not id:
id = secrets.token_urlsafe()[:8].lower()
while Class.objects.filter(id=id).exclude(pk=self.pk).exists():
id = sercrets.token_urlsafe()[:8].lower()
self.id = id
return super(Class, self).save(*args, **kwargs) return super(Class, self).save(*args, **kwargs)
def __str__(self): def __str__(self):

View File

@ -3,7 +3,7 @@
<div class="content-section"> <div class="content-section">
{% for class in classes %} {% for class in classes %}
<div class="card-columns"> <div class="card-columns">
<a class="card" href="#" style="text-decoration: none;"> <a class="card" href="/class/{{ class.pk }}" style="text-decoration: none;">
<div class="card-body"> <div class="card-body">
<h5 class="card-title">{{ class.name }}</h5> <h5 class="card-title">{{ class.name }}</h5>
<p class="card-text">{{ class.description }}</p> <p class="card-text">{{ class.description }}</p>

View File

@ -5,5 +5,6 @@ from . import views
# Additionally, we include login URLs for the browsable API. # Additionally, we include login URLs for the browsable API.
urlpatterns = [ urlpatterns = [
path('', views.home, name='home'), path('', views.home, name='home'),
path('profile/', views.profile, name='profile') path('profile/', views.profile, name='profile'),
path("class/<int:id>", views.classDetail, name="class"),
] ]

View File

@ -1,7 +1,8 @@
from django.shortcuts import render from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.views.generic import ListView
from api.models import Student, Teacher from api.models import Student, Teacher, Class, Assignment
# Create your views here. # Create your views here.
@ -24,3 +25,7 @@ def home (request):
@login_required() @login_required()
def profile (request): def profile (request):
pass pass
def classDetail (request, id):
classObj = Class.objects.get(id=id)
return redirect('/')