Merge branch 'main' into production

This commit is contained in:
Mouse Reeve 2021-04-08 09:22:24 -07:00
commit 4ee738ae52
4 changed files with 50 additions and 5 deletions

View file

@ -0,0 +1,27 @@
# Generated by Django 3.1.6 on 2021-04-08 15:56
import bookwyrm.models.fields
import django.contrib.postgres.fields.citext
import django.contrib.postgres.operations
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("bookwyrm", "0062_auto_20210407_1545"),
]
operations = [
django.contrib.postgres.operations.CITextExtension(),
migrations.AlterField(
model_name="user",
name="localname",
field=django.contrib.postgres.fields.citext.CICharField(
max_length=255,
null=True,
unique=True,
validators=[bookwyrm.models.fields.validate_localname],
),
),
]

View file

@ -4,6 +4,7 @@ from urllib.parse import urlparse
from django.apps import apps
from django.contrib.auth.models import AbstractUser, Group
from django.contrib.postgres.fields import CICharField
from django.core.validators import MinValueValidator
from django.db import models
from django.utils import timezone
@ -54,7 +55,7 @@ class User(OrderedCollectionPageMixin, AbstractUser):
summary = fields.HtmlField(null=True, blank=True)
local = models.BooleanField(default=False)
bookwyrm_user = fields.BooleanField(default=True)
localname = models.CharField(
localname = CICharField(
max_length=255,
null=True,
unique=True,

View file

@ -90,7 +90,7 @@
<h2 class="title is-4">{% trans "Metadata" %}</h2>
<p class="mb-2">
<label class="label" for="id_title">{% trans "Title:" %}</label>
<input type="text" name="title" value="{{ form.title.value }}" maxlength="255" class="input" required="" id="id_title">
<input type="text" name="title" value="{{ form.title.value|default:'' }}" maxlength="255" class="input" required="" id="id_title">
</p>
{% for error in form.title.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -98,7 +98,7 @@
<p class="mb-2">
<label class="label" for="id_subtitle">{% trans "Subtitle:" %}</label>
<input type="text" name="subtitle" value="{{ form.subtitle.value }}" maxlength="255" class="input" required="" id="id_subtitle">
<input type="text" name="subtitle" value="{{ form.subtitle.value|default:'' }}" maxlength="255" class="input" required="" id="id_subtitle">
</p>
{% for error in form.subtitle.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -130,7 +130,7 @@
<p class="mb-2">
<label class="label" for="id_first_published_date">{% trans "First published date:" %}</label>
<input type="date" name="first_published_date" class="input" id="id_first_published_date"{% if book.first_published_date %} value="{{ book.first_published_date|date:'Y-m-d' }}"{% endif %}>
<input type="date" name="first_published_date" class="input" id="id_first_published_date"{% if form.first_published_date.value %} value="{{ form.first_published_date.value|date:'Y-m-d' }}"{% endif %}>
</p>
{% for error in form.first_published_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>
@ -138,7 +138,7 @@
<p class="mb-2">
<label class="label" for="id_published_date">{% trans "Published date:" %}</label>
<input type="date" name="published_date" class="input" id="id_published_date"{% if book.published_date %} value="{{ book.published_date|date:'Y-m-d' }}"{% endif %}>
<input type="date" name="published_date" class="input" id="id_published_date"{% if form.published_date.value %} value="{{ form.published_date.value|date:'Y-m-d'}}"{% endif %}>
</p>
{% for error in form.published_date.errors %}
<p class="help is-danger">{{ error | escape }}</p>

View file

@ -1,6 +1,8 @@
""" the good stuff! the books! """
from datetime import datetime
from uuid import uuid4
from dateutil.parser import parse as dateparse
from django.contrib.auth.decorators import login_required, permission_required
from django.contrib.postgres.search import SearchRank, SearchVector
from django.core.files.base import ContentFile
@ -10,6 +12,7 @@ from django.db.models import Avg, Q
from django.http import HttpResponseBadRequest, HttpResponseNotFound
from django.shortcuts import get_object_or_404, redirect
from django.template.response import TemplateResponse
from django.utils.datastructures import MultiValueDictKeyError
from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.http import require_POST
@ -172,6 +175,20 @@ class EditBook(View):
data["confirm_mode"] = True
# this isn't preserved because it isn't part of the form obj
data["remove_authors"] = request.POST.getlist("remove_authors")
# we have to make sure the dates are passed in as datetime, they're currently a string
# QueryDicts are immutable, we need to copy
formcopy = data["form"].data.copy()
try:
formcopy["first_published_date"] = dateparse(
formcopy["first_published_date"]
)
except MultiValueDictKeyError:
pass
try:
formcopy["published_date"] = dateparse(formcopy["published_date"])
except MultiValueDictKeyError:
pass
data["form"].data = formcopy
return TemplateResponse(request, "book/edit_book.html", data)
remove_authors = request.POST.getlist("remove_authors")