Commit 18d1d0ae authored by nheoxoz's avatar nheoxoz

Merge branch 'assignments' into staging

parents b5f68311 d822d5c8
from django.contrib import admin
from .models import Assignment, Course
class AssignmentAdmin(admin.ModelAdmin):
model = Assignment
list_display = ('assignment_name', 'description', 'course', 'perfect_score',)
search_fields = ('assignment_name', 'description', 'course', 'perfect_score',)
list_filter = ('assignment_name', 'description', 'course', 'perfect_score',)
class CourseAdmin(admin.ModelAdmin):
model = Course
list_display = ('code', 'title', 'section',)
search_fields = ('code', 'title', 'section',)
list_filter = ('code', 'title', 'section',)
admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(Course, CourseAdmin)
from django.apps import AppConfig
class AssignmentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'assignments'
# Generated by Django 4.1.7 on 2023-03-05 14:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('code', models.CharField(max_length=10)),
('title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('assignment_name', models.CharField(max_length=50)),
('description', models.TextField()),
('perfect_score', models.IntegerField()),
('course', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='assignments.course')),
],
),
]
from django.db import models
class Course(models.Model):
code = models.CharField(max_length=10)
title = models.CharField(max_length=100)
section = models.CharField(max_length=3)
def __str__(self):
return '''{}, {}, {}'''.format(
self.code,
self.title,
self.section,
)
class Assignment(models.Model):
assignment_name = models.CharField(max_length=50)
description = models.TextField()
course = models.ForeignKey(Course, on_delete=models.CASCADE)
perfect_score = models.IntegerField()
def __str__(self):
return '''{}, {}, {}, {}'''.format(
self.assignment_name,
self.description,
self.course,
self.perfect_score,
)
\ No newline at end of file
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name= 'index'),
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse
from .models import Assignment
def index(request):
return_string = "<p>Widget's Assignment Page</p>"
for a in Assignment.objects.all():
return_string += '''Assignment Name: {} <br>Description: {}
<br>Perfect Score: {} <br>Passing Score: {}
<br>Course/Section: {} {}-{}<br><br>'''.format(
a.assignment_name,
a.description,
a.perfect_score,
int(a.perfect_score * 0.60),
a.course.code,
a.course.title,
a.course.section,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
...@@ -44,7 +44,7 @@ INSTALLED_APPS = [ ...@@ -44,7 +44,7 @@ INSTALLED_APPS = [
'forum', 'forum',
'widget_calendar', 'widget_calendar',
'announcements', 'announcements',
>>>>>>> f6700b35f7db8ac5d251ad6b596528ba9f7d4fac 'assignments',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
......
...@@ -21,5 +21,6 @@ urlpatterns = [ ...@@ -21,5 +21,6 @@ urlpatterns = [
path('forum/', include('forum.urls', namespace="forum")), path('forum/', include('forum.urls', namespace="forum")),
path('announcements/', include('announcements.urls', namespace="announcements")), path('announcements/', include('announcements.urls', namespace="announcements")),
path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")), path('widget_calendar/', include('widget_calendar.urls', namespace="calendar")),
path('assignments/', include('assignments.urls', namespace="assignments")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment