Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polishing #98

Merged
merged 10 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.sqlite3
__pycache__/
Binary file removed Dr_R/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/settings.cpython-311.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/wsgi.cpython-310.pyc
Binary file not shown.
Binary file removed Dr_R/__pycache__/wsgi.cpython-311.pyc
Binary file not shown.
3 changes: 2 additions & 1 deletion Dr_R/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
DEBUG = True

ALLOWED_HOSTS = ['*']
CSRF_TRUSTED_ORIGINS = ['https://*.mars-valpo.com']


# Application definition
Expand All @@ -39,7 +40,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_extensions'
'django_extensions',
]

MIDDLEWARE = [
Expand Down
Binary file removed astros/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/tests.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed astros/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file removed astros/__pycache__/views.cpython-311.pyc
Binary file not shown.
Binary file not shown.
Binary file removed astros/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed astros/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions astros/templates/astros/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<input class="btn btn-primary r" type="submit" value="Login">
<input type="hidden" name="next" value="{{ request.GET.next }}">
</form>
<u class='forgot-password-link'>forgot password?</u>
<ul class='forgot-password-link'>forgot password?</ul>
<br>
<br>
<div class="change-pwd-deimos registration-form cpwd" style="display: none">
Expand Down Expand Up @@ -72,7 +72,7 @@
<input class="btn btn-primary r" type="submit" value="Login">
<input type="hidden" name="next" value="{{ request.GET.next }}">
</form>
<u class='forgot-password-link'>forgot password?</u>
<ul class='forgot-password-link'>forgot password?</ul>
<br>
<br>

Expand Down
22 changes: 11 additions & 11 deletions astros/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.shortcuts import render, redirect
from django.contrib.auth.models import User
from phobos.models import Course, Professor,EnrollmentCode,CourseInfo
from deimos.models import Student, Enrollment
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -27,12 +28,10 @@ def register(request):
return render(request, 'astros/register.html')

def all_courses(request):

# TODO: you may *need* to user request.user._wrapped instead
try:
courses = Course.objects.all().order_by('-timestamp')
professor = Professor.objects.get(pk=request.user.pk)
is_professor_list = [1 if course.professors.filter(pk = request.user.pk).exists() or course.name=='Question Bank'\
courses = Course.objects.exclude(name='Question Bank').order_by('-timestamp')
is_professor_list = [1 if course.professors.filter(pk = request.user.pk).exists()\
else 0 for course in courses]
context = {
"courses__is_professor": zip(courses, is_professor_list),
Expand All @@ -43,8 +42,8 @@ def all_courses(request):
except Professor.DoesNotExist:
pass
try:
courses = Course.objects.exclude(name='Question Bank').order_by('-timestamp')
student = Student.objects.get(pk=request.user.pk)
courses = Course.objects.exclude(name='Question Bank').order_by('-timestamp')
is_student_list = [1 if Enrollment.objects.filter(student=request.user, course=course).exists()\
else 0 for course in courses]
context = {
Expand All @@ -66,10 +65,11 @@ def course_enroll(request, course_id, code):
if not Enrollment.objects.filter(student=student, course=course).exists():
# Checking whether code is valid.
try:
code = EnrollmentCode.objects.get(course=course, code=code)
except:
return HttpResponse(json.dumps({'state':False,'response':'Invalid code'}))
if code.expiring_date >= date.today():
enrollment_code = EnrollmentCode.objects.filter(course=course, code=code)
except EnrollmentCode.DoesNotExist:
return HttpResponse(json.dumps({'state': False, 'response': 'Invalid code'}))

if enrollment_code.expiring_date >= date.today():
# If not enrolled, create a new Enrollment instance
enrollment, created = Enrollment.objects.get_or_create(student=student, course=course)
enrollment.save()
Expand Down Expand Up @@ -156,7 +156,7 @@ def generate_auth_code(request):
def validate_auth_code(request):
if request.method == "POST":
data = json.loads(request.body)
email = data["email"]
email = data["email"].strip()
str_email = str(email)
code= int(data["code"].strip())
if str_email in code_base:
Expand All @@ -166,7 +166,7 @@ def validate_auth_code(request):
if code in valid_codes:
code_base[str_email] = [] # Clearing out the list for that email.
return JsonResponse({'success':True,
'message':'You have been registered successfully.'})
'message':'You will be registered in a couple of seconds.'})
else:
return JsonResponse({'success':False,
'message':'Wrong code. Try again.'})
Expand Down
Binary file removed db.sqlite3
Binary file not shown.
Binary file removed deimos/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/admin.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/apps.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/forms.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/forms.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/models.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/urls.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/utils.cpython-311.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/views.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/__pycache__/views.cpython-311.pyc
Binary file not shown.
18 changes: 18 additions & 0 deletions deimos/migrations/0022_assignmentstudent_is_complete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.3 on 2023-11-13 05:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('deimos', '0021_questionstudent_is_complete'),
]

operations = [
migrations.AddField(
model_name='assignmentstudent',
name='is_complete',
field=models.BooleanField(default=False),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.3 on 2023-11-21 03:20

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('phobos', '0049_remove_question_category_unit_questioncategory'),
('deimos', '0022_assignmentstudent_is_complete'),
]

operations = [
migrations.AlterUniqueTogether(
name='assignmentstudent',
unique_together={('student', 'assignment')},
),
migrations.AlterUniqueTogether(
name='enrollment',
unique_together={('student', 'course')},
),
migrations.AlterUniqueTogether(
name='questionstudent',
unique_together={('student', 'question')},
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed deimos/migrations/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed deimos/migrations/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
46 changes: 39 additions & 7 deletions deimos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.core.validators import MaxValueValidator, MinValueValidator
from .utils import *
from datetime import date

class Student(User):
"""
Student class to handle students in the platform.
Expand All @@ -14,6 +15,9 @@ class Student(User):
assignments = models.ManyToManyField(Assignment, through='AssignmentStudent')
questions = models.ManyToManyField(Question, through='QuestionStudent')

def __str__(self):
return f"First Name: {self.first_name} Last Name: {self.last_name} Email: {self.email}"



class Resource(models.Model):
Expand Down Expand Up @@ -66,6 +70,13 @@ class Enrollment(models.Model):
grade = models.FloatField(validators=[MaxValueValidator(100)], default=0, null=True)
registration_date = models.DateTimeField(auto_now_add=True)

class Meta:
unique_together = ('student', 'course')

def __str__(self):
return f'{self.student} enrolled in {self.course}'


class AssignmentStudent(models.Model):
"""
Used to manage `Assigment` - `Student` relationship.
Expand All @@ -74,6 +85,10 @@ class AssignmentStudent(models.Model):
assignment = models.ForeignKey(Assignment, on_delete=models.CASCADE)
grade = models.FloatField(validators=[MaxValueValidator(100)], default=0, null=True)
due_date = models.DateTimeField(null=True, blank=True)
is_complete = models.BooleanField(default=False)

class Meta:
unique_together = ('student', 'assignment')

def get_grade(self):
"""
Expand All @@ -99,8 +114,15 @@ def get_grade(self):
self.grade = round((num_points/total) * 100, 2)
else:
self.grade = 0
self.assignment.num_points = total
self.save(update_fields=['grade'])
return self.grade

def get_status(self):
return self.is_complete

def __str__(self):
return f"{self.assignment.name} for {self.student}"

def save(self, *args, **kwargs):
if not self.due_date:
self.due_date = self.assignment.due_date
Expand All @@ -118,6 +140,15 @@ class QuestionStudent(models.Model):
instances_created = models.BooleanField(default=False)
num_units_attempts = models.IntegerField(default=0, null=True, blank=True, validators=[MinValueValidator(0)])
is_complete = models.BooleanField(default=False)

class Meta:
unique_together = ('student', 'question')

def save(self, *args, **kwargs):
if self.success == True:
self.is_complete = True
super(QuestionStudent, self).save(*args, **kwargs)

def create_instances(self):
"""
Get variable instances from the variables associated to the question.
Expand All @@ -132,6 +163,8 @@ def create_instances(self):
if not parent_question_student.instances_created:
parent_question_student.create_instances()
self.instances_created = True
self.save()

def compute_structural_answer(self):
"""
Computes the answer to the question if it's a `Question` with `Variable` answers.
Expand Down Expand Up @@ -225,7 +258,7 @@ def get_num_points(self):
# are not successful. Maybe due to a new functionality
# or the teacher manually giving points for that attempt
total += attempt.num_points
self.num_points = total
self.num_points = total # useless for now. That's why it is not even saved()
return total

def get_num_attempts(self):
Expand Down Expand Up @@ -254,11 +287,10 @@ def get_status(self):
Otherwise False
"""
parent_question = self.question.parent_question if self.question.parent_question else self.question
question_students = QuestionStudent.objects.filter(question__parent_question=parent_question)
for qs in question_students:
if not qs.is_complete:
return False
return True
sub_questions = parent_question.sub_questions.all()
children_complete = not QuestionStudent.objects.filter(question__in=sub_questions, student=self.student, is_complete=False).exists()
parent_qs = QuestionStudent.objects.get(question=parent_question, student=self.student)
return parent_qs.is_complete and children_complete

def get_potential(self, no_unit = False):
"""
Expand Down
12 changes: 12 additions & 0 deletions deimos/static/deimos/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,17 @@ div.image-container img.course-image {
}


.edit-btn {
background-color: rgba(23, 137, 252, 1) !important;
transition: background-color 0.2s !important;
color: rgba(0,0,0,0.95) !important;
font-weight:400 !important;
font-family: 'Aileron', sans-serif;

}
.edit-btn:hover {
background-color: rgba(23, 137, 252, 0.7) !important;
}

/* ------------------------------Style for answer_question.html-------------*/
.formatted-mp {
Expand Down Expand Up @@ -727,6 +737,8 @@ more than assignment display */

.original-size {
font-size: initial;
width: auto;
height: auto;
}
@keyframes blink {
0%, 100% {
Expand Down
Loading
Loading