Commit f066a017 authored by Deokhyun Lee's avatar Deokhyun Lee

Merge remote-tracking branch 'origin/announcementsv2'

parents 62282de2 ed442441
{% extends 'base.html'%}
{% block title %}
Add Announcement
{% endblock %}
{% block content %}
<h2>Add a new announcement:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Announcement</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html'%}
{% block title %}
{{ object.title }}
{% endblock %}
{% block content %}
<h2>{{ object.title }}</h2>
by {{ object.author.first_name }} {{ object.author.last_name}}<br>
{{ object.pub_datetime|date:"m/d/Y" }} {{ object.pub_datetime|time:"H:i A" }}<br><br>
{{ object.body }}<br><br>
{% for reaction in reactions %}
{% if reaction.announcement.title == object.title %}
{{ reaction.name}}: {{ reaction.tally }}<br>
{% endif %}
{% endfor %}
<button type="button" onclick="window.location.href='/announcements/{{announcement.pk}}/edit'">Edit Announcement</button>
{% endblock %}
\ No newline at end of file
{% extends 'base.html'%}
{% block title %}
Edit Announcement
{% endblock %}
{% block content %}
<h2>Edit announcement:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes to Announcement</button>
</form>
{% endblock %}
\ No newline at end of file
{% extends 'base.html'%}
{% block title %}
Widget's Announcement Board
{% endblock %}
{% block content %}
<h1>Welcome to Widget's Announcement Board!</h1><br>
Announcements:
{% if announcements %}
<ul>
{% for announcement in announcements %}
<a href={{announcement.id}}/details>{{announcement.title}} by
{{announcement.author.first_name}} {{announcement.author.last_name}}</a><br>
{% endfor %}
</ul>
{% else %}
<p>No Available Announcements.</p>
{% endif %}
<ul>
<li><button type="button" onclick="window.location.href='/announcements/add'">New Announcement</button></li>
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/forum">Forum</a></li>
<li><a href="/assignments/">Assignments</a></li>
<li><a href="/calendar">Calendar</a></li>
</ul>
{% endblock %}
\ No newline at end of file
from django.urls import path from django.urls import path
from .import views from .import views
# url for announcement_board
# url for announcement
urlpatterns = [ urlpatterns = [
path("", views.announcement_boardIndex, name = "announcement_boardIndex") path('', views.announcements_view, name='announcements'),
path('add', views.AnnouncementsAddView.as_view(), name='announcement_add'),
path('<int:pk>/details', views.AnnouncementsDetailsView.as_view(), name='announcement_details'),
path('<int:pk>/edit', views.AnnouncementsEditView.as_view(), name='announcement_edit'),
] ]
app_name = "announcement_board" app_name = "announcement_board"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from django.shortcuts import render
from django.views.generic import CreateView, UpdateView, DetailView
from .models import Announcement, Reaction from .models import Announcement, Reaction
# announcemnet view from .models # announcemnet view for FBV implementation
def announcements_view(request):
announcements = Announcement.objects.all().order_by('-pub_datetime') #https://www.w3schools.com/django/django_queryset_orderby.php
return render(request, 'announcements.html', {'announcements': announcements})
# announcement detail view for CBV implementation
class AnnouncementsDetailsView(DetailView):
model = Announcement
template_name = 'announcement-details.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['reactions'] = Reaction.objects.all()
return context
# add announcement, CBV implementation
class AnnouncementsAddView(CreateView):
model = Announcement
fields = '__all__'
template_name = 'announcement-add.html'
# edit announcement, CBV implementation
class AnnouncementsEditView(UpdateView):
model = Announcement
fields = '__all__'
template_name = 'announcement-edit.html'
def announcement_boardIndex(request): def announcement_boardIndex(request):
announcements = Announcement.objects.all() announcements = Announcement.objects.all()
reactions = Reaction.objects.all() reactions = Reaction.objects.all()
......
from django import forms
from .models import Assignment
class AddAssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
exclude = ['passing_score']
{% extends 'base.html'%}
{% block title %}
Add Assignment
{% endblock %}
{% block content %}
<h2>Add a new assignment:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save New Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
...@@ -14,15 +14,15 @@ ...@@ -14,15 +14,15 @@
<ul> <ul>
<h2>{{assignment.course.code}} {{assignment.course.title}} - {{assignment.course.section}} </h2> <h2>{{assignment.course.code}} {{assignment.course.title}} - {{assignment.course.section}} </h2>
<br> <br>
<h2>Description: {{assignment.description}}</h2><br> <p>Description: {{assignment.description}}</p><br>
<h2>Description: {{assignment.description}}</h2><br> <p>Perfect Score: {{assignment.perfect_score}}</p><br>
<h2>Description: {{assignment.description}}</h2><br> <p>Passing Score: {{assignment.passing_score}}</p><br>
</ul> </ul>
{% else %} {% else %}
<p>No Available Books.</p> <p>No Available Books.</p>
{% endif %} {% endif %}
<ul> <ul>
<li ><button type="button" onclick="window.location.href='/assignments/{{assignments.pk}}/edit'">Edit Assignments</button></li> <li ><button type="button" onclick="window.location.href='/assignments/{{assignment.pk}}/edit'">Edit Assignments</button></li>
</ul> </ul>
{% endblock %} {% endblock %}
\ No newline at end of file
{% extends 'base.html'%}
{% block title %}
Edit Assignment
{% endblock %}
{% block content %}
<h2>Edit Assignment:</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Save Changes to Assignment</button>
</form>
{% endblock %}
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<p>No Available Assignments.</p> <p>No Available Assignments.</p>
{% endif %} {% endif %}
<ul> <ul>
<li><button type="button" onclick="window.location.href='/books/add'">New Assignments</button></li> <li><button type="button" onclick="window.location.href='/assignments/add'">New Assignments</button></li>
<li><a href="/dashboard">Dashboard</a></li> <li><a href="/dashboard">Dashboard</a></li>
<li><a href="/announcements">Announcements</a></li> <li><a href="/announcements">Announcements</a></li>
<li><a href="/forum">Forum</a></li> <li><a href="/forum">Forum</a></li>
......
...@@ -4,4 +4,7 @@ from . import views ...@@ -4,4 +4,7 @@ from . import views
# url for assignments # url for assignments
urlpatterns = [ urlpatterns = [
path('', views.assignments_view, name='assignment'), path('', views.assignments_view, name='assignment'),
path('add', views.AssignmentAddListView.as_view(), name="assignment_add" ),
path('<int:pk>/details', views.AssignmentDetailView.as_view(), name='assignment_details'),
path('<int:pk>/edit', views.AssignmentEditView.as_view(), name='assignment_edit'),
] ]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render, redirect
from django.views.generic import DetailView, CreateView, UpdateView
from .models import Assignment from .models import Assignment
from .forms import AddAssignmentForm
# assignment view for FBV implementation. # assignment view for FBV implementation.
def assignments_view(request): def assignments_view(request):
assignments = Assignment.objects.all().order_by('id') assignments = Assignment.objects.all().order_by('id')
return render(request, 'assignments.html', {'assignments': assignments}) return render(request, 'assignments.html', {'assignments': assignments})
\ No newline at end of file
# assignement Detail view for CBV implementation.
class AssignmentDetailView(DetailView):
model = Assignment
template_name = 'assignment-details.html'
context_object_name = 'assignment'
# assignment for adding CBV implementation.
class AssignmentAddListView(CreateView):
model = Assignment
form_class = AddAssignmentForm
template_name = "assignment-add.html"
def post(self, request):
form = AddAssignmentForm(request.POST)
if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well.
new_assignment = form.save()
# pass the pk and redirect.
return redirect('assignment_details', pk = new_assignment.pk)
else:
return render(request, 'assignment_details.html', {'form': form})
# assignment for edditing CBV implementation.
class AssignmentEditView(UpdateView):
model = Assignment
form_class = AddAssignmentForm
template_name = 'assignment-edit.html'
# This will get the object, and this object is used to tell Django
# that we are updating.
def get_object(self, queryset = None):
pk = self.kwargs.get('pk')
return Assignment.objects.get(pk=pk)
def post(self, request, pk):
assignment = self.get_object()
form = AddAssignmentForm(request.POST, instance = assignment)
if form.is_valid():
# onSave is called, the form will have essential data and this includes pk as well.
update_assignment = form.save()
# pass the pk and redirect.
return redirect('assignment_details', pk = update_assignment.pk)
else:
return render(request, 'assignment_details.html', {'form': form})
\ No newline at end of file
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