From 653d9d470716c64c5fcbd26b6ac18713e7da8a36 Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 21 Jan 2017 22:47:30 +0100 Subject: [PATCH] Some other great forum improvements --- core/static/core/style.css | 18 +++++++++++++- forum/admin.py | 6 ++++- forum/models.py | 20 ++++++++++++++- forum/templates/forum/forum.jinja | 40 +++++++++++++++++++----------- forum/templates/forum/macros.jinja | 36 +++++++++++++++++++-------- forum/templates/forum/topic.jinja | 12 ++++++--- forum/views.py | 8 +++--- 7 files changed, 106 insertions(+), 34 deletions(-) diff --git a/core/static/core/style.css b/core/static/core/style.css index 240347c1..8f3aaf34 100644 --- a/core/static/core/style.css +++ b/core/static/core/style.css @@ -11,6 +11,20 @@ a { } a:hover { color: #7FDBFF; } a:active { color: #007BE6; } +.ib { + display: inline-block; + padding: 2px; + margin: 2px; +} +.w_big { + width: 75%; +} +.w_medium { + width: 45%; +} +.w_small { + width: 20%; +} /*--------------------------------HEADER-------------------------------*/ #logo { margin-left: 5%; @@ -377,7 +391,8 @@ textarea { color: black; } .topic a:hover, .forum a:hover, .category a:hover { - color: #242424; + color: #424242; + text-decoration: underline; } .topic { border: solid skyblue 1px; @@ -403,6 +418,7 @@ textarea { .msg_author { display: inline-block; width: 19%; + text-align: center; } .msg_author img { max-width: 80%; diff --git a/forum/admin.py b/forum/admin.py index 8c38f3f3..162589b1 100644 --- a/forum/admin.py +++ b/forum/admin.py @@ -1,3 +1,7 @@ from django.contrib import admin -# Register your models here. +from forum.models import * + +admin.site.register(Forum) +admin.site.register(ForumTopic) +admin.site.register(ForumMessage) diff --git a/forum/models.py b/forum/models.py index 59605114..a69e5b0d 100644 --- a/forum/models.py +++ b/forum/models.py @@ -52,6 +52,24 @@ class Forum(models.Model): p = p.parent return l + def get_topic_number(self): + number = self.topics.all().count() + for c in self.children.all(): + number += c.get_topic_number() + return number + + def get_last_message(self): + last_msg = None + for m in ForumMessage.objects.order_by('-id'): + forum = m.topic.forum + if self in (forum.get_parent_list() + [forum]): + return m + last_msg = m + try: + pass + except: pass + return last_msg + class ForumTopic(models.Model): forum = models.ForeignKey(Forum, related_name='topics') author = models.ForeignKey(User, related_name='forum_topics') @@ -93,7 +111,7 @@ class ForumMessage(models.Model): return self.topic.is_owned_by(user) or user.id == self.author.id def can_be_edited_by(self, user): - return user.can_edit(self.topic) + return user.is_owner(self.topic) def can_be_viewed_by(self, user): return user.can_view(self.topic) diff --git a/forum/templates/forum/forum.jinja b/forum/templates/forum/forum.jinja index 9a159082..624b13f2 100644 --- a/forum/templates/forum/forum.jinja +++ b/forum/templates/forum/forum.jinja @@ -3,13 +3,13 @@ {% from 'core/macros.jinja' import user_profile_link %} {% block content %} -

+

Forum {% for f in forum.get_parent_list() %} > {{ f }} {% endfor %} > {{ forum }} -

+

{{ forum.name }}

New forum {% for f in forum.children.all() %} @@ -17,19 +17,31 @@ {% endfor %} {% for t in topics %}
-

- Edit -

- -
-
{{ t.title }}
-

{{ t.description }}

+
+ +
{{ t.title }}
+

{{ t.description }}

+
+ {% if user.can_edit(t) %} +
+ Edit +
+ {% endif %}
- -
- {% 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) }}

+
+
+
+ {{ user_profile_link(t.author) }} +
+
+ {{ t.messages.count() }} +
+
+
+ {% set last_msg = t.messages.order_by('id').last() %} + {{ user_profile_link(last_msg.author) }}
+ {{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }} +
{% endfor %} diff --git a/forum/templates/forum/macros.jinja b/forum/templates/forum/macros.jinja index bbb1e3d7..1e83ac80 100644 --- a/forum/templates/forum/macros.jinja +++ b/forum/templates/forum/macros.jinja @@ -1,17 +1,33 @@ {% macro display_forum(forum) %}
-

- Edit -

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

{{ forum.description }}

+
{% if not forum.is_category %} - +
+
+ {{ forum.get_topic_number() }} +
+
+ {% set last_msg = forum.get_last_message() %} + {% if last_msg %} + {{ last_msg.author }}
+ {{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }} + {% endif %} +
+
{% endif %}
{% endmacro %} diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja index 6fb562c8..9d624cb0 100644 --- a/forum/templates/forum/topic.jinja +++ b/forum/templates/forum/topic.jinja @@ -40,21 +40,25 @@ {% else %} {% trans %}Profile{% endtrans %} {% endif %} +
{{ user_profile_link(m.author) }}
-
+
{% if m.title %}
{{ m.title }}
-
{% endif %}
- {% trans %}Edit{% endtrans %} - {% trans %}Reply as quote{% endtrans %}
+ {% trans %}Reply as quote{% endtrans %} + {% if user.can_edit(m) %} + {% trans %}Edit{% endtrans %} + {% endif %} +
{{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }}
+
{{ m.message|markdown }}
diff --git a/forum/views.py b/forum/views.py index 5f172c99..73da4e56 100644 --- a/forum/views.py +++ b/forum/views.py @@ -23,8 +23,10 @@ class ForumCreateView(CanCreateMixin, CreateView): def get_initial(self): init = super(ForumCreateView, self).get_initial() - parent = Forum.objects.filter(id=self.request.GET['parent']).first() - init['parent'] = parent + try: + parent = Forum.objects.filter(id=self.request.GET['parent']).first() + init['parent'] = parent + except: pass return init class ForumEditView(CanEditPropMixin, UpdateView): @@ -62,7 +64,7 @@ class ForumTopicCreateView(CanCreateMixin, CreateView): form.instance.author = self.request.user return super(ForumTopicCreateView, self).form_valid(form) -class ForumTopicEditView(CanEditPropMixin, UpdateView): +class ForumTopicEditView(CanEditMixin, UpdateView): model = ForumTopic fields = ['title', 'forum'] pk_url_kwarg = "topic_id"