diff --git a/bookwyrm/forms/admin.py b/bookwyrm/forms/admin.py index 6b2984b3b..4141327d3 100644 --- a/bookwyrm/forms/admin.py +++ b/bookwyrm/forms/admin.py @@ -5,6 +5,7 @@ from django import forms from django.forms import widgets from django.utils import timezone from django.utils.translation import gettext_lazy as _ +from django_celery_beat.models import IntervalSchedule from bookwyrm import models from .custom_form import CustomForm @@ -127,3 +128,14 @@ class AutoModRuleForm(CustomForm): class Meta: model = models.AutoMod fields = ["string_match", "flag_users", "flag_statuses", "created_by"] + + +class IntervalScheduleForm(CustomForm): + class Meta: + model = IntervalSchedule + fields = ["every", "period"] + + widgets = { + "every": forms.NumberInput(attrs={"aria-describedby": "desc_every"}), + "period": forms.Select(attrs={"aria-describedby": "desc_period"}), + } diff --git a/bookwyrm/forms/books.py b/bookwyrm/forms/books.py index 72df1371c..20f307fae 100644 --- a/bookwyrm/forms/books.py +++ b/bookwyrm/forms/books.py @@ -85,3 +85,27 @@ class EditionForm(CustomForm): ), "ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}), } + + +class EditionFromWorkForm(CustomForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + # make all fields hidden + for visible in self.visible_fields(): + visible.field.widget = forms.HiddenInput() + + class Meta: + model = models.Work + fields = [ + "title", + "subtitle", + "authors", + "description", + "languages", + "series", + "series_number", + "subjects", + "subject_places", + "cover", + "first_published_date", + ] diff --git a/bookwyrm/forms/landing.py b/bookwyrm/forms/landing.py index 61b92ee83..b01c2cc98 100644 --- a/bookwyrm/forms/landing.py +++ b/bookwyrm/forms/landing.py @@ -42,4 +42,4 @@ class InviteRequestForm(CustomForm): class Meta: model = models.InviteRequest - fields = ["email"] + fields = ["email", "answer"] diff --git a/bookwyrm/management/commands/instance_version.py b/bookwyrm/management/commands/instance_version.py new file mode 100644 index 000000000..ca150d640 --- /dev/null +++ b/bookwyrm/management/commands/instance_version.py @@ -0,0 +1,54 @@ +""" Get your admin code to allow install """ +from django.core.management.base import BaseCommand + +from bookwyrm import models +from bookwyrm.settings import VERSION + + +# pylint: disable=no-self-use +class Command(BaseCommand): + """command-line options""" + + help = "What version is this?" + + def add_arguments(self, parser): + """specify which function to run""" + parser.add_argument( + "--current", + action="store_true", + help="Version stored in database", + ) + parser.add_argument( + "--target", + action="store_true", + help="Version stored in settings", + ) + parser.add_argument( + "--update", + action="store_true", + help="Update database version", + ) + + # pylint: disable=unused-argument + def handle(self, *args, **options): + """execute init""" + site = models.SiteSettings.objects.get() + current = site.version or "0.0.1" + target = VERSION + if options.get("current"): + print(current) + return + + if options.get("target"): + print(target) + return + + if options.get("update"): + site.version = target + site.save() + return + + if current != target: + print(f"{current}/{target}") + else: + print(current) diff --git a/bookwyrm/migrations/0145_sitesettings_version.py b/bookwyrm/migrations/0145_sitesettings_version.py new file mode 100644 index 000000000..649f90abe --- /dev/null +++ b/bookwyrm/migrations/0145_sitesettings_version.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-03-16 18:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0144_alter_announcement_display_type"), + ] + + operations = [ + migrations.AddField( + model_name="sitesettings", + name="version", + field=models.CharField(blank=True, max_length=10, null=True), + ), + ] diff --git a/bookwyrm/migrations/0146_auto_20220316_2352.py b/bookwyrm/migrations/0146_auto_20220316_2352.py new file mode 100644 index 000000000..2eab3b562 --- /dev/null +++ b/bookwyrm/migrations/0146_auto_20220316_2352.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.12 on 2022-03-16 23:52 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0145_sitesettings_version"), + ] + + operations = [ + migrations.AddField( + model_name="inviterequest", + name="answer", + field=models.TextField(blank=True, max_length=50, null=True), + ), + migrations.AddField( + model_name="sitesettings", + name="invite_question_text", + field=models.CharField( + blank=True, default="What is your favourite book?", max_length=255 + ), + ), + migrations.AddField( + model_name="sitesettings", + name="invite_request_question", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookwyrm/models/site.py b/bookwyrm/models/site.py index c6c53f765..7730391f1 100644 --- a/bookwyrm/models/site.py +++ b/bookwyrm/models/site.py @@ -27,6 +27,7 @@ class SiteSettings(models.Model): default_theme = models.ForeignKey( "Theme", null=True, blank=True, on_delete=models.SET_NULL ) + version = models.CharField(null=True, blank=True, max_length=10) # admin setup options install_mode = models.BooleanField(default=False) @@ -48,8 +49,12 @@ class SiteSettings(models.Model): # registration allow_registration = models.BooleanField(default=False) allow_invite_requests = models.BooleanField(default=True) + invite_request_question = models.BooleanField(default=False) require_confirm_email = models.BooleanField(default=True) + invite_question_text = models.CharField( + max_length=255, blank=True, default="What is your favourite book?" + ) # images logo = models.ImageField(upload_to="logos/", null=True, blank=True) logo_small = models.ImageField(upload_to="logos/", null=True, blank=True) @@ -99,11 +104,14 @@ class SiteSettings(models.Model): return urljoin(STATIC_FULL_URL, default_path) def save(self, *args, **kwargs): - """if require_confirm_email is disabled, make sure no users are pending""" + """if require_confirm_email is disabled, make sure no users are pending, + if enabled, make sure invite_question_text is not empty""" if not self.require_confirm_email: User.objects.filter(is_active=False, deactivation_reason="pending").update( is_active=True, deactivation_reason=None ) + if not self.invite_question_text: + self.invite_question_text = "What is your favourite book?" super().save(*args, **kwargs) @@ -149,6 +157,7 @@ class InviteRequest(BookWyrmModel): invite = models.ForeignKey( SiteInvite, on_delete=models.SET_NULL, null=True, blank=True ) + answer = models.TextField(max_length=50, unique=False, null=True, blank=True) invite_sent = models.BooleanField(default=False) ignored = models.BooleanField(default=False) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index ca4003eff..bb7d81220 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -11,7 +11,7 @@ from django.utils.translation import gettext_lazy as _ env = Env() env.read_env() DOMAIN = env("DOMAIN") -VERSION = "0.3.3" +VERSION = "0.3.4" RELEASE_API = env( "RELEASE_API", @@ -90,6 +90,7 @@ INSTALLED_APPS = [ "sass_processor", "bookwyrm", "celery", + "django_celery_beat", "imagekit", "storages", ] diff --git a/bookwyrm/static/css/themes/bookwyrm-dark.scss b/bookwyrm/static/css/themes/bookwyrm-dark.scss index 466d8026d..0a4f6f23e 100644 --- a/bookwyrm/static/css/themes/bookwyrm-dark.scss +++ b/bookwyrm/static/css/themes/bookwyrm-dark.scss @@ -8,7 +8,9 @@ $primary: #005e50; $primary-light: #1d2b28; $info: #1f4666; $success: #246447; +$success-light: #0d2f1e; $warning: #8b6c15; +$warning-light: #372e13; $danger: #872538; $danger-light: #481922; $light: #393939; diff --git a/bookwyrm/templates/book/book.html b/bookwyrm/templates/book/book.html index fa098281e..453480f99 100644 --- a/bookwyrm/templates/book/book.html +++ b/bookwyrm/templates/book/book.html @@ -208,9 +208,17 @@ {% endif %} - {% if book.parent_work.editions.count > 1 %} -

{% blocktrans with path=book.parent_work.local_path count=book.parent_work.editions.count %}{{ count }} editions{% endblocktrans %}

- {% endif %} + {% with work=book.parent_work %} +

+ + {% blocktrans trimmed count counter=work.editions.count with count=work.editions.count|intcomma %} + {{ count }} edition + {% plural %} + {{ count }} editions + {% endblocktrans %} + +

+ {% endwith %} {# user's relationship to the book #} diff --git a/bookwyrm/templates/book/edit/edit_book.html b/bookwyrm/templates/book/edit/edit_book.html index 3d41058e3..b088c1e87 100644 --- a/bookwyrm/templates/book/edit/edit_book.html +++ b/bookwyrm/templates/book/edit/edit_book.html @@ -3,18 +3,24 @@ {% load humanize %} {% load utilities %} -{% block title %}{% if book %}{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}{% else %}{% trans "Add Book" %}{% endif %}{% endblock %} +{% block title %} + {% if book.title %} + {% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %} + {% else %} + {% trans "Add Book" %} + {% endif %} +{% endblock %} {% block content %}

- {% if book %} + {% if book.title %} {% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %} {% else %} {% trans "Add Book" %} {% endif %}

- {% if book %} + {% if book.created_date %}
{% trans "Added:" %}
{{ book.created_date | naturaltime }}
@@ -33,7 +39,7 @@
{{ match.parent_work.title }} {% endfor %} -