Commit f1e47d65 authored by Giancarlo Angelo U. de Torres's avatar Giancarlo Angelo U. de Torres

Merge branch 'main' into detorres/assignments

parents 13802bf5 7ab0d4b9
......@@ -16,7 +16,7 @@ class Assignment(models.Model):
course = models.ForeignKey(Course, on_delete = models.CASCADE, default = 1)
def get_absolute_url(self):
return reverse('assignment', args=[(self.full_assignment)])
return reverse('assignment-detail', args=[(self.pk)])
@property
def full_assignment(self):
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assignment List</title>
</head>
<body>
<h1>Assignments Per Course</h1>
{% for course in courses %}
<ul>
<li>{{ course.course_code }} {{ course.course_title }} {{ course.section }}
<ul>
{% for assignment in assignments %}
{%if assignment.course == course%}
<li><a href="{{assignment.get_absolute_url}}">{{assignment.name}}</a></li>
{%endif%}
{% endfor %}
</ul>
</li>
</ul>
{% endfor %}
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Assignment Detail</title>
</head>
<body>
<p>{{assignment.name}}</p>
<p>{{assignment.description}}</p>
<p>Max Points: {{assignment.max_points}}</p>
<p>Passing Score: {{assignment.passing_score}}</p>
<p>{{assignment.course}}</p>
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import assignments
from .views import AssignmentListView, AssignmentDetailView
urlpatterns = [
path('', assignments, name='Assignments')
path('', AssignmentListView.as_view(), name='assignment-list'),
path('<int:pk>/details', AssignmentDetailView, name='assignment-detail'),
]
\ No newline at end of file
from django.http import HttpResponse
from ast import Assign
from django.shortcuts import render, get_object_or_404
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import Assignment, Course
def assignments(request):
assignments = Assignment.objects.all()
courses = Course.objects.all()
output = "ASSIGNMENTS:\n" + "\n".join(
['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
.format(str(assignment.name),
str(assignment.description),
str(assignment.max_points),
str(assignment.passing_score),
str(assignment.course))
for assignment in assignments]
)
return HttpResponse(output, content_type = "text/plain")
# def assignments(request):
# assignments = Assignment.objects.all()
# courses = Course.objects.all()
# output = "ASSIGNMENTS:\n" + "\n".join(
# ['Assignment Name: {}\n Description: {}\n Perfect Score: {}\n Passing Score: {}\n Course/Section: {}'
# .format(str(assignment.name),
# str(assignment.description),
# str(assignment.max_points),
# str(assignment.passing_score),
# str(assignment.course))
# for assignment in assignments]
# )
# return HttpResponse(output, content_type = "text/plain")
class AssignmentListView(View):
def get(self, request):
assignments = Assignment.objects.all()
courses = Course.objects.all()
context = {
'assignments': assignments,
'courses' : courses
}
return render(request, 'assignments/assignment_list.html', context)
def AssignmentDetailView(request, pk):
assignment = get_object_or_404(Assignment, pk=pk)
return render(request, 'assignments/assignments_detail.html', {
'assignment': assignment
})
# class AssignmentListView(ListView):
# model = Assignment
No preview for this file type
from django import forms
class IndexCardForm(forms.Form):
name = forms.CharField(label='Full Name', max_length=100)
section = forms.CharField(label='CSCI40 Section', max_length=5)
age = forms.IntegerField(label='Current Age')
\ No newline at end of file
......@@ -10,7 +10,7 @@ class Department(models.Model):
return '{}, {}'.format(self.dept_name, self.home_unit)
class WidgetUser(models.Model):
id_num = models.CharField(max_length=7, validators=[RegexValidator(r'^\d{1,10}$')])
id_num = models.CharField(max_length=7, validators=[RegexValidator(r'^\d{1,10}$')], primary_key=True)
first_name = models.CharField(max_length=90)
middle_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
......@@ -18,7 +18,8 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, on_delete=models.CASCADE, default=1)
def get_absolute_url(self):
return reverse('widget_user', args=[(self.full_name)])
return reverse('widget_user-detail', args=[str(self.id_num)])
# return reverse('widget_user', args=[(self.full_name)])
def full_name(self):
return '{} {} {}'.format(self.first_name, self.middle_name, self.last_name)
return '{}, {} {}'.format(self.first_name, self.middle_name, self.last_name)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Widget User</title>
</head>
<body>
<h1>Add Widget User</h1>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Detail</title>
</head>
<body>
<p>{{user.last_name}},{{user.first_name}} {{user.middle_name}}</p>
<p>{{user.id_num}}</p>
<p>{{user.email}}</p>
<p>{{user.department.dept_name}}</p>
<p>{{user.department.home_unit}}</p>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User List</title>
</head>
<body>
<h1>Welcome to Widget!</h1>
{% for user in object_list %}
<a href="{{ user.get_absolute_url }}"> {{ user.last_name }}, {{user.first_name}} {{user.middle_name}} </a> <br>
{% endfor %}
<a href="/users/add">test</a>
</body>
</html>
\ No newline at end of file
from django.urls import path
from .views import homepage
from .views import homepage, UserDetailView, UserListView
urlpatterns = [
path('', homepage, name='homepage')
path('', UserListView.as_view(), name='widget_user-list'),
path('<int:pk>/details', UserDetailView, name='widget_user-detail'),
]
\ No newline at end of file
from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404
from django.views import View
from django.views.generic.detail import DetailView
from django.views.generic.list import ListView
from .models import WidgetUser, Department
def homepage(request):
widget_users = WidgetUser.objects.all()
output = "WIDGET USERS:\n" + "\n".join(
['{}, {} {}: {}, {}, {}'.format(str(user.last_name),
str(user.first_name),
str(user.middle_name),
str(user.id_num),
str(user.email),
str(user.department))
for user in widget_users]
)
return HttpResponse(output, content_type="text/plain")
\ No newline at end of file
class homepage(View):
def get(self, request):
widget_users = WidgetUser.objects.all()
context = {
'widget_users': widget_users,
}
return render(request, 'homepage/homepage.html', context)
def UserDetailView(request, pk):
user = get_object_or_404(WidgetUser, pk=pk)
return render(request, 'homepage/widgetuser_detail.html', {
'user': user
})
class UserListView(ListView):
model = WidgetUser
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-04-08 07:16
# Generated by Django 4.0.3 on 2022-04-07 22:37
from django.db import migrations, models
import django.db.models.deletion
......@@ -22,12 +22,20 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name='Course',
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
],
),
migrations.CreateModel(
name='Department',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
('dept_name', models.CharField(max_length=100)),
('home_unit', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
......@@ -43,19 +51,12 @@ class Migration(migrations.Migration):
name='WidgetUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('id_num', models.IntegerField()),
('first_name', models.CharField(max_length=100)),
('middle_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Assignment',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('description', models.CharField(max_length=200)),
('max_points', models.IntegerField()),
('course', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='widget_group3.course')),
('email', models.EmailField(max_length=254)),
('department', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='widget_group3.department')),
],
),
]
# Generated by Django 4.0.3 on 2022-04-08 03:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_group3', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='first_name',
field=models.CharField(max_length=90),
),
]
# Generated by Django 4.0.3 on 2022-04-08 06:12
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('widget_group3', '0002_alter_widgetuser_first_name'),
]
operations = [
migrations.AlterField(
model_name='widgetuser',
name='id_num',
field=models.CharField(max_length=7, validators=[django.core.validators.RegexValidator('^\\d{1,10}$')]),
),
]
......@@ -21,6 +21,7 @@ urlpatterns = [
path('admin/', admin.site.urls),
path('', include('homepage.urls'), name='Homepage'),
path('homepage/', include('homepage.urls'), name='Homepage'),
path('users/', include('homepage.urls'), name='Homepage'),
path('forum/', include('forum.urls'), name='Forum'),
path('assignments/', include('assignments.urls'), name='Assignments'),
path('announcements/', include('announcements.urls'), name='Announcement Board'),
......
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