def account_list_view(request): users = (User.objects.prefetch_related("groups").order_by( "-date_joined").filter(is_active=True).all()) if "name" in request.GET or "group" in request.GET: name, group = request.GET.get("name"), request.GET.get("group") query = None if name: query = Q(first_name__icontains=name) | Q( last_name__icontains=name) if group: group_query = Q(groups__name=group) query = (query & group_query) if query else group_query if query: users = users.filter(query) context = { "users": UserSerializer(users, many=True).data, "create_url": reverse("account-create"), } if is_react_api_call(request): return Response(data=context["users"]) else: return render_react_page(request, "Accounts", "accounts-list", context)
def case_list_view(request): """ List of all cases for paralegals and coordinators to view. """ issue_qs = _get_issue_qs_for_user(request.user) form = IssueSearchForm(request.GET) issue_qs = form.search(issue_qs).order_by("-created_at").all() page, next_page, prev_page = get_page(request, issue_qs, per_page=14, return_qs=False) context = { "issues": IssueDetailSerializer(page.object_list, many=True).data, "next_page": next_page, "total_pages": page.paginator.num_pages, "total_count": page.paginator.count, "prev_page": prev_page, "choices": { "stage": CaseStage.CHOICES, "topic": CaseTopic.CHOICES, "outcome": CaseOutcome.CHOICES, "is_open": [ ("True", "Open"), ("False", "Closed"), ], }, } if is_react_api_call(request): return Response(context) else: return render_react_page(request, f"Cases", "case-list", context)
def account_detail_view(request, pk): try: user = (User.objects.prefetch_related( "groups", "issue_notes", "issue_set__paralegal__groups", "issue_set__lawyer__groups", "issue_set__client", "lawyer_issues__paralegal__groups", "lawyer_issues__lawyer__groups", "lawyer_issues__client", ).distinct().get(pk=pk)) except User.DoesNotExist: raise Http404() if request.method == "GET": name = user.get_full_name() context = {"account": UserDetailSerializer(user).data} return render_react_page(request, f"Client {name}", "account-detail", context) elif request.method == "PATCH": serializer = UserDetailSerializer(instance=user, data=request.data, partial=True) serializer.is_valid(raise_exception=True) serializer.save() return Response({"account": serializer.data})
def template_doc_list_view(request): context = { "topic": CaseTopic.REPAIRS, "create_url": reverse("template-doc-create"), } return render_react_page(request, "Document Templates", "doc-template-list", context)
def template_email_list_view(request): templates = EmailTemplate.objects.order_by("-created_at").all() context = { "templates": EmailTemplateSerializer(templates, many=True).data, "create_url": reverse("template-email-create"), } return render_react_page(request, "Email Templates", "email-template-list", context)
def template_email_create_view(request): if request.method == "POST": serializer = EmailTemplateSerializer(data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) return render_react_page(request, "Email Templates", "email-template-create", {})
def email_list_view(request, pk): issue = _get_issue_for_emails(request, pk) case_email_address = build_clerk_address(issue) email_threads = _get_email_threads(issue) context = { "issue": IssueDetailSerializer(issue).data, "email_threads": EmailThreadSerializer(email_threads, many=True).data, "case_email_address": case_email_address, "urls": get_detail_urls(issue), "draft_url": reverse("case-email-draft", args=(issue.pk, )), } return render_react_page(request, f"Case {issue.fileref}", "email-list", context)
def paralegal_list_view(request): paralegals = User.objects.filter( groups__name__in=[CaseGroups.PARALEGAL, CaseGroups.COORDINATOR ]).prefetch_related("issue_set", "groups") lawyers = User.objects.filter( groups__name=CaseGroups.LAWYER).prefetch_related( "issue_set", "groups") paralegals = _calculate_user_capacity(paralegals, "issue") lawyers = _calculate_user_capacity(lawyers, "lawyer_issue") context = { "paralegals": ParalegalSerializer(paralegals, many=True).data, "lawyers": ParalegalSerializer(lawyers, many=True).data, } return render_react_page(request, f"Paralegals", "paralegal-list", context)
def case_detail_documents_view(request, pk): """ The documents of a given case. """ try: issue = (Issue.objects.check_permissions(request).select_related( "client").get(pk=pk)) except Issue.DoesNotExist: raise Http404() context = { "issue": IssueDetailSerializer(issue).data, "urls": get_detail_urls(issue), } return render_react_page(request, f"Case {issue.fileref}", "document-list", context)
def email_thread_view(request, pk, slug): issue = _get_issue_for_emails(request, pk) case_email_address = build_clerk_address(issue) email_threads = [t for t in _get_email_threads(issue) if t.slug == slug] if email_threads: # Assume thread slugs are unique. email_thread = email_threads[0] else: raise Http404() context = { "issue": IssueDetailSerializer(issue).data, "subject": email_thread.subject, "emails": EmailSerializer(email_thread.emails, many=True).data, "case_email_address": case_email_address, "case_email_list_url": reverse("case-email-list", args=(issue.pk, )), } return render_react_page(request, f"Case {issue.fileref}", "email-thread", context)
def case_detail_view(request, pk): """ The details of a given case. """ issue = _get_issue(request, pk) tenancy = _get_tenancy(issue) notes = _get_issue_notes(request, pk) context = { "issue": IssueDetailSerializer(issue).data, "tenancy": TenancySerializer(tenancy).data, "notes": IssueNoteSerializer(notes, many=True).data, "details": _get_submitted_details(issue), "actionstep_url": _get_actionstep_url(issue), "urls": get_detail_urls(issue), "permissions": { "is_paralegal_or_better": request.user.is_paralegal_or_better, "is_coordinator_or_better": request.user.is_coordinator_or_better, }, } return render_react_page(request, f"Case {issue.fileref}", "case-detail", context)
def template_email_detail_view(request, pk): try: template = EmailTemplate.objects.get(pk=pk) except EmailTemplate.DoesNotExist: raise Http404() if request.method == "PUT": if request.user.is_coordinator_or_better: serializer = EmailTemplateSerializer(instance=template, data=request.data) serializer.is_valid(raise_exception=True) serializer.save() return Response(serializer.data, status=status.HTTP_200_OK) else: raise Http404() context = { "template": EmailTemplateSerializer(template).data, "editable": request.user.is_coordinator_or_better, } return render_react_page(request, "Email Templates", "email-template-detail", context)
def client_detail_view(request, pk): try: client = Client.objects.prefetch_related("issue_set").get(pk=pk) if request.user.is_paralegal: is_assigned = Issue.objects.filter( client=client, paralegal=request.user).exists() if not is_assigned: # Not allowed raise Http404() except Client.DoesNotExist: raise Http404() if request.method == "GET": name = client.get_full_name() context = {"client": ClientDetailSerializer(client).data} return render_react_page(request, f"Client {name}", "client-detail", context) elif request.method == "PATCH": serializer = ClientDetailSerializer(instance=client, data=request.data, partial=True) serializer.is_valid(raise_exception=True) serializer.save() return Response({"client": serializer.data})