diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index dbe3cb887..29c6b6de7 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -159,3 +159,8 @@ class CreateInviteForm(CustomForm): choices=[(i, "%d uses" % (i,)) for i in [1, 5, 10, 25, 50, 100]] + [(None, 'Unlimited')]) } + +class ShelfForm(CustomForm): + class Meta: + model = models.Shelf + fields = ['user', 'name', 'privacy'] diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index dafc8ff59..59e5f8413 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -1,4 +1,5 @@ ''' puttin' books on shelves ''' +import re from django.db import models from bookwyrm import activitypub @@ -23,6 +24,15 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): through_fields=('shelf', 'book') ) + def save(self, *args, **kwargs): + ''' set the identifier ''' + saved = super().save(*args, **kwargs) + if not self.identifier: + slug = re.sub(r'[^\w]', '', self.name) + self.identifier = '%s-%d' % (slug, self.id) + return super().save(*args, **kwargs) + return saved + @property def collection_queryset(self): ''' list of books for this shelf, overrides OrderedCollectionMixin ''' diff --git a/bookwyrm/templates/shelf.html b/bookwyrm/templates/shelf.html index 660d400c9..f6b0972a5 100644 --- a/bookwyrm/templates/shelf.html +++ b/bookwyrm/templates/shelf.html @@ -12,32 +12,61 @@ shelves + + +{% include 'snippets/user_header.html' with user=user %} + +