mirror of
https://codeberg.org/rimu/pyfedi
synced 2025-02-02 16:21:32 -08:00
post licence - save and display
This commit is contained in:
parent
88d28c1464
commit
21ae50f6ff
3 changed files with 23 additions and 4 deletions
|
@ -15,7 +15,7 @@ from sqlalchemy import text, func, desc
|
|||
from app import db, cache, constants, celery
|
||||
from app.models import User, Post, Community, BannedInstances, File, PostReply, AllowedInstances, Instance, utcnow, \
|
||||
PostVote, PostReplyVote, ActivityPubLog, Notification, Site, CommunityMember, InstanceRole, Report, Conversation, \
|
||||
Language, Tag, Poll, PollChoice, UserFollower, CommunityBan, CommunityJoinRequest, NotificationSubscription
|
||||
Language, Tag, Poll, PollChoice, UserFollower, CommunityBan, CommunityJoinRequest, NotificationSubscription, Licence
|
||||
from app.activitypub.signature import signed_get_request, post_request
|
||||
import time
|
||||
from app.constants import *
|
||||
|
@ -398,6 +398,16 @@ def find_language_or_create(code: str, name: str) -> Language:
|
|||
return new_language
|
||||
|
||||
|
||||
def find_licence_or_create(name: str) -> Licence:
|
||||
existing_licence = Licence.query.filter(Licence.name == name.strip()).first()
|
||||
if existing_licence:
|
||||
return existing_licence
|
||||
else:
|
||||
new_licence = Licence(name=name.strip())
|
||||
db.session.add(new_licence)
|
||||
return new_licence
|
||||
|
||||
|
||||
def find_hashtag_or_create(hashtag: str) -> Tag:
|
||||
if hashtag is None or hashtag == '':
|
||||
return None
|
||||
|
|
|
@ -1124,7 +1124,7 @@ class Post(db.Model):
|
|||
community = db.relationship('Community', lazy='joined', overlaps='posts', foreign_keys=[community_id])
|
||||
replies = db.relationship('PostReply', lazy='dynamic', backref='post')
|
||||
language = db.relationship('Language', foreign_keys=[language_id])
|
||||
licence = db.relationship('Licence', foreign_keys=[language_id], lazy='dynamic')
|
||||
licence = db.relationship('Licence', foreign_keys=[licence_id])
|
||||
|
||||
# db relationship tracked by the "read_posts" table
|
||||
# this is the Post side, so its referencing the User side
|
||||
|
@ -1141,7 +1141,7 @@ class Post(db.Model):
|
|||
@classmethod
|
||||
def new(cls, user: User, community: Community, request_json: dict, announce_id=None):
|
||||
from app.activitypub.util import instance_weight, find_language_or_create, find_language, find_hashtag_or_create, \
|
||||
make_image_sizes, notify_about_post
|
||||
find_licence_or_create, make_image_sizes, notify_about_post
|
||||
from app.utils import allowlist_html, markdown_to_html, html_to_text, microblog_content_to_title, blocked_phrases, \
|
||||
is_image_url, is_video_url, domain_from_url, opengraph_parse, shorten_string, remove_tracking_from_link, \
|
||||
is_video_hosting_site, communities_banned_from
|
||||
|
@ -1279,10 +1279,13 @@ class Post(db.Model):
|
|||
if 'language' in request_json['object'] and isinstance(request_json['object']['language'], dict):
|
||||
language = find_language_or_create(request_json['object']['language']['identifier'],
|
||||
request_json['object']['language']['name'])
|
||||
post.language_id = language.id
|
||||
post.language = language
|
||||
elif 'contentMap' in request_json['object'] and isinstance(request_json['object']['contentMap'], dict):
|
||||
language = find_language(next(iter(request_json['object']['contentMap'])))
|
||||
post.language_id = language.id if language else None
|
||||
if 'licence' in request_json['object'] and isinstance(request_json['object']['licence'], dict):
|
||||
licence = find_licence_or_create(request_json['object']['licence']['name'])
|
||||
post.licence = licence
|
||||
if 'tag' in request_json['object'] and isinstance(request_json['object']['tag'], list):
|
||||
for json_tag in request_json['object']['tag']:
|
||||
if json_tag and json_tag['type'] == 'Hashtag':
|
||||
|
|
|
@ -46,6 +46,9 @@
|
|||
</div>
|
||||
<div class="post_body mt-2"{% if post.language_id and post.language.code != 'en' %} lang="{{ post.language.code }}"{% endif %}>
|
||||
{{ post.body_html|community_links|safe if post.body_html else '' }}
|
||||
{% if post.licence_id -%}
|
||||
<p>Licence: {{ post.licence.name }}</p>
|
||||
{% endif -%}
|
||||
</div>
|
||||
</div>
|
||||
{% else -%}
|
||||
|
@ -141,6 +144,9 @@
|
|||
{% if archive_link -%}
|
||||
<p><a href="{{ archive_link }}" rel="nofollow ucg noindex" target="_blank">{{ _('Archive.ph link') }} <span class="fe fe-external"></span></a></p>
|
||||
{% endif -%}
|
||||
{% if post.licence_id -%}
|
||||
<p>Licence: {{ post.licence.name }}</p>
|
||||
{% endif -%}
|
||||
</div>
|
||||
{% if post.type == POST_TYPE_POLL -%}
|
||||
<div class="post_poll">
|
||||
|
|
Loading…
Add table
Reference in a new issue