Improve forum style and templates

This commit is contained in:
Skia 2017-01-21 12:28:32 +01:00
parent ff77df3646
commit 93f5096140
7 changed files with 98 additions and 49 deletions

View File

@ -372,6 +372,42 @@ textarea {
display: inline; display: inline;
} }
/*------------------------------FORUM----------------------------------*/
.topic a, .forum a, .category a {
color: black;
}
.topic a:hover, .forum a:hover, .category a:hover {
color: #242424;
}
.topic {
border: solid skyblue 1px;
padding: 2px;
margin: 2px;
}
.forum {
background: lightblue;
padding: 2px;
margin: 2px;
}
.category {
background: skyblue;
}
.message {
padding: 2px;
margin: 2px;
background: skyblue;
}
.message h5 {
font-size: 100%;
}
.msg_author {
display: inline-block;
width: 19%;
}
.msg_author img {
max-width: 80%;
margin: 0px auto;
}
/*------------------------------SAS------------------------------------*/ /*------------------------------SAS------------------------------------*/
.album { .album {
display: inline-block; display: inline-block;

View File

@ -1,24 +1,6 @@
{% extends "core/base.jinja" %} {% extends "core/base.jinja" %}
{% from 'forum/macros.jinja' import display_forum %} {% from 'forum/macros.jinja' import display_forum %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block head %}
{{ super() }}
<style type="text/css" media="all">
.topic {
border: solid skyblue 1px;
padding: 2px;
margin: 2px;
}
.forum {
background: lightblue;
padding: 2px;
margin: 2px;
}
.category {
background: skyblue;
}
</style>
{% endblock %}
{% block content %} {% block content %}
<p> <p>
@ -33,14 +15,22 @@
{% for f in forum.children.all() %} {% for f in forum.children.all() %}
{{ display_forum(f) }} {{ display_forum(f) }}
{% endfor %} {% endfor %}
{% for t in forum.topics.all() %} {% for t in topics %}
<div class="topic"> <div class="topic">
<p> <p>
<a href="{{ url('forum:view_topic', topic_id=t.id) }}">View</a>
<a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a> <a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a>
</p> </p>
<h5>{{ t.title }}</h5> <a href="{{ url('forum:view_topic', topic_id=t.id) }}">
<p>{{ t.description }}</p> <div style="display: inline-block; width: 80%">
<h5>{{ t.title }}</h5>
<p>{{ t.description }}</p>
</div>
</a>
<div style="display: inline-block; width: 19%">
{% set last_msg = t.messages.order_by('id').last() %}
<p>Last message by {{ user_profile_link(last_msg.author) }} at {{ last_msg.date|date(DATETIME_FORMAT) }} {{
last_msg.date|time(DATETIME_FORMAT) }}</p>
</div>
</div> </div>
{% endfor %} {% endfor %}
<a href="{{ url('forum:new_topic', forum_id=forum.id) }}">New topic</a> <a href="{{ url('forum:new_topic', forum_id=forum.id) }}">New topic</a>

View File

@ -1,13 +1,18 @@
{% macro display_forum(forum) %} {% macro display_forum(forum) %}
<div class="forum {% if forum.is_category %}category{% endif %}"> <div class="forum {% if forum.is_category %}category{% endif %}">
<p> <p>
{% if not forum.is_category %}
<a href="{{ url('forum:view_forum', forum_id=forum.id) }}">View</a>
{% endif %}
<a href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a> <a href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a>
</p> </p>
<h5>{{ forum.name }}</h5> {% if not forum.is_category %}
<p>{{ forum.description }}</p> <a href="{{ url('forum:view_forum', forum_id=forum.id) }}">
{% endif %}
<div>
<h5>{{ forum.name }}</h5>
<p>{{ forum.description }}</p>
</div>
{% if not forum.is_category %}
</a>
{% endif %}
</div> </div>
{% endmacro %} {% endmacro %}

View File

@ -2,20 +2,6 @@
{% from 'core/macros.jinja' import user_profile_link %} {% from 'core/macros.jinja' import user_profile_link %}
{% from 'forum/macros.jinja' import display_forum %} {% from 'forum/macros.jinja' import display_forum %}
{% block head %}
{{ super() }}
<style type="text/css" media="all">
.forum {
background: lightblue;
padding: 2px;
margin: 2px;
}
.category {
background: skyblue;
}
</style>
{% endblock %}
{% block content %} {% block content %}
<p> <p>
<a href="{{ url('forum:main') }}">Forum</a> > <a href="{{ url('forum:main') }}">Forum</a> >

View File

@ -33,13 +33,32 @@
<p>{{ topic.description }}</p> <p>{{ topic.description }}</p>
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">Reply</a></p> <p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">Reply</a></p>
{% for m in topic.messages.all() %} {% for m in topic.messages.all() %}
<hr> <div class="message">
<div> <div class="msg_author">
<h5>{{ m.title }}</h5> {% if m.author.profile_pict %}
<p><strong>{{ user_profile_link(m.author) }}</strong> - {{ m.date|date(DATETIME_FORMAT) }} <img src="{{ m.author.profile_pict.get_download_url() }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{{ m.date|time(DATETIME_FORMAT) }} - {% else %}
<a href="{{ url('forum:new_message', topic_id=topic.id) }}?quote_id={{ m.id }}">Reply as quote</a></p> <img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
<p>{{ m.message|markdown }}</p> {% endif %}
<strong>{{ user_profile_link(m.author) }}</strong>
</div>
<div style="display: inline-block; width: 80%;">
<div style="display: inline-block; width: 74%;">
{% if m.title %}
<h5>{{ m.title }}</h5>
<hr>
{% endif %}
</div>
<div style="display: inline-block; width: 25%;">
<span> <a href="{{ url('forum:edit_message', message_id=m.id) }}">{% trans %}Edit{% endtrans %}</a></span>
<span><a href="{{ url('forum:new_message', topic_id=topic.id) }}?quote_id={{ m.id }}">
{% trans %}Reply as quote{% endtrans %}</a></span><br/>
<span>{{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }}</span>
</div>
<div>
{{ m.message|markdown }}
</div>
</div>
</div> </div>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

View File

@ -11,5 +11,6 @@ urlpatterns = [
url(r'^topic/(?P<topic_id>[0-9]+)$', ForumTopicDetailView.as_view(), name='view_topic'), url(r'^topic/(?P<topic_id>[0-9]+)$', ForumTopicDetailView.as_view(), name='view_topic'),
url(r'^topic/(?P<topic_id>[0-9]+)/edit$', ForumTopicEditView.as_view(), name='edit_topic'), url(r'^topic/(?P<topic_id>[0-9]+)/edit$', ForumTopicEditView.as_view(), name='edit_topic'),
url(r'^topic/(?P<topic_id>[0-9]+)/new_message$', ForumMessageCreateView.as_view(), name='new_message'), url(r'^topic/(?P<topic_id>[0-9]+)/new_message$', ForumMessageCreateView.as_view(), name='new_message'),
url(r'^message/(?P<message_id>[0-9]+)/edit$', ForumMessageEditView.as_view(), name='edit_message'),
] ]

View File

@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse, reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.conf import settings from django.conf import settings
from django import forms from django import forms
from django.db import models
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
@ -38,6 +39,11 @@ class ForumDetailView(CanViewMixin, DetailView):
template_name = "forum/forum.jinja" template_name = "forum/forum.jinja"
pk_url_kwarg = "forum_id" pk_url_kwarg = "forum_id"
def get_context_data(self, **kwargs):
kwargs = super(ForumDetailView, self).get_context_data(**kwargs)
kwargs['topics'] = self.object.topics.annotate(models.Max('messages__date')).order_by('-messages__date__max')
return kwargs
class ForumTopicCreateView(CanCreateMixin, CreateView): class ForumTopicCreateView(CanCreateMixin, CreateView):
model = ForumMessage model = ForumMessage
fields = ['title', 'message'] fields = ['title', 'message']
@ -68,6 +74,12 @@ class ForumTopicDetailView(CanViewMixin, DetailView):
template_name = "forum/topic.jinja" template_name = "forum/topic.jinja"
context_object_name = "topic" context_object_name = "topic"
class ForumMessageEditView(CanEditMixin, UpdateView):
model = ForumMessage
fields = ['title', 'message']
template_name = "core/edit.jinja"
pk_url_kwarg = "message_id"
class ForumMessageCreateView(CanCreateMixin, CreateView): class ForumMessageCreateView(CanCreateMixin, CreateView):
model = ForumMessage model = ForumMessage
fields = ['title', 'message'] fields = ['title', 'message']