Exemple #1
0
def get_associated_objects_json(plan):
    """ Gather associated objects to send to destination """
    def get_obj_dict(obj):
        d = {}
        for field in obj._meta.fields:
            if field.get_internal_type() not in [
                    "AutoField",
                    "ForeignKey",
                    "OneToOneField",
                    "ManyToManyField",
            ]:
                d[field.name] = getattr(obj, field.name)
        return d

    obj_dict = {}

    # Samples
    samples = plan.experiment.samples.all()
    obj_dict["samples"] = []
    for sample in samples:
        d = get_obj_dict(sample)
        obj_dict["samples"].append(d)

    # SampleSet
    obj_dict["sampleSets"] = []
    for sampleSet in plan.sampleSets.all():
        sampleSet_dict = get_obj_dict(sampleSet)
        sampleSet_dict[
            "SampleGroupType_CV_id"] = sampleSet.SampleGroupType_CV_id
        sampleSet_dict["libraryPrepInstrumentData"] = (
            get_obj_dict(sampleSet.libraryPrepInstrumentData)
            if sampleSet.libraryPrepInstrumentData else {})

        sampleSet_dict["sampleSetItems"] = []
        for setitem in sampleSet.samples.filter(sample__in=samples):
            setitem_dict = get_obj_dict(setitem)
            setitem_dict["sample__name"] = setitem.sample.name
            if setitem.dnabarcode:
                setitem_dict["dnabarcode"] = {
                    "name": setitem.dnabarcode.name,
                    "id_str": setitem.dnabarcode.id_str,
                }
            sampleSet_dict["sampleSetItems"].append(setitem_dict)

        obj_dict["sampleSets"].append(sampleSet_dict)

    # Ion Reporter account
    eas = plan.latest_eas
    if "IonReporterUploader" in eas.selectedPlugins:
        try:
            accountId = (eas.selectedPlugins["IonReporterUploader"].get(
                "userInput", {}).get("accountId"))
            iru_config = Plugin.objects.get(name="IonReporterUploader",
                                            active=True).config
            obj_dict["IR_account"] = find_IRU_account(iru_config, accountId)
        except Exception:
            logger.error(traceback.format_exc())

    return json.dumps(obj_dict, cls=LazyDjangoJSONEncoder)
Exemple #2
0
def get_associated_objects_json(plan):
    ''' Gather associated objects to send to destination '''
    def get_obj_dict(obj):
        d = {}
        for field in obj._meta.fields:
            if field.get_internal_type() not in [
                    'AutoField', 'ForeignKey', 'OneToOneField',
                    'ManyToManyField'
            ]:
                d[field.name] = getattr(obj, field.name)
        return d

    obj_dict = {}

    # Samples
    samples = plan.experiment.samples.all()
    obj_dict['samples'] = []
    for sample in samples:
        d = get_obj_dict(sample)
        obj_dict['samples'].append(d)

    # SampleSet
    obj_dict['sampleSets'] = []
    for sampleSet in plan.sampleSets.all():
        sampleSet_dict = get_obj_dict(sampleSet)
        sampleSet_dict[
            'SampleGroupType_CV_id'] = sampleSet.SampleGroupType_CV_id
        sampleSet_dict['libraryPrepInstrumentData'] = get_obj_dict(
            sampleSet.libraryPrepInstrumentData
        ) if sampleSet.libraryPrepInstrumentData else {}

        sampleSet_dict['sampleSetItems'] = []
        for setitem in sampleSet.samples.filter(sample__in=samples):
            setitem_dict = get_obj_dict(setitem)
            setitem_dict['sample__name'] = setitem.sample.name
            if setitem.dnabarcode:
                setitem_dict['dnabarcode'] = {
                    'name': setitem.dnabarcode.name,
                    'id_str': setitem.dnabarcode.id_str
                }
            sampleSet_dict['sampleSetItems'].append(setitem_dict)

        obj_dict['sampleSets'].append(sampleSet_dict)

    # Ion Reporter account
    eas = plan.latest_eas
    if 'IonReporterUploader' in eas.selectedPlugins:
        try:
            accountId = eas.selectedPlugins['IonReporterUploader'].get(
                'userInput', {}).get('accountId')
            iru_config = Plugin.objects.get(name='IonReporterUploader',
                                            active=True).config
            obj_dict['IR_account'] = find_IRU_account(iru_config, accountId)
        except:
            logger.error(traceback.format_exc())

    return json.dumps(obj_dict, cls=DjangoJSONEncoder)
Exemple #3
0
def get_associated_objects_json(plan):
    ''' Gather associated objects to send to destination '''
    def get_obj_dict(obj):
        d = {}
        for field in obj._meta.fields:
            if field.get_internal_type() not in ['AutoField', 'ForeignKey', 'OneToOneField', 'ManyToManyField']:
                d[field.name] = getattr(obj, field.name)
        return d

    obj_dict = {}

    # Samples
    samples = plan.experiment.samples.all()
    obj_dict['samples'] = []
    for sample in samples:
        d = get_obj_dict(sample)
        obj_dict['samples'].append(d)

    # SampleSet
    obj_dict['sampleSets'] = []
    for sampleSet in plan.sampleSets.all():
        sampleSet_dict = get_obj_dict(sampleSet)
        sampleSet_dict['SampleGroupType_CV_id'] = sampleSet.SampleGroupType_CV_id
        sampleSet_dict['libraryPrepInstrumentData'] = get_obj_dict(sampleSet.libraryPrepInstrumentData) if sampleSet.libraryPrepInstrumentData else {}

        sampleSet_dict['sampleSetItems'] = []
        for setitem in sampleSet.samples.filter(sample__in=samples):
            setitem_dict = get_obj_dict(setitem)
            setitem_dict['sample__name'] = setitem.sample.name
            if setitem.dnabarcode:
                setitem_dict['dnabarcode'] = {
                    'name': setitem.dnabarcode.name,
                    'id_str': setitem.dnabarcode.id_str
                }
            sampleSet_dict['sampleSetItems'].append(setitem_dict)

        obj_dict['sampleSets'].append(sampleSet_dict)

    # Ion Reporter account
    eas = plan.latest_eas
    if 'IonReporterUploader' in eas.selectedPlugins:
        try:
            accountId = eas.selectedPlugins['IonReporterUploader'].get('userInput', {}).get('accountId')
            iru_config = Plugin.objects.get(name='IonReporterUploader', active=True).config
            obj_dict['IR_account'] = find_IRU_account(iru_config, accountId)
        except:
            logger.error(traceback.format_exc())

    return json.dumps(obj_dict, cls=DjangoJSONEncoder)