mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-09 08:45:28 +00:00
more todos and cleanup
This commit is contained in:
parent
3998c662cc
commit
96ebb43235
3 changed files with 20 additions and 4 deletions
|
@ -19,11 +19,15 @@ def get_or_create_remote_user(actor):
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# TODO: also bring in the user's prevous reviews and books
|
||||||
|
|
||||||
# load the user's info from the actor url
|
# load the user's info from the actor url
|
||||||
response = requests.get(
|
response = requests.get(
|
||||||
actor,
|
actor,
|
||||||
headers={'Accept': 'application/activity+json'}
|
headers={'Accept': 'application/activity+json'}
|
||||||
)
|
)
|
||||||
|
if not response.ok:
|
||||||
|
response.raise_for_status()
|
||||||
data = response.json()
|
data = response.json()
|
||||||
|
|
||||||
# the webfinger format for the username.
|
# the webfinger format for the username.
|
||||||
|
|
|
@ -16,6 +16,7 @@ from fedireads.openlibrary import get_or_create_book
|
||||||
from fedireads.settings import DOMAIN
|
from fedireads.settings import DOMAIN
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: this should probably live somewhere else
|
||||||
class HttpResponseUnauthorized(HttpResponse):
|
class HttpResponseUnauthorized(HttpResponse):
|
||||||
''' http response for authentication failure '''
|
''' http response for authentication failure '''
|
||||||
status_code = 401
|
status_code = 401
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
''' application views/pages '''
|
''' application views/pages '''
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
from django.db.models import Avg, FilteredRelation, Q
|
from django.db.models import Avg, Q
|
||||||
from django.http import HttpResponseNotFound
|
from django.http import HttpResponseNotFound
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
|
@ -14,6 +14,7 @@ from fedireads.settings import DOMAIN
|
||||||
@login_required
|
@login_required
|
||||||
def home(request):
|
def home(request):
|
||||||
''' user's homepage with activity feed '''
|
''' user's homepage with activity feed '''
|
||||||
|
# user's shelves for display
|
||||||
reading = models.Shelf.objects.get(
|
reading = models.Shelf.objects.get(
|
||||||
user=request.user,
|
user=request.user,
|
||||||
shelf_type='reading'
|
shelf_type='reading'
|
||||||
|
@ -22,15 +23,19 @@ def home(request):
|
||||||
user=request.user,
|
user=request.user,
|
||||||
shelf_type='to-read'
|
shelf_type='to-read'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# 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()
|
||||||
|
|
||||||
|
# books new to the instance, for discovery
|
||||||
recent_books = models.Book.objects.order_by(
|
recent_books = models.Book.objects.order_by(
|
||||||
'-added_date'
|
'-added_date'
|
||||||
)[:5]
|
)[:5]
|
||||||
|
|
||||||
|
# status updates for your follow network
|
||||||
following = models.User.objects.filter(
|
following = models.User.objects.filter(
|
||||||
Q(followers=request.user) | Q(id=request.user.id)
|
Q(followers=request.user) | Q(id=request.user.id)
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: handle post privacy
|
# TODO: handle post privacy
|
||||||
activities = models.Activity.objects.filter(
|
activities = models.Activity.objects.filter(
|
||||||
user__in=following,
|
user__in=following,
|
||||||
|
@ -46,7 +51,7 @@ def home(request):
|
||||||
'recent_books': recent_books,
|
'recent_books': recent_books,
|
||||||
'user_books': user_books,
|
'user_books': user_books,
|
||||||
'activities': activities,
|
'activities': activities,
|
||||||
'login_form': login_form,
|
'login_form': login_form, # TODO remove this
|
||||||
}
|
}
|
||||||
return TemplateResponse(request, 'feed.html', data)
|
return TemplateResponse(request, 'feed.html', data)
|
||||||
|
|
||||||
|
@ -61,6 +66,7 @@ def user_login(request):
|
||||||
# authenticate user
|
# authenticate user
|
||||||
form = forms.LoginForm(request.POST)
|
form = forms.LoginForm(request.POST)
|
||||||
if not form.is_valid():
|
if not form.is_valid():
|
||||||
|
# TODO messaging about a login failure
|
||||||
return TemplateResponse(request, 'login.html')
|
return TemplateResponse(request, 'login.html')
|
||||||
|
|
||||||
username = form.data['username']
|
username = form.data['username']
|
||||||
|
@ -106,6 +112,7 @@ def register(request):
|
||||||
def user_profile(request, username):
|
def user_profile(request, username):
|
||||||
''' profile page for a user '''
|
''' profile page for a user '''
|
||||||
content = request.headers.get('Accept')
|
content = request.headers.get('Accept')
|
||||||
|
# TODO: this should probably be the full content type? maybe?
|
||||||
if 'json' in content:
|
if 'json' in content:
|
||||||
# we have a json request
|
# we have a json request
|
||||||
return incoming.get_actor(request, username)
|
return incoming.get_actor(request, username)
|
||||||
|
@ -119,8 +126,10 @@ def user_profile(request, username):
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
|
# TODO: change display with privacy and authentication considerations
|
||||||
shelves = models.Shelf.objects.filter(user=user)
|
shelves = models.Shelf.objects.filter(user=user)
|
||||||
ratings = {r.book.id: r.rating for r in models.Review.objects.filter(user=user, book__shelves__user=user)}
|
ratings = {r.book.id: r.rating for r in \
|
||||||
|
models.Review.objects.filter(user=user, book__shelves__user=user)}
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'user': user,
|
'user': user,
|
||||||
|
@ -147,6 +156,7 @@ def user_profile_edit(request, username):
|
||||||
return TemplateResponse(request, 'edit_user.html', data)
|
return TemplateResponse(request, 'edit_user.html', data)
|
||||||
|
|
||||||
|
|
||||||
|
# TODO: there oughta be clear naming between endpoints and pages
|
||||||
@login_required
|
@login_required
|
||||||
def edit_profile(request):
|
def edit_profile(request):
|
||||||
''' les get fancy with images '''
|
''' les get fancy with images '''
|
||||||
|
@ -169,6 +179,7 @@ def edit_profile(request):
|
||||||
def book_page(request, book_identifier):
|
def book_page(request, book_identifier):
|
||||||
''' info about a book '''
|
''' info about a book '''
|
||||||
book = openlibrary.get_or_create_book('/work/' + book_identifier)
|
book = openlibrary.get_or_create_book('/work/' + book_identifier)
|
||||||
|
# TODO: again, post privacy?
|
||||||
reviews = models.Review.objects.filter(book=book)
|
reviews = models.Review.objects.filter(book=book)
|
||||||
rating = reviews.aggregate(Avg('rating'))
|
rating = reviews.aggregate(Avg('rating'))
|
||||||
review_form = forms.ReviewForm()
|
review_form = forms.ReviewForm()
|
||||||
|
|
Loading…
Reference in a new issue