forked from mirrors/bookwyrm
Adds list creation form
This commit is contained in:
parent
91483b56f5
commit
69c2b192a4
6 changed files with 104 additions and 12 deletions
|
@ -206,3 +206,9 @@ class SiteForm(CustomForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.SiteSettings
|
model = models.SiteSettings
|
||||||
exclude = []
|
exclude = []
|
||||||
|
|
||||||
|
|
||||||
|
class ListForm(CustomForm):
|
||||||
|
class Meta:
|
||||||
|
model = models.List
|
||||||
|
fields = ['user', 'name', 'description', 'curation', 'privacy']
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from bookwyrm import activitypub
|
from bookwyrm import activitypub
|
||||||
|
from bookwyrm.settings import DOMAIN
|
||||||
from .base_model import ActivitypubMixin, BookWyrmModel
|
from .base_model import ActivitypubMixin, BookWyrmModel
|
||||||
from .base_model import OrderedCollectionMixin
|
from .base_model import OrderedCollectionMixin
|
||||||
from . import fields
|
from . import fields
|
||||||
|
@ -35,6 +36,11 @@ class List(OrderedCollectionMixin, BookWyrmModel):
|
||||||
through='ListItem',
|
through='ListItem',
|
||||||
through_fields=('book_list', 'book'),
|
through_fields=('book_list', 'book'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_remote_id(self):
|
||||||
|
''' don't want the user to be in there in this case '''
|
||||||
|
return 'https://%s/list/%d' % (DOMAIN, self.id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def collection_queryset(self):
|
def collection_queryset(self):
|
||||||
''' list of books for this shelf, overrides OrderedCollectionMixin '''
|
''' list of books for this shelf, overrides OrderedCollectionMixin '''
|
||||||
|
|
|
@ -1,16 +1,92 @@
|
||||||
{% extends 'layout.html' %}
|
{% extends 'layout.html' %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>lists</h1>
|
<header class="block">
|
||||||
|
<h1 class="title">Lists</h1>
|
||||||
|
</header>
|
||||||
|
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<h2>Your lists</h2>
|
<section class="block">
|
||||||
|
<header class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<h2 class="title is-3">Your lists</h2>
|
||||||
|
</div>
|
||||||
|
<div class="column is-narrow">
|
||||||
|
{% include 'snippets/toggle/open_button.html' with controls_text="create-list" icon="plus" text="Create new list" %}
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<form name="create-list" method="post" action="{% url 'lists' %}" class="box hiddenx" id="create-list">
|
||||||
|
<h3 class="title is-4">Create list</h3>
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="user" value="{{ request.user.id }}">
|
||||||
|
|
||||||
|
<div class="columns">
|
||||||
|
<div class="column">
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_name">Name:</label>
|
||||||
|
{{ list_form.name }}
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="label" for="id_description">Description:</label>
|
||||||
|
{{ list_form.description }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="column">
|
||||||
|
<fieldset class="field">
|
||||||
|
<legend class="label">List curation:</legend>
|
||||||
|
|
||||||
|
<label class="field">
|
||||||
|
<input type="radio" name="curation" value="closed" checked> Closed
|
||||||
|
<p class="help mb-2">Only you can add and remove books to this list</p>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="field">
|
||||||
|
<input type="radio" name="curation" value="curated"> Curated
|
||||||
|
<p class="help mb-2">Anyone can suggest books, subject to your approval</p>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<label class="field">
|
||||||
|
<input type="radio" name="curation" value="open"> Open
|
||||||
|
<p class="help mb-2">Anyone can add books to this list, but only you can remove them</p>
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field has-addons">
|
||||||
|
<div class="control">
|
||||||
|
{% include 'snippets/privacy_select.html' %}
|
||||||
|
</div>
|
||||||
|
<div class="control">
|
||||||
|
<button type="submit" class="button is-primary">Save</button>
|
||||||
|
{% include 'snippets/toggle/close_button.html' with controls_text='create-list' text="Cancel" %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% if request.user.list_set.exists %}
|
||||||
|
<ul>
|
||||||
{% for list in request.user.list_set.all %}
|
{% for list in request.user.list_set.all %}
|
||||||
{{ list }}
|
<li>
|
||||||
|
<a href="{{ list.local_path }}">{{ list.name }}</a>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
{% endif %}
|
||||||
|
</section>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if lists.exists %}
|
||||||
|
<section class="block">
|
||||||
|
<h2 class="title is-2">Recent Lists</h2>
|
||||||
|
<ul>
|
||||||
{% for list in lists %}
|
{% for list in lists %}
|
||||||
{{ list }}
|
<li>
|
||||||
|
<a href="{{ list.local_path }}">{{ list.name }}</a>
|
||||||
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{% include 'snippets/toggle/toggle_button.html' with controls_text="show-comment" controls_uid=status.id text="Reply" icon="comment" class="is-small" focus="id_content_reply" %}
|
{% include 'snippets/toggle/toggle_button.html' with controls_text="show-comment" controls_uid=status.id text="Reply" icon="comment" class="is-small toggle-button" focus="id_content_reply" %}
|
||||||
</div>
|
</div>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
{% include 'snippets/boost_button.html' with status=status %}
|
{% include 'snippets/boost_button.html' with status=status %}
|
||||||
|
|
|
@ -55,7 +55,6 @@ class ListViews(TestCase):
|
||||||
self.assertEqual(result.status_code, 200)
|
self.assertEqual(result.status_code, 200)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def test_list_page(self):
|
def test_list_page(self):
|
||||||
''' there are so many views, this just makes sure it LOADS '''
|
''' there are so many views, this just makes sure it LOADS '''
|
||||||
view = views.List.as_view()
|
view = views.List.as_view()
|
||||||
|
|
|
@ -7,7 +7,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views import View
|
from django.views import View
|
||||||
|
|
||||||
from bookwyrm import models
|
from bookwyrm import forms, models
|
||||||
from bookwyrm.activitypub import ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from .helpers import is_api_request, object_visible_to_user
|
from .helpers import is_api_request, object_visible_to_user
|
||||||
|
|
||||||
|
@ -19,7 +19,12 @@ class Lists(View):
|
||||||
''' display a book list '''
|
''' display a book list '''
|
||||||
user = request.user if request.user.is_authenticated else None
|
user = request.user if request.user.is_authenticated else None
|
||||||
lists = models.List.objects.filter(~Q(user=user)).all()
|
lists = models.List.objects.filter(~Q(user=user)).all()
|
||||||
return TemplateResponse(request, 'lists/lists.html', {'lists': lists})
|
data = {
|
||||||
|
'title': 'Lists',
|
||||||
|
'lists': lists,
|
||||||
|
'list_form': forms.ListForm()
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'lists/lists.html', data)
|
||||||
|
|
||||||
@method_decorator(login_required, name='dispatch')
|
@method_decorator(login_required, name='dispatch')
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
|
Loading…
Reference in a new issue