Commit 20f101f0 authored by Neal Berones's avatar Neal Berones

created new.html and add.html templates

parent 9a02d0f4
{% load static %}
<!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">
<link rel="stylesheet" type="text/css"
href="{% static 'announcements/style.css' %}">
<title>{% block page-title %}{% endblock %}</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "base.html" %} {% extends "announcements/base.html" %}
{% block page-title %}Announcements Page{% endblock %} {% block page-title %}Announcements Page{% endblock %}
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
<p>Like: {{ like_tally }}</p> <p>Like: {{ like_tally }}</p>
<p>Love: {{ love_tally }}</p> <p>Love: {{ love_tally }}</p>
<p>Angry: {{ angry_tally }}</p> <p>Angry: {{ angry_tally }}</p>
<img src = "../../static/{{ announcement.file }}" width="400" height="200"> <img src = "../../static/announcements/{{ announcement.file }}" width="400" height="200">
</body> </body>
{% endblock %} {% endblock %}
{% extends "base.html" %} {% extends "announcements/base.html" %}
{% block page-title %}Announcements Page{% endblock %} {% block page-title %}Announcements Page{% endblock %}
...@@ -16,5 +16,8 @@ ...@@ -16,5 +16,8 @@
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<form method="get" action="announcements/new/">
<button type="submit">New Announcement</button>
</form>
</body> </body>
{% endblock %} {% endblock %}
{% extends "announcements/base.html" %}
{% block page-title %}Add New Announcement{% endblock %}
{% block content %}
<h1>New Announcement</h1>
<form action="announcements/add" method="POST">
<h2>Announcement Title: </h2><input type="text" name="announcement_title">
<h2>Announcement Body: </h2><input type="text" name="announcement_body">
</form>
...@@ -4,6 +4,8 @@ from . import views ...@@ -4,6 +4,8 @@ from . import views
app_name = "announcements" app_name = "announcements"
urlpatterns = [ urlpatterns = [
path('', views.index, name='index'), path('', views.index, name='index'),
path('announcements/new/', views.new, name='new'),
path('announcements/add/', views.add, name='add'),
path('<int:announcement_id>/details', views.detail, name="detail") path('<int:announcement_id>/details', views.detail, name="detail")
#path('welcome', views.welcome, name='welcome') #path('welcome', views.welcome, name='welcome')
] ]
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
import datetime
from django.shortcuts import render from django.shortcuts import render
from .models import WidgetUser, Announcement, Reaction from .models import WidgetUser, Announcement, Reaction
from django.template import loader from django.template import loader
...@@ -19,16 +20,16 @@ def detail(request, announcement_id): ...@@ -19,16 +20,16 @@ def detail(request, announcement_id):
reaction_list = Reaction.objects.all() reaction_list = Reaction.objects.all()
except Announcement.DoesNotExist: except Announcement.DoesNotExist:
raise Http404("Announcement does not exist!") raise Http404("Announcement does not exist!")
like_tally=0 like_tally = 0
love_tally=0 love_tally = 0
angry_tally=0 angry_tally = 0
for r in reaction_list: for r in reaction_list:
if r.reaction_name=="Like" and r.announcement==announcement: if r.reaction_name == "Like" and r.announcement == announcement:
like_tally+=r.tally like_tally += r.tally
elif r.reaction_name=="Love" and r.announcement==announcement: elif r.reaction_name == "Love" and r.announcement == announcement:
love_tally+=r.tally love_tally += r.tally
elif r.reaction_name=="Angry" and r.announcement==announcement: elif r.reaction_name == "Angry" and r.announcement == announcement:
angry_tally+=r.tally angry_tally += r.tally
context = { context = {
"announcement": announcement, "announcement": announcement,
...@@ -38,6 +39,24 @@ def detail(request, announcement_id): ...@@ -38,6 +39,24 @@ def detail(request, announcement_id):
} }
return render(request, "announcements/details.html", context) return render(request, "announcements/details.html", context)
def new(request):
user_list = WidgetUser.objects.all()
context = {
"user_list":user_list
}
return render(request, "announcements/new.html", context)
def add(request):
if request.method == "POST":
announcement_title = request.POST.get("announcement_title")
announcement_body = request.POST.get("announcement_body")
author = request.POST.get("author")
image = request.POST.get("image")
pub_date = datetime.date.today()
announcement = Announcement.objects.create(announcement_title = announcement_title, announcement_body = announcement_body, author = author, image = image, pub_date = pub_date)
messages.success(request, "Announcement Saved.")
return render(request, "")
# Code from previous lab activities: # Code from previous lab activities:
# def welcome(request): # def welcome(request):
# return HttpResponse("This is the Announcement Board!") # return HttpResponse("This is the Announcement Board!")
......
{% load static %}
<!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">
<link rel="stylesheet" type="text/css"
href="{% static 'forum/style.css' %}">
<title>{% block page-title %}{% endblock %}</title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "base.html" %} {% extends "forum/base.html" %}
{% block page-title %}Details{% endblock %} {% block page-title %}Details{% endblock %}
......
{% extends "base.html" %} {% extends "forum/base.html" %}
{% block page-title %}Forum Posts{% endblock %} {% block page-title %}Forum Posts{% endblock %}
......
...@@ -13,4 +13,4 @@ ...@@ -13,4 +13,4 @@
{% block content %} {% block content %}
{% endblock %} {% endblock %}
</body> </body>
</html> </html>
\ 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