Skip to content

Commit

Permalink
Merge branch 'main' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-reeve committed Mar 17, 2022
2 parents 6f9488f + 2047365 commit 67bb154
Show file tree
Hide file tree
Showing 54 changed files with 3,139 additions and 2,025 deletions.
12 changes: 12 additions & 0 deletions bookwyrm/forms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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
Expand Down Expand Up @@ -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"}),
}
24 changes: 24 additions & 0 deletions bookwyrm/forms/books.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ class Meta:
),
"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",
]
2 changes: 1 addition & 1 deletion bookwyrm/forms/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ def clean(self):

class Meta:
model = models.InviteRequest
fields = ["email"]
fields = ["email", "answer"]
54 changes: 54 additions & 0 deletions bookwyrm/management/commands/instance_version.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions bookwyrm/migrations/0145_sitesettings_version.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
30 changes: 30 additions & 0 deletions bookwyrm/migrations/0146_auto_20220316_2352.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
11 changes: 10 additions & 1 deletion bookwyrm/models/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -99,11 +104,14 @@ def get_url(self, field, default_path):
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)


Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion bookwyrm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
env = Env()
env.read_env()
DOMAIN = env("DOMAIN")
VERSION = "0.3.3"
VERSION = "0.3.4"

RELEASE_API = env(
"RELEASE_API",
Expand Down Expand Up @@ -90,6 +90,7 @@
"sass_processor",
"bookwyrm",
"celery",
"django_celery_beat",
"imagekit",
"storages",
]
Expand Down
2 changes: 2 additions & 0 deletions bookwyrm/static/css/themes/bookwyrm-dark.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 11 additions & 3 deletions bookwyrm/templates/book/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,17 @@ <h1 class="title" itemprop="name">
{% endif %}


{% if book.parent_work.editions.count > 1 %}
<p>{% blocktrans with path=book.parent_work.local_path count=book.parent_work.editions.count %}<a href="{{ path }}/editions">{{ count }} editions</a>{% endblocktrans %}</p>
{% endif %}
{% with work=book.parent_work %}
<p>
<a href="{{ work.local_path }}/editions">
{% blocktrans trimmed count counter=work.editions.count with count=work.editions.count|intcomma %}
{{ count }} edition
{% plural %}
{{ count }} editions
{% endblocktrans %}
</a>
</p>
{% endwith %}
</div>

{# user's relationship to the book #}
Expand Down
18 changes: 12 additions & 6 deletions bookwyrm/templates/book/edit/edit_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
<header class="block">
<h1 class="title level-left">
{% if book %}
{% if book.title %}
{% blocktrans with book_title=book.title %}Edit "{{ book_title }}"{% endblocktrans %}
{% else %}
{% trans "Add Book" %}
{% endif %}
</h1>
{% if book %}
{% if book.created_date %}
<dl>
<dt class="is-pulled-left mr-5 has-text-weight-semibold">{% trans "Added:" %}</dt>
<dd class="ml-2">{{ book.created_date | naturaltime }}</dd>
Expand All @@ -33,7 +39,7 @@ <h1 class="title level-left">

<form
class="block"
{% if book %}
{% if book.id %}
name="edit-book"
action="{{ book.local_path }}/{% if confirm_mode %}confirm{% else %}edit{% endif %}"
{% else %}
Expand Down Expand Up @@ -97,7 +103,7 @@ <h2 class="title is-4">{% trans "Confirm Book Info" %}</h2>
<input type="radio" name="parent_work" value="{{ match.parent_work.id }}"> {{ match.parent_work.title }}
</label>
{% endfor %}
<label>
<label class="label mt-2">
<input type="radio" name="parent_work" value="0" required> {% trans "This is a new work" %}
</label>
</fieldset>
Expand All @@ -119,7 +125,7 @@ <h2 class="title is-4">{% trans "Confirm Book Info" %}</h2>
{% if not confirm_mode %}
<div class="block">
<button class="button is-primary" type="submit">{% trans "Save" %}</button>
{% if book %}
{% if book.id %}
<a class="button" href="{{ book.local_path }}">{% trans "Cancel" %}</a>
{% else %}
<a href="/" class="button" data-back>
Expand Down
4 changes: 4 additions & 0 deletions bookwyrm/templates/book/edit/edit_book_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
{% csrf_token %}

<input type="hidden" name="last_edited_by" value="{{ request.user.id }}">
<input type="hidden" name="parent_work" value="{% firstof book.parent_work.id form.parent_work %}">

<div class="columns">
<div class="column is-half">
<section class="block">
Expand Down Expand Up @@ -175,6 +177,8 @@ <h2 class="title is-4">
</h2>
<div class="box">
{% if book.authors.exists %}
{# preserve authors if the book is unsaved #}
<input type="hidden" name="authors" value="{% for author in book.authors %}{{ author.id }},{% endfor %}">
<fieldset>
{% for author in book.authors.all %}
<div class="is-flex is-justify-content-space-between">
Expand Down
31 changes: 30 additions & 1 deletion bookwyrm/templates/book/editions/editions.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,36 @@ <h2 class="title is-5 mb-1">
{% endfor %}
</div>

<div>
<div class="block">
{% include 'snippets/pagination.html' with page=editions path=request.path %}
</div>

<div class="block has-text-centered help">
<p>
{% trans "Can't find the edition you're looking for?" %}
</p>

<form action="{% url 'create-book-data' %}" method="POST" name="add-edition-form">
{% csrf_token %}
{{ work_form.title }}
{{ work_form.subtitle }}
{{ work_form.authors }}
{{ work_form.description }}
{{ work_form.languages }}
{{ work_form.series }}
{{ work_form.cover }}
{{ work_form.first_published_date }}
{% for subject in work.subjects %}
<input type="hidden" name="subjects" value="{{ subject }}">
{% endfor %}

<input type="hidden" name="parent_work" value="{{ work.id }}">
<div>
<button class="button is-small" type="submit">
{% trans "Add another edition" %}
</button>
</div>
</form>
</div>

{% endblock %}
2 changes: 1 addition & 1 deletion bookwyrm/templates/book/file_links/edit_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<header class="block">
<h1 class="title">
{% blocktrans with title=book|book_title %}
{% blocktrans trimmed with title=book|book_title %}
Links for "<em>{{ title }}</em>"
{% endblocktrans %}
</h1>
Expand Down
8 changes: 8 additions & 0 deletions bookwyrm/templates/landing/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ <h2 class="title">

{% include 'snippets/form_errors.html' with errors_list=request_form.email.errors id="desc_request_email" %}
</div>
{% if site.invite_request_question %}
<div class="block">
<label for="id_answer_register" class="label">{{ site.invite_question_text }}</label>
<input type="answer" name="answer" maxlength="50" class="input" required="true" id="id_answer_register" aria-describedby="desc_answer_register">
{% include 'snippets/form_errors.html' with errors_list=request_form.answer.errors id="desc_answer_register" %}
</div>
{% endif %}

<button type="submit" class="button is-link">{% trans "Submit" %}</button>
</form>
{% endif %}
Expand Down
Loading

0 comments on commit 67bb154

Please sign in to comment.