def clean(self):
        # only act on category_ items.  There may be other fields
        # like "build" in here if a run series is being executed.
        selected_element_ids = set(
            [int(eid) for k, eid in self.cleaned_data.iteritems()
                if k.find("category_") == 0 and eid])
        matches = [
            envid for envid, element_ids in self.elementids_by_envid.items()
            if set([e for e in element_ids if e]).issubset(selected_element_ids)
            ]
        if not matches:
            raise forms.ValidationError(
                "The selected environment is not valid for this test run. "
                "Please select a different combination.")

        self.cleaned_data["environment"] = matches[0]

        return self.cleaned_data
Validate that selected elements form valid environment.
dataset/ETHPy150Open mozilla/moztrap/moztrap/view/runtests/forms.py/EnvironmentSelectionForm.clean