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 @@ ...@@ -7,10 +7,9 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'announcements/style.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'announcements/style.css' %}">
<!-- <title>Announcement Board</title> --> <title>Announcements</title>
</head> </head>
<body> <body>
<!-- <script src="index.js"></script> -->
{% block content %} {% block content %}
{% endblock %} {% endblock %}
......
...@@ -14,5 +14,5 @@ ...@@ -14,5 +14,5 @@
<p>No reactions are available.</p> <p>No reactions are available.</p>
{% endif %} {% endif %}
{% load static %} {% load static %}
<img src="{% static image_url %}" alt="Photo of Post"/> <img src="{% static image_url %}" alt="Photo of announcement"/>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -11,7 +11,9 @@ ...@@ -11,7 +11,9 @@
{% else %} {% else %}
<p>No announcements are available.</p> <p>No announcements are available.</p>
{% endif %} {% endif %}
<button type="button" onclick="location.href='add'">New Announcement</button>
{% endblock %} {% endblock %}
<!-- -->
\ No newline at end of file
...@@ -4,12 +4,10 @@ from . import views ...@@ -4,12 +4,10 @@ from . import views
app_name = "announcements" app_name = "announcements"
urlpatterns = [ urlpatterns = [
# announcements/
path('', views.index, name='index'), path('', views.index, name='index'),
#announcements/1/details # announcements/1/details
path("<int:announcement_id>/details", views.details, name="details"), path("<int:announcement_id>/details", views.details, name="details"),
# announcements/add
#announcements/1/reactions path("add", views.add, name="add"),
# path("<int:announcement_id>/reactions", views.reactions, name="reactions"),
#announcements/1/react
# path("<int:announcement_id>/react", views.react, name="react")
] ]
\ No newline at end of file
from django.http import HttpResponse, Http404 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 .models import Announcement, Reaction
from .forms import AnnouncementForm
# Create your views here. # Create your views here.
def index(request): def index(request):
...@@ -23,32 +25,18 @@ def details(request, announcement_id): ...@@ -23,32 +25,18 @@ def details(request, announcement_id):
raise Http404("Announcement does not exist!") raise Http404("Announcement does not exist!")
return render(request, "announcements/details.html", context) return render(request, "announcements/details.html", context)
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,
# def reactions(request, announcement_id): "pub_date": pub_date
# response = "This are the reactions to announcement # %s." }
# return HttpResponse(response % announcement_id) return render(request, "announcements/add.html", context)
\ No newline at end of file
# 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
from django import forms
from .models import Assignment, Course
class AssignmentForm(forms.ModelForm):
class Meta:
model = Assignment
fields = '__all__'
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
{% block content %} {% block content %}
{% load static %} {% 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> <h3>{{ assignment.course.course_code }} {{ assignment.course.course_title }} {{ assignment.course.section }}</h3>
<ul> <ul>
<p>Assignment Name: {{ assignment.name }}</p> <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 @@ ...@@ -21,4 +21,7 @@
{% else %} {% else %}
<p>No course available.</p> <p>No course available.</p>
{% endif %} {% endif %}
<a href="add/">
<input type="button" value="New Assignment">
</a>
{% endblock %} {% endblock %}
...@@ -2,8 +2,10 @@ from django.urls import path ...@@ -2,8 +2,10 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
#assignments
path('', views.index, name='index'),
#assignments/ #assignments/
path('', views.index, name='index'),
#assignments/<int:assignment_id>/details/
path('<int:assignment_id>/details/', views.detail, name="detail"), 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 ...@@ -3,7 +3,7 @@ from django.http import HttpResponse
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views import View
from .models import Course, Assignment from .models import Course, Assignment
from .forms import AssignmentForm
# Create your views here. # Create your views here.
def index(request): def index(request):
...@@ -19,9 +19,21 @@ def index(request): ...@@ -19,9 +19,21 @@ def index(request):
def detail(request, assignment_id): def detail(request, assignment_id):
assignment = Assignment.objects.get(pk=assignment_id) assignment = Assignment.objects.get(pk=assignment_id)
assignment.passing_score = assignment.max_points * 0.6
image = f'assignments/{assignment.id}.jpg' image = f'assignments/{assignment.id}.jpg'
context = { context = {
"assignment": assignment, "assignment": assignment,
"assignment_image": image "assignment_image": image
} }
return render(request, "assignment_detail.html", context) 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