Ejemplo n.º 1
0
    def submit(self, *args, **kwargs):
        policy = self.get_object()
        if policy.state != POLICY_STATUS_INIT:
            raise ValidationError('Policy already submited')

        serializer = PolicySubmissionSerializer(policy, data=self.request.data)
        serializer.is_valid(raise_exception=True)
        submitted_policy = serializer.save()

        # TODO remove when old frontend will disabled
        calculate_and_set_smart_deposit_coast(policy)

        self.request.user.keybase_username = self.request.data["keybase_username"]
        self.request.user.save()
        messages.success(
            # messages framework requires we use the Django HTTPRequest object
            # instead of DRF's request object.
            self.request._request, "Policy #{0} has been submitted".format(submitted_policy.pk)
        )

        policy.submit()
        policy.save()
        policy.smart_deposit.init_to_wait()
        policy.smart_deposit.save()

        return Response(status=status.HTTP_200_OK)
Ejemplo n.º 2
0
 def perform_update(self, serializer):
     policy = serializer.save()
     if policy.state != POLICY_STATUS_INIT:
         policy.cancel_submission()
         policy.save()
     self.generate_employment_history_jobs(policy)
     self.set_answers_on_questions(policy)
     calculate_and_set_smart_deposit_coast(policy)
Ejemplo n.º 3
0
 def perform_create(self, serializer):
     policy = serializer.save(user=self.request.user)
     self.generate_employment_history_jobs(policy)
     self.set_answers_on_questions(policy)
     calculate_and_set_smart_deposit_coast(policy)
     return policy