Skip to content

Commit

Permalink
Merge pull request #194 from leolivier:troves
Browse files Browse the repository at this point in the history
Fixed paginator issue + new Troves module
  • Loading branch information
leolivier authored Dec 31, 2024
2 parents 08b4d8a + 20aec64 commit fbc9e9e
Show file tree
Hide file tree
Showing 68 changed files with 1,543 additions and 1,113 deletions.
12 changes: 11 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,14 @@ BIRTHDAY_DAYS=50
# if you want to forbid members to create members, set to False and only admins will be able to do it
# ALLOW_MEMBERS_TO_CREATE_MEMBERS=True
# if you want to forbid members to invite members, set to False and only admins will be able to do it
# ALLOW_MEMBERS_TO_INVITE_MEMBERS=True
# ALLOW_MEMBERS_TO_INVITE_MEMBERS=True

# Troves settings
# Maximum size of a trove file
# TROVE_FILE_MAX_SIZE=20*1024*1024 # 20MB
# Maximum size of a trove picture
# TROVE_PICTURE_FILE_MAX_SIZE=5*1024*1024 # 5MB
# Maximum size of a trove thumbnail in pixels
# TROVE_THUMBNAIL_SIZE=GALLERIES_THUMBNAIL_SIZE
# Default number of troves per page
# DEFAULT_TROVE_PAGE_SIZE=10
51 changes: 28 additions & 23 deletions chat/views/views_private_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from members.models import Member
from ..models import ChatMessage, ChatRoom, PrivateChatRoom
from cousinsmatter.utils import Paginator, assert_request_is_ajax
from cousinsmatter.utils import PageOutOfBounds, Paginator, assert_request_is_ajax


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -95,21 +95,24 @@ def private_chat_rooms(request, page_num=1):
first_message_author=Subquery(first_msg_auth_subquery)
).order_by('date_added')

page = Paginator.get_page(request, private_chat_rooms, page_num,
reverse_link="chat:private_chat_page",
default_page_size=settings.DEFAULT_CHATROOMS_PER_PAGE)
author_ids = [room.first_message_author for room in page.object_list if room.first_message_author is not None]
# print("author ids", author_ids)
authors = Member.objects.filter(id__in=author_ids)
for room in page.object_list:
if room.first_message_author:
# print("first msg auth=", room.first_message_author)
for author in authors:
# print("author name:", author.username)
if room.first_message_author == author.id:
room.first_message_author = author
# print("final author:", room.first_message_author)
return render(request, 'chat/chat_rooms.html', {"page": page, 'private': True})
try:
page = Paginator.get_page(request, private_chat_rooms, page_num,
reverse_link="chat:private_chat_page",
default_page_size=settings.DEFAULT_CHATROOMS_PER_PAGE)
author_ids = [room.first_message_author for room in page.object_list if room.first_message_author is not None]
# print("author ids", author_ids)
authors = Member.objects.filter(id__in=author_ids)
for room in page.object_list:
if room.first_message_author:
# print("first msg auth=", room.first_message_author)
for author in authors:
# print("author name:", author.username)
if room.first_message_author == author.id:
room.first_message_author = author
# print("final author:", room.first_message_author)
return render(request, 'chat/chat_rooms.html', {"page": page, 'private': True})
except PageOutOfBounds as exc:
return redirect(exc.redirect_to)


@login_required
Expand Down Expand Up @@ -201,13 +204,15 @@ def private_chat_room(request, room_slug, page_num=None):
messages.error(request, _("You are not a member of this private room"))
return redirect(reverse('chat:private_chat_rooms'))
message_list = ChatMessage.objects.filter(room=room.id)

page = Paginator.get_page(request, message_list,
page_num=page_num,
reverse_link="chat:room_page",
compute_link=lambda page_num: reverse("chat:room_page", args=[room_slug, page_num]),
default_page_size=100)
return render(request, 'chat/room_detail.html', {'room': room, "page": page, "private": True})
try:
page = Paginator.get_page(request, message_list,
page_num=page_num,
reverse_link="chat:room_page",
compute_link=lambda page_num: reverse("chat:room_page", args=[room_slug, page_num]),
default_page_size=100)
return render(request, 'chat/room_detail.html', {'room': room, "page": page, "private": True})
except PageOutOfBounds as exc:
return redirect(exc.redirect_to)


@login_required
Expand Down
58 changes: 31 additions & 27 deletions chat/views/views_public_rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from members.models import Member
from ..models import ChatMessage, ChatRoom
from cousinsmatter.utils import Paginator, assert_request_is_ajax
from cousinsmatter.utils import PageOutOfBounds, Paginator, assert_request_is_ajax
from cm_main import followers

from urllib.parse import unquote
Expand All @@ -36,24 +36,26 @@ def chat_rooms(request, page_num=1):
num_messages=Count("chatmessage"),
first_message_author=Subquery(first_msg_auth_subquery)
).order_by('date_added')

page = Paginator.get_page(request,
object_list=chat_rooms,
page_num=page_num,
reverse_link="chat:chat_page",
default_page_size=settings.DEFAULT_CHATROOMS_PER_PAGE)
author_ids = [room.first_message_author for room in page.object_list if room.first_message_author is not None]
# print("author ids", author_ids)
authors = Member.objects.filter(id__in=author_ids)
for room in page.object_list:
if room.first_message_author:
# print("first msg auth=", room.first_message_author)
for author in authors:
# print("author name:", author.username)
if room.first_message_author == author.id:
room.first_message_author = author
# print("final author:", room.first_message_author)
return render(request, 'chat/chat_rooms.html', {"page": page})
try:
page = Paginator.get_page(request,
object_list=chat_rooms,
page_num=page_num,
reverse_link="chat:chat_page",
default_page_size=settings.DEFAULT_CHATROOMS_PER_PAGE)
author_ids = [room.first_message_author for room in page.object_list if room.first_message_author is not None]
# print("author ids", author_ids)
authors = Member.objects.filter(id__in=author_ids)
for room in page.object_list:
if room.first_message_author:
# print("first msg auth=", room.first_message_author)
for author in authors:
# print("author name:", author.username)
if room.first_message_author == author.id:
room.first_message_author = author
# print("final author:", room.first_message_author)
return render(request, 'chat/chat_rooms.html', {"page": page})
except PageOutOfBounds as exc:
return redirect(exc.redirect_to)


@login_required
Expand Down Expand Up @@ -88,14 +90,16 @@ def new_room(request):
def chat_room(request, room_slug, page_num=None):
room = get_object_or_404(ChatRoom, slug=room_slug)
messages = ChatMessage.objects.filter(room=room.id)

page = Paginator.get_page(request,
object_list=messages,
page_num=page_num,
reverse_link="chat:room_page",
compute_link=lambda page_num: reverse("chat:room_page", args=[room_slug, page_num]),
default_page_size=settings.DEFAULT_CHATMESSAGES_PER_PAGE)
return render(request, 'chat/room_detail.html', {'room': room, "page": page})
try:
page = Paginator.get_page(request,
object_list=messages,
page_num=page_num,
reverse_link="chat:room_page",
compute_link=lambda page_num: reverse("chat:room_page", args=[room_slug, page_num]),
default_page_size=settings.DEFAULT_CHATMESSAGES_PER_PAGE)
return render(request, 'chat/room_detail.html', {'room': room, "page": page})
except PageOutOfBounds as exc:
return redirect(exc.redirect_to)


@login_required
Expand Down
Binary file modified cm_main/locale/de/LC_MESSAGES/django.mo
Binary file not shown.
72 changes: 38 additions & 34 deletions cm_main/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Cousins Matter 0.1.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-11-11 19:57+0100\n"
"POT-Creation-Date: 2024-12-30 16:46+0100\n"
"PO-Revision-Date: 2024-10-21 09:03+00:00\n"
"Last-Translator: Olivier LEVILLAIN\n"
"Language-Team: German <LL@li.org>\n"
Expand Down Expand Up @@ -111,23 +111,23 @@ msgstr "Diese Seite zeigt einige Statistiken über diese Website an:"
msgid "Statistics"
msgstr "Statistiken"

