Commit 5c3b03e1 authored by Emmanuel Linus T. Evangelista's avatar Emmanuel Linus T. Evangelista

Merge branch 'evangelista/forum' into 'master'

Evangelista/forum

See merge request !11
parents c20478ae 12737867
body {
padding: 64px 160px;
}
#back {
margin: 0 0 32px;
display: flex;
align-items: center;
}
#back a {
color: black;
text-decoration: none;
margin-left: 8px;
}
#back a:hover {
text-decoration: underline;
}
#thumbnail {
width: 150px;
height: 150px;
object-fit: cover;
object-position: center;
margin: 0 0 16px;
}
#title {
margin: 0 0 16px;
}
#subtitle {
margin: 0 0 32px;
}
.body-text {
margin: 0 0 64px;
width: 80%;
}
.replies {
padding: 0;
}
.replies > li {
margin: 0 0 16px;
width: 60%;
}
\ No newline at end of file
body {
padding: 64px 160px;
}
#title {
margin: 0 0 64px;
}
#subtitle {
margin: 0 0 16px;
}
.posts {
padding: 0;
}
.posts > li {
margin: 0 0 16px;
width: 80%;
}
.posts > li a {
color: black;
text-decoration: none;
}
.posts > li a:hover {
text-decoration: underline;
}
\ No newline at end of file
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;700&family=Montserrat:ital,wght@0,100;0,200;0,300;0,500;0,700;0,800;0,900;1,400;1,500&display=swap');
* {
font-family: 'Inter', sans-serif;
}
html,
body {
margin: 0;
}
h1 {
font-size: 61.04px;
}
h2 {
font-size: 48.83px;
}
h3 {
font-size: 39.06px;
}
h4 {
font-size: 31.25px;
}
h5 {
font-size: 25.00px;
}
h6 {
font-size: 16.00px;
}
:root {
font-size: 16.00px;
}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Forum/styles.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'Forum/details.css' %}">
{% endblock %}
{% block title %}
{{ post.post_title }}
{% endblock %}
{% block content %}
<article>
<div id="back">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16">
<path
fill-rule="evenodd"
d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"
stroke="black"
/>
</svg>
<a href="/forum">Back to all posts</a>
</div>
<img id="thumbnail" src="{% static 'Forum/thumbnail.jpg' %}" alt="placeholder image" />
<h1 id="title">{{ post.post_title }}</h1>
<h4 id="subtitle">by {{ post.author.first_name }} {{ post.author.last_name }}, {{ post.pub_date|date:"d/m/Y" }}</h4>
<p class="body-text">{{ post.post_body }}</p>
<ul class="replies">
{% for reply in replies_sorted %}
<li><strong>{{ reply.author.first_name }} {{ reply.author.last_name }}, {{ reply.pub_date|date:"d/m/Y" }}:</strong> {{ reply.reply_body }}</li>
{% endfor %}
</ul>
</article>
{% endblock %}
\ No newline at end of file
{% extends "base.html" %}
{% load static %}
{% block styles %}
<link rel="stylesheet" type="text/css" href="{% static 'Forum/styles.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'Forum/index.css' %}">
{% endblock %}
{% block title %}Widget's Forum{% endblock %}
{% block content %}
<main>
<h1 id="title">Welcome to Widget's Forum!</h1>
<h5 id="subtitle">Forum posts:</h5>
<ul class="posts">
{% for post in posts_sorted %}
<li><a href="/posts/{{ post.pk }}/details"><strong>{{ post.post_title }}</strong> by <strong>{{ post.author.first_name }} {{ post.author.last_name }}</strong> dated <strong>{{ post.pub_date|date:"d/m/Y" }}</strong></a></li>
{% endfor %}
</ul>
</main>
{% endblock %}
\ No newline at end of file
from django.http import HttpResponse
from django.http import HttpResponse, Http404
from django.shortcuts import render
from .models import Post, Reply
def get_readable_time(timestamp):
return timestamp.strftime("%m/%d/%Y")
def index(request):
out = "FORUM POSTS: <br />"
posts = Post.objects.all()
for post in posts:
out += f'{post.post_title} by {post.author.first_name} {post.author.last_name} dated {get_readable_time(post.pub_date)}: <br />'
out += f'{post.post_body} <br />'
post_replies = post.reply_set.all()
for reply in post_replies:
out += f'Reply by {reply.author.first_name} {reply.author.last_name} dated {get_readable_time(reply.pub_date)}: <br />'
out += f'{reply.reply_body} <br />'
out += '<br />'
return HttpResponse(out)
\ No newline at end of file
return render(request, 'Forum/index.html', {'posts_sorted': Post.objects.order_by('-pub_date')})
def details(request, post_id):
try:
post = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404('Post does not exist')
return render(request, 'Forum/details.html', {'post': post, 'replies_sorted': post.reply_set.order_by('-pub_date')})
\ No newline at end of file
......@@ -15,10 +15,12 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path, include
import Forum.views as Forum_views
urlpatterns = [
path('admin/', admin.site.urls),
path('forum/', include('Forum.urls', namespace='Forum')),
path('posts/<int:post_id>/details/', Forum_views.details, name='post_details'),
path('homepage/', include('Homepage.urls', namespace="Homepage")),
path('announcements/', include('Announcements.urls', namespace="Announcements")),
path('assignments/', include('Assignments.urls', namespace="Assignments")),
......
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