def almacenamientoTarea(request): restricciones = models.TaskRestriction( start_time=request.POST.get('HoraInicio'), end_time=request.POST.get('HoraCierre'), task_start_date=request.POST.get('tarfechainicio'), task_end_date=request.POST.get('tarfechacierre')) territorioSubconjunto = models.TerritorialDimension( dimension_name=request.POST.get('nombreSubconjunto'), dimension_geojson=request.POST.get('geojsonsubconjunto'), dimension_type=models.DimensionType.objects.get( pk="35b0b478-9675-45fe-8da5-02ea9ef88f1b")) territorioSubconjunto.full_clean() territorioSubconjunto.save() restricciones.full_clean() restricciones.save() proyid = request.POST.get('proyid') dimen = models.TerritorialDimension.objects.get( pk=request.POST.get('dimensionIDparaTerritorialD')) with transaction.atomic(): tarea = models.Task( task_name=request.POST.get('tarenombre'), task_type=models.TaskType.objects.get( pk=request.POST.get('taretipo')), task_quantity=request.POST.get('tarerestriccant'), task_priority=models.TaskPriority.objects.get( priority_number=request.POST.get('tareprioridad')), task_description=request.POST.get('taredescripcion'), project=models.Project.objects.get(pk=proyid), task_observation="esto es para reportes", proj_dimension=dimen, instrument=models.Instrument.objects.get( pk=request.POST.get('instrid')), territorial_dimension=territorioSubconjunto, task_restriction=restricciones, ) try: tarea.full_clean() tarea.save() data = serializers.serialize('python', [tarea]) response = {'code': 201, 'tarea': data, 'status': 'success'} except ValidationError as e: territorioSubconjunto.delete() restricciones.delete() response = {'code': 400, 'errors': dict(e), 'status': 'error'} except IntegrityError as e: territorioSubconjunto.delete() restricciones.delete() response = {'code': 400, 'message': str(e), 'status': 'success'} return JsonResponse(response, safe=False, status=response['code']) ##
def almacenarDelimitacionesGeograficas(proyecto, delimitacionesGeograficas): try: for d in delimitacionesGeograficas: delimitacion = None delimitacion = models.TerritorialDimension( dimension_name=d['nombre'], dimension_geojson=d['geojson'], dimension_type=models.DimensionType.objects.get( dim_type_id__exact='35b0b478-9675-45fe-8da5-02ea9ef88f1b')) delimitacion.save() delimitacionP = models.ProjectTerritorialDimension( project=proyecto, territorial_dimension=delimitacion) delimitacionP.save() delimitacionP = None return True except ValidationError as e: return False