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;
|
||||
width: 100%;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
#main {
|
||||
flex-direction: column-reverse;
|
||||
}
|
||||
}
|
||||
|
||||
#feed, #content, #sidebar {
|
||||
display: flex;
|
||||
|
@ -163,6 +168,10 @@ blockquote {
|
|||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.interaction textarea {
|
||||
height: 2em;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
margin: 1em;
|
||||
|
|
|
@ -2,33 +2,26 @@
|
|||
{% load fr_display %}
|
||||
{% block content %}
|
||||
<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">
|
||||
{% include 'snippets/book.html' with book=book size="small" %}
|
||||
<form name="shelve" action="/shelve/{{ user.localname }}/read/{{ book.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="book.id"></input>
|
||||
<button type="submit">I'm done!</button>
|
||||
</form>
|
||||
{% include 'snippets/shelve-button.html' with book=book %}
|
||||
</div>
|
||||
{% 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>
|
||||
|
@ -37,11 +30,7 @@
|
|||
<div class="book-preview">
|
||||
{% include 'snippets/book.html' with book=book size="small" %}
|
||||
{% if not book in user_books.all %}
|
||||
<form name="shelve" action="/shelve/{{ user.localname }}/to-read/{{ book.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
<input type="hidden" name="book" value="book.id"></input>
|
||||
<button type="submit">Want to read</button>
|
||||
</form>
|
||||
{% include 'snippets/shelve-button.html' with book=book %}
|
||||
{% endif %}
|
||||
</div>
|
||||
{% 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.content | safe }}</p>
|
||||
</div>
|
||||
<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="review" value="{{ activity.id }}"></input>
|
||||
{{ comment_form.content }}
|
||||
<button type="submit">Comment</button>
|
||||
</form>
|
||||
</div>
|
||||
{% include 'snippets/interaction.html' with activity=activity %}
|
||||
{% elif activity.status_type == 'Note' %}
|
||||
{% include 'snippets/status_banner.html' %}
|
||||
<span>{{ activity.content | safe }}</span>
|
||||
|
@ -34,6 +18,7 @@
|
|||
{% include 'snippets/book.html' with book=book size=large description=True %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% include 'snippets/interaction.html' with activity=activity %}
|
||||
{% else %}
|
||||
{# generic handling for a misc activity, which perhaps should not be displayed at all #}
|
||||
did {{ activity.activity_type }}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
''' template filters '''
|
||||
from django import template
|
||||
|
||||
from fedireads import models
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
||||
@register.filter(name='dict_key')
|
||||
|
@ -34,3 +37,39 @@ def bio_format(bio):
|
|||
bio = bio['value']
|
||||
bio = bio.split('\n')
|
||||
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
|
||||
def home_tab(request, tab):
|
||||
''' user's homepage with activity feed '''
|
||||
# user's shelves for display
|
||||
reading = models.Shelf.objects.get(
|
||||
user=request.user,
|
||||
identifier='reading'
|
||||
)
|
||||
to_read = models.Shelf.objects.get(
|
||||
user=request.user,
|
||||
identifier='to-read'
|
||||
)
|
||||
shelves = []
|
||||
for identifier in ['reading', 'to-read']:
|
||||
shelf = models.Shelf.objects.get(
|
||||
user=request.user,
|
||||
identifier=identifier,
|
||||
)
|
||||
if not shelf.books.count():
|
||||
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
|
||||
user_books = models.Book.objects.filter(shelves__user=request.user).all()
|
||||
|
@ -65,8 +70,7 @@ def home_tab(request, tab):
|
|||
comment_form = forms.CommentForm()
|
||||
data = {
|
||||
'user': request.user,
|
||||
'reading': reading,
|
||||
'to_read': to_read,
|
||||
'shelves': shelves,
|
||||
'recent_books': recent_books,
|
||||
'user_books': user_books,
|
||||
'activities': activities,
|
||||
|
@ -326,8 +330,8 @@ def comment(request):
|
|||
# this is a bit of a formality, the form is just one text field
|
||||
if not form.is_valid():
|
||||
return redirect('/')
|
||||
review_id = request.POST['review']
|
||||
parent = models.Review.objects.get(id=review_id)
|
||||
parent_id = request.POST['parent']
|
||||
parent = models.Status.objects.get(id=parent_id)
|
||||
outgoing.handle_comment(request.user, parent, form.data['content'])
|
||||
return redirect('/')
|
||||
|
||||
|
|
Loading…
Reference in a new issue