bookwyrm-mastodon/bookwyrm/status.py

38 lines
1.1 KiB
Python
Raw Normal View History

''' Handle user activity '''
2021-02-10 16:09:04 -05:00
from django.db import transaction
from django.utils import timezone
2020-03-29 03:05:09 -04:00
2020-12-12 21:06:48 -05:00
from bookwyrm import models
from bookwyrm.sanitize_html import InputHtmlParser
2020-10-08 15:32:45 -04:00
def delete_status(status):
''' replace the status with a tombstone '''
status.deleted = True
status.deleted_date = timezone.now()
2020-10-08 15:32:45 -04:00
status.save()
2020-10-26 18:00:15 -04:00
2020-11-06 11:51:50 -05:00
def create_generated_note(user, content, mention_books=None, privacy='public'):
''' a note created by the app about user activity '''
# sanitize input html
parser = InputHtmlParser()
parser.feed(content)
content = parser.get_output()
2021-02-10 16:09:04 -05:00
with transaction.atomic():
# create but don't save
status = models.GeneratedNote(
user=user,
content=content,
privacy=privacy
)
# we have to save it to set the related fields, but hold off on telling
# folks about it because it is not ready
status.save(broadcast=False)
if mention_books:
status.mention_books.set(mention_books)
status.save(created=True)
return status