Skip to content

Views

hypha.apply.activity.views

ActivityContextMixin

Mixin to add related 'comments' of the current view's 'self.object'

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, **kwargs):
    # Comments for both projects and applications exist under the original application
    if isinstance(self.object, ApplicationSubmission):
        application_obj = self.object
    else:
        application_obj = self.object.submission

    extra = {
        "comments_count": services.get_comment_count(
            application_obj, self.request.user
        )
    }
    return super().get_context_data(**extra, **kwargs)

AttachmentView

Bases: PrivateMediaView

storage class-attribute instance-attribute

storage = PrivateStorage()

model class-attribute instance-attribute

get

get(*args, **kwargs)
Source code in hypha/apply/utils/storage.py
def get(self, *args, **kwargs):
    file_to_serve = self.get_media(*args, **kwargs)
    return FileResponse(file_to_serve)

dispatch

dispatch(*args, **kwargs)
Source code in hypha/apply/activity/views.py
def dispatch(self, *args, **kwargs):
    file_pk = kwargs.get("file_pk")
    self.instance = get_object_or_404(ActivityAttachment, uuid=file_pk)

    return super().dispatch(*args, **kwargs)

get_media

get_media(*args, **kwargs)
Source code in hypha/apply/activity/views.py
def get_media(self, *args, **kwargs):
    return self.instance.file

NotificationsView

Bases: ListView

model class-attribute instance-attribute

model = Activity

template_name class-attribute instance-attribute

template_name = 'activity/notifications.html'

filterset_class class-attribute instance-attribute

filterset_class = NotificationFilter

get_queryset

get_queryset()
Source code in hypha/apply/activity/views.py
def get_queryset(self):
    queryset = Activity.objects.filter(current=True).latest()

    # filter by one month by default
    date_filter = self.request.GET.get("date", "month")

    self.filterset = self.filterset_class(
        {"date": date_filter}
        if date_filter not in self.request.GET
        else self.request.GET,
        queryset=queryset,
    )
    return self.filterset.qs.distinct().order_by("-timestamp", "source_object_id")

get_context_data

get_context_data(*, object_list=None, **kwargs)
Source code in hypha/apply/activity/views.py
def get_context_data(self, *, object_list=None, **kwargs):
    context = super().get_context_data()
    context["filter"] = self.filterset
    return context

partial_comments

partial_comments(request, pk)

Render a partial view of comments for a given submission primary key.

This view handles comments for both submission and (if existing) pulls related project activities. It checks the user's permissions and fetches the related comments for the user. The comments are paginated and rendered in the 'activity_list' template.

Parameters:

  • request (HttpRequest) –

    The HTTP request object.

  • content_type (str) –

    The type of content ('submission' or 'project').

  • pk (int) –

    The primary key of the content object.

Returns:

  • HttpResponse –

    The rendered 'activity_list' template with the context data.

Source code in hypha/apply/activity/views.py
@login_required
@require_http_methods(["GET"])
def partial_comments(request, pk: int):
    """
    Render a partial view of comments for a given submission primary key.

    This view handles comments for both submission and (if existing) pulls related project activities.
    It checks the user's permissions and fetches the related comments for the user.
    The comments are paginated and rendered in the 'activity_list' template.

    Args:
        request (HttpRequest): The HTTP request object.
        content_type (str): The type of content ('submission' or 'project').
        pk (int): The primary key of the content object.

    Returns:
        HttpResponse: The rendered 'activity_list' template with the context data.
    """
    submission = get_object_or_404(ApplicationSubmission, pk=pk)
    if not has_object_permission("view_comments", request.user, submission):
        raise PermissionDenied

    editable = not submission.is_archive

    qs = services.get_related_activities_for_user(submission, request.user)
    page = Paginator(qs, per_page=10, orphans=5).page(request.GET.get("page", 1))

    ctx = {
        "page": page,
        "activities": page.object_list,
        "editable": editable,
    }
    return render(request, "activity/include/activity_list.html", ctx)

edit_comment

edit_comment(request, pk)

Edit a comment.

Source code in hypha/apply/activity/views.py
@login_required
def edit_comment(request, pk):
    """Edit a comment."""
    activity = get_object_or_404(Activity, id=pk)

    if activity.type != COMMENT or activity.user != request.user:
        raise PermissionError("You can only edit your own comments")

    if request.GET.get("action") == "cancel":
        return render(
            request,
            "activity/partial_comment_message.html",
            {"activity": activity},
        )

    if request.method == "POST":
        activity = services.edit_comment(activity, request.POST.get("message"))

        return render(
            request,
            "activity/partial_comment_message.html",
            {"activity": activity, "success": True},
        )

    return render(request, "activity/ui/edit_comment_form.html", {"activity": activity})