mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-27 10:30:32 +00:00
Fixes untag
This commit is contained in:
parent
a7a586ea90
commit
69af2f4cd3
4 changed files with 29 additions and 12 deletions
|
@ -66,7 +66,7 @@ class UserTag(BookWyrmModel):
|
|||
id='%s#remove' % self.remote_id,
|
||||
actor=user.remote_id,
|
||||
object=self.book.to_activity(),
|
||||
target=self.to_activity(),
|
||||
target=self.remote_id,
|
||||
).serialize()
|
||||
|
||||
|
||||
|
|
|
@ -283,16 +283,6 @@ def to_markdown(content):
|
|||
return sanitizer.get_output()
|
||||
|
||||
|
||||
def handle_untag(user, book, name):
|
||||
''' tag a book '''
|
||||
book = models.Book.objects.get(id=book)
|
||||
tag = models.Tag.objects.get(name=name, book=book, user=user)
|
||||
tag_activity = tag.to_remove_activity(user)
|
||||
tag.delete()
|
||||
|
||||
broadcast(user, tag_activity)
|
||||
|
||||
|
||||
def handle_favorite(user, status):
|
||||
''' a user likes a status '''
|
||||
try:
|
||||
|
|
|
@ -374,3 +374,23 @@ class ViewActions(TestCase):
|
|||
self.assertEqual(tag.identifier, 'A+Tag%21%3F')
|
||||
self.assertEqual(user_tag.user, self.local_user)
|
||||
self.assertEqual(user_tag.book, self.book)
|
||||
|
||||
|
||||
def test_untag(self):
|
||||
''' remove a tag from a book '''
|
||||
tag = models.Tag.objects.create(name='A Tag!?')
|
||||
user_tag = models.UserTag.objects.create(
|
||||
user=self.local_user, book=self.book, tag=tag)
|
||||
request = self.factory.post(
|
||||
'', {
|
||||
'user': self.local_user.id,
|
||||
'book': self.book.id,
|
||||
'name': tag.name,
|
||||
})
|
||||
request.user = self.local_user
|
||||
|
||||
with patch('bookwyrm.broadcast.broadcast_task.delay'):
|
||||
actions.untag(request)
|
||||
|
||||
self.assertTrue(models.Tag.objects.filter(name='A Tag!?').exists())
|
||||
self.assertFalse(models.UserTag.objects.exists())
|
||||
|
|
|
@ -593,9 +593,16 @@ def tag(request):
|
|||
def untag(request):
|
||||
''' untag a book '''
|
||||
name = request.POST.get('name')
|
||||
tag = get_object_or_404(models.Tag, name=name)
|
||||
book_id = request.POST.get('book')
|
||||
book = get_object_or_404(models.Edition, id=book_id)
|
||||
|
||||
outgoing.handle_untag(request.user, book_id, name)
|
||||
tag = get_object_or_404(
|
||||
models.UserTag, tag=tag, book=book, user=request.user)
|
||||
tag_activity = tag.to_remove_activity(request.user)
|
||||
tag.delete()
|
||||
|
||||
broadcast(request.user, tag_activity)
|
||||
return redirect('/book/%s' % book_id)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue