Newer
Older
from django.views.generic import CreateView
from opentech.apply.utils.views import DelegatedViewMixin
class AllActivityContextMixin:
def get_context_data(self, **kwargs):
extra = {
'actions': Activity.actions.filter(submission__in=self.object_list).select_related(
'submission',
'user',
)[:ACTIVITY_LIMIT],
'comments': Activity.comments.filter(submission__in=self.object_list).select_related(
'submission',
'user',
)[:ACTIVITY_LIMIT],
'all_activity': Activity.objects.filter(submission__in=self.object_list).select_related(
'submission',
'user',
)[:ACTIVITY_LIMIT],
}
return super().get_context_data(**extra, **kwargs)
def get_context_data(self, **kwargs):
extra = {
'actions': Activity.actions.filter(submission=self.object).select_related(
'user',
).prefetch_related(
'related_object',
).visible_to(self.request.user),
'comments': Activity.comments.filter(submission=self.object).select_related(
'user',
).prefetch_related(
'related_object',
).visible_to(self.request.user),
}
return super().get_context_data(**extra, **kwargs)
class CommentFormView(DelegatedViewMixin, CreateView):
context_name = 'comment_form'
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.submission = self.kwargs['submission']
submission=self.object.submission,
comment=self.object,
return self.object.submission.get_absolute_url() + '#communications'
def contribute_form(cls, submission, user):
# We dont want to pass the submission as the instance
return super().contribute_form(None, user=user)