def populate_datasets(app, created_models, verbosity, **kwargs):
    datasets = DataSet.objects.filter(code='DEMO').all()
    
    if len(datasets) == 0:
        dataset = DataSet()
        dataset.name = 'DEMO'
        dataset.code = 'DEMO'
        dataset.filename = 'inst.json'
        dataset.size = 440

        dataset.save()
示例#2
0
def get_data_set(request, data_set_form, user_session, default_name):
    if data_set_form.cleaned_data['is_created'] is True:
        name = data_set_form.data['name_created']

        def init_folders(data_set):
            data_set_dirpath = data_set.get_dirpath()  #, posted_file.name)
            if not isdir(data_set_dirpath):
                os.makedirs(data_set_dirpath)

            for kind in ['reference', 'genes', 'operons']:
                posted_file = request.FILES.get(kind)
                if posted_file:
                    with open(os.path.join(data_set_dirpath, posted_file.name), 'wb+') as f:
                        for chunk in posted_file.chunks():
                            f.write(chunk)
                    setattr(data_set, kind + '_fname', posted_file.name)

        if name == '':
            data_set = DataSet(name=default_name, remember=False, user_session=user_session, user=user_session.user)
            data_set.save()
            init_folders(data_set)
            data_set.save()

        else:
            base_name = name
            i = 1
            while DataSet.objects.filter(name=name).exists():
                name = base_name + ' (' + str(i) + ')'
                i += 1

            data_set = DataSet(name=name, remember=True, user_session=user_session, user=user_session.user)
            data_set.save()
            init_folders(data_set)
            data_set.save()

    else:
        name = data_set_form.data['name_selected']
        if name == '' or name == 'no data set':
            data_set = None
        else:
            try:
                data_set = DataSet.objects.get(name=name)
            except DataSet.DoesNotExist:
                logger.error('Data set with name %s does not exits' % name)
                return HttpResponseBadRequest('Data set does not exist')

    return data_set