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):
    extra = {
        # Do not prefetch on the related_object__author as the models
        # are not homogeneous and this will fail
        "comments": get_related_comments_for_user(self.object, self.request.user)
    }
    return super().get_context_data(**extra, **kwargs)

CommentFormView

Bases: DelegatedViewMixin, CreateView

form_class class-attribute instance-attribute

form_class = CommentForm

context_name class-attribute instance-attribute

context_name = 'comment_form'

setup

setup(request, *args, **kwargs)

Initialize attributes shared by all view methods.

Source code in hypha/apply/utils/views.py
def setup(self, request, *args, **kwargs):
    """Initialize attributes shared by all view methods."""
    self.request = request
    self.args = args
    self.kwargs = kwargs

get_object

get_object()
Source code in hypha/apply/utils/views.py
def get_object(self):
    # Make sure the form instance, bound at the parent class level,  is the same as the
    # value we work with on the class.
    # If we don't have self.object, bind the parent instance to it. This value will then
    # be used by the form. Any further calls to get_object will get a new instance of the object
    if not hasattr(self, "object"):
        parent_object = self.get_parent_object()
        if isinstance(parent_object, self.model):
            return parent_object

    return super().get_object()

get_template_names

get_template_names()
Source code in hypha/apply/utils/views.py
def get_template_names(self):
    return self.kwargs["template_names"]

get_form_name

get_form_name()
Source code in hypha/apply/utils/views.py
def get_form_name(self):
    return self.context_name

get_parent_kwargs

get_parent_kwargs()
Source code in hypha/apply/utils/views.py
def get_parent_kwargs(self):
    try:
        return self.parent.get_form_kwargs()
    except AttributeError:
        return self.kwargs["parent"].get_form_kwargs()

get_parent_object

get_parent_object()
Source code in hypha/apply/utils/views.py
def get_parent_object(self):
    return self.get_parent_kwargs()["instance"]

get_form

get_form(*args, **kwargs)
Source code in hypha/apply/utils/views.py
def get_form(self, *args, **kwargs):
    form = super().get_form(*args, **kwargs)
    form.name = self.get_form_name()
    return form

get_context_data

get_context_data(**kwargs)
Source code in hypha/apply/utils/views.py
def get_context_data(self, **kwargs):
    # Use the previous context but override the validated form
    form = kwargs.pop("form")
    kwargs.update(self.kwargs["context"])
    kwargs.update(**{self.context_name: form})
    return super().get_context_data(**kwargs)

is_model_form classmethod

is_model_form()
Source code in hypha/apply/utils/views.py
@classmethod
def is_model_form(cls):
    return issubclass(cls.form_class, ModelForm)

contribute_form

contribute_form(parent)
Source code in hypha/apply/utils/views.py
def contribute_form(self, parent):
    self.parent = parent

    # We do not want to bind any forms generated this way
    # pretend we are doing a get request to avoid passing data to forms
    old_method = None
    if self.request.method in ("POST", "PUT"):
        old_method = self.request.method
        self.request.method = "GET"

    form = self.get_form()

    if old_method:
        self.request.method = old_method
    return self.context_name, form

form_valid

form_valid(form)
Source code in hypha/apply/activity/views.py
def form_valid(self, form):
    source = self.kwargs["object"]
    form.instance.user = self.request.user
    form.instance.source = source
    form.instance.type = COMMENT
    form.instance.timestamp = timezone.now()
    response = super().form_valid(form)
    messenger(
        MESSAGES.COMMENT,
        request=self.request,
        user=self.request.user,
        source=source,
        related=self.object,
    )
    return response

get_success_url

get_success_url()
Source code in hypha/apply/activity/views.py
def get_success_url(self):
    return self.object.source.get_absolute_url() + "#communications"

get_form_kwargs

get_form_kwargs()

Get the kwargs for the CommentForm.

Returns:

  • dict –

    A dict of kwargs to be passed to CommentForm. The submission instance is removed from this return, while a boolean of has_partners is added based off the submission.

Source code in hypha/apply/activity/views.py
def get_form_kwargs(self) -> dict:
    """Get the kwargs for the [`CommentForm`][hypha.apply.activity.forms.CommentForm].

    Returns:
        A dict of kwargs to be passed to [`CommentForm`][hypha.apply.activity.forms.CommentForm]. The submission instance is removed from this return, while a boolean of `has_partners` is added based off the submission.
    """
    kwargs = super().get_form_kwargs()
    instance = kwargs.pop("instance")
    if isinstance(instance, ApplicationSubmission):
        kwargs["submission_partner_list"] = instance.partners.all()
    return 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_template_names

get_template_names()
Source code in hypha/apply/activity/views.py
def get_template_names(self):
    if self.request.htmx and self.request.GET.get("type") == "header_dropdown":
        return ["activity/include/notifications_dropdown.html"]
    return super().get_template_names()

get_queryset

get_queryset()
Source code in hypha/apply/activity/views.py
def get_queryset(self):
    # List only last 30 days' activities
    queryset = Activity.objects.filter(current=True).latest()

    self.filterset = self.filterset_class(self.request.GET, queryset=queryset)
    qs = self.filterset.qs.distinct().order_by("-timestamp")

    if self.request.htmx and self.request.GET.get("type") == "header_dropdown":
        qs = qs[:5]
    return qs

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(NotificationsView, self).get_context_data()
    context["filter"] = self.filterset
    return context