2021-03-08 16:49:10 +00:00
|
|
|
""" Handle user activity """
|
2021-02-10 21:09:04 +00:00
|
|
|
from django.db import transaction
|
2020-11-28 00:24:53 +00:00
|
|
|
from django.utils import timezone
|
2020-03-29 07:05:09 +00:00
|
|
|
|
2020-12-13 02:06:48 +00:00
|
|
|
from bookwyrm import models
|
2020-09-21 15:10:37 +00:00
|
|
|
from bookwyrm.sanitize_html import InputHtmlParser
|
2020-02-18 04:12:19 +00:00
|
|
|
|
|
|
|
|
2020-10-08 19:32:45 +00:00
|
|
|
def delete_status(status):
|
2021-03-08 16:49:10 +00:00
|
|
|
""" replace the status with a tombstone """
|
2020-10-08 19:32:45 +00:00
|
|
|
status.deleted = True
|
2020-11-28 00:24:53 +00:00
|
|
|
status.deleted_date = timezone.now()
|
2020-10-08 19:32:45 +00:00
|
|
|
status.save()
|
|
|
|
|
2020-10-26 22:00:15 +00:00
|
|
|
|
2021-03-08 16:49:10 +00:00
|
|
|
def create_generated_note(user, content, mention_books=None, privacy="public"):
|
|
|
|
""" a note created by the app about user activity """
|
2020-09-29 00:26:15 +00:00
|
|
|
# sanitize input html
|
|
|
|
parser = InputHtmlParser()
|
|
|
|
parser.feed(content)
|
|
|
|
content = parser.get_output()
|
|
|
|
|
2021-02-10 21:09:04 +00:00
|
|
|
with transaction.atomic():
|
|
|
|
# create but don't save
|
2021-03-08 16:49:10 +00:00
|
|
|
status = models.GeneratedNote(user=user, content=content, privacy=privacy)
|
2021-02-10 21:09:04 +00:00
|
|
|
# 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)
|
2020-09-29 00:26:15 +00:00
|
|
|
return status
|