mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-25 18:44:23 +00:00
Some other great forum improvements
This commit is contained in:
parent
93f5096140
commit
653d9d4707
@ -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%;
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -3,13 +3,13 @@
|
||||
{% from 'core/macros.jinja' import user_profile_link %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
<div>
|
||||
<a href="{{ url('forum:main') }}">Forum</a>
|
||||
{% for f in forum.get_parent_list() %}
|
||||
> <a href="{{ f.get_absolute_url() }}">{{ f }}</a>
|
||||
{% endfor %}
|
||||
> <a href="{{ forum.get_absolute_url() }}">{{ forum }}</a>
|
||||
</p>
|
||||
</div>
|
||||
<h3>{{ forum.name }}</h3>
|
||||
<a href="{{ url('forum:new_forum') }}?parent={{ forum.id }}">New forum</a>
|
||||
{% for f in forum.children.all() %}
|
||||
@ -17,19 +17,31 @@
|
||||
{% endfor %}
|
||||
{% for t in topics %}
|
||||
<div class="topic">
|
||||
<p>
|
||||
<a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a>
|
||||
</p>
|
||||
<a href="{{ url('forum:view_topic', topic_id=t.id) }}">
|
||||
<div style="display: inline-block; width: 80%">
|
||||
<div class="ib w_medium">
|
||||
<a class="ib w_big" href="{{ url('forum:view_topic', topic_id=t.id) }}">
|
||||
<h5>{{ t.title }}</h5>
|
||||
<p>{{ t.description }}</p>
|
||||
</div>
|
||||
</a>
|
||||
<div style="display: inline-block; width: 19%">
|
||||
{% if user.can_edit(t) %}
|
||||
<div class="ib" style="text-align: center;">
|
||||
<a href="{{ url('forum:edit_topic', topic_id=t.id) }}">Edit</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="ib w_medium">
|
||||
<div class="ib w_medium">
|
||||
<div class="ib w_medium" style="text-align: center;">
|
||||
{{ user_profile_link(t.author) }}
|
||||
</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() %}
|
||||
<p>Last message by {{ user_profile_link(last_msg.author) }} at {{ last_msg.date|date(DATETIME_FORMAT) }} {{
|
||||
last_msg.date|time(DATETIME_FORMAT) }}</p>
|
||||
{{ user_profile_link(last_msg.author) }} <br/>
|
||||
{{ last_msg.date|date(DATETIME_FORMAT) }} {{ last_msg.date|time(DATETIME_FORMAT) }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
@ -1,17 +1,33 @@
|
||||
{% macro display_forum(forum) %}
|
||||
<div class="forum {% if forum.is_category %}category{% endif %}">
|
||||
<p>
|
||||
<a href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a>
|
||||
</p>
|
||||
<div class="ib w_big">
|
||||
{% if not forum.is_category %}
|
||||
<a href="{{ url('forum:view_forum', forum_id=forum.id) }}">
|
||||
<a class="ib w_big" href="{{ url('forum:view_forum', forum_id=forum.id) }}">
|
||||
{% else %}
|
||||
<div class="ib w_big">
|
||||
{% endif %}
|
||||
<div>
|
||||
<h5>{{ forum.name }}</h5>
|
||||
<p>{{ forum.description }}</p>
|
||||
</div>
|
||||
{% if not forum.is_category %}
|
||||
</a>
|
||||
{% else %}
|
||||
</div>
|
||||
{% endif %}
|
||||
<a class="ib" href="{{ url('forum:edit_forum', forum_id=forum.id) }}">Edit</a>
|
||||
</div>
|
||||
{% if not forum.is_category %}
|
||||
<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 %}
|
||||
</div>
|
||||
{% endmacro %}
|
||||
|
@ -40,21 +40,25 @@
|
||||
{% else %}
|
||||
<img src="{{ static('core/img/unknown.jpg') }}" alt="{% trans %}Profile{% endtrans %}" id="picture" />
|
||||
{% endif %}
|
||||
<br/>
|
||||
<strong>{{ user_profile_link(m.author) }}</strong>
|
||||
</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%;">
|
||||
{% 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/>
|
||||
{% 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>
|
||||
</div>
|
||||
<hr>
|
||||
<div>
|
||||
{{ m.message|markdown }}
|
||||
</div>
|
||||
|
@ -23,8 +23,10 @@ class ForumCreateView(CanCreateMixin, CreateView):
|
||||
|
||||
def get_initial(self):
|
||||
init = super(ForumCreateView, self).get_initial()
|
||||
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"
|
||||
|
Loading…
Reference in New Issue
Block a user