#: templates/cm_main/base.html:8
#: templates/cm_main/base.html:9
msgid "Home"
msgstr "Heim"

#: templates/cm_main/base.html:68
#: templates/cm_main/base.html:69
msgid "This site proudly built using"
msgstr "Diese Website stolz gebaut mit"

#: templates/cm_main/base.html:70
#: templates/cm_main/base.html:71
msgid "The source code is licensed"
msgstr "Die Quellcode ist lizenziert"

#: templates/cm_main/base.html:76
#: templates/cm_main/base.html:77
msgid "Copyright © 2024 Cousins Matter. All rights reserved."
msgstr "Urheberrecht © 2024 Cousins Matter. Alle Rechte vorbehalten."

#: templates/cm_main/base.html:79 templates/cm_main/navbar.html:138
#: templates/cm_main/base.html:80 templates/cm_main/navbar.html:145
msgid "Contact the site admin"
msgstr "Kontaktiere den Site-Administrator"

Expand Down Expand Up @@ -166,25 +166,25 @@ msgstr "Schalten Sie die Notizbearbeitungs-Werkzeugleiste ein"
msgid "Remaining characters:"
msgstr "Verbleibende Zeichen:"

#: templates/cm_main/common/paginate_template.html:27
#: templates/cm_main/common/paginate_template.html:25
msgid "Items per page:"
msgstr "Items pro Seite:"

#: templates/cm_main/common/paginate_template.html:47
#: templates/cm_main/common/paginate_template.html:45
msgid "go to first page"
msgstr "Gehe zur ersten Seite"

#: templates/cm_main/common/paginate_template.html:59
#: templates/cm_main/common/paginate_template.html:57
#, python-format
msgid "go to page #%(page_num)s"
msgstr "Gehe zur Seite #%(page_num)s"

#: templates/cm_main/common/paginate_template.html:62
#: templates/cm_main/common/paginate_template.html:60
#, python-format
msgid "page #%(page_num)s"
msgstr "Seite #%(page_num)s"

#: templates/cm_main/common/paginate_template.html:75
#: templates/cm_main/common/paginate_template.html:73
msgid "go to last page"
msgstr "Gehe zur letzten Seite"

Expand Down Expand Up @@ -279,95 +279,99 @@ msgstr "Stopp Folgen"
msgid "Follow"
msgstr "Folgen"

#: templates/cm_main/navbar.html:26 views/views_stats.py:106
#: templates/cm_main/navbar.html:28 views/views_stats.py:106
msgid "Members"
msgstr "Mitglieder"

#: templates/cm_main/navbar.html:29
#: templates/cm_main/navbar.html:31
msgid "Birthdays"
msgstr "Geburtstag"

#: templates/cm_main/navbar.html:31
#: templates/cm_main/navbar.html:33
msgid "Show directory"
msgstr "Zeige Verzeichnis"

#: templates/cm_main/navbar.html:34
#: templates/cm_main/navbar.html:36
msgid "Create Member"
msgstr "Erstellen Sie Mitglied"

#: templates/cm_main/navbar.html:38
#: templates/cm_main/navbar.html:40
msgid "Invite Member"
msgstr "Einladung zum Mitglied werden"

#: templates/cm_main/navbar.html:45 views/views_stats.py:114
#: templates/cm_main/navbar.html:47 views/views_stats.py:114
msgid "Galleries"
msgstr "Gallerie"

#: templates/cm_main/navbar.html:48
#: templates/cm_main/navbar.html:50
msgid "Create Gallery"
msgstr "Erstelle Galerie"

#: templates/cm_main/navbar.html:50
#: templates/cm_main/navbar.html:52
msgid "Bulk Upload"
msgstr "Maschinelle Datenübertragung"

#: templates/cm_main/navbar.html:56
#: templates/cm_main/navbar.html:58
msgid "Forum"
msgstr "Forum"

#: templates/cm_main/navbar.html:59
#: templates/cm_main/navbar.html:61
msgid "Create Post"
msgstr "Erstelle einen Beitrag"

#: templates/cm_main/navbar.html:64
#: templates/cm_main/navbar.html:66
msgid "Chat"
msgstr "Chat"

#: templates/cm_main/navbar.html:67
#: templates/cm_main/navbar.html:69
msgid "Public Chat Rooms"
msgstr "Öffentliche Chaträume"

#: templates/cm_main/navbar.html:69
#: templates/cm_main/navbar.html:71
msgid "Private Chat Rooms"
msgstr "Privat-Chat-Rooms"

#: templates/cm_main/navbar.html:92
#: templates/cm_main/navbar.html:77
msgid "Troves"
msgstr "Schätze"

#: templates/cm_main/navbar.html:99
msgid "Change language"
msgstr "Sprache ändern"

#: templates/cm_main/navbar.html:112
#: templates/cm_main/navbar.html:119
msgid "Edit Pages"
msgstr "Bearbeiten Sie Seiten"

#: templates/cm_main/navbar.html:114
#: templates/cm_main/navbar.html:121
msgid "Import members from CSV"
msgstr "Importiere Mitglieder aus CSV"

#: templates/cm_main/navbar.html:115
#: templates/cm_main/navbar.html:122
msgid "Admin site"
msgstr "Verwaltungsseite"

#: templates/cm_main/navbar.html:118
#: templates/cm_main/navbar.html:125
msgid "Export Members as CSV"
msgstr "Exportiere Mitglieder als CSV"

#: templates/cm_main/navbar.html:136
#: templates/cm_main/navbar.html:143
msgid "About the site"
msgstr "Über den Site"

#: templates/cm_main/navbar.html:147
#: templates/cm_main/navbar.html:154
msgid "Sign in"
msgstr "Anmelden"

#: templates/cm_main/navbar.html:151
#: templates/cm_main/navbar.html:158
msgid "Request invitation link"
msgstr "Bitte um Einladungslink"

#: templates/cm_main/navbar.html:160
#: templates/cm_main/navbar.html:167
msgid "Profile"
msgstr "Profil"

#: templates/cm_main/navbar.html:162
#: templates/cm_main/navbar.html:169
msgid "Log Out"
msgstr "Ausloggen"

Expand Down
Binary file modified cm_main/locale/de/LC_MESSAGES/djangojs.mo
Binary file not shown.
12 changes: 7 additions & 5 deletions cm_main/locale/de/LC_MESSAGES/djangojs.po
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
# using the qwen2.5:3b model. Depending on the model, it may contain some errors and should be reviewed
# by a human translator. Also depending on the model, each translation can be preceded by an explanation provided
# by the model.
# <OWNER> <OWNER EMAIL>, 2024.
# Olivier LEVILLAIN <olivier@levillain.eu>, 2024.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Cousins Matter 0.1.0\n"
"Report-Msgid-Bugs-To: \n"
"Report-Msgid-Bugs-To: Olivier LEVILLAIN <olivier@levillain.eu>\n"
"POT-Creation-Date: 2024-04-28 16:06+0200\n"
"PO-Revision-Date: 2024-10-21 09:03+00:00\n"
"\n"
"Last-Translator: Auto-po-lyglot using qwen2.5:3b (https://github.com/leolivier/auto-po-lyglot)\n"
"PO-Revision-Date: 2024-12-30 12:56+0100\n"
"Last-Translator: Olivier LEVILLAIN <olivier@levillain.eu>\n"
"Language-Team: French <LL@li.org>\n"
"Language: DE\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -136,3 +135,6 @@ msgstr[1] "%s commentaires"
#. meaning.
msgid "profile"
msgstr "Profil"

msgid "Are you sure you want to delete this treasure?"
msgstr "Bist du sicher, dass du diesen Schatz löschen möchtest?"
Binary file modified cm_main/locale/es/LC_MESSAGES/django.mo
Binary file not shown.
Loading

0 comments on commit fbc9e9e

Please sign in to comment.