mirror of
https://github.com/Rushilwiz/SkoolOS.git
synced 2025-04-16 02:10:19 -04:00
Added profile view and class detail
This commit is contained in:
parent
f7cac96ee2
commit
febb089ccf
|
@ -26,7 +26,6 @@ class Class(models.Model):
|
|||
description = models.CharField(default="Class Description", max_length=500)
|
||||
repo=models.URLField(default="", blank=True)
|
||||
path=models.CharField(blank=True, max_length=100, default="")
|
||||
assignments=models.TextField(default="", blank=True)
|
||||
default_file=models.CharField(max_length=100, default="", blank=True)
|
||||
confirmed=models.ManyToManyField(Student, blank=True, related_name='confirmed')
|
||||
unconfirmed=models.ManyToManyField(Student, blank=True, related_name='unconfirmed')
|
||||
|
@ -49,12 +48,13 @@ class Teacher(models.Model):
|
|||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
classes=models.ManyToManyField(Class, blank=True, related_name='classes')
|
||||
git=models.CharField(max_length=100, default="", blank=True)
|
||||
ion_user=models.CharField(primary_key=True, max_length=100)
|
||||
ion_user=models.CharField(primary_key=True, blank=True, max_length=100)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user.username}'s Profile"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.ion_user = self.user.username
|
||||
super(Teacher, self).save(*args, **kwargs)
|
||||
|
||||
# class Student(models.Model):
|
||||
|
@ -71,16 +71,14 @@ class Teacher(models.Model):
|
|||
|
||||
|
||||
class Assignment(models.Model):
|
||||
owner = models.ForeignKey('auth.User', related_name='assignments', on_delete=models.CASCADE)
|
||||
myClass = models.ForeignKey(Class, 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)
|
||||
path=models.CharField(max_length=100, blank=True)
|
||||
def __str__(self):
|
||||
return '%s' % (self.name)
|
||||
return f'{self.name}'
|
||||
|
||||
|
||||
class DefFiles(models.Model):
|
||||
|
|
28
Website/skoolos/forms.py
Normal file
28
Website/skoolos/forms.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django import forms
|
||||
from django.contrib.auth.models import User
|
||||
from api.models import Student, Teacher
|
||||
import re
|
||||
|
||||
class UserUpdateForm(forms.ModelForm):
|
||||
|
||||
username = forms.CharField(max_length=50, disabled=True)
|
||||
first_name = forms.CharField(max_length=50, disabled=True)
|
||||
last_name = forms.CharField(max_length=50, disabled=True)
|
||||
email = forms.EmailField()
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(UserUpdateForm, self).__init__(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
model = User
|
||||
fields = ['username','first_name','last_name','email']
|
||||
|
||||
class StudentUpdateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Student
|
||||
fields = ['git']
|
||||
|
||||
class TeacherUpdateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Teacher
|
||||
fields = ['git']
|
|
@ -36,3 +36,59 @@ h1, h2, h3, h4, h5, h6 {
|
|||
.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;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,16 @@
|
|||
</nav>
|
||||
</header>
|
||||
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
<div class="alert alert-{{ message.tags }} alert-dismissible fade show">
|
||||
{{ message }}
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% block content %}{% endblock %}
|
||||
<!-- Bootstrap JS -->
|
||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||
|
|
28
Website/skoolos/templates/skoolos/class_detail.html
Normal file
28
Website/skoolos/templates/skoolos/class_detail.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends "skoolos/base.html" %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<h4>Assignments:</h4>
|
||||
<hr>
|
||||
{% for assignment in assignments %}
|
||||
<article class="media content-section">
|
||||
<div class="media-body">
|
||||
<a class="mr-2" href="#">{{ assignment }}</a>
|
||||
<small class="text-muted">Due: {{ assignment.due_date|date:"F d, Y" }}</small>
|
||||
</div>
|
||||
</article>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="col-md-4 content-section">
|
||||
<h3>{{ class.name }}</h3>
|
||||
<p>Teachers:</p>
|
||||
<ul>
|
||||
{% for teacher in teachers %}
|
||||
<li>{{ teacher.user.first_name }} {{ teacher.user.last_name }} ({{teacher.ion_user}})</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -3,7 +3,7 @@
|
|||
<div class="content-section">
|
||||
{% for class in classes %}
|
||||
<div class="card-columns">
|
||||
<a class="card" href="/class/{{ class.pk }}" style="text-decoration: none;">
|
||||
<a class="card" href="/class/{{ class.id }}" style="text-decoration: none;">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">{{ class.name }}</h5>
|
||||
<p class="card-text">{{ class.description }}</p>
|
||||
|
|
34
Website/skoolos/templates/skoolos/profile_student.html
Normal file
34
Website/skoolos/templates/skoolos/profile_student.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
{% extends "skoolos/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<div class="media">
|
||||
<div class="media-body">
|
||||
<h2 class="account-heading">{{ user.username }}</h2>
|
||||
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
||||
<p class="text-secondary">
|
||||
{{ user.email }}
|
||||
<a href="https://github.com/{{ user.student.git }}" target="_blank">GitHub</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<legend class="border-bottom mb-4">Classes</legend>
|
||||
<ul>
|
||||
{% for class in classes %}
|
||||
<li>{{ class.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4"> Your profile </legend>
|
||||
{{ userForm|crispy}}
|
||||
{{ profileForm|crispy }}
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-outline-info">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
34
Website/skoolos/templates/skoolos/profile_teacher.html
Normal file
34
Website/skoolos/templates/skoolos/profile_teacher.html
Normal file
|
@ -0,0 +1,34 @@
|
|||
{% extends "skoolos/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
{% block content %}
|
||||
<div class="content-section">
|
||||
<div class="media">
|
||||
<div class="media-body">
|
||||
<h2 class="account-heading">{{ user.username }}</h2>
|
||||
<large>{{ user.first_name }} {{ user.last_name }}</large>
|
||||
<p class="text-secondary">
|
||||
{{ user.email }}
|
||||
<a href="https://github.com/{{ user.student.git }}" target="_blank">GitHub</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<legend class="border-bottom mb-4">Classes</legend>
|
||||
<ul>
|
||||
{% for class in classes %}
|
||||
<li>{{ class.name }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
<fieldset class="form-group">
|
||||
<legend class="border-bottom mb-4"> Your profile </legend>
|
||||
{{ userForm|crispy}}
|
||||
{{ profileForm|crispy }}
|
||||
</fieldset>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-outline-info">Update</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
|
@ -6,5 +6,5 @@ from . import views
|
|||
urlpatterns = [
|
||||
path('', views.home, name='home'),
|
||||
path('profile/', views.profile, name='profile'),
|
||||
path("class/<int:id>", views.classDetail, name="class"),
|
||||
path("class/<str:id>", views.classDetail, name="class"),
|
||||
]
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
from django.shortcuts import render, redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.views.generic import ListView
|
||||
from django.contrib import messages
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from .forms import UserUpdateForm, StudentUpdateForm, TeacherUpdateForm
|
||||
|
||||
from api.models import Student, Teacher, Class, Assignment
|
||||
|
||||
|
@ -16,7 +21,7 @@ def home (request):
|
|||
|
||||
try:
|
||||
teacher = Teacher.objects.get(user=request.user)
|
||||
return render(request, "skoolos/home.html", {'classes': teacher.classes})
|
||||
return render(request, "skoolos/home.html", {'classes': teacher.classes.all()})
|
||||
except Teacher.DoesNotExist:
|
||||
pass
|
||||
|
||||
|
@ -26,6 +31,89 @@ def home (request):
|
|||
def profile (request):
|
||||
pass
|
||||
|
||||
@login_required()
|
||||
def classDetail (request, id):
|
||||
classObj = Class.objects.get(id=id)
|
||||
|
||||
try:
|
||||
student = Student.objects.get(user=request.user)
|
||||
except Student.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
if classObj.confirmed.filter(user=student.user).count() != 1:
|
||||
return redirect('/')
|
||||
else:
|
||||
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all()})
|
||||
|
||||
try:
|
||||
teacher = Teacher.objects.get(user=request.user)
|
||||
return render(request, "skoolos/home.html", {'classes': teacher.classes.all()})
|
||||
except Teacher.DoesNotExist:
|
||||
pass
|
||||
else:
|
||||
if classObj.confirmed.filter(user=student.user).count() != 1:
|
||||
return redirect('/')
|
||||
else:
|
||||
return render(request, "skoolos/class_detail.html", {'class': classObj,'assignments': classObj.assignments.all(), 'teachers': classObj.classes.all()})
|
||||
|
||||
return redirect('/')
|
||||
|
||||
@login_required()
|
||||
def profile (request):
|
||||
try:
|
||||
student = Student.objects.get(user=request.user)
|
||||
return student_profile(request)
|
||||
except Student.DoesNotExist:
|
||||
pass
|
||||
|
||||
try:
|
||||
teacher = Teacher.objects.get(user=request.user)
|
||||
return teacher_profile(request)
|
||||
except Teacher.DoesNotExist:
|
||||
pass
|
||||
|
||||
return redirect("/")
|
||||
|
||||
def student_profile (request):
|
||||
if request.method == "POST":
|
||||
userForm = UserUpdateForm(request.POST, instance=request.user)
|
||||
profileForm = StudentUpdateForm(request.POST,
|
||||
instance=request.user.student)
|
||||
if userForm.is_valid() and profileForm.is_valid():
|
||||
userForm.save()
|
||||
profileForm.save()
|
||||
messages.success(request, "Your account has been updated!")
|
||||
return redirect('profile')
|
||||
else:
|
||||
userForm = UserUpdateForm(instance=request.user)
|
||||
profileForm = StudentUpdateForm(instance=request.user.student)
|
||||
|
||||
context = {
|
||||
'userForm': userForm,
|
||||
'profileForm': profileForm,
|
||||
'classes': request.user.student.confirmed.all()
|
||||
}
|
||||
|
||||
return render(request, 'skoolos/profile_student.html', context)
|
||||
|
||||
def teacher_profile (request):
|
||||
if request.method == "POST":
|
||||
userForm = UserUpdateForm(request.POST, instance=request.user)
|
||||
profileForm = TeacherUpdateForm(request.POST,
|
||||
instance=request.user.student)
|
||||
if userForm.is_valid() and profileForm.is_valid():
|
||||
userForm.save()
|
||||
profileForm.save()
|
||||
messages.success(request, "Your account has been updated!")
|
||||
return redirect('profile')
|
||||
else:
|
||||
userForm = UserUpdateForm(instance=request.user)
|
||||
profileForm = TeacherUpdateForm(instance=request.user.student)
|
||||
|
||||
context = {
|
||||
'userForm': userForm,
|
||||
'profileForm': profileForm,
|
||||
'classes': request.user.teacher.classes.all()
|
||||
}
|
||||
|
||||
return render(request, 'skoolos/profile_teacher.html', context)
|
||||
|
|
Loading…
Reference in New Issue
Block a user