forked from mirrors/bookwyrm
Disentangles user pages
This commit is contained in:
parent
ab0f9230c7
commit
c3fe8e041a
1 changed files with 30 additions and 24 deletions
|
@ -311,8 +311,9 @@ def notifications_page(request):
|
||||||
notifications.update(read=True)
|
notifications.update(read=True)
|
||||||
return TemplateResponse(request, 'notifications.html', data)
|
return TemplateResponse(request, 'notifications.html', data)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def user_page(request, username, subpage=None, shelf=None):
|
def user_page(request, username):
|
||||||
''' profile page for a user '''
|
''' profile page for a user '''
|
||||||
try:
|
try:
|
||||||
user = get_user_from_username(username)
|
user = get_user_from_username(username)
|
||||||
|
@ -329,19 +330,6 @@ def user_page(request, username, subpage=None, shelf=None):
|
||||||
'user': user,
|
'user': user,
|
||||||
'is_self': request.user.id == user.id,
|
'is_self': request.user.id == user.id,
|
||||||
}
|
}
|
||||||
if subpage == 'followers':
|
|
||||||
data['followers'] = user.followers.all()
|
|
||||||
return TemplateResponse(request, 'followers.html', data)
|
|
||||||
if subpage == 'following':
|
|
||||||
data['following'] = user.following.all()
|
|
||||||
return TemplateResponse(request, 'following.html', data)
|
|
||||||
if subpage == 'shelves':
|
|
||||||
data['shelves'] = user.shelf_set.all()
|
|
||||||
if shelf:
|
|
||||||
data['shelf'] = user.shelf_set.get(identifier=shelf)
|
|
||||||
else:
|
|
||||||
data['shelf'] = user.shelf_set.first()
|
|
||||||
return TemplateResponse(request, 'shelf.html', data)
|
|
||||||
|
|
||||||
data['shelf_count'] = user.shelf_set.count()
|
data['shelf_count'] = user.shelf_set.count()
|
||||||
shelves = []
|
shelves = []
|
||||||
|
@ -376,7 +364,13 @@ def followers_page(request, username):
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
return JsonResponse(user.to_followers_activity(**request.GET))
|
return JsonResponse(user.to_followers_activity(**request.GET))
|
||||||
|
|
||||||
return user_page(request, username, subpage='followers')
|
data = {
|
||||||
|
'title': '%s: followers' % user.name,
|
||||||
|
'user': user,
|
||||||
|
'is_self': request.user.id == user.id,
|
||||||
|
'followers': user.followers.all(),
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'followers.html', data)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -393,16 +387,19 @@ def following_page(request, username):
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
return JsonResponse(user.to_following_activity(**request.GET))
|
return JsonResponse(user.to_following_activity(**request.GET))
|
||||||
|
|
||||||
return user_page(request, username, subpage='following')
|
data = {
|
||||||
|
'title': '%s: following' % user.name,
|
||||||
|
'user': user,
|
||||||
|
'is_self': request.user.id == user.id,
|
||||||
|
'following': user.following.all(),
|
||||||
|
}
|
||||||
|
return TemplateResponse(request, 'following.html', data)
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def user_shelves_page(request, username):
|
def user_shelves_page(request, username):
|
||||||
''' list of followers '''
|
''' list of followers '''
|
||||||
if request.method != 'GET':
|
return shelf_page(request, username, None)
|
||||||
return HttpResponseBadRequest()
|
|
||||||
|
|
||||||
return user_page(request, username, subpage='shelves')
|
|
||||||
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
|
@ -629,10 +626,19 @@ def shelf_page(request, username, shelf_identifier):
|
||||||
except models.User.DoesNotExist:
|
except models.User.DoesNotExist:
|
||||||
return HttpResponseNotFound()
|
return HttpResponseNotFound()
|
||||||
|
|
||||||
shelf = models.Shelf.objects.get(user=user, identifier=shelf_identifier)
|
|
||||||
|
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
|
shelf = models.Shelf.objects.get(user=user, identifier=shelf_identifier)
|
||||||
return JsonResponse(shelf.to_activity(**request.GET))
|
return JsonResponse(shelf.to_activity(**request.GET))
|
||||||
|
|
||||||
return user_page(
|
data = {
|
||||||
request, username, subpage='shelves', shelf=shelf_identifier)
|
'title': user.name,
|
||||||
|
'user': user,
|
||||||
|
'is_self': request.user.id == user.id,
|
||||||
|
}
|
||||||
|
|
||||||
|
data['shelves'] = user.shelf_set.all()
|
||||||
|
if shelf:
|
||||||
|
data['shelf'] = user.shelf_set.get(identifier=shelf)
|
||||||
|
else:
|
||||||
|
data['shelf'] = user.shelf_set.first()
|
||||||
|
return TemplateResponse(request, 'shelf.html', data)
|
||||||
|
|
Loading…
Reference in a new issue