From 93f5096140ef1f1e5540fb090ec7bc7d2edf6bbc Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 21 Jan 2017 12:28:32 +0100 Subject: [PATCH] Improve forum style and templates --- core/static/core/style.css | 36 ++++++++++++++++++++++++++++++ forum/templates/forum/forum.jinja | 36 +++++++++++------------------- forum/templates/forum/macros.jinja | 15 ++++++++----- forum/templates/forum/main.jinja | 14 ------------ forum/templates/forum/topic.jinja | 33 +++++++++++++++++++++------ forum/urls.py | 1 + forum/views.py | 12 ++++++++++ 7 files changed, 98 insertions(+), 49 deletions(-) diff --git a/core/static/core/style.css b/core/static/core/style.css index d5aef3de..240347c1 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -372,6 +372,42 @@ textarea { 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------------------------------------*/ .album { display: inline-block; diff --git a/forum/templates/forum/forum.jinja b/forum/templates/forum/forum.jinja index 1e052c9a..9a159082 100644 --- a/forum/templates/forum/forum.jinja +++ b/forum/templates/forum/forum.jinja @@ -1,24 +1,6 @@ {% extends "core/base.jinja" %} {% from 'forum/macros.jinja' import display_forum %} - -{% block head %} -{{ super() }} - -{% endblock %} +{% from 'core/macros.jinja' import user_profile_link %} {% block content %}

@@ -33,14 +15,22 @@ {% for f in forum.children.all() %} {{ display_forum(f) }} {% endfor %} - {% for t in forum.topics.all() %} + {% for t in topics %}

- View Edit

-
{{ t.title }}
-

{{ t.description }}

+ +
+
{{ t.title }}
+

{{ t.description }}

+
+
+
+ {% set last_msg = t.messages.order_by('id').last() %} +

Last message by {{ user_profile_link(last_msg.author) }} at {{ last_msg.date|date(DATETIME_FORMAT) }} {{ + last_msg.date|time(DATETIME_FORMAT) }}

+
{% endfor %} New topic diff --git a/forum/templates/forum/macros.jinja b/forum/templates/forum/macros.jinja index cda278ea..bbb1e3d7 100644 --- a/forum/templates/forum/macros.jinja +++ b/forum/templates/forum/macros.jinja @@ -1,13 +1,18 @@ {% macro display_forum(forum) %}

- {% if not forum.is_category %} - View - {% endif %} Edit

-
{{ forum.name }}
-

{{ forum.description }}

+ {% if not forum.is_category %} + + {% endif %} +
+
{{ forum.name }}
+

{{ forum.description }}

+
+ {% if not forum.is_category %} +
+ {% endif %}
{% endmacro %} diff --git a/forum/templates/forum/main.jinja b/forum/templates/forum/main.jinja index 12c75b19..ab83abf3 100644 --- a/forum/templates/forum/main.jinja +++ b/forum/templates/forum/main.jinja @@ -2,20 +2,6 @@ {% from 'core/macros.jinja' import user_profile_link %} {% from 'forum/macros.jinja' import display_forum %} -{% block head %} -{{ super() }} - -{% endblock %} - {% block content %}

Forum > diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja index 0909b51c..6fb562c8 100644 --- a/forum/templates/forum/topic.jinja +++ b/forum/templates/forum/topic.jinja @@ -33,13 +33,32 @@

{{ topic.description }}

Reply

{% for m in topic.messages.all() %} -
-
-
{{ m.title }}
-

{{ user_profile_link(m.author) }} - {{ m.date|date(DATETIME_FORMAT) }} - {{ m.date|time(DATETIME_FORMAT) }} - - Reply as quote

-

{{ m.message|markdown }}

+
+
+ {% if m.author.profile_pict %} + {% trans %}Profile{% endtrans %} + {% else %} + {% trans %}Profile{% endtrans %} + {% endif %} + {{ user_profile_link(m.author) }} +
+
+
+ {% if m.title %} +
{{ m.title }}
+
+ {% endif %} +
+
+ {% trans %}Edit{% endtrans %} + + {% trans %}Reply as quote{% endtrans %}
+ {{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }} +
+
+ {{ m.message|markdown }} +
+
{% endfor %} {% endblock %} diff --git a/forum/urls.py b/forum/urls.py index ef1c180e..e7e8ae8d 100644 --- a/forum/urls.py +++ b/forum/urls.py @@ -11,5 +11,6 @@ urlpatterns = [ url(r'^topic/(?P[0-9]+)$', ForumTopicDetailView.as_view(), name='view_topic'), url(r'^topic/(?P[0-9]+)/edit$', ForumTopicEditView.as_view(), name='edit_topic'), url(r'^topic/(?P[0-9]+)/new_message$', ForumMessageCreateView.as_view(), name='new_message'), + url(r'^message/(?P[0-9]+)/edit$', ForumMessageEditView.as_view(), name='edit_message'), ] diff --git a/forum/views.py b/forum/views.py index e1126bef..5f172c99 100644 --- a/forum/views.py +++ b/forum/views.py @@ -6,6 +6,7 @@ from django.core.urlresolvers import reverse, reverse_lazy from django.utils import timezone from django.conf import settings from django import forms +from django.db import models from django.core.exceptions import PermissionDenied from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin @@ -38,6 +39,11 @@ class ForumDetailView(CanViewMixin, DetailView): template_name = "forum/forum.jinja" 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): model = ForumMessage fields = ['title', 'message'] @@ -68,6 +74,12 @@ class ForumTopicDetailView(CanViewMixin, DetailView): template_name = "forum/topic.jinja" 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): model = ForumMessage fields = ['title', 'message']