Commit 3c66e70d authored by Izaac Daniel B. Muncal's avatar Izaac Daniel B. Muncal

Fixed pycache errors and updated db.sqlite3

parents 9659de97 2d877f16
from django.db import models from django.db import models
from django.urls import reverse
class Course(models.Model): class Course(models.Model):
...@@ -23,3 +24,6 @@ class Assignment(models.Model): ...@@ -23,3 +24,6 @@ class Assignment(models.Model):
def __str__(self): def __str__(self):
return self.name return self.name
def get_absolute_url(self):
return reverse('assignments:assignment-details', kwargs={'pk': self.pk})
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block header %}Add a new assignment:{% endblock %}
{% block body %}
<form method="POST" enctype="multipart/form-data" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save New Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}{{ object.name }}{% endblock %}
{% block header %}{{ object.name }}{% endblock %}
{% block body %}
{{ object.course }} {{ object.course.title }} - {{ object.course.section }} <br/> <br/>
Description: {{ object.description }} <br/>
Perfect Score: {{ object.perfect_score}} <br/>
Passing Score: {{ object.passing_score }} <br/> <br/>
<button>
<a href="edit">Edit Assignment</a>
</button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Add Post{% endblock %}
{% block header %}Edit Assignment:{% endblock %}
{% block body %}
<form method="POST" enctype="multipart/form-data" action="">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Changes to Assignment">
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html' %}
{% block title %}Widget's Assignments{% endblock %}
{% block header %}Welcome to Widget's Assignments{% endblock %}
{% block body %}
<ul>
{% for assignment in assignment_list %}
<li>
<a href="{{ assignment.pk }}/details">
{{ assignment.name }}
</a>
</li>
{% endfor %}
</ul>
<button>
<a href="add">New Assignment</a>
</button>
<br/>
<a href="/dashboard">Dashboard</a> <br/>
<a href="/forum/">Forum</a>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import assignments from .views import assignments
from .views import AssignmentDetails, AssignmentAdd, AssignmentEdit
urlpatterns = [ urlpatterns = [
path('', assignments, name='assignments'), path('', assignments, name='assignments'),
path('<pk>/details', AssignmentDetails.as_view(), name='assignment-details'),
path('add', AssignmentAdd.as_view(), name='assignment-add'),
path('<pk>/edit', AssignmentEdit.as_view(), name='assignment-edit'),
] ]
# This might be needed depending on your Django version # This might be needed depending on your Django version
......
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Assignment, Course from .models import Assignment, Course
def assignments(request): def assignments(request):
return_string = "Widget's Assignments Page<br><br>" context = {}
for assignment, course in zip(Assignment.objects.all(), Course.objects.all()): context["assignment_list"] = Assignment.objects.all()
return_string += 'Assignment: {}<br>'.format(assignment.name) return render(request, 'assignments/assignments.html', context)
return_string += 'Description: {}<br>'.format(assignment.description)
return_string += 'Perfect Score: {}<br>'.format(assignment.perfect_score)
return_string += 'Passing Score: {}<br>'.format(assignment.passing_score)
return_string += 'Course/Section: {} {}-{}<br><br>'.format(
course.code, course.title, course.section)
return HttpResponse(return_string) class AssignmentDetails(DetailView):
model = Assignment
template_name = 'assignments/assignment-details.html'
class AssignmentAdd(CreateView):
model = Assignment
template_name = 'assignments/assignment-add.html'
fields = [
'name',
'description',
'course',
'perfect_score',]
class AssignmentEdit(UpdateView):
model = Assignment
template_name = 'assignments/assignment-edit.html'
fields = [
'name',
'description',
'course',
'perfect_score',
]
...@@ -17,7 +17,7 @@ class WidgetUser(models.Model): ...@@ -17,7 +17,7 @@ class WidgetUser(models.Model):
department = models.ForeignKey(Department, null=True, on_delete=models.CASCADE) department = models.ForeignKey(Department, null=True, on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return '{}, {} {} : {}'.format(self.last_name, self.first_name, self.middle_name, self.department) return '{}, {}'.format(self.last_name, self.first_name)
def get_absolute_url(self): def get_absolute_url(self):
return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk}) return reverse('dashboard:widgetuser-details', kwargs={'pk': self.pk})
......
from django import forms
from .models import ForumPost
class ForumPostForm(forms.ModelForm):
pub_datetime = forms.DateTimeField(input_formats=['%d/%m/%Y %H:%M'],
widget = forms.DateTimeInput(format = '%d/%m/%Y %H:%M',
attrs = {'class': 'form-control'}),
label = 'Date and Time')
class Meta:
model = ForumPost
fields = '__all__'
\ No newline at end of file
# Generated by Django 3.2 on 2023-05-12 08:38
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forum', '0002_alter_forumpost_author'),
]
operations = [
migrations.AlterModelOptions(
name='forumpost',
options={'ordering': ['pub_datetime']},
),
]
# Generated by Django 3.2 on 2023-05-13 13:54
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('forum', '0003_alter_forumpost_options'),
]
operations = [
migrations.AlterModelOptions(
name='forumpost',
options={'ordering': ['-pub_datetime']},
),
]
...@@ -12,9 +12,15 @@ class ForumPost(models.Model): ...@@ -12,9 +12,15 @@ class ForumPost(models.Model):
) )
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField()
class Meta:
ordering = ['-pub_datetime']
def __str__(self): def __str__(self):
return '{}'.format(self.title) return '{}'.format(self.title)
def get_absolute_url(self):
return reverse("forum:forumpostdetails", kwargs={"pk": self.pk})
class Reply(models.Model): class Reply(models.Model):
body = models.TextField() body = models.TextField()
author = models.CharField(max_length=50) author = models.CharField(max_length=50)
...@@ -23,4 +29,5 @@ class Reply(models.Model): ...@@ -23,4 +29,5 @@ class Reply(models.Model):
ForumPost, ForumPost,
on_delete=models.CASCADE on_delete=models.CASCADE
) )
def get_absolute_url(self):
\ No newline at end of file return reverse("forum:replydetails", kwargs={'pk': self.pk})
\ No newline at end of file
{%extends "base.html"%}
{%block title %}Widget's Forum{%endblock%}
{%block header %}Welcome to Widget's Forum!{%endblock %}
{%block body %}
<h2>Forum Posts:</h2>
{% for post in forum%}
<a href="{% url 'forum:forumpostdetails' post.pk%}">
{{post.title}} by {{post.author.first_name}} {{post.author.last_name}}<br>
</a>
{%endfor%}
<br>
<a href="{%url 'forum:forumpostnew' %}">
<input type="button" value= "New Post"></a>
<br>
<br>
<a href= "/dashboard">Dashboard</a><br>
<a href= "/assignments/">Assignments</a>
<br>
{% endblock%}
\ No newline at end of file
{%extends "base.html"%}
{%block title %}Add Post{%endblock%}
{%block header %}Add a new post:{%endblock %}
{%block body %}
<form method= "POST">
{% csrf_token %}
{{ form.as_p }}
<input type= "submit" value="Save New Post">
</form>
{% endblock%}
\ No newline at end of file
{%extends "base.html"%}
{%block title %}{{object.title}}{%endblock%}
{%block header %}{{object.title}}{%endblock %}
{%block body %}
by {{object.author.first_name}} {{object.author.last_name}}<br>
{{object.pub_datetime}}<br>
{{object.body}}<br>
<br>
<br>
POST REPLIES:
<br>
{% for reply in object.reply_set.all%}
{{reply.author}}<br>
{{reply.pub_datetime}}<br>
{{reply.body}}<br>
<br>
{%endfor%}
<a href="{%url 'forum:forumpostedit' object.pk %}">
<input type="button" value= "Edit Post"></a>
<br>
{% endblock%}
\ No newline at end of file
{%extends "base.html"%}
{%block title %}Edit Post{%endblock%}
{%block header %}Edit Post:{%endblock %}
{%block body %}
<form method= "POST">
{% csrf_token %}
{{ form.as_p }}
<input type= "submit" value="Save Changes to Post">
</form>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .views import index from . import views
from .views import (ForumViews, ForumPostDetails,
ForumPostNew, ForumPostEdit)
urlpatterns = [ urlpatterns = [
path('', index, name='index'), path('', views.ForumViews, name='forum'),
path('forumposts/<int:pk>/details/', ForumPostDetails.as_view(), name="forumpostdetails"),
path('forumposts/add/', ForumPostNew.as_view(), name='forumpostnew'),
path('forumposts/<int:pk>/edit/', ForumPostEdit.as_view(), name = 'forumpostedit'),
] ]
app_name = "forum" app_name = "forum"
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.urls import reverse
from django.views.generic import DetailView, CreateView, UpdateView
from .models import ForumPost, Reply from .models import ForumPost, Reply
from .forms import ForumPostForm
# Create your views here. # Create your views here.
def index(request): def ForumViews(request):
return_string = '<body> <ul>' forum = ForumPost.objects.all()
context = {'forum':forum}
return render(request, 'forum/forum.html', context)
for post in ForumPost.objects.all(): class ForumPostDetails(DetailView):
return_string += '<li>{} by {} posted {}:<br>{}</li>'.format( template_name= "forum/forumpost-details.html"
post.title, post.author, post.pub_datetime.strftime('%m/%d/%Y %H:%M %p'), post.body model = ForumPost
)
for replypost in Reply.objects.all():
if replypost.forum_post == post:
return_string += '<li>Reply by {} posted {}:<br>{}</li>'.format(
replypost.author, replypost.pub_datetime.strftime('%m/%d/%Y %I:%M %p'), replypost.body
)
return_string += '<br>'
return_string += '</ul></body>' class ForumPostNew(CreateView):
form_class = ForumPostForm
template_name = "forum/forumpost-add.html"
html_string = '<html>{}</html>'.format(return_string) def get_success(self):
return reverse('forum:forumpostnew', kwargs = {'pk': self.object.id},
current_app=self.request.resolver_match.namespace)
return HttpResponse(html_string) class ForumPostEdit(UpdateView):
\ No newline at end of file form_class = ForumPostForm
template_name = "forum/forumpost-edit.html"
queryset = ForumPost.objects.all()
def get_success_url(self):
return reverse('forum:forumpostdetails', kwargs = {'pk': self.object.pk},
current_app=self.request.resolver_match.namespace)
\ No newline at end of file
...@@ -2,11 +2,10 @@ ...@@ -2,11 +2,10 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>{% block title %} title {% endblock %}</title> <title>{% block title %}{% endblock %}</title>
</head> </head>
<h1>{% block header %} header {% endblock %}
</h1>
<body> <body>
{% block body %} body {% endblock %} <h1>{% block header %}{% endblock %}</h1>
{% block body %}{% endblock %}
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -20,7 +20,6 @@ from django.urls import include, path ...@@ -20,7 +20,6 @@ from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('forum/', include(('forum.urls', 'forum'), namespace="forum" )), path('forum/', include(('forum.urls', 'forum'), namespace="forum" )),
path('assignments/', include(('assignments.urls', 'assignments'), namespace="assignments")), path('assignments/', include(('assignments.urls', 'assignments'), namespace="assignments")),
path('Announcement_Board/', include(('Announcement_Board.urls', 'Announcement_Board'), namespace="Announcement_Board")),
path('dashboard', include(('dashboard.urls', 'dashboard'), namespace="dashboard")), path('dashboard', include(('dashboard.urls', 'dashboard'), namespace="dashboard")),
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