mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-23 19:36:56 -08:00
put recently used languages first in the list #210
This commit is contained in:
parent
a9aef1ab0d
commit
4c64631b8a
4 changed files with 26 additions and 10 deletions
|
@ -550,7 +550,6 @@ def add_discussion_post(actor):
|
|||
else:
|
||||
form.communities.data = community.id
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
if community.posting_warning:
|
||||
flash(community.posting_warning)
|
||||
|
||||
|
@ -633,7 +632,6 @@ def add_image_post(actor):
|
|||
else:
|
||||
form.communities.data = community.id
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
|
||||
return render_template('community/add_image_post.html', title=_('Add post to community'), form=form, community=community,
|
||||
markdown_editor=current_user.markdown_editor, low_bandwidth=False, actor=actor,
|
||||
|
@ -714,7 +712,6 @@ def add_link_post(actor):
|
|||
else:
|
||||
form.communities.data = community.id
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
|
||||
return render_template('community/add_link_post.html', title=_('Add post to community'), form=form, community=community,
|
||||
markdown_editor=current_user.markdown_editor, low_bandwidth=False, actor=actor,
|
||||
|
@ -795,7 +792,6 @@ def add_video_post(actor):
|
|||
else:
|
||||
form.communities.data = community.id
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
|
||||
return render_template('community/add_video_post.html', title=_('Add post to community'), form=form, community=community,
|
||||
markdown_editor=current_user.markdown_editor, low_bandwidth=False, actor=actor,
|
||||
|
@ -862,7 +858,6 @@ def add_poll_post(actor):
|
|||
else:
|
||||
form.communities.data = community.id
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
form.finish_in.data = '3d'
|
||||
if community.posting_warning:
|
||||
flash(community.posting_warning)
|
||||
|
|
|
@ -28,7 +28,7 @@ from app.utils import render_template, get_setting, gibberish, request_etag_matc
|
|||
ap_datetime, ip_address, retrieve_block_list, shorten_string, markdown_to_text, user_filters_home, \
|
||||
joined_communities, moderating_communities, parse_page, theme_list, get_request, markdown_to_html, allowlist_html, \
|
||||
blocked_instances, communities_banned_from, topic_tree, recently_upvoted_posts, recently_downvoted_posts, \
|
||||
generate_image_from_video_url, blocked_users, microblog_content_to_title, menu_topics
|
||||
generate_image_from_video_url, blocked_users, microblog_content_to_title, menu_topics, languages_for_form
|
||||
from app.models import Community, CommunityMember, Post, Site, User, utcnow, Domain, Topic, File, Instance, \
|
||||
InstanceRole, Notification, Language, community_language, PostReply
|
||||
from PIL import Image
|
||||
|
@ -397,6 +397,8 @@ def list_files(directory):
|
|||
@bp.route('/test')
|
||||
def test():
|
||||
|
||||
x = languages_for_form()
|
||||
|
||||
#for community in Community.query.filter(Community.content_retention != -1):
|
||||
# for post in community.posts.filter(Post.posted_at < utcnow() - timedelta(days=Community.content_retention)):
|
||||
# post.delete_dependencies()
|
||||
|
|
|
@ -227,7 +227,6 @@ def show_post(post_id: int):
|
|||
else:
|
||||
replies = post_replies(post.id, sort)
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
|
||||
og_image = post.image.source_url if post.image_id else None
|
||||
description = shorten_string(markdown_to_text(post.body), 150) if post.body else None
|
||||
|
@ -838,7 +837,6 @@ def add_reply(post_id: int, comment_id: int):
|
|||
return redirect(url_for('post.continue_discussion', post_id=post_id, comment_id=reply.parent_id))
|
||||
else:
|
||||
form.notify_author.data = True
|
||||
form.language_id.data = current_user.language_id if current_user.is_authenticated and current_user.language_id else english_language_id()
|
||||
|
||||
return render_template('post/add_reply.html', title=_('Discussing %(title)s', title=post.title), post=post,
|
||||
is_moderator=is_moderator, form=form, comment=in_reply_to, markdown_editor=current_user.is_authenticated and current_user.markdown_editor,
|
||||
|
|
25
app/utils.py
25
app/utils.py
|
@ -1049,9 +1049,30 @@ def recently_downvoted_post_replies(user_id) -> List[int]:
|
|||
|
||||
def languages_for_form():
|
||||
result = []
|
||||
for language in Language.query.order_by(Language.name).all():
|
||||
if language.code != 'und':
|
||||
used_languages = []
|
||||
if current_user.is_authenticated:
|
||||
recently_used_post_languages = db.session.execute(text("""SELECT language_id
|
||||
FROM (
|
||||
SELECT language_id, posted_at
|
||||
FROM "post"
|
||||
WHERE user_id = :user_id
|
||||
UNION ALL
|
||||
SELECT language_id, posted_at
|
||||
FROM "post_reply"
|
||||
WHERE user_id = :user_id
|
||||
) AS subquery
|
||||
GROUP BY language_id
|
||||
ORDER BY MAX(posted_at) DESC
|
||||
LIMIT 4"""),
|
||||
{'user_id': current_user.id}).scalars()
|
||||
for language in Language.query.filter(Language.id.in_(recently_used_post_languages)).all():
|
||||
result.append((language.id, language.name))
|
||||
used_languages.append(language.id)
|
||||
|
||||
for language in Language.query.order_by(Language.name).all():
|
||||
if language.code != 'und' and language.id not in used_languages:
|
||||
result.append((language.id, language.name))
|
||||
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue