From f262014f9bfd591afebbd3d37fa46971145d2dc6 Mon Sep 17 00:00:00 2001 From: Skia Date: Fri, 24 Feb 2017 04:37:01 +0100 Subject: [PATCH] Some various forum fixes and improvements --- forum/templates/forum/forum.jinja | 6 +++--- forum/templates/forum/macros.jinja | 4 ++-- forum/templates/forum/main.jinja | 2 +- forum/templates/forum/topic.jinja | 5 +++-- forum/views.py | 18 +++++++++++------- 5 files changed, 20 insertions(+), 15 deletions(-) diff --git a/forum/templates/forum/forum.jinja b/forum/templates/forum/forum.jinja index dff85d15..a159f1e1 100644 --- a/forum/templates/forum/forum.jinja +++ b/forum/templates/forum/forum.jinja @@ -7,7 +7,7 @@ {% block content %}
- Forum + {% trans %}Forum{% endtrans %} {% for f in forum.get_parent_list() %} > {{ f }} {% endfor %} @@ -16,9 +16,9 @@

{{ forum.name }}

{% if user.is_in_group(settings.SITH_GROUP_FORUM_ADMIN_ID) or user.is_in_group(settings.SITH_GROUP_COM_ADMIN_ID) %} - New forum
+ {% trans %}New forum{% endtrans %}
{% endif %} - New topic + {% trans %}New topic{% endtrans %}

{% for f in forum.children.all() %} {{ display_forum(f, user) }} diff --git a/forum/templates/forum/macros.jinja b/forum/templates/forum/macros.jinja index 7c5fbc2b..8617ad60 100644 --- a/forum/templates/forum/macros.jinja +++ b/forum/templates/forum/macros.jinja @@ -16,8 +16,8 @@
{% endif %} {% if user.is_owner(forum) %} - Edit - Delete + {% trans %}Edit{% endtrans %} + {% trans %}Delete{% endtrans %} {% endif %} {% if not forum.is_category %} diff --git a/forum/templates/forum/main.jinja b/forum/templates/forum/main.jinja index ce304def..243cbb12 100644 --- a/forum/templates/forum/main.jinja +++ b/forum/templates/forum/main.jinja @@ -8,7 +8,7 @@ {% block content %}

- Forum > + {% trans %}Forum{% endtrans %} >

{% trans %}Forum{% endtrans %}

diff --git a/forum/templates/forum/topic.jinja b/forum/templates/forum/topic.jinja index bf199cca..126c1dcb 100644 --- a/forum/templates/forum/topic.jinja +++ b/forum/templates/forum/topic.jinja @@ -26,7 +26,7 @@ {% block content %}

- Forum + {% trans %}Forum{% endtrans %} {% for f in topic.forum.get_parent_list() %} > {{ f }} {% endfor %} @@ -52,7 +52,8 @@
{{ user_profile_link(m.author) }} -

+
{% if m.title %}
{{ m.title }}
diff --git a/forum/views.py b/forum/views.py index 11323968..7b504bfc 100644 --- a/forum/views.py +++ b/forum/views.py @@ -10,7 +10,7 @@ from django import forms from django.db import models from django.core.exceptions import PermissionDenied -import math +from ajax_select import make_ajax_form, make_ajax_field from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from forum.models import Forum, ForumMessage, ForumTopic, ForumMessageMeta @@ -40,9 +40,16 @@ class ForumLastUnread(ListView): date__gt=self.request.user.forum_infos.last_read_date).values_list('topic') # TODO try to do better return self.model.objects.filter(id__in=l).annotate(models.Max('messages__date')).order_by('-messages__date__max').select_related('author') +class ForumForm(forms.ModelForm): + class Meta: + model = Forum + fields = ['name', 'parent', 'owner_club', 'is_category', 'edit_groups', 'view_groups'] + edit_groups = make_ajax_field(Forum, 'edit_groups', 'groups', help_text="") + view_groups = make_ajax_field(Forum, 'view_groups', 'groups', help_text="") + class ForumCreateView(CanCreateMixin, CreateView): model = Forum - fields = ['name', 'parent', 'owner_club', 'is_category', 'edit_groups', 'view_groups'] + form_class = ForumForm template_name = "core/create.jinja" def get_initial(self): @@ -54,10 +61,7 @@ class ForumCreateView(CanCreateMixin, CreateView): except: pass return init -class ForumEditForm(forms.ModelForm): - class Meta: - model = Forum - fields = ['name', 'parent', 'owner_club', 'is_category', 'edit_groups', 'view_groups'] +class ForumEditForm(ForumForm): recursive = forms.BooleanField(label=_("Apply rights and club owner recursively"), required=False) class ForumEditView(CanEditPropMixin, UpdateView): @@ -126,7 +130,7 @@ class ForumTopicDetailView(CanViewMixin, DetailView): try: kwargs['first_unread_message_id'] = msg.id except: - kwargs['first_unread_message_id'] = math.inf + kwargs['first_unread_message_id'] = float("inf") return kwargs class ForumMessageEditView(CanEditMixin, UpdateView):