def save(self):
        """Create and return the new case(s) and version(s)."""
        assert self.is_valid()

        product = self.cleaned_data["product"]
        idprefix = self.cleaned_data["idprefix"]
        priority = self.cleaned_data["priority"]

        # ensure priority is an int, if not, store "None"
        try:
            int(priority)
        except __HOLE__:
            priority = None

        self.save_new_tags(product)

        productversions = [self.cleaned_data["productversion"]]
        if self.cleaned_data.get("and_later_versions"):
            productversions.extend(product.versions.filter(
                    order__gt=productversions[0].order))

        suite = self.cleaned_data.get("suite")

        cases = []

        order = 0
        if suite:
            order = model.SuiteCase.objects.filter(
                suite=suite,
                ).aggregate(Max("order"))["order__max"] or 0

        for case_data in self.cleaned_data["cases"]:
            case = model.Case.objects.create(
                product=product,
                user=self.user,
                idprefix=idprefix,
                priority=priority,
                )

            version_kwargs = case_data.copy()
            steps_data = version_kwargs.pop("steps")

            version_kwargs["case"] = case
            version_kwargs["status"] = self.cleaned_data["status"]
            version_kwargs["user"] = self.user

            if suite:
                order += 1
                model.SuiteCase.objects.create(
                    case=case,
                    suite=suite,
                    user=self.user,
                    order=order,
                    )

            for productversion in productversions:
                this_version_kwargs = version_kwargs.copy()
                this_version_kwargs["productversion"] = productversion
                caseversion = model.CaseVersion.objects.create(
                    **this_version_kwargs)
                for i, step_kwargs in enumerate(steps_data, 1):
                    model.CaseStep.objects.create(
                        user=self.user,
                        caseversion=caseversion,
                        number=i,
                        **step_kwargs)
                self.save_tags(caseversion)

            cases.append(case)

        return cases
dataset/ETHPy150Open mozilla/moztrap/moztrap/view/manage/cases/forms.py/AddBulkCaseForm.save