def quotate(request): ''' create a book quotation ''' form = forms.QuotationForm(request.POST) book_identifier = request.POST.get('book') if not form.is_valid(): return redirect('/book/%s' % book_identifier) quote = form.cleaned_data.get('quote') content = form.cleaned_data.get('content') outgoing.handle_quotation(request.user, book_identifier, content, quote) return redirect('/book/%s' % book_identifier)
def home_tab(request, tab): ''' user's homepage with activity feed ''' page_size = 15 try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 shelves = [] shelves = get_user_shelf_preview(request.user, [('reading', 3), ('read', 1), ('to-read', 3)]) size = sum(len(s['books']) for s in shelves) # books new to the instance, for discovery if size < 6: recent_books = models.Work.objects.order_by('-created_date')[:6 - size] recent_books = [b.default_edition for b in recent_books] shelves.append({ 'name': 'Recently added', 'identifier': None, 'books': recent_books, 'count': 6 - size, }) # allows us to check if a user has shelved a book user_books = models.Edition.objects.filter( shelves__user=request.user).all() activities = get_activity_feed(request.user, tab) activity_count = activities.count() activities = activities[(page - 1) * page_size:page * page_size] next_page = '/?page=%d' % (page + 1) prev_page = '/?page=%d' % (page - 1) data = { 'user': request.user, 'shelves': shelves, 'user_books': user_books, 'activities': activities, 'feed_tabs': [{ 'id': 'home', 'display': 'Home' }, { 'id': 'local', 'display': 'Local' }, { 'id': 'federated', 'display': 'Federated' }], 'active_tab': tab, 'review_form': forms.ReviewForm(), 'quotation_form': forms.QuotationForm(), 'comment_form': forms.CommentForm(), 'next': next_page if activity_count > (page_size * page) else None, 'prev': prev_page if page > 1 else None, } return TemplateResponse(request, 'feed.html', data)