diff --git a/Dockerfile b/Dockerfile index 1892ae23..349dd82b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,4 +8,4 @@ WORKDIR /app COPY requirements.txt /app/ RUN pip install -r requirements.txt --no-cache-dir -RUN apt-get update && apt-get install -y gettext libgettextpo-dev && apt-get clean +RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-get clean diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 23063ff7..5acde9ea 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -29,8 +29,7 @@ class CustomForm(ModelForm): input_type = visible.field.widget.input_type if isinstance(visible.field.widget, Textarea): input_type = "textarea" - visible.field.widget.attrs["cols"] = None - visible.field.widget.attrs["rows"] = None + visible.field.widget.attrs["rows"] = 5 visible.field.widget.attrs["class"] = css_classes[input_type] @@ -228,7 +227,7 @@ class ExpiryWidget(widgets.Select): elif selected_string == "forever": return None else: - return selected_string # "This will raise + return selected_string # This will raise return timezone.now() + interval @@ -269,7 +268,7 @@ class CreateInviteForm(CustomForm): class ShelfForm(CustomForm): class Meta: model = models.Shelf - fields = ["user", "name", "privacy"] + fields = ["user", "name", "privacy", "description"] class GoalForm(CustomForm): diff --git a/bookwyrm/migrations/0099_readthrough_is_active.py b/bookwyrm/migrations/0099_readthrough_is_active.py new file mode 100644 index 00000000..e7b177ba --- /dev/null +++ b/bookwyrm/migrations/0099_readthrough_is_active.py @@ -0,0 +1,37 @@ +# Generated by Django 3.2.4 on 2021-09-22 16:53 + +from django.db import migrations, models + + +def set_active_readthrough(apps, schema_editor): + """best-guess for deactivation date""" + db_alias = schema_editor.connection.alias + apps.get_model("bookwyrm", "ReadThrough").objects.using(db_alias).filter( + start_date__isnull=False, + finish_date__isnull=True, + ).update(is_active=True) + + +def reverse_func(apps, schema_editor): + """noop""" + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0098_auto_20210918_2238"), + ] + + operations = [ + migrations.AddField( + model_name="readthrough", + name="is_active", + field=models.BooleanField(default=False), + ), + migrations.RunPython(set_active_readthrough, reverse_func), + migrations.AlterField( + model_name="readthrough", + name="is_active", + field=models.BooleanField(default=True), + ), + ] diff --git a/bookwyrm/migrations/0100_shelf_description.py b/bookwyrm/migrations/0100_shelf_description.py new file mode 100644 index 00000000..18185b17 --- /dev/null +++ b/bookwyrm/migrations/0100_shelf_description.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.5 on 2021-09-28 23:20 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0099_readthrough_is_active"), + ] + + operations = [ + migrations.AddField( + model_name="shelf", + name="description", + field=models.TextField(blank=True, max_length=500, null=True), + ), + ] diff --git a/bookwyrm/models/base_model.py b/bookwyrm/models/base_model.py index aa174a14..ca32521a 100644 --- a/bookwyrm/models/base_model.py +++ b/bookwyrm/models/base_model.py @@ -1,8 +1,11 @@ """ base model with default fields """ import base64 from Crypto import Random + +from django.core.exceptions import PermissionDenied from django.db import models from django.dispatch import receiver +from django.http import Http404 from django.utils.translation import gettext_lazy as _ from bookwyrm.settings import DOMAIN @@ -48,26 +51,26 @@ class BookWyrmModel(models.Model): """how to link to this object in the local app""" return self.get_remote_id().replace(f"https://{DOMAIN}", "") - def visible_to_user(self, viewer): + def raise_visible_to_user(self, viewer): """is a user authorized to view an object?""" # make sure this is an object with privacy owned by a user if not hasattr(self, "user") or not hasattr(self, "privacy"): - return None + return # viewer can't see it if the object's owner blocked them if viewer in self.user.blocks.all(): - return False + raise Http404() # you can see your own posts and any public or unlisted posts if viewer == self.user or self.privacy in ["public", "unlisted"]: - return True + return # you can see the followers only posts of people you follow if ( self.privacy == "followers" and self.user.followers.filter(id=viewer.id).first() ): - return True + return # you can see dms you are tagged in if hasattr(self, "mention_users"): @@ -75,8 +78,32 @@ class BookWyrmModel(models.Model): self.privacy == "direct" and self.mention_users.filter(id=viewer.id).first() ): - return True - return False + return + raise Http404() + + def raise_not_editable(self, viewer): + """does this user have permission to edit this object? liable to be overwritten + by models that inherit this base model class""" + if not hasattr(self, "user"): + return + + # generally moderators shouldn't be able to edit other people's stuff + if self.user == viewer: + return + + raise PermissionDenied() + + def raise_not_deletable(self, viewer): + """does this user have permission to delete this object? liable to be + overwritten by models that inherit this base model class""" + if not hasattr(self, "user"): + return + + # but generally moderators can delete other people's stuff + if self.user == viewer or viewer.has_perm("moderate_post"): + return + + raise PermissionDenied() @receiver(models.signals.post_save) diff --git a/bookwyrm/models/book.py b/bookwyrm/models/book.py index 70df3bd4..8ae75baf 100644 --- a/bookwyrm/models/book.py +++ b/bookwyrm/models/book.py @@ -3,8 +3,8 @@ import re from django.contrib.postgres.search import SearchVectorField from django.contrib.postgres.indexes import GinIndex -from django.db import models -from django.db import transaction +from django.db import models, transaction +from django.db.models import Prefetch from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ from model_utils import FieldTracker @@ -321,6 +321,27 @@ class Edition(Book): return super().save(*args, **kwargs) + @classmethod + def viewer_aware_objects(cls, viewer): + """annotate a book query with metadata related to the user""" + queryset = cls.objects + if not viewer or not viewer.is_authenticated: + return queryset + + queryset = queryset.prefetch_related( + Prefetch( + "shelfbook_set", + queryset=viewer.shelfbook_set.all(), + to_attr="current_shelves", + ), + Prefetch( + "readthrough_set", + queryset=viewer.readthrough_set.filter(is_active=True).all(), + to_attr="active_readthroughs", + ), + ) + return queryset + def isbn_10_to_13(isbn_10): """convert an isbn 10 into an isbn 13""" diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 49fb5375..022a0d98 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -92,6 +92,12 @@ class ListItem(CollectionItemMixin, BookWyrmModel): notification_type="ADD", ) + def raise_not_deletable(self, viewer): + """the associated user OR the list owner can delete""" + if self.book_list.user == viewer: + return + super().raise_not_deletable(viewer) + class Meta: """A book may only be placed into a list once, and each order in the list may be used only once""" diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index e1090f41..f75918ac 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -26,10 +26,14 @@ class ReadThrough(BookWyrmModel): ) start_date = models.DateTimeField(blank=True, null=True) finish_date = models.DateTimeField(blank=True, null=True) + is_active = models.BooleanField(default=True) def save(self, *args, **kwargs): """update user active time""" self.user.update_active_date() + # an active readthrough must have an unset finish date + if self.finish_date: + self.is_active = False super().save(*args, **kwargs) def create_update(self): diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 6f134402..c578f082 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -1,5 +1,6 @@ """ puttin' books on shelves """ import re +from django.core.exceptions import PermissionDenied from django.db import models from django.utils import timezone @@ -20,6 +21,7 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): name = fields.CharField(max_length=100) identifier = models.CharField(max_length=100) + description = models.TextField(blank=True, null=True, max_length=500) user = fields.ForeignKey( "User", on_delete=models.PROTECT, activitypub_field="owner" ) @@ -51,12 +53,23 @@ class Shelf(OrderedCollectionMixin, BookWyrmModel): """list of books for this shelf, overrides OrderedCollectionMixin""" return self.books.order_by("shelfbook") + @property + def deletable(self): + """can the shelf be safely deleted?""" + return self.editable and not self.shelfbook_set.exists() + def get_remote_id(self): """shelf identifier instead of id""" base_path = self.user.remote_id identifier = self.identifier or self.get_identifier() return f"{base_path}/books/{identifier}" + def raise_not_deletable(self, viewer): + """don't let anyone delete a default shelf""" + super().raise_not_deletable(viewer) + if not self.deletable: + raise PermissionDenied() + class Meta: """user/shelf unqiueness""" diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 3a0fad5e..b6203678 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -3,6 +3,7 @@ from dataclasses import MISSING import re from django.apps import apps +from django.core.exceptions import PermissionDenied from django.core.validators import MaxValueValidator, MinValueValidator from django.db import models from django.dispatch import receiver @@ -187,6 +188,13 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): """json serialized activitypub class""" return self.to_activity_dataclass(pure=pure).serialize() + def raise_not_editable(self, viewer): + """certain types of status aren't editable""" + # first, the standard raise + super().raise_not_editable(viewer) + if isinstance(self, (GeneratedNote, ReviewRating)): + raise PermissionDenied() + class GeneratedNote(Status): """these are app-generated messages about user activity""" diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 31c2edf8..895a537a 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -13,7 +13,7 @@ VERSION = "0.0.1" PAGE_LENGTH = env("PAGE_LENGTH", 15) DEFAULT_LANGUAGE = env("DEFAULT_LANGUAGE", "English") -JS_CACHE = "7f2343cf" +JS_CACHE = "e2bc0653" # email EMAIL_BACKEND = env("EMAIL_BACKEND", "django.core.mail.backends.smtp.EmailBackend") diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js index b3e345b1..2a50bfcb 100644 --- a/bookwyrm/static/js/status_cache.js +++ b/bookwyrm/static/js/status_cache.js @@ -141,8 +141,10 @@ let StatusCache = new class { modal.getElementsByClassName("modal-close")[0].click(); // Update shelve buttons - document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']") - .forEach(button => this.cycleShelveButtons(button, form.reading_status.value)); + if (form.reading_status) { + document.querySelectorAll("[data-shelve-button-book='" + form.book.value +"']") + .forEach(button => this.cycleShelveButtons(button, form.reading_status.value)); + } return; } diff --git a/bookwyrm/templates/book/edit_book.html b/bookwyrm/templates/book/edit_book.html index ebfeccf5..5a859e3d 100644 --- a/bookwyrm/templates/book/edit_book.html +++ b/bookwyrm/templates/book/edit_book.html @@ -236,14 +236,12 @@ {{ form.cover }} - {% if book %}
- +
- {% endif %} {% for error in form.cover.errors %}

{{ error | escape }}

{% endfor %} diff --git a/bookwyrm/templates/components/inline_form.html b/bookwyrm/templates/components/inline_form.html index a8924ef2..37f9f556 100644 --- a/bookwyrm/templates/components/inline_form.html +++ b/bookwyrm/templates/components/inline_form.html @@ -1,5 +1,5 @@ {% load i18n %} - @@ -39,38 +35,32 @@

{% trans "Activity" %}

-
-
{% trans "Users:" %}
-
- {{ users.count }} - {% if server.user_set.count %}({% trans "View all" %}){% endif %} -
-
-
-
{% trans "Reports:" %}
-
- {{ reports.count }} - {% if reports.count %}({% trans "View all" %}){% endif %} -
-
-
-
{% trans "Followed by us:" %}
-
- {{ followed_by_us.count }} -
-
-
-
{% trans "Followed by them:" %}
-
- {{ followed_by_them.count }} -
-
-
-
{% trans "Blocked by us:" %}
-
- {{ blocked_by_us.count }} -
-
+
{% trans "Users:" %}
+
+ {{ users.count }} + {% if server.user_set.count %}({% trans "View all" %}){% endif %} +
+ +
{% trans "Reports:" %}
+
+ {{ reports.count }} + {% if reports.count %}({% trans "View all" %}){% endif %} +
+ +
{% trans "Followed by us:" %}
+
+ {{ followed_by_us.count }} +
+ +
{% trans "Followed by them:" %}
+
+ {{ followed_by_them.count }} +
+ +
{% trans "Blocked by us:" %}
+
+ {{ blocked_by_us.count }} +
@@ -86,14 +76,13 @@ {% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_notes" %} - {% if server.notes %} -
{{ server.notes|to_markdown|safe }}
- {% endif %} + {% trans "No notes" as null_text %} +
{{ server.notes|to_markdown|default:null_text|safe }}
{% csrf_token %}

- +

{% trans "Cancel" as button_text %} diff --git a/bookwyrm/templates/settings/server_blocklist.html b/bookwyrm/templates/settings/federation/instance_blocklist.html similarity index 100% rename from bookwyrm/templates/settings/server_blocklist.html rename to bookwyrm/templates/settings/federation/instance_blocklist.html diff --git a/bookwyrm/templates/settings/federation.html b/bookwyrm/templates/settings/federation/instance_list.html similarity index 95% rename from bookwyrm/templates/settings/federation.html rename to bookwyrm/templates/settings/federation/instance_list.html index ffbabca3..61afb317 100644 --- a/bookwyrm/templates/settings/federation.html +++ b/bookwyrm/templates/settings/federation/instance_list.html @@ -59,7 +59,11 @@ {{ server.get_status_display }} {% endfor %} + {% if not servers %} + {% trans "No instances found" %} + {% endif %} + {% include 'snippets/pagination.html' with page=servers path=request.path %} {% endblock %} diff --git a/bookwyrm/templates/settings/invite_request_filters.html b/bookwyrm/templates/settings/invites/invite_request_filters.html similarity index 66% rename from bookwyrm/templates/settings/invite_request_filters.html rename to bookwyrm/templates/settings/invites/invite_request_filters.html index c55cc069..a29518d8 100644 --- a/bookwyrm/templates/settings/invite_request_filters.html +++ b/bookwyrm/templates/settings/invites/invite_request_filters.html @@ -1,6 +1,6 @@ {% extends 'snippets/filters_panel/filters_panel.html' %} {% block filter_fields %} -{% include 'settings/status_filter.html' %} +{% include 'settings/invites/status_filter.html' %} {% endblock %} diff --git a/bookwyrm/templates/settings/manage_invite_requests.html b/bookwyrm/templates/settings/invites/manage_invite_requests.html similarity index 97% rename from bookwyrm/templates/settings/manage_invite_requests.html rename to bookwyrm/templates/settings/invites/manage_invite_requests.html index e0cfd646..fb7c0b1f 100644 --- a/bookwyrm/templates/settings/manage_invite_requests.html +++ b/bookwyrm/templates/settings/invites/manage_invite_requests.html @@ -26,7 +26,7 @@ {% endif %} ({{ count }}) - {% include 'settings/invite_request_filters.html' %} + {% include 'settings/invites/invite_request_filters.html' %} {% url 'settings-invite-requests' as url %} @@ -47,7 +47,7 @@ {% if not requests %} - + {% endif %} {% for req in requests %} diff --git a/bookwyrm/templates/settings/manage_invites.html b/bookwyrm/templates/settings/invites/manage_invites.html similarity index 100% rename from bookwyrm/templates/settings/manage_invites.html rename to bookwyrm/templates/settings/invites/manage_invites.html diff --git a/bookwyrm/templates/settings/status_filter.html b/bookwyrm/templates/settings/invites/status_filter.html similarity index 100% rename from bookwyrm/templates/settings/status_filter.html rename to bookwyrm/templates/settings/invites/status_filter.html diff --git a/bookwyrm/templates/settings/ip_address_form.html b/bookwyrm/templates/settings/ip_blocklist/ip_address_form.html similarity index 100% rename from bookwyrm/templates/settings/ip_address_form.html rename to bookwyrm/templates/settings/ip_blocklist/ip_address_form.html diff --git a/bookwyrm/templates/settings/ip_blocklist.html b/bookwyrm/templates/settings/ip_blocklist/ip_blocklist.html similarity index 85% rename from bookwyrm/templates/settings/ip_blocklist.html rename to bookwyrm/templates/settings/ip_blocklist/ip_blocklist.html index c978c126..239baa84 100644 --- a/bookwyrm/templates/settings/ip_blocklist.html +++ b/bookwyrm/templates/settings/ip_blocklist/ip_blocklist.html @@ -12,7 +12,7 @@ {% endblock %} {% block panel %} -{% include 'settings/ip_address_form.html' with controls_text="add_address" class="block" %} +{% include 'settings/ip_blocklist/ip_address_form.html' with controls_text="add_address" class="block" %}

{% trans "Any traffic from this IP address will get a 404 response when trying to access any part of the application." %} @@ -42,6 +42,9 @@

{% endfor %} + {% if not addresses.exists %} + + {% endif %}
{% trans "Action" %}
{% trans "No requests" %}
{% trans "No requests" %}
{% trans "No IP addresses currently blocked" %}
{% endblock %} diff --git a/bookwyrm/templates/settings/ip_tooltip.html b/bookwyrm/templates/settings/ip_blocklist/ip_tooltip.html similarity index 100% rename from bookwyrm/templates/settings/ip_tooltip.html rename to bookwyrm/templates/settings/ip_blocklist/ip_tooltip.html diff --git a/bookwyrm/templates/settings/layout.html b/bookwyrm/templates/settings/layout.html index dd315347..d7a840af 100644 --- a/bookwyrm/templates/settings/layout.html +++ b/bookwyrm/templates/settings/layout.html @@ -74,14 +74,7 @@
  • {% url 'settings-site' as url %} {% trans "Site Settings" %} - {% if url in request.path %} - - {% endif %} + {% block site-subtabs %}{% endblock %}
  • {% endif %} diff --git a/bookwyrm/templates/moderation/report.html b/bookwyrm/templates/settings/reports/report.html similarity index 78% rename from bookwyrm/templates/moderation/report.html rename to bookwyrm/templates/settings/reports/report.html index d0e4026a..37593f3c 100644 --- a/bookwyrm/templates/moderation/report.html +++ b/bookwyrm/templates/settings/reports/report.html @@ -3,20 +3,21 @@ {% load humanize %} {% block title %}{% blocktrans with report_id=report.id username=report.user.username %}Report #{{ report_id }}: {{ username }}{% endblocktrans %}{% endblock %} -{% block header %}{% blocktrans with report_id=report.id username=report.user.username %}Report #{{ report_id }}: {{ username }}{% endblocktrans %}{% endblock %} + +{% block header %} +{% blocktrans with report_id=report.id username=report.user.username %}Report #{{ report_id }}: {{ username }}{% endblocktrans %} +{% trans "Back to reports" %} +{% endblock %} {% block panel %} -
    - {% trans "Back to reports" %} -
    - {% include 'moderation/report_preview.html' with report=report %} + {% include 'settings/reports/report_preview.html' with report=report %}
    -{% include 'user_admin/user_info.html' with user=report.user %} +{% include 'settings/users/user_info.html' with user=report.user %} -{% include 'user_admin/user_moderation_actions.html' with user=report.user %} +{% include 'settings/users/user_moderation_actions.html' with user=report.user %}

    {% trans "Moderator Comments" %}

    diff --git a/bookwyrm/templates/moderation/report_preview.html b/bookwyrm/templates/settings/reports/report_preview.html similarity index 100% rename from bookwyrm/templates/moderation/report_preview.html rename to bookwyrm/templates/settings/reports/report_preview.html diff --git a/bookwyrm/templates/moderation/reports.html b/bookwyrm/templates/settings/reports/reports.html similarity index 90% rename from bookwyrm/templates/moderation/reports.html rename to bookwyrm/templates/settings/reports/reports.html index c83f626f..c72fd03d 100644 --- a/bookwyrm/templates/moderation/reports.html +++ b/bookwyrm/templates/settings/reports/reports.html @@ -30,7 +30,7 @@
    -{% include 'user_admin/user_admin_filters.html' %} +{% include 'settings/users/user_admin_filters.html' %}
    {% if not reports %} @@ -39,7 +39,7 @@ {% for report in reports %}
    - {% include 'moderation/report_preview.html' with report=report %} + {% include 'settings/reports/report_preview.html' with report=report %}
    {% endfor %}
    diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 50895485..da5b7705 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -5,36 +5,46 @@ {% block header %}{% trans "Site Settings" %}{% endblock %} -{% block panel %} +{% block site-subtabs %} + +{% endblock %} +{% block panel %} {% csrf_token %}

    {% trans "Instance Info" %}

    -
    - - {{ site_form.name }} -
    -
    - - {{ site_form.instance_tagline }} -
    -
    - - {{ site_form.instance_description }} -
    -
    - -

    {% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support html or markdown." %}

    - {{ site_form.instance_short_description }} -
    -
    - - {{ site_form.code_of_conduct }} -
    -
    - - {{ site_form.privacy_policy }} +
    +
    + + {{ site_form.name }} +
    +
    + + {{ site_form.instance_tagline }} +
    +
    + + {{ site_form.instance_description }} +
    +
    + +

    {% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support html or markdown." %}

    + {{ site_form.instance_short_description }} +
    +
    + + {{ site_form.code_of_conduct }} +
    +
    + + {{ site_form.privacy_policy }} +
    @@ -42,16 +52,16 @@

    {% trans "Images" %}

    -
    -
    +
    +
    {{ site_form.logo }}
    -
    +
    {{ site_form.logo_small }}
    -
    +
    {{ site_form.favicon }}
    @@ -62,21 +72,23 @@ @@ -84,35 +96,37 @@

    {% trans "Registration" %}

    -
    - -
    -
    - -
    -
    - -

    {% trans "(Recommended if registration is open)" %}

    -
    -
    - - {{ site_form.registration_closed_text }} -
    -
    - - {{ site_form.invite_request_text }} - {% for error in site_form.invite_request_text.errors %} -

    {{ error|escape }}

    - {% endfor %} +
    +
    + +
    +
    + +
    +
    + +

    {% trans "(Recommended if registration is open)" %}

    +
    +
    + + {{ site_form.registration_closed_text }} +
    +
    + + {{ site_form.invite_request_text }} + {% for error in site_form.invite_request_text.errors %} +

    {{ error|escape }}

    + {% endfor %} +
    diff --git a/bookwyrm/templates/user_admin/delete_user_form.html b/bookwyrm/templates/settings/users/delete_user_form.html similarity index 100% rename from bookwyrm/templates/user_admin/delete_user_form.html rename to bookwyrm/templates/settings/users/delete_user_form.html diff --git a/bookwyrm/templates/user_admin/server_filter.html b/bookwyrm/templates/settings/users/server_filter.html similarity index 100% rename from bookwyrm/templates/user_admin/server_filter.html rename to bookwyrm/templates/settings/users/server_filter.html diff --git a/bookwyrm/templates/settings/users/user.html b/bookwyrm/templates/settings/users/user.html new file mode 100644 index 00000000..676502e6 --- /dev/null +++ b/bookwyrm/templates/settings/users/user.html @@ -0,0 +1,16 @@ +{% extends 'settings/layout.html' %} +{% load i18n %} + +{% block title %}{{ user.username }}{% endblock %} +{% block header %} +{{ user.username }} +{% trans "Back to users" %} +{% endblock %} + +{% block panel %} +{% include 'settings/users/user_info.html' with user=user %} + +{% include 'settings/users/user_moderation_actions.html' with user=user %} + +{% endblock %} + diff --git a/bookwyrm/templates/user_admin/user_admin.html b/bookwyrm/templates/settings/users/user_admin.html similarity index 97% rename from bookwyrm/templates/user_admin/user_admin.html rename to bookwyrm/templates/settings/users/user_admin.html index 024ebfec..874ce818 100644 --- a/bookwyrm/templates/user_admin/user_admin.html +++ b/bookwyrm/templates/settings/users/user_admin.html @@ -13,7 +13,7 @@ {% block panel %} -{% include 'user_admin/user_admin_filters.html' %} +{% include 'settings/users/user_admin_filters.html' %} diff --git a/bookwyrm/templates/user_admin/user_admin_filters.html b/bookwyrm/templates/settings/users/user_admin_filters.html similarity index 59% rename from bookwyrm/templates/user_admin/user_admin_filters.html rename to bookwyrm/templates/settings/users/user_admin_filters.html index c9c7a93f..48a3b7c8 100644 --- a/bookwyrm/templates/user_admin/user_admin_filters.html +++ b/bookwyrm/templates/settings/users/user_admin_filters.html @@ -1,7 +1,7 @@ {% extends 'snippets/filters_panel/filters_panel.html' %} {% block filter_fields %} -{% include 'user_admin/username_filter.html' %} +{% include 'settings/users/username_filter.html' %} {% include 'directory/community_filter.html' %} -{% include 'user_admin/server_filter.html' %} +{% include 'settings/users/server_filter.html' %} {% endblock %} diff --git a/bookwyrm/templates/user_admin/user_info.html b/bookwyrm/templates/settings/users/user_info.html similarity index 57% rename from bookwyrm/templates/user_admin/user_info.html rename to bookwyrm/templates/settings/users/user_info.html index 7ad57e0e..8d332b1a 100644 --- a/bookwyrm/templates/user_admin/user_info.html +++ b/bookwyrm/templates/settings/users/user_info.html @@ -48,58 +48,42 @@
    {% if user.local %} -
    -
    {% trans "Email:" %}
    -
    {{ user.email }}
    -
    +
    {% trans "Email:" %}
    +
    {{ user.email }}
    {% endif %} {% with report_count=user.report_set.count %} -
    -
    {% trans "Reports:" %}
    -
    - {{ report_count|intcomma }} - {% if report_count > 0 %} - - {% trans "(View reports)" %} - - {% endif %} -
    -
    +
    {% trans "Reports:" %}
    +
    + {{ report_count|intcomma }} + {% if report_count > 0 %} + + {% trans "(View reports)" %} + + {% endif %} +
    {% endwith %} -
    -
    {% trans "Blocked by count:" %}
    -
    {{ user.blocked_by.count }}
    -
    +
    {% trans "Blocked by count:" %}
    +
    {{ user.blocked_by.count }}
    -
    -
    {% trans "Last active date:" %}
    -
    {{ user.last_active_date }}
    -
    +
    {% trans "Last active date:" %}
    +
    {{ user.last_active_date }}
    -
    -
    {% trans "Manually approved followers:" %}
    -
    {{ user.manually_approves_followers }}
    -
    +
    {% trans "Manually approved followers:" %}
    +
    {{ user.manually_approves_followers }}
    -
    -
    {% trans "Discoverable:" %}
    -
    {{ user.discoverable }}
    -
    +
    {% trans "Discoverable:" %}
    +
    {{ user.discoverable }}
    {% if not user.is_active %} -
    -
    {% trans "Deactivation reason:" %}
    -
    {{ user.deactivation_reason }}
    -
    +
    {% trans "Deactivation reason:" %}
    +
    {{ user.deactivation_reason }}
    {% endif %} {% if not user.is_active and user.deactivation_reason == "pending" %} -
    -
    {% trans "Confirmation code:" %}
    -
    {{ user.confirmation_code }}
    -
    +
    {% trans "Confirmation code:" %}
    +
    {{ user.confirmation_code }}
    {% endif %}
    @@ -113,18 +97,14 @@ {% if server %}
    {{ server.server_name }}
    -
    -
    {% trans "Software:" %}
    -
    {{ server.application_type }}
    -
    -
    -
    {% trans "Version:" %}
    -
    {{ server.application_version }}
    -
    -
    -
    {% trans "Status:" %}
    -
    {{ server.status }}
    -
    +
    {% trans "Software:" %}
    +
    {{ server.application_type }}
    + +
    {% trans "Version:" %}
    +
    {{ server.application_version }}
    + +
    {% trans "Status:" %}
    +
    {{ server.status }}
    {% if server.notes %}
    {% trans "Notes" %}
    diff --git a/bookwyrm/templates/user_admin/user_moderation_actions.html b/bookwyrm/templates/settings/users/user_moderation_actions.html similarity index 95% rename from bookwyrm/templates/user_admin/user_moderation_actions.html rename to bookwyrm/templates/settings/users/user_moderation_actions.html index 12b70d3c..a976359f 100644 --- a/bookwyrm/templates/user_admin/user_moderation_actions.html +++ b/bookwyrm/templates/settings/users/user_moderation_actions.html @@ -36,7 +36,7 @@ {% if user.local %}
    - {% include "user_admin/delete_user_form.html" with controls_text="delete_user" class="mt-2 mb-2" %} + {% include "settings/users/delete_user_form.html" with controls_text="delete_user" class="mt-2 mb-2" %}
    {% endif %} diff --git a/bookwyrm/templates/user_admin/username_filter.html b/bookwyrm/templates/settings/users/username_filter.html similarity index 100% rename from bookwyrm/templates/user_admin/username_filter.html rename to bookwyrm/templates/settings/users/username_filter.html diff --git a/bookwyrm/templates/shelf/create_shelf_form.html b/bookwyrm/templates/shelf/create_shelf_form.html new file mode 100644 index 00000000..e15e1cc1 --- /dev/null +++ b/bookwyrm/templates/shelf/create_shelf_form.html @@ -0,0 +1,13 @@ +{% extends 'components/inline_form.html' %} +{% load i18n %} + +{% block header %} +{% trans "Create Shelf" %} +{% endblock %} + +{% block form %} + + {% include "shelf/form.html" with editable=shelf.editable form=create_form %} + +{% endblock %} + diff --git a/bookwyrm/templates/shelf/edit_shelf_form.html b/bookwyrm/templates/shelf/edit_shelf_form.html new file mode 100644 index 00000000..5951b6da --- /dev/null +++ b/bookwyrm/templates/shelf/edit_shelf_form.html @@ -0,0 +1,13 @@ +{% extends 'components/inline_form.html' %} +{% load i18n %} + +{% block header %} +{% trans "Edit Shelf" %} +{% endblock %} + +{% block form %} + + {% include "shelf/form.html" with editable=shelf.editable form=edit_form privacy=shelf.privacy %} + +{% endblock %} + diff --git a/bookwyrm/templates/shelf/form.html b/bookwyrm/templates/shelf/form.html new file mode 100644 index 00000000..ff7f8b5e --- /dev/null +++ b/bookwyrm/templates/shelf/form.html @@ -0,0 +1,28 @@ +{% load i18n %} +{% load utilities %} +{% with 0|uuid as uuid %} +{% csrf_token %} + + +{% if editable %} +
    + + +
    +{% else %} + +{% endif %} + +
    + + +
    +
    +
    + {% include 'snippets/privacy_select.html' with current=privacy %} +
    +
    + +
    +
    +{% endwith %} diff --git a/bookwyrm/templates/user/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html similarity index 70% rename from bookwyrm/templates/user/shelf/shelf.html rename to bookwyrm/templates/shelf/shelf.html index 06507d3e..88f4b2bb 100644 --- a/bookwyrm/templates/user/shelf/shelf.html +++ b/bookwyrm/templates/shelf/shelf.html @@ -5,7 +5,7 @@ {% load i18n %} {% block title %} -{% include 'user/shelf/books_header.html' %} +{% include 'user/books_header.html' %} {% endblock %} {% block opengraph_images %} @@ -15,7 +15,7 @@ {% block content %}

    - {% include 'user/shelf/books_header.html' %} + {% include 'user/books_header.html' %}

    @@ -60,45 +60,62 @@
    - {% include 'user/shelf/create_shelf_form.html' with controls_text='create_shelf_form' %} + {% include 'shelf/create_shelf_form.html' with controls_text='create_shelf_form' %}
    -
    -
    -

    - {{ shelf.name }} - - {% include 'snippets/privacy-icons.html' with item=shelf %} - - {% with count=books.paginator.count %} - {% if count %} -

    - {% blocktrans trimmed count counter=count with formatted_count=count|intcomma %} - {{ formatted_count }} book - {% plural %} - {{ formatted_count }} books - {% endblocktrans %} - - {% if books.has_other_pages %} - {% blocktrans trimmed with start=books.start_index end=books.end_index %} - (showing {{ start }}-{{ end }}) +

    +
    +
    +

    + {{ shelf.name }} + + {% include 'snippets/privacy-icons.html' with item=shelf %} + + {% with count=books.paginator.count %} + {% if count %} +

    + {% blocktrans trimmed count counter=count with formatted_count=count|intcomma %} + {{ formatted_count }} book + {% plural %} + {{ formatted_count }} books {% endblocktrans %} + + {% if books.has_other_pages %} + {% blocktrans trimmed with start=books.start_index end=books.end_index %} + (showing {{ start }}-{{ end }}) + {% endblocktrans %} + {% endif %} +

    {% endif %} -

    - {% endif %} - {% endwith %} -

    -
    - {% if is_self and shelf.id %} -
    - {% trans "Edit shelf" as button_text %} - {% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_shelf_form" focus="edit_shelf_form_header" %} + {% endwith %} +

    +
    + {% if is_self and shelf.id %} +
    +
    + {% trans "Edit shelf" as button_text %} + {% include 'snippets/toggle/open_button.html' with text=button_text icon_with_text="pencil" controls_text="edit_shelf_form" focus="edit_shelf_form_header" %} + + {% if shelf.deletable %} +
    + {% csrf_token %} + + + + {% endif %} +
    +
    + {% endif %}
    + {% if shelf.description %} +

    {{ shelf.description }}

    {% endif %}
    - {% include 'user/shelf/edit_shelf_form.html' with controls_text="edit_shelf_form" %} + {% include 'shelf/edit_shelf_form.html' with controls_text="edit_shelf_form" %}
    @@ -167,17 +184,7 @@
    {% else %} -

    {% trans "This shelf is empty." %}

    - {% if shelf.id and shelf.editable %} -
    - {% csrf_token %} - - -
    - {% endif %} - +

    {% trans "This shelf is empty." %}

    {% endif %}
    diff --git a/bookwyrm/templates/snippets/goal_form.html b/bookwyrm/templates/snippets/goal_form.html index 3afcf2ac..f05d8b8b 100644 --- a/bookwyrm/templates/snippets/goal_form.html +++ b/bookwyrm/templates/snippets/goal_form.html @@ -1,36 +1,36 @@ {% load i18n %} -
    - {% csrf_token %} - - +
    +

    {% blocktrans %}Set a goal for how many books you'll finish reading in {{ year }}, and track your progress throughout the year.{% endblocktrans %}

    -
    -
    - -
    -
    - + + {% csrf_token %} + + + +
    +
    + +
    +
    + +
    +
    - +
    + +
    + + {% include 'snippets/privacy_select.html' with no_label=True current=goal.privacy uuid=goal.id %}
    -
    - -
    -
    - + -

    - - {% if goal %} - {% trans "Cancel" as button_text %} - {% include 'snippets/toggle/close_button.html' with text=button_text controls_text="show_edit_goal" %} - {% endif %} -

    - +
    + +
    + +
    diff --git a/bookwyrm/templates/snippets/privacy_select.html b/bookwyrm/templates/snippets/privacy_select.html index d7184e13..e1053051 100644 --- a/bookwyrm/templates/snippets/privacy_select.html +++ b/bookwyrm/templates/snippets/privacy_select.html @@ -1,7 +1,7 @@ {% load i18n %} {% load utilities %}
    - {% with 0|uuid as uuid %} + {% firstof uuid 0|uuid as uuid %} {% if not no_label %} {% endif %} @@ -20,6 +20,5 @@ {% trans "Private" %} - {% endwith %}
    diff --git a/bookwyrm/templates/snippets/progress_field.html b/bookwyrm/templates/snippets/progress_field.html new file mode 100644 index 00000000..8feb5a58 --- /dev/null +++ b/bookwyrm/templates/snippets/progress_field.html @@ -0,0 +1,27 @@ +{% load i18n %} +
    +
    + +
    +
    + +
    +
    diff --git a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html index b041b70a..96e4da9b 100644 --- a/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/finish_reading_modal.html @@ -11,6 +11,7 @@ Finish "{{ book_title }}" {% block modal-form-open %}
    {% csrf_token %} + {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/form.html b/bookwyrm/templates/snippets/reading_modals/form.html index 382407ba..4a7ac3a5 100644 --- a/bookwyrm/templates/snippets/reading_modals/form.html +++ b/bookwyrm/templates/snippets/reading_modals/form.html @@ -5,12 +5,13 @@ {% block content_label %} {% trans "Comment:" %} +{% if optional %} {% trans "(Optional)" %} +{% endif %} {% endblock %} {% block initial_fields %} - {% endblock %} diff --git a/bookwyrm/templates/snippets/reading_modals/layout.html b/bookwyrm/templates/snippets/reading_modals/layout.html index 0f5dedb0..95010b37 100644 --- a/bookwyrm/templates/snippets/reading_modals/layout.html +++ b/bookwyrm/templates/snippets/reading_modals/layout.html @@ -13,14 +13,18 @@ {% trans "Post to feed" %}
    - {% include "snippets/reading_modals/form.html" with optional=True %} + {% comparison_bool controls_text "progress_update" True as optional %} + {% include "snippets/reading_modals/form.html" with optional=optional %}
    {% endwith %} diff --git a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html index b2aa27a6..713dad8d 100644 --- a/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html +++ b/bookwyrm/templates/snippets/reading_modals/progress_update_modal.html @@ -1,4 +1,4 @@ -{% extends 'components/modal.html' %} +{% extends 'snippets/reading_modals/layout.html' %} {% load i18n %} {% block modal-title %} @@ -6,42 +6,12 @@ {% endblock %} {% block modal-form-open %} - -{% endblock %} - -{% block modal-body %} + {% csrf_token %} - -
    - -
    -
    - -
    -
    - -
    -
    - {% if readthrough.progress_mode == 'PG' and book.pages %} -

    {% blocktrans with pages=book.pages %}of {{ pages }} pages{% endblocktrans %}

    - {% endif %} -
    + {% endblock %} -{% block modal-footer %} - -{% trans "Cancel" as button_text %} -{% include 'snippets/toggle/toggle_button.html' with text=button_text %} +{% block reading-dates %} + +{% include "snippets/progress_field.html" with progress_required=True %} {% endblock %} -{% block modal-form-close %}{% endblock %} diff --git a/bookwyrm/templates/snippets/readthrough_form.html b/bookwyrm/templates/snippets/readthrough_form.html index 132472d2..8810778c 100644 --- a/bookwyrm/templates/snippets/readthrough_form.html +++ b/bookwyrm/templates/snippets/readthrough_form.html @@ -13,17 +13,7 @@ -
    -
    - -
    -
    - -
    -
    +{% include "snippets/progress_field.html" %} {% endif %}