forked from mirrors/bookwyrm
Use urlfield
This commit is contained in:
parent
1d6b200172
commit
4f576b77a0
7 changed files with 36 additions and 14 deletions
|
@ -216,6 +216,12 @@ class CoverForm(CustomForm):
|
|||
help_texts = {f: None for f in fields}
|
||||
|
||||
|
||||
class FileLinkForm(CustomForm):
|
||||
class Meta:
|
||||
model = models.FileLink
|
||||
exclude = ["remote_id"]
|
||||
|
||||
|
||||
class EditionForm(CustomForm):
|
||||
class Meta:
|
||||
model = models.Edition
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# Generated by Django 3.2.5 on 2021-12-15 18:18
|
||||
# Generated by Django 3.2.5 on 2021-12-15 20:38
|
||||
|
||||
import bookwyrm.models.activitypub_mixin
|
||||
import bookwyrm.models.fields
|
||||
|
@ -35,13 +35,13 @@ class Migration(migrations.Migration):
|
|||
validators=[bookwyrm.models.fields.validate_remote_id],
|
||||
),
|
||||
),
|
||||
("url", bookwyrm.models.fields.CharField(max_length=255)),
|
||||
("url", bookwyrm.models.fields.URLField(max_length=255)),
|
||||
("name", bookwyrm.models.fields.CharField(max_length=255)),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
bases=(bookwyrm.models.activitypub_mixin.CollectionItemMixin, models.Model),
|
||||
bases=(bookwyrm.models.activitypub_mixin.ActivitypubMixin, models.Model),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="FileLink",
|
||||
|
@ -58,10 +58,6 @@ class Migration(migrations.Migration):
|
|||
),
|
||||
),
|
||||
("filetype", bookwyrm.models.fields.CharField(max_length=5)),
|
||||
(
|
||||
"filetype_description",
|
||||
bookwyrm.models.fields.CharField(max_length=100),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
|
@ -516,6 +516,10 @@ class CharField(ActivitypubFieldMixin, models.CharField):
|
|||
"""activitypub-aware char field"""
|
||||
|
||||
|
||||
class URLField(ActivitypubFieldMixin, models.URLField):
|
||||
"""activitypub-aware url field"""
|
||||
|
||||
|
||||
class TextField(ActivitypubFieldMixin, models.TextField):
|
||||
"""activitypub-aware text field"""
|
||||
|
||||
|
|
|
@ -1,18 +1,24 @@
|
|||
""" outlink data """
|
||||
from .activitypub_mixin import CollectionItemMixin
|
||||
from .activitypub_mixin import ActivitypubMixin
|
||||
from .base_model import BookWyrmModel
|
||||
from . import fields
|
||||
|
||||
|
||||
class Link(CollectionItemMixin, BookWyrmModel):
|
||||
class Link(ActivitypubMixin, BookWyrmModel):
|
||||
"""a link to a website"""
|
||||
|
||||
url = fields.CharField(max_length=255)
|
||||
url = fields.URLField(max_length=255)
|
||||
name = fields.CharField(max_length=255)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""create a link"""
|
||||
# this is never broadcast, the owning model broadcasts an update
|
||||
if "broadcast" in kwargs:
|
||||
del kwargs["broadcast"]
|
||||
return super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class FileLink(Link):
|
||||
"""a link to a file"""
|
||||
|
||||
filetype = fields.CharField(max_length=5)
|
||||
filetype_description = fields.CharField(max_length=100)
|
||||
|
|
|
@ -351,7 +351,10 @@
|
|||
{% if book.file_links %}
|
||||
<ul>
|
||||
{% for link in book.file_links.all %}
|
||||
<li><a href="{{ link.url }}">{{ link.name }}</a> ({{ link.filetype }})</li>
|
||||
<li>
|
||||
<a href="{{ link.url }}" rel="noopener" target="_blank" title="{{ link.url }}">{{ link.name }}</a>
|
||||
({{ link.filetype }})
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{% endif %}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<div class="columns">
|
||||
<div class="column is-four-fifths">
|
||||
<label class="label" for="id_url">{% trans "URL:" %}</label>
|
||||
<input type="text" name="url" maxlength="255" class="input" required="" id="id_url" value="{% firstof file_link_form.url.value "" %}" placeholder="https://...">
|
||||
<input type="url" name="url" maxlength="255" class="input" required="" id="id_url" value="{% firstof file_link_form.url.value "" %}" placeholder="https://...">
|
||||
</div>
|
||||
<div class="column is-one-fifth">
|
||||
<label class="label" for="id_filetype">{% trans "File type:" %}</label>
|
||||
|
|
|
@ -427,7 +427,14 @@ urlpatterns = [
|
|||
re_path(
|
||||
r"^upload-cover/(?P<book_id>\d+)/?$", views.upload_cover, name="upload-cover"
|
||||
),
|
||||
re_path(r"^add-description/(?P<book_id>\d+)/?$", views.add_description),
|
||||
re_path(
|
||||
r"^add-description/(?P<book_id>\d+)/?$",
|
||||
views.add_description,
|
||||
name="add-description",
|
||||
),
|
||||
re_path(
|
||||
r"^add-file-link/(?P<book_id>\d+)/?$", views.add_file_link, name="add-file-link"
|
||||
),
|
||||
re_path(r"^resolve-book/?$", views.resolve_book, name="resolve-book"),
|
||||
re_path(r"^switch-edition/?$", views.switch_edition, name="switch-edition"),
|
||||
re_path(
|
||||
|
|
Loading…
Reference in a new issue