forked from mirrors/bookwyrm
parent
0ce9677029
commit
3eb91980e0
7 changed files with 108 additions and 57 deletions
|
@ -70,6 +70,11 @@ h2 {
|
||||||
max-width: 75rem;
|
max-width: 75rem;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
#main {
|
||||||
|
flex-direction: column-reverse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#feed, #content, #sidebar {
|
#feed, #content, #sidebar {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -163,6 +168,10 @@ blockquote {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.interaction textarea {
|
||||||
|
height: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
table {
|
table {
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
margin: 1em;
|
margin: 1em;
|
||||||
|
|
|
@ -2,33 +2,26 @@
|
||||||
{% load fr_display %}
|
{% load fr_display %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div id="sidebar">
|
<div id="sidebar">
|
||||||
<div>
|
|
||||||
<h2>Currently Reading</h2>
|
|
||||||
{# listing books currently on user's shelves #}
|
|
||||||
{% if not reading.books.all %}
|
|
||||||
<p>Start a book!</p>
|
|
||||||
{% for book in to_read.books.all %}
|
|
||||||
<div class="book-preview">
|
|
||||||
{% include 'snippets/book.html' with book=book size="small" %}
|
|
||||||
<form name="shelve" action="/shelve/{{ user.localname }}/reading/{{ book.id }}" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="book" value="book.id"></input>
|
|
||||||
<button type="submit">Start reading</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% for book in reading.books.all %}
|
<div>
|
||||||
|
{% if shelves %}
|
||||||
|
{% for shelf in shelves %}
|
||||||
|
<h2>{{ shelf.name }}</h2>
|
||||||
|
{% for book in shelf.books %}
|
||||||
<div class="book-preview">
|
<div class="book-preview">
|
||||||
{% include 'snippets/book.html' with book=book size="small" %}
|
{% include 'snippets/book.html' with book=book size="small" %}
|
||||||
<form name="shelve" action="/shelve/{{ user.localname }}/read/{{ book.id }}" method="post">
|
{% include 'snippets/shelve-button.html' with book=book %}
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="book" value="book.id"></input>
|
|
||||||
<button type="submit">I'm done!</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if shelf.size > shelf.books.count %}
|
||||||
|
<a href="/shelf/{{ shelf.identifier }}">See all {{ shelf.size }}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% else %}
|
||||||
|
<h2>Reading Activity</h2>
|
||||||
|
<p>Start a book!</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
@ -37,11 +30,7 @@
|
||||||
<div class="book-preview">
|
<div class="book-preview">
|
||||||
{% include 'snippets/book.html' with book=book size="small" %}
|
{% include 'snippets/book.html' with book=book size="small" %}
|
||||||
{% if not book in user_books.all %}
|
{% if not book in user_books.all %}
|
||||||
<form name="shelve" action="/shelve/{{ user.localname }}/to-read/{{ book.id }}" method="post">
|
{% include 'snippets/shelve-button.html' with book=book %}
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="book" value="book.id"></input>
|
|
||||||
<button type="submit">Want to read</button>
|
|
||||||
</form>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
18
fedireads/templates/snippets/interaction.html
Normal file
18
fedireads/templates/snippets/interaction.html
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<div class="interaction">
|
||||||
|
{% if activity.favorites.all %}
|
||||||
|
<span>
|
||||||
|
{{ activity.favorites.count }} like(s)
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
<form name="favorite" action="/favorite/{{ activity.id }}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<button>⭐️ Like</button>
|
||||||
|
</form>
|
||||||
|
<form name="comment" action="/comment" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="parent" value="{{ activity.id }}"></input>
|
||||||
|
{{ comment_form.content }}
|
||||||
|
<button type="submit">Comment</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
7
fedireads/templates/snippets/shelve-button.html
Normal file
7
fedireads/templates/snippets/shelve-button.html
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{% load fr_display %}
|
||||||
|
<form name="shelve" action="/shelve/{{ user.localname }}/{% shelve_button_identifier book %}/{{ book.id }}" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="book" value="book.id"></input>
|
||||||
|
<button type="submit">{% shelve_button_text book %}</button>
|
||||||
|
</form>
|
||||||
|
|
|
@ -9,23 +9,7 @@
|
||||||
<p>{{ activity.rating | stars }}</p>
|
<p>{{ activity.rating | stars }}</p>
|
||||||
<p>{{ activity.content | safe }}</p>
|
<p>{{ activity.content | safe }}</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="interaction">
|
{% include 'snippets/interaction.html' with activity=activity %}
|
||||||
{% if activity.favorites.all %}
|
|
||||||
<span>
|
|
||||||
{{ activity.favorites.count }} like(s)
|
|
||||||
</span>
|
|
||||||
{% endif %}
|
|
||||||
<form name="favorite" action="/favorite/{{ activity.id }}" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<button>⭐️ Like</button>
|
|
||||||
</form>
|
|
||||||
<form name="comment" action="/comment" method="post">
|
|
||||||
{% csrf_token %}
|
|
||||||
<input type="hidden" name="review" value="{{ activity.id }}"></input>
|
|
||||||
{{ comment_form.content }}
|
|
||||||
<button type="submit">Comment</button>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% elif activity.status_type == 'Note' %}
|
{% elif activity.status_type == 'Note' %}
|
||||||
{% include 'snippets/status_banner.html' %}
|
{% include 'snippets/status_banner.html' %}
|
||||||
<span>{{ activity.content | safe }}</span>
|
<span>{{ activity.content | safe }}</span>
|
||||||
|
@ -34,6 +18,7 @@
|
||||||
{% include 'snippets/book.html' with book=book size=large description=True %}
|
{% include 'snippets/book.html' with book=book size=large description=True %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% include 'snippets/interaction.html' with activity=activity %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{# generic handling for a misc activity, which perhaps should not be displayed at all #}
|
{# generic handling for a misc activity, which perhaps should not be displayed at all #}
|
||||||
did {{ activity.activity_type }}
|
did {{ activity.activity_type }}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
''' template filters '''
|
''' template filters '''
|
||||||
from django import template
|
from django import template
|
||||||
|
|
||||||
|
from fedireads import models
|
||||||
|
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@register.filter(name='dict_key')
|
@register.filter(name='dict_key')
|
||||||
|
@ -34,3 +37,39 @@ def bio_format(bio):
|
||||||
bio = bio['value']
|
bio = bio['value']
|
||||||
bio = bio.split('\n')
|
bio = bio.split('\n')
|
||||||
return bio[0].strip()
|
return bio[0].strip()
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def shelve_button_identifier(context, book):
|
||||||
|
''' check what shelf a user has a book on, if any '''
|
||||||
|
try:
|
||||||
|
shelf = models.ShelfBook.objects.get(
|
||||||
|
shelf__user=context['user'],
|
||||||
|
book=book
|
||||||
|
)
|
||||||
|
except models.ShelfBook.DoesNotExist:
|
||||||
|
return 'to-read'
|
||||||
|
identifier = shelf.shelf.identifier
|
||||||
|
if identifier == 'to-read':
|
||||||
|
return 'reading'
|
||||||
|
elif identifier == 'reading':
|
||||||
|
return 'read'
|
||||||
|
return 'to-read'
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def shelve_button_text(context, book):
|
||||||
|
''' check what shelf a user has a book on, if any '''
|
||||||
|
try:
|
||||||
|
shelf = models.ShelfBook.objects.get(
|
||||||
|
shelf__user=context['user'],
|
||||||
|
book=book
|
||||||
|
)
|
||||||
|
except models.ShelfBook.DoesNotExist:
|
||||||
|
return 'Want to read'
|
||||||
|
identifier = shelf.shelf.identifier
|
||||||
|
if identifier == 'Start reading':
|
||||||
|
return 'reading'
|
||||||
|
elif identifier == 'reading':
|
||||||
|
return 'I\'m done!'
|
||||||
|
return 'Want to read'
|
||||||
|
|
|
@ -20,15 +20,20 @@ def home(request):
|
||||||
@login_required
|
@login_required
|
||||||
def home_tab(request, tab):
|
def home_tab(request, tab):
|
||||||
''' user's homepage with activity feed '''
|
''' user's homepage with activity feed '''
|
||||||
# user's shelves for display
|
shelves = []
|
||||||
reading = models.Shelf.objects.get(
|
for identifier in ['reading', 'to-read']:
|
||||||
user=request.user,
|
shelf = models.Shelf.objects.get(
|
||||||
identifier='reading'
|
user=request.user,
|
||||||
)
|
identifier=identifier,
|
||||||
to_read = models.Shelf.objects.get(
|
)
|
||||||
user=request.user,
|
if not shelf.books.count():
|
||||||
identifier='to-read'
|
continue
|
||||||
)
|
shelves.append({
|
||||||
|
'name': shelf.name,
|
||||||
|
'identifier': shelf.identifier,
|
||||||
|
'books': shelf.books.all()[:3],
|
||||||
|
'size': shelf.books.count(),
|
||||||
|
})
|
||||||
|
|
||||||
# allows us to check if a user has shelved a book
|
# allows us to check if a user has shelved a book
|
||||||
user_books = models.Book.objects.filter(shelves__user=request.user).all()
|
user_books = models.Book.objects.filter(shelves__user=request.user).all()
|
||||||
|
@ -65,8 +70,7 @@ def home_tab(request, tab):
|
||||||
comment_form = forms.CommentForm()
|
comment_form = forms.CommentForm()
|
||||||
data = {
|
data = {
|
||||||
'user': request.user,
|
'user': request.user,
|
||||||
'reading': reading,
|
'shelves': shelves,
|
||||||
'to_read': to_read,
|
|
||||||
'recent_books': recent_books,
|
'recent_books': recent_books,
|
||||||
'user_books': user_books,
|
'user_books': user_books,
|
||||||
'activities': activities,
|
'activities': activities,
|
||||||
|
@ -326,8 +330,8 @@ def comment(request):
|
||||||
# this is a bit of a formality, the form is just one text field
|
# this is a bit of a formality, the form is just one text field
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
review_id = request.POST['review']
|
parent_id = request.POST['parent']
|
||||||
parent = models.Review.objects.get(id=review_id)
|
parent = models.Status.objects.get(id=parent_id)
|
||||||
outgoing.handle_comment(request.user, parent, form.data['content'])
|
outgoing.handle_comment(request.user, parent, form.data['content'])
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue