mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-24 02:21:04 +00:00
Adds basic view and template files
This commit is contained in:
parent
af65509527
commit
0815b36ec9
6 changed files with 88 additions and 3 deletions
|
@ -53,13 +53,16 @@
|
|||
<div class="navbar-menu" id="main-nav">
|
||||
<div class="navbar-start">
|
||||
{% if request.user.is_authenticated %}
|
||||
<a href="/user/{{ request.user.localname }}/shelves" class="navbar-item">
|
||||
<a href="{% url 'user-shelves' request.user.localname %}" class="navbar-item">
|
||||
Your shelves
|
||||
</a>
|
||||
<a href="/#feed" class="navbar-item">
|
||||
Feed
|
||||
</a>
|
||||
{% endif %}
|
||||
<a href="{% url 'lists' %}" class="navbar-item">
|
||||
Lists
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="navbar-end">
|
||||
|
|
7
bookwyrm/templates/lists/list.html
Normal file
7
bookwyrm/templates/lists/list.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
<h1>{{ list.name }}</h1>
|
||||
|
||||
{{ list }}
|
||||
|
||||
{% endblock %}
|
16
bookwyrm/templates/lists/lists.html
Normal file
16
bookwyrm/templates/lists/lists.html
Normal file
|
@ -0,0 +1,16 @@
|
|||
{% extends 'layout.html' %}
|
||||
{% block content %}
|
||||
|
||||
<h1>lists</h1>
|
||||
{% if request.user.is_authenticated %}
|
||||
<h2>Your lists</h2>
|
||||
{% for list in request.user.list_set.all %}
|
||||
{{ list }}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% for list in lists %}
|
||||
{{ list }}
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
|
@ -80,10 +80,15 @@ urlpatterns = [
|
|||
# users
|
||||
re_path(r'%s/?$' % user_path, views.User.as_view()),
|
||||
re_path(r'%s\.json$' % user_path, views.User.as_view()),
|
||||
re_path(r'%s/shelves/?$' % user_path, views.user_shelves_page),
|
||||
re_path(r'%s/rss' % user_path, views.rss_feed.RssFeed()),
|
||||
re_path(r'%s/followers(.json)?/?$' % user_path, views.Followers.as_view()),
|
||||
re_path(r'%s/following(.json)?/?$' % user_path, views.Following.as_view()),
|
||||
re_path(r'%s/rss' % user_path, views.rss_feed.RssFeed()),
|
||||
re_path(r'%s/shelves/?$' % user_path,
|
||||
views.user_shelves_page, name='user-shelves'),
|
||||
|
||||
# lists
|
||||
re_path(r'^list/?$', views.Lists.as_view(), name='lists'),
|
||||
re_path(r'^list/(?P<list_id>\d+)(.json)?/?$', views.List.as_view(), name='list'),
|
||||
|
||||
# preferences
|
||||
re_path(r'^preferences/profile/?$', views.EditUser.as_view()),
|
||||
|
|
|
@ -14,6 +14,7 @@ from .import_data import Import, ImportStatus
|
|||
from .interaction import Favorite, Unfavorite, Boost, Unboost
|
||||
from .invite import ManageInvites, Invite
|
||||
from .landing import About, Home, Discover
|
||||
from .list import Lists, List
|
||||
from .notifications import Notifications
|
||||
from .outbox import Outbox
|
||||
from .reading import edit_readthrough, create_readthrough, delete_readthrough
|
||||
|
|
53
bookwyrm/views/list.py
Normal file
53
bookwyrm/views/list.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
''' book list views'''
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.db.models import Q
|
||||
from django.http import HttpResponseNotFound
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.template.response import TemplateResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views import View
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.activitypub import ActivitypubResponse
|
||||
from .helpers import is_api_request
|
||||
|
||||
|
||||
# pylint: disable=no-self-use
|
||||
class Lists(View):
|
||||
''' book list page '''
|
||||
def get(self, request):
|
||||
''' display a book list '''
|
||||
user = request.user if request.user.is_authenticated else None
|
||||
lists = models.List.objects.filter(~Q(user=user)).all()
|
||||
return TemplateResponse(request, 'lists/lists.html', {'lists': lists})
|
||||
|
||||
@method_decorator(login_required, name='dispatch')
|
||||
# pylint: disable=unused-argument
|
||||
def post(self, request):
|
||||
''' create a book_list '''
|
||||
book_list = None
|
||||
return redirect(book_list.local_path)
|
||||
|
||||
|
||||
class List(View):
|
||||
''' book list page '''
|
||||
def get(self, request, list_id):
|
||||
''' display a book list '''
|
||||
book_list = get_object_or_404(models.List, id=list_id)
|
||||
if not object_visible_to_user(request.user, book_list):
|
||||
return HttpResponseNotFound()
|
||||
|
||||
if is_api_request(request):
|
||||
return ActivitypubResponse(book_list.to_activity())
|
||||
data = {
|
||||
'list': book_list
|
||||
}
|
||||
return TemplateResponse(request, 'lists/list.html', data)
|
||||
|
||||
|
||||
@method_decorator(login_required, name='dispatch')
|
||||
# pylint: disable=unused-argument
|
||||
def post(self, request, list_id):
|
||||
''' create a book_list '''
|
||||
book_list = get_object_or_404(models.List, id=list_id)
|
||||
return redirect(book_list.local_path)
|
Loading…
Reference in a new issue