Add Ariadne's thread

This commit is contained in:
Skia 2017-01-21 04:19:15 +01:00
parent ea52462217
commit 4dd6f01e60
5 changed files with 32 additions and 8 deletions

View File

@ -56,7 +56,10 @@ class ForumTopic(models.Model):
description = models.CharField(_('description'), max_length=256, default="")
class Meta:
ordering = ['-id']
ordering = ['-id'] # TODO: add date message ordering
def __str__(self):
return "%s" % (self.title)
def get_absolute_url(self):
return reverse('forum:view_topic', kwargs={'topic_id': self.id})
@ -72,7 +75,7 @@ class ForumMessage(models.Model):
date = models.DateTimeField(_('date'), default=timezone.now)
class Meta:
ordering = ['-id']
ordering = ['id']
def get_absolute_url(self):
return self.topic.get_absolute_url()

View File

@ -21,7 +21,13 @@
{% endblock %}
{% block content %}
<p>{{ forum.get_parent_list() }}</p>
<p>
<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>
<h3>{{ forum.name }}</h3>
<a href="{{ url('forum:new_forum') }}?parent={{ forum.id }}">New forum</a>
{% for f in forum.children.all() %}

View File

@ -17,6 +17,9 @@
{% endblock %}
{% block content %}
<p>
<a href="{{ url('forum:main') }}">Forum</a> >
</p>
<h3>{% trans %}Forum{% endtrans %}</h3>
<a href="{{ url('forum:new_forum') }}">New forum</a>
{% for f in forum_list %}

View File

@ -1,4 +1,5 @@
{% extends "core/base.jinja" %}
{% from 'core/macros.jinja' import user_profile_link %}
{% block head %}
{{ super() }}
@ -20,13 +21,22 @@
{% endblock %}
{% block content %}
<p>
<a href="{{ url('forum:main') }}">Forum</a>
{% for f in topic.forum.get_parent_list() %}
> <a href="{{ f.get_absolute_url() }}">{{ f }}</a>
{% endfor %}
> <a href="{{ topic.forum.get_absolute_url() }}">{{ topic.forum }}</a>
> <a href="{{ topic.get_absolute_url() }}">{{ topic }}</a>
</p>
<h3>{{ topic.title }}</h3>
<p>{{ topic.description }}</p>
<p><a href="{{ url('forum:new_message', topic_id=topic.id) }}">Reply</a></p>
{% for m in topic.messages.all() %}
<hr>
<div>
<h5>{{ m.title }}</h5>
<p><strong>{{ m.author.get_display_name() }}</strong> - {{ m.date|date(DATETIME_FORMAT) }}
<p><strong>{{ user_profile_link(m.author) }}</strong> - {{ m.date|date(DATETIME_FORMAT) }}
{{ m.date|time(DATETIME_FORMAT) }} -
<a href="{{ url('forum:new_message', topic_id=topic.id) }}?quote_id={{ m.id }}">Reply as quote</a></p>
<p>{{ m.message|markdown }}</p>

View File

@ -38,8 +38,8 @@ class ForumDetailView(DetailView):
pk_url_kwarg = "forum_id"
class ForumTopicCreateView(CreateView):
model = ForumTopic
fields = ['title']
model = ForumMessage
fields = ['title', 'message']
template_name = "core/create.jinja"
def dispatch(self, request, *args, **kwargs):
@ -49,13 +49,15 @@ class ForumTopicCreateView(CreateView):
return super(ForumTopicCreateView, self).dispatch(request, *args, **kwargs)
def form_valid(self, form):
form.instance.forum = self.forum
topic = ForumTopic(title=form.instance.title, author=self.request.user, forum=self.forum)
topic.save()
form.instance.topic = topic
form.instance.author = self.request.user
return super(ForumTopicCreateView, self).form_valid(form)
class ForumTopicEditView(UpdateView):
model = ForumTopic
fields = ['title']
fields = ['title', 'forum']
pk_url_kwarg = "topic_id"
template_name = "core/edit.jinja"