Skip to content

Views

hypha.apply.flags.views

FlagSubmissionCreateView

Bases: UserPassesTestMixin, View

model class-attribute instance-attribute

model = Flag

post

post(request, type, submission_pk)
Source code in hypha/apply/flags/views.py
def post(self, request, type, submission_pk):
    if request.headers.get("x-requested-with") != "XMLHttpRequest":
        return HttpResponseNotAllowed()

    # Only staff can create staff flags.
    if type == self.model.STAFF and not self.request.user.is_apply_staff:
        return HttpResponseNotAllowed()

    submission_type = ContentType.objects.get_for_model(ApplicationSubmission)
    # Trying to get a flag from the table, or create a new one
    flag, created = self.model.objects.get_or_create(
        user=request.user,
        target_object_id=submission_pk,
        target_content_type=submission_type,
        type=type,
    )
    # If no new flag has been created,
    # Then we believe that the request was to delete the flag.
    if not created:
        flag.delete()

    return JsonResponse({"result": created})

test_func

test_func()
Source code in hypha/apply/flags/views.py
def test_func(self):
    return self.request.user.is_apply_staff or self.request.user.is_reviewer