Commit d523ce09 authored by nheoxoz's avatar nheoxoz

created proj level base.html and implemented FBV

parent b5cc0a1e
{% extends 'base.html' %}
{% load static %}
{% block title %}Widget's Announcement Board{% endblock %}
{% block heading %}Welcome to Widget's Announcement Board!{% endblock %}
{% block content %}
<p>
Announcements:<br>
{% for a in announcements %}
<a href="{{ user.get_absolute_url }}">
{{a.title}} by {{ a.author }}
</a><br>
{% endfor %}
</p>
{% endblock %}
{% block footing %}
<a href="{% url 'announcements:announcement-create' %}">
<button class="btn add">Add Announcement</button>
</a>
{% endblock %}
from django.urls import path
from .views import index
from .views import (
index,
AnnouncementsDetailView,
AnnouncementsCreateView,
AnnouncementsUpdateView,
)
urlpatterns = [
path('', index, name='index'),
path('announcements/<int:pk>/details/',
AnnouncementsDetailView.as_view(),
name='announcement-details'),
path('announcements/add/',
AnnouncementsCreateView.as_view(),
name='announcement-create'),
path('announcements/<int:pk>/edit/',
AnnouncementsUpdateView.as_view(),
name='announcement-update'),
]
app_name = "announcements"
from django.http import HttpResponse
from .models import Announcement, Reaction
from django.shortcuts import render
from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView, UpdateView
from .models import Announcement
def index(request):
return_string = "<p>Widget's Announcement Board</p>Announcements:<br>"
for a in Announcement.objects.all():
return_string += '''{} by {} {} published {}{}<br>'''.format(
a.title,
a.author.first_name,
a.author.last_name,
a.pub_datetime.strftime('%m/%d/%Y, %H:%M %p:'),
a.body,
)
likeTally = 0
loveTally = 0
angryTally = 0
for r in Reaction.objects.all():
if r.name == "LIKE" and r.announcement == a:
likeTally += r.tally
if r.name == "LOVE" and r.announcement == a:
loveTally += r.tally
if r.name == "ANGRY" and r.announcement == a:
angryTally += r.tally
return_string += '''Like: {}<br>Love: {}
<br>Angry: {}<br><br>'''.format(
likeTally,
loveTally,
angryTally,
)
html_string = '<html><body>{}</body></html>'.format(return_string)
return HttpResponse(html_string)
announcements = Announcement.objects.all()
return render(
request,
'announcements/announcements.html',
{'announcements': announcements},
)
class AnnouncementsDetailView(DetailView):
model = Announcement
template_name = 'announcements/announcement-details.html'
class AnnouncementsCreateView(CreateView):
model = Announcement
fields = '__all__'
template_name = 'announcements/announcement-add.html'
class AnnouncementsUpdateView(UpdateView):
model = Announcement
fields = '__all__'
template_name = 'announcements/announcement-edit.html'
{% load static %}
<!DOCTYPE html>
<html lang="">
<head>
<link rel="stylesheet" href="{% static 'style.css' %}">
<title>{% block title %}{% endblock %}</title>
</head>
<body>
<div id="heading">
{% block heading %}{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
<div id="footing">
{% block footing %}{% endblock %}
</div>
</body>
</html>
......@@ -62,7 +62,7 @@ ROOT_URLCONF = 'widget_OhMyBash.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
......@@ -124,6 +124,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/4.1/howto/static-files/
STATIC_URL = 'static/'
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field
......
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