def person(request, pk): selected_person = get_object_or_404(Person, id=pk) search_params = {"person": pk} try: handle_subscribe_requests( request, search_params, _('You will now receive notifications about new documents.'), _('You will no longer receive notifications.'), _('You have already subscribed to this person.')) except NeedsLoginError as err: return redirect(err.redirect_url) filter_self = Paper.objects.filter(persons__id=pk) filter_organization = Paper.objects.filter( organizations__organizationmembership__person__id=pk) paper = (filter_self | filter_organization).distinct() context = { "person": selected_person, "papers": paper, "subscribable": True, "is_subscribed": is_subscribed_to_search(request.user, search_params), } return render(request, 'mainapp/person.html', context)
def _search_to_context(query, main_search: MainappSearch, executed, results, request): context = { "query": query, "results": results, "options": main_search.options, "document_types": DOCUMENT_TYPE_NAMES, "map": build_map_object(), "pagination_length": settings.SEARCH_PAGINATION_LENGTH, "total_hits": executed.hits.total, "subscribable": params_are_subscribable(main_search.params), "is_subscribed": is_subscribed_to_search(request.user, main_search.params) } return context
def person(request, pk): selected_person = get_object_or_404(Person, id=pk) search_params = {"person": pk} try: handle_subscribe_requests( request, search_params, _("You will now receive notifications about new documents."), _("You will no longer receive notifications."), _("You have already subscribed to this person."), ) except NeedsLoginError as err: return redirect(err.redirect_url) filter_self = Paper.objects.filter(persons__id=pk) filter_organization = Paper.objects.filter( organizations__membership__person__id=pk) paper = (filter_self | filter_organization).distinct() memberships = get_ordered_memberships(selected_person) mentioned = defaultdict(list) files_mentioned = File.objects.filter( mentioned_persons__in=[pk]).prefetch_related("paper_set") for file_mentioned in files_mentioned: for paper_mentioned in file_mentioned.paper_set.all(): mentioned[paper_mentioned].append(file_mentioned) # The template doesn't like defaultdicts mentioned = dict(mentioned) context = { "person": selected_person, "papers": paper, "mentioned_in": mentioned, "memberships": memberships, "subscribable": True, "is_subscribed": is_subscribed_to_search(request.user, search_params), "to_search_url": reverse("search", args=["person:" + str(selected_person.id)]), } return render(request, "mainapp/person.html", context)
def person(request, pk): selected_person = get_object_or_404(Person, id=pk) search_params = {"person": pk} try: handle_subscribe_requests( request, search_params, _('You will now receive notifications about new documents.'), _('You will no longer receive notifications.'), _('You have already subscribed to this person.')) except NeedsLoginError as err: return redirect(err.redirect_url) filter_self = Paper.objects.filter(persons__id=pk) filter_organization = Paper.objects.filter( organizations__organizationmembership__person__id=pk) paper = (filter_self | filter_organization).distinct() mentioned = [] for paper_mentioned in Paper.objects.filter( files__mentioned_persons__in=[pk]).order_by( '-modified').distinct(): mentioned.append({ "paper": paper_mentioned, "files": paper_mentioned.files.filter(mentioned_persons__in=[pk]) }) memberships = get_ordered_memberships(selected_person) context = { "person": selected_person, "papers": paper, "mentioned_in": mentioned, "memberships": memberships, "subscribable": True, "is_subscribed": is_subscribed_to_search(request.user, search_params), "to_search_url": reverse("search", args=["person:" + str(selected_person.id)]) } return render(request, 'mainapp/person.html', context)
def search_index(request, query): params = search_string_to_params(query) options, search, errors = params_to_query(params) for error in errors: messages.error(request, error) try: handle_subscribe_requests( request, params, _('You will now receive notifications about new search results.'), _('You will no longer receive notifications.'), _('You have already subscribed to this search.')) except NeedsLoginError as err: return redirect(err.redirect_url) context = _search_to_context(query, params, options, search) context['subscribable'] = params_are_subscribable(params) context['is_subscribed'] = is_subscribed_to_search(request.user, params) return render(request, "mainapp/search.html", context)
def search_results_only(request, query): """ Returns only the result list items. Used for the endless scrolling """ params = search_string_to_params(query) options, search, _ = params_to_query(params) after = int(request.GET.get('after', 0)) search = search[after:after + 20] context = _search_to_context(query, params, options, search) context['subscribable'] = params_are_subscribable(params) context['is_subscribed'] = is_subscribed_to_search(request.user, params) result = { 'results': loader.render_to_string('partials/mixed_results.html', context, request), 'total_results': context['total_hits'], 'subscribe_widget': loader.render_to_string('partials/subscribe_widget.html', context, request), } return JsonResponse(result, safe=False)