Some other great forum improvements

This commit is contained in:
Skia 2017-01-21 22:47:30 +01:00
parent 93f5096140
commit 653d9d4707
7 changed files with 106 additions and 34 deletions

View File

@ -11,6 +11,20 @@ a {
} }
a:hover { color: #7FDBFF; } a:hover { color: #7FDBFF; }
a:active { color: #007BE6; } 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-------------------------------*/ /*--------------------------------HEADER-------------------------------*/
#logo { #logo {
margin-left: 5%; margin-left: 5%;
@ -377,7 +391,8 @@ textarea {
color: black; color: black;
} }
.topic a:hover, .forum a:hover, .category a:hover { .topic a:hover, .forum a:hover, .category a:hover {
color: #242424; color: #424242;
text-decoration: underline;
} }
.topic { .topic {
border: solid skyblue 1px; border: solid skyblue 1px;
@ -403,6 +418,7 @@ textarea {
.msg_author { .msg_author {
display: inline-block; display: inline-block;
width: 19%; width: 19%;
text-align: center;
} }
.msg_author img { .msg_author img {
max-width: 80%; max-width: 80%;

View File

@ -1,3 +1,7 @@
from django.contrib import admin 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)

View File

@ -52,6 +52,24 @@ class Forum(models.Model):
p = p.parent p = p.parent
return l 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): class ForumTopic(models.Model):
forum = models.ForeignKey(Forum, related_name='topics') forum = models.ForeignKey(Forum, related_name='topics')
author = models.ForeignKey(User, related_name='forum_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 return self.topic.is_owned_by(user) or user.id == self.author.id
def can_be_edited_by(self, user): 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): def can_be_viewed_by(self, user):
return user.can_view(self.topic) return user.can_view(self.topic)

View File

@ -3,13 +3,13 @@
{% from 'core/macros.jinja' import user_profile_link %} {% from 'core/macros.jinja' import user_profile_link %}
{% block content %} {% block content %}
<p> <div>
<a href="{{ url('forum:main') }}">Forum</a> <a href="{{ url('forum:main') }}">Forum</a>
{% for f in forum.get_parent_list() %} {% for f in forum.get_parent_list() %}
> <a href="{{ f.get_absolute_url() }}">{{ f }}</a> > <a href="{{ f.get_absolute_url() }}">{{ f }}</a>
{% endfor %} {% endfor %}
> <a href="{{ forum.get_absolute_url() }}">{{ forum }}</a> > <a href="{{ forum.get_absolute_url() }}">{{ forum }}</a>
</p> </div>
<h3>{{ forum.name }}</h3> <h3>{{ forum.name }}</h3>
<a href="{{ url('forum:new_forum') }}?parent={{ forum.id }}">New forum</a> <a href="{{ url('forum:new_forum') }}?parent={{ forum.id }}">New forum</a>
{% for f in forum.children.all() %} {% for f in forum.children.all() %}
@ -17,19 +17,31 @@
{% endfor %} {% endfor %}
{% for t in topics %} {% for t in topics %}
<div class="topic"> <div class="topic">
<p> <div class="ib w_medium">
<a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a> <a class="ib w_big" href="{{ url('forum:view_topic', topic_id=t.id) }}">
</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%"> </a>
<h5>{{ t.title }}</h5> {% if user.can_edit(t) %}
<p>{{ t.description }}</p> <div class="ib" style="text-align: center;">
<a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a>
</div>
{% endif %}
</div> </div>
</a> <div class="ib w_medium">
<div style="display: inline-block; width: 19%"> <div class="ib w_medium">
{% set last_msg = t.messages.order_by('id').last() %} <div class="ib w_medium" style="text-align: center;">
<p>Last message by {{ user_profile_link(last_msg.author) }} at {{ last_msg.date|date(DATETIME_FORMAT) }} {{ {{ user_profile_link(t.author) }}
last_msg.date|time(DATETIME_FORMAT) }}</p> </div>
<div class="ib w_medium" style="text-align: center;">
{{ t.messages.count() }}
</div>
</div>
<div class="ib w_medium" style="text-align: center;">
{% set last_msg = t.messages.order_by('id').last() %}
{{ user_profile_link(last_msg.author) }} <br/>
{{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
</div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}

View File

@ -1,17 +1,33 @@
{% 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> <div class="ib w_big">
<a href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a> {% if not forum.is_category %}
</p> <a class="ib w_big" href="{{ url('forum:view_forum', forum_id=forum.id) }}">
{% if not forum.is_category %} {% else %}
<a href="{{ url('forum:view_forum', forum_id=forum.id) }}"> <div class="ib w_big">
{% endif %} {% endif %}
<div> <h5>{{ forum.name }}</h5>
<h5>{{ forum.name }}</h5> <p>{{ forum.description }}</p>
<p>{{ forum.description }}</p> {% if not forum.is_category %}
</a>
{% else %}
</div>
{% endif %}
<a class="ib" href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a>
</div> </div>
{% if not forum.is_category %} {% if not forum.is_category %}
</a> <div class="ib w_small">
<div class="ib w_medium">
{{ forum.get_topic_number() }}
</div>
<div class="ib w_medium">
{% set last_msg = forum.get_last_message() %}
{% if last_msg %}
{{ last_msg.author }} <br/>
{{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
{% endif %}
</div>
</div>
{% endif %} {% endif %}
</div> </div>
{% endmacro %} {% endmacro %}

View File

@ -40,21 +40,25 @@
{% else %} {% else %}
<img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" /> <img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
{% endif %} {% endif %}
<br/>
<strong>{{ user_profile_link(m.author) }}</strong> <strong>{{ user_profile_link(m.author) }}</strong>
</div> </div>
<div style="display: inline-block; width: 80%;"> <div style="display: inline-block; width: 80%; vertical-align: top;">
<div style="display: inline-block; width: 74%;"> <div style="display: inline-block; width: 74%;">
{% if m.title %} {% if m.title %}
<h5>{{ m.title }}</h5> <h5>{{ m.title }}</h5>
<hr>
{% endif %} {% endif %}
</div> </div>
<div style="display: inline-block; width: 25%;"> <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 }}"> <span><a href="{{ url('forum:new_message', topic_id=topic.id) }}?quote_id={{ m.id }}">
{% trans %}Reply as quote{% endtrans %}</a></span><br/> {% trans %}Reply as quote{% endtrans %}</a></span>
{% if user.can_edit(m) %}
<span> <a href="{{ url('forum:edit_message', message_id=m.id) }}">{% trans %}Edit{% endtrans %}</a></span>
{% endif %}
<br/>
<span>{{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }}</span> <span>{{ m.date|date(DATETIME_FORMAT) }} {{ m.date|time(DATETIME_FORMAT) }}</span>
</div> </div>
<hr>
<div> <div>
{{ m.message|markdown }} {{ m.message|markdown }}
</div> </div>

View File

@ -23,8 +23,10 @@ class ForumCreateView(CanCreateMixin, CreateView):
def get_initial(self): def get_initial(self):
init = super(ForumCreateView, self).get_initial() init = super(ForumCreateView, self).get_initial()
parent = Forum.objects.filter(id=self.request.GET['parent']).first() try:
init['parent'] = parent parent = Forum.objects.filter(id=self.request.GET['parent']).first()
init['parent'] = parent
except: pass
return init return init
class ForumEditView(CanEditPropMixin, UpdateView): class ForumEditView(CanEditPropMixin, UpdateView):
@ -62,7 +64,7 @@ class ForumTopicCreateView(CanCreateMixin, CreateView):
form.instance.author = self.request.user form.instance.author = self.request.user
return super(ForumTopicCreateView, self).form_valid(form) return super(ForumTopicCreateView, self).form_valid(form)
class ForumTopicEditView(CanEditPropMixin, UpdateView): class ForumTopicEditView(CanEditMixin, UpdateView):
model = ForumTopic model = ForumTopic
fields = ['title', 'forum'] fields = ['title', 'forum']
pk_url_kwarg = "topic_id" pk_url_kwarg = "topic_id"