mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-01-24 03:43:42 -08:00
show sticky posts at top of their community fixes #16
This commit is contained in:
parent
cfe4feb934
commit
0210adafa5
10 changed files with 59 additions and 4 deletions
|
@ -89,6 +89,7 @@ class CreatePostForm(FlaskForm):
|
||||||
render_kw={'placeholder': 'Text (optional)'})
|
render_kw={'placeholder': 'Text (optional)'})
|
||||||
image_file = FileField(_('Image'))
|
image_file = FileField(_('Image'))
|
||||||
# flair = SelectField(_l('Flair'), coerce=int)
|
# flair = SelectField(_l('Flair'), coerce=int)
|
||||||
|
sticky = BooleanField(_l('Sticky'))
|
||||||
nsfw = BooleanField(_l('NSFW'))
|
nsfw = BooleanField(_l('NSFW'))
|
||||||
nsfl = BooleanField(_l('Gore/gross'))
|
nsfl = BooleanField(_l('Gore/gross'))
|
||||||
notify_author = BooleanField(_l('Notify about replies'))
|
notify_author = BooleanField(_l('Notify about replies'))
|
||||||
|
|
|
@ -120,6 +120,8 @@ def show_community(community: Community):
|
||||||
|
|
||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
sort = request.args.get('sort', '' if current_user.is_anonymous else current_user.default_sort)
|
sort = request.args.get('sort', '' if current_user.is_anonymous else current_user.default_sort)
|
||||||
|
if sort is None:
|
||||||
|
sort = ''
|
||||||
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
low_bandwidth = request.cookies.get('low_bandwidth', '0') == '1'
|
||||||
if low_bandwidth:
|
if low_bandwidth:
|
||||||
post_layout = None
|
post_layout = None
|
||||||
|
@ -171,13 +173,13 @@ def show_community(community: Community):
|
||||||
posts = posts.filter(or_(Post.instance_id.not_in(instance_ids), Post.instance_id == None))
|
posts = posts.filter(or_(Post.instance_id.not_in(instance_ids), Post.instance_id == None))
|
||||||
|
|
||||||
if sort == '' or sort == 'hot':
|
if sort == '' or sort == 'hot':
|
||||||
posts = posts.order_by(desc(Post.ranking)).order_by(desc(Post.posted_at))
|
posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.ranking)).order_by(desc(Post.posted_at))
|
||||||
elif sort == 'top':
|
elif sort == 'top':
|
||||||
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.score))
|
posts = posts.filter(Post.posted_at > utcnow() - timedelta(days=7)).order_by(desc(Post.sticky)).order_by(desc(Post.score))
|
||||||
elif sort == 'new':
|
elif sort == 'new':
|
||||||
posts = posts.order_by(desc(Post.posted_at))
|
posts = posts.order_by(desc(Post.posted_at))
|
||||||
elif sort == 'active':
|
elif sort == 'active':
|
||||||
posts = posts.order_by(desc(Post.last_active))
|
posts = posts.order_by(desc(Post.sticky)).order_by(desc(Post.last_active))
|
||||||
per_page = 100
|
per_page = 100
|
||||||
if post_layout == 'masonry':
|
if post_layout == 'masonry':
|
||||||
per_page = 200
|
per_page = 200
|
||||||
|
@ -444,6 +446,8 @@ def add_post(actor):
|
||||||
if community.nsfl:
|
if community.nsfl:
|
||||||
form.nsfl.data = True
|
form.nsfl.data = True
|
||||||
form.nsfw.render_kw = {'disabled': True}
|
form.nsfw.render_kw = {'disabled': True}
|
||||||
|
if not(community.is_moderator() or community.is_owner() or current_user.is_admin()):
|
||||||
|
form.sticky.render_kw = {'disabled': True}
|
||||||
|
|
||||||
form.communities.choices = [(c.id, c.display_name()) for c in current_user.communities()]
|
form.communities.choices = [(c.id, c.display_name()) for c in current_user.communities()]
|
||||||
|
|
||||||
|
@ -485,6 +489,7 @@ def add_post(actor):
|
||||||
'commentsEnabled': post.comments_enabled,
|
'commentsEnabled': post.comments_enabled,
|
||||||
'sensitive': post.nsfw,
|
'sensitive': post.nsfw,
|
||||||
'nsfl': post.nsfl,
|
'nsfl': post.nsfl,
|
||||||
|
'stickied': post.sticky,
|
||||||
'published': ap_datetime(utcnow()),
|
'published': ap_datetime(utcnow()),
|
||||||
'audience': community.ap_profile_id
|
'audience': community.ap_profile_id
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ def url_to_thumbnail_file(filename) -> File:
|
||||||
|
|
||||||
def save_post(form, post: Post):
|
def save_post(form, post: Post):
|
||||||
post.indexable = current_user.indexable
|
post.indexable = current_user.indexable
|
||||||
|
post.sticky = form.sticky.data
|
||||||
post.nsfw = form.nsfw.data
|
post.nsfw = form.nsfw.data
|
||||||
post.nsfl = form.nsfl.data
|
post.nsfl = form.nsfl.data
|
||||||
post.notify_author = form.notify_author.data
|
post.notify_author = form.notify_author.data
|
||||||
|
|
|
@ -649,6 +649,7 @@ def post_edit(post_id: int):
|
||||||
'commentsEnabled': post.comments_enabled,
|
'commentsEnabled': post.comments_enabled,
|
||||||
'sensitive': post.nsfw,
|
'sensitive': post.nsfw,
|
||||||
'nsfl': post.nsfl,
|
'nsfl': post.nsfl,
|
||||||
|
'stickied': post.sticky,
|
||||||
'published': ap_datetime(post.posted_at),
|
'published': ap_datetime(post.posted_at),
|
||||||
'updated': ap_datetime(post.edited_at),
|
'updated': ap_datetime(post.edited_at),
|
||||||
'audience': post.community.ap_profile_id
|
'audience': post.community.ap_profile_id
|
||||||
|
@ -722,6 +723,9 @@ def post_edit(post_id: int):
|
||||||
form.notify_author.data = post.notify_author
|
form.notify_author.data = post.notify_author
|
||||||
form.nsfw.data = post.nsfw
|
form.nsfw.data = post.nsfw
|
||||||
form.nsfl.data = post.nsfl
|
form.nsfl.data = post.nsfl
|
||||||
|
form.sticky.data = post.sticky
|
||||||
|
if not (post.community.is_moderator() or post.community.is_owner() or current_user.is_admin()):
|
||||||
|
form.sticky.render_kw = {'disabled': True}
|
||||||
return render_template('post/post_edit.html', title=_('Edit post'), form=form, post=post,
|
return render_template('post/post_edit.html', title=_('Edit post'), form=form, post=post,
|
||||||
markdown_editor=current_user.markdown_editor,
|
markdown_editor=current_user.markdown_editor,
|
||||||
moderating_communities=moderating_communities(current_user.get_id()),
|
moderating_communities=moderating_communities(current_user.get_id()),
|
||||||
|
|
|
@ -309,6 +309,19 @@ h1 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fe-sticky-left::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e934";
|
||||||
|
}
|
||||||
|
|
||||||
|
.fe-sticky-right::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e933";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
a.no-underline {
|
a.no-underline {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|
|
@ -333,6 +333,18 @@ h1 .fe-bell, h1 .fe-no-bell {
|
||||||
/* possibly e985 */
|
/* possibly e985 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fe-sticky-left::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e934";
|
||||||
|
}
|
||||||
|
|
||||||
|
.fe-sticky-right::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e933";
|
||||||
|
}
|
||||||
|
|
||||||
a.no-underline {
|
a.no-underline {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -332,6 +332,18 @@ h1 .fe-bell, h1 .fe-no-bell {
|
||||||
/* possibly e985 */
|
/* possibly e985 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.fe-sticky-left::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e934";
|
||||||
|
}
|
||||||
|
|
||||||
|
.fe-sticky-right::before {
|
||||||
|
position: relative;
|
||||||
|
top: 2px;
|
||||||
|
content: "\e933";
|
||||||
|
}
|
||||||
|
|
||||||
a.no-underline {
|
a.no-underline {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,9 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{{ render_field(form.notify_author) }}
|
{{ render_field(form.notify_author) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-1">
|
||||||
|
{{ render_field(form.sticky) }}
|
||||||
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="col-md-1">
|
||||||
{{ render_field(form.nsfw) }}
|
{{ render_field(form.nsfw) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h3><a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None) }}" class="post_teaser_title_a">{{ post.title }}</a>
|
<h3>{% if post.sticky %}<span class="fe fe-sticky-left"></span>{% endif %}<a href="{{ url_for('activitypub.post_ap', post_id=post.id, sort='new' if sort == 'active' else None) }}" class="post_teaser_title_a">{{ post.title }}</a>
|
||||||
{% if post.type == POST_TYPE_IMAGE %}<span class="fe fe-image" aria-hidden="true"> </span>{% endif %}
|
{% if post.type == POST_TYPE_IMAGE %}<span class="fe fe-image" aria-hidden="true"> </span>{% endif %}
|
||||||
{% if post.type == POST_TYPE_LINK and post.domain_id %}
|
{% if post.type == POST_TYPE_LINK and post.domain_id %}
|
||||||
{% if post.url and 'youtube.com' in post.url %}
|
{% if post.url and 'youtube.com' in post.url %}
|
||||||
|
@ -58,6 +58,7 @@
|
||||||
{% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %}
|
{% if post.reports and current_user.is_authenticated and post.community.is_moderator(current_user) %}
|
||||||
<span class="red fe fe-report" title="{{ _('Reported. Check post for issues.') }}"></span>
|
<span class="red fe fe-report" title="{{ _('Reported. Check post for issues.') }}"></span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if post.sticky %}<span class="fe fe-sticky-right"></span>{% endif %}
|
||||||
</h3>
|
</h3>
|
||||||
|
|
||||||
<span class="small">{% if show_post_community %}<strong><a href="/c/{{ post.community.link() }}" aria-label="{{ _('Go to community %(name)s', name=post.community.name) }}">c/{{ post.community.name }}</a></strong>{% endif %}
|
<span class="small">{% if show_post_community %}<strong><a href="/c/{{ post.community.link() }}" aria-label="{{ _('Go to community %(name)s', name=post.community.name) }}">c/{{ post.community.name }}</a></strong>{% endif %}
|
||||||
|
|
|
@ -120,6 +120,9 @@
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
{{ render_field(form.notify_author) }}
|
{{ render_field(form.notify_author) }}
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-1">
|
||||||
|
{{ render_field(form.sticky) }}
|
||||||
|
</div>
|
||||||
<div class="col-md-1">
|
<div class="col-md-1">
|
||||||
{{ render_field(form.nsfw) }}
|
{{ render_field(form.nsfw) }}
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue