Exemplo n.º 1
0
def createSample(sample_name, sample_type, **kwargs):
    """
    sample_name:  string, name for the new sample, required
    sample_type:  required, either:
                  - string, name for existing type in Types collection, or
                  - mongo type object for existing type in Types collection
    kwargs:       passed to constructor
    """
    kwargs['sampleName'] = sample_name
    kwargs['requestList'] = []
    kwargs['resultList'] = []

    # initialize request count to zero
    if not kwargs.has_key('request_count'):
        kwargs['request_count'] = 0

    if isinstance(sample_type, unicode) or isinstance(sample_type, str):
        kwargs['sample_type'] = type_from_name(sample_type, as_mongo_obj=True)

#    try:
#        kwargs['sample_type'] = Types.objects(__raw__={'name': type_name})[0]
#    except IndexError:
#        raise ValueError('no sample type found matching "{0}"'.format(type_name))

    s = Sample(**kwargs)
    s.save()

    return s.sample_id