From 4dd6f01e60f1fb76cc8b78d3beedb21fcb86164e Mon Sep 17 00:00:00 2001 From: Skia Date: Sat, 21 Jan 2017 04:19:15 +0100 Subject: [PATCH] Add Ariadne's thread --- forum/models.py | 7 +++++-- forum/templates/forum/forum.jinja | 8 +++++++- forum/templates/forum/main.jinja | 3 +++ forum/templates/forum/topic.jinja | 12 +++++++++++- forum/views.py | 10 ++++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/forum/models.py b/forum/models.py index a9953066..0ae36af0 100644 --- a/forum/models.py +++ b/forum/models.py @@ -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() diff --git a/forum/templates/forum/forum.jinja b/forum/templates/forum/forum.jinja index 6b0fa851..1e052c9a 100644 --- a/forum/templates/forum/forum.jinja +++ b/forum/templates/forum/forum.jinja @@ -21,7 +21,13 @@ {% endblock %} {% block content %} -

{{ forum.get_parent_list() }}

+

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

{{ forum.name }}

New forum {% for f in forum.children.all() %} diff --git a/forum/templates/forum/main.jinja b/forum/templates/forum/main.jinja index 0477e50f..12c75b19 100644 --- a/forum/templates/forum/main.jinja +++ b/forum/templates/forum/main.jinja @@ -17,6 +17,9 @@ {% endblock %} {% block content %} +

+ Forum > +

{% trans %}Forum{% endtrans %}

New forum {% for f in forum_list %} diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja index 9005d62b..0909b51c 100644 --- a/forum/templates/forum/topic.jinja +++ b/forum/templates/forum/topic.jinja @@ -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 %} +

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

{{ topic.title }}

{{ topic.description }}

Reply

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

{{ m.author.get_display_name() }} - {{ m.date|date(DATETIME_FORMAT) }} +

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

{{ m.message|markdown }}

diff --git a/forum/views.py b/forum/views.py index bf642f66..fef22b34 100644 --- a/forum/views.py +++ b/forum/views.py @@ -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"