Forum post
This commit is contained in:
parent
a668626654
commit
40319f2a2e
@ -33,6 +33,7 @@ urlpatterns = [
|
||||
url(r'^experts/(?P<id>\d+)', expert_witnesses.views.viewer, name='expert'),
|
||||
url(r'^experts/', expert_witnesses.views.browser, name='experts'),
|
||||
url(r'^forum/post/(?P<post>\d*)', forum.views.post, name='post'),
|
||||
url(r'^forum/comment', forum.views.comment, name='comment'),
|
||||
url(r'^forum/(?P<thread>\d*)?', forum.views.view, name='forum'),
|
||||
url(r'^login/', main.views.login, name='login'),
|
||||
url(r'^logout/', main.views.logout, name='logout'),
|
||||
|
51
forum/templates/post.html
Normal file
51
forum/templates/post.html
Normal file
@ -0,0 +1,51 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block body %}
|
||||
<div class="container-fluid bg-dark-primary">
|
||||
<div class="container py-3">
|
||||
<div class="col-12 bg-white p-3">
|
||||
<div class="col-12">
|
||||
<h2 class="mb-0">{{ post.title }}</h2>
|
||||
<small class="text-muted">Asked By: {{ post.creator }}</small>
|
||||
</div>
|
||||
<div class="col-12 mt-3">
|
||||
{{ post }}
|
||||
</div>
|
||||
{% for comment in comments %}
|
||||
<div class="col-12 bg-white p-3 mt-3 rounded" style="border: 1px solid rgba(0, 0, 0, 0.2">
|
||||
<div class="col-12">
|
||||
<small class="text-muted">Answered By: {{ comment.creator }}</small>
|
||||
<div class="w-100">
|
||||
{% autoescape off %}
|
||||
{{ comment }}
|
||||
{% endautoescape %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
<div class="col-12 bg-white mt-3 py-3" style="position: relative">
|
||||
<div>
|
||||
<h5>Comment</h5>
|
||||
<form method="post" action="{% url 'comment' %}">
|
||||
{% csrf_token %}
|
||||
<input name="post" type="hidden" value="{{ post.id }}">
|
||||
<textarea class="form-control" name="comment" value="{{ comment }}"
|
||||
{% if not request.user.is_authenticated or not perms.form.add_comment %}disabled{% endif %}></textarea>
|
||||
<button class="btn btn-primary float-right">Create</button>
|
||||
</form>
|
||||
{% if not request.user.is_authenticated %}
|
||||
<span style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%)">You must <a
|
||||
href="{% url 'login' %}">login</a> to comment</span>
|
||||
{% endif %}
|
||||
{% if request.user.is_authenticatednot and perms.form.add_comment %}
|
||||
<span style="position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%)">You do not have permission to comment</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
@ -1,4 +1,4 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect
|
||||
|
||||
from .models import Thread, Post, Comment
|
||||
|
||||
@ -16,8 +16,10 @@ def view(request, thread=None):
|
||||
return render(request, 'view.html', {'threads': threads, 'posts': posts, 'myPosts': myPosts})
|
||||
|
||||
|
||||
def post(request):
|
||||
pass
|
||||
def post(request, post):
|
||||
this_post = Post.objects.get(id=post)
|
||||
comments = Comment.objects.filter(post=post)
|
||||
return render(request, 'post.html', {'post': this_post, 'comments': comments})
|
||||
|
||||
|
||||
def create(request):
|
||||
@ -25,4 +27,14 @@ def create(request):
|
||||
|
||||
|
||||
def comment(request):
|
||||
pass
|
||||
success = False
|
||||
post = Post.objects.get(id=request.POST.get('post'))
|
||||
comments = Comment.objects.filter(post=post)
|
||||
try:
|
||||
|
||||
success = Comment.objects.create(post=post,
|
||||
reply=request.POST.get('comment'),
|
||||
creator=request.user)
|
||||
success.save()
|
||||
finally:
|
||||
return redirect('forum', post.id)
|
||||
|
Loading…
Reference in New Issue
Block a user