updating local branch

parent d5740d61
from django.forms import ModelForm
from.models import Announcement
class AnnouncementForm(ModelForm):
class Meta:
model = Announcement
fields = ["announcement_title", "announcement_body", "author"]
\ No newline at end of file
{% extends "announcements/base.html" %}
{% block content %}
<form method="POST" action="add">
{% csrf_token %}
{{ announcement_form.as_p }}
<button class="button" type="submit">Save Announcement</button>
</form>
<br>
<a href="/announcements">Back to announcement board</a>
{% endblock %}
<!-- -->
\ No newline at end of file
......@@ -7,10 +7,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'announcements/style.css' %}">
<!-- <title>Announcement Board</title> -->
<title>Announcements</title>
</head>
<body>
<!-- <script src="index.js"></script> -->
{% block content %}
{% endblock %}
......
......@@ -14,5 +14,5 @@
<p>No reactions are available.</p>
{% endif %}
{% load static %}
<img src="{% static image_url %}" alt="Photo of Post"/>
<img src="{% static image_url %}" alt="Photo of announcement"/>
{% endblock %}
\ No newline at end of file
......@@ -10,8 +10,10 @@
</ul>
{% else %}
<p>No announcements are available.</p>
{% endif %}
{% endif %}
<button type="button" onclick="location.href='add'">New Announcement</button>
{% endblock %}
<!-- -->
\ No newline at end of file
......@@ -4,12 +4,10 @@ from . import views
app_name = "announcements"
urlpatterns = [
# announcements/
path('', views.index, name='index'),
#announcements/1/details
# announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"),
#announcements/1/reactions
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react
# path("<int:announcement_id>/react", views.react, name="react")
# announcements/add
path("add", views.add, name="add"),
]
\ No newline at end of file
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import render, redirect
import datetime
from .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here.
def index(request):
......@@ -23,32 +25,18 @@ def details(request, announcement_id):
raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context)
# def reactions(request, announcement_id):
# response = "This are the reactions to announcement # %s."
# return HttpResponse(response % announcement_id)
# def react(request, announcement_id):
# return HttpResponse("You are reacting to announcement # %s." % announcement_id)
# this belongs in index
# announcements_list = Announcement.objects.order_by("pub_date")
# output = ", ".join([a.announcement_title for a in announcements_list])
# return HttpResponse(output)
# content = 'ANNOUNCEMENTS:<br/>'
# announcements = Announcement.objects.all()
# reacts = Reaction.objects.all()
# for i in announcements:
# announcement_date = i.pub_date.date().strftime("%m/%d/%Y")
# content += f'{i.announcement_title} by {i.author.first_name} {i.author.last_name} dated {announcement_date}:<br/>{i.announcement_body}<br/>'
# for j in reacts:
# if j.announcement == i:
# content += f'{j.reaction_name}: {j.tally}<br/>'
# content += '<br/>'
# return HttpResponse(content)
\ No newline at end of file
def add(request):
if request.method == "POST":
announcement_form = AnnouncementForm(request.POST)
if announcement_form.is_valid():
new_announcement = announcement_form.save()
return redirect("announcements:add")
else:
announcement_form = AnnouncementForm()
pub_date = datetime.datetime.now()
context = {
"announcement_form": announcement_form,
"pub_date": pub_date
}
return render(request, "announcements/add.html", context)
\ No newline at end of file
from django import forms
from .models import Assignment, Course
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = '__all__'
......@@ -4,7 +4,7 @@
{% block content %}
{% load static %}
<img src="{% static assignment_image %}" alt="Photo of assignments"/>
<img src="{% static assignment_image %}" alt="No available image :("/>
<h3>{{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}</h3>
<ul>
<p>Assignment Name: {{ assignment.name }}</p>
......
{% extends 'assignment_base.html' %}
{% load static %}
{% block title %}Widget's Assignments{% endblock %}
{% block content %}
<h3>New Assignment</h3>
<form action="" method="POST" enctype="multipart/form-data">
{% csrf_token %}
{{ AssignmentForm.as_p }}
<input type='submit' value='Save Assignment'>
</form>
<a href="../">
<input type="button" value="Back to Assignments">
</a>
{% endblock %}
......@@ -21,4 +21,7 @@
{% else %}
<p>No course available.</p>
{% endif %}
<a href="add/">
<input type="button" value="New Assignment">
</a>
{% endblock %}
......@@ -2,8 +2,10 @@ from django.urls import path
from . import views
urlpatterns = [
#assignments
path('', views.index, name='index'),
#assignments/
path('', views.index, name='index'),
#assignments/<int:assignment_id>/details/
path('<int:assignment_id>/details/', views.detail, name="detail"),
#assignments/add/
path('add/', views.add, name="add"),
]
......@@ -3,7 +3,7 @@ from django.http import HttpResponse
from django.shortcuts import render
from django.views import View
from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here.
def index(request):
......@@ -19,9 +19,21 @@ def index(request):
def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id)
assignment.passing_score = assignment.max_points * 0.6
image = f'assignments/{assignment.id}.jpg'
context = {
"assignment": assignment,
"assignment_image": image
}
return render(request, "assignment_detail.html", context)
def add(request):
assignmentForm = AssignmentForm()
if request.method == 'POST':
assignmentForm = AssignmentForm(request.POST, request.FILES)
if assignmentForm.is_valid():
assignmentForm.save()
context = {
"AssignmentForm": assignmentForm,
}
return render(request, "assignment_form.html", context)
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