| 334 | logger.warning("Could not move assets folder for task {}. We're going to proceed anyway, but you might experience issues: {}".format(self, e)) |
| 335 | |
| 336 | def save(self, *args, **kwargs): |
| 337 | if self.project.id != self.__original_project_id: |
| 338 | self.move_assets(self.__original_project_id, self.project.id) |
| 339 | self.__original_project_id = self.project.id |
| 340 | |
| 341 | # Manually validate the fields we want, |
| 342 | # since Django's clean_fields() method obliterates |
| 343 | # our foreign keys without explanation :/ |
| 344 | errors = {} |
| 345 | for f in self._meta.fields: |
| 346 | if f.attname in ["options"]: |
| 347 | raw_value = getattr(self, f.attname) |
| 348 | if f.blank and raw_value in f.empty_values: |
| 349 | continue |
| 350 | |
| 351 | try: |
| 352 | setattr(self, f.attname, f.clean(raw_value, self)) |
| 353 | except ValidationError as e: |
| 354 | errors[f.name] = e.error_list |
| 355 | |
| 356 | if errors: |
| 357 | raise ValidationError(errors) |
| 358 | |
| 359 | # Validate crop area |
| 360 | # must be enclosed within all raster extents |
| 361 | # and have a positive area |
| 362 | if self.crop is not None: |
| 363 | if self.crop.valid: |
| 364 | has_extents = False |
| 365 | for extent in [self.orthophoto_extent, self.dsm_extent, self.dtm_extent]: |
| 366 | if extent is not None: |
| 367 | has_extents = True |
| 368 | self.crop = extent.intersection(self.crop) |
| 369 | if not has_extents or self.crop.area <= 0: |
| 370 | self.crop = None |
| 371 | else: |
| 372 | self.crop = None |
| 373 | |
| 374 | self.clean() |
| 375 | self.validate_unique() |
| 376 | |
| 377 | super(Task, self).save(*args, **kwargs) |
| 378 | |
| 379 | def get_extent(self): |
| 380 | if self.orthophoto_extent is not None: |