Runs black
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
''' models for storing different kinds of Activities '''
|
||||
""" models for storing different kinds of Activities """
|
||||
import urllib.parse
|
||||
|
||||
from django.apps import apps
|
||||
@ -12,28 +12,30 @@ from . import fields
|
||||
|
||||
|
||||
class Tag(OrderedCollectionMixin, BookWyrmModel):
|
||||
''' freeform tags for books '''
|
||||
""" freeform tags for books """
|
||||
|
||||
name = fields.CharField(max_length=100, unique=True)
|
||||
identifier = models.CharField(max_length=100)
|
||||
|
||||
@property
|
||||
def books(self):
|
||||
''' count of books associated with this tag '''
|
||||
edition_model = apps.get_model('bookwyrm.Edition', require_ready=True)
|
||||
return edition_model.objects.filter(
|
||||
usertag__tag__identifier=self.identifier
|
||||
).order_by('-created_date').distinct()
|
||||
""" count of books associated with this tag """
|
||||
edition_model = apps.get_model("bookwyrm.Edition", require_ready=True)
|
||||
return (
|
||||
edition_model.objects.filter(usertag__tag__identifier=self.identifier)
|
||||
.order_by("-created_date")
|
||||
.distinct()
|
||||
)
|
||||
|
||||
collection_queryset = books
|
||||
|
||||
def get_remote_id(self):
|
||||
''' tag should use identifier not id in remote_id '''
|
||||
base_path = 'https://%s' % DOMAIN
|
||||
return '%s/tag/%s' % (base_path, self.identifier)
|
||||
|
||||
""" tag should use identifier not id in remote_id """
|
||||
base_path = "https://%s" % DOMAIN
|
||||
return "%s/tag/%s" % (base_path, self.identifier)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
''' create a url-safe lookup key for the tag '''
|
||||
""" create a url-safe lookup key for the tag """
|
||||
if not self.id:
|
||||
# add identifiers to new tags
|
||||
self.identifier = urllib.parse.quote_plus(self.name)
|
||||
@ -41,18 +43,21 @@ class Tag(OrderedCollectionMixin, BookWyrmModel):
|
||||
|
||||
|
||||
class UserTag(CollectionItemMixin, BookWyrmModel):
|
||||
''' an instance of a tag on a book by a user '''
|
||||
""" an instance of a tag on a book by a user """
|
||||
|
||||
user = fields.ForeignKey(
|
||||
'User', on_delete=models.PROTECT, activitypub_field='actor')
|
||||
"User", on_delete=models.PROTECT, activitypub_field="actor"
|
||||
)
|
||||
book = fields.ForeignKey(
|
||||
'Edition', on_delete=models.PROTECT, activitypub_field='object')
|
||||
tag = fields.ForeignKey(
|
||||
'Tag', on_delete=models.PROTECT, activitypub_field='target')
|
||||
"Edition", on_delete=models.PROTECT, activitypub_field="object"
|
||||
)
|
||||
tag = fields.ForeignKey("Tag", on_delete=models.PROTECT, activitypub_field="target")
|
||||
|
||||
activity_serializer = activitypub.Add
|
||||
object_field = 'book'
|
||||
collection_field = 'tag'
|
||||
object_field = "book"
|
||||
collection_field = "tag"
|
||||
|
||||
class Meta:
|
||||
''' unqiueness constraint '''
|
||||
unique_together = ('user', 'book', 'tag')
|
||||
""" unqiueness constraint """
|
||||
|
||||
unique_together = ("user", "book", "tag")
|
||||
|
Reference in New Issue
Block a user