示例#1
0
def workbook_create_with_variables(request):
    json_data = request.POST.get('json_data')
    if json_data:
        data = json.loads(json_data)
        # TODO: Refactor so that user can create using multiple variable lists
        var_list_id = data['variable_list_id'][0]
    else:
        var_list_id    = request.POST.get('variable_list_id')


    var_list_model = VariableFavorite.objects.get(id=var_list_id)
    name = request.POST.get('name', var_list_model.name + ' workbook')
    workbook_model = Workbook.create(name=name, description="this is an untitled workbook with all variables of variable favorite list \"" + var_list_model.name + "\" added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
    workbook_model.save()
    worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
    worksheet_model.save()

    print workbook_model.id
    for var in var_list_model.get_variables() :
        work_var = Worksheet_variable.objects.create(worksheet_id = worksheet_model.id,
                                          name         = var.name,
                                          url_code     = var.code,
                                          type         = var.type,
                                          feature_id   = var.feature_id)

        work_var.save()

    redirect_url = reverse('workbook_detail', kwargs={'workbook_id':workbook_model.id})
    if json_data:
        return JsonResponse({'workbook_id': workbook_model.id, 'worksheet_id': worksheet_model.id})
    else:
        return redirect(redirect_url)
示例#2
0
def workbook_create_with_program(request):
    program_id = request.POST.get('program_id')
    program_model = Program.objects.get(id=program_id)

    workbook_model = Workbook.create(
        name="Untitled Workbook",
        description=
        "this is an untitled workbook with all variables of program \"" +
        program_model.name +
        "\" added to the first worksheet. Click Edit Details to change your workbook title and description.",
        user=request.user)
    worksheet_model = Worksheet.objects.create(name="worksheet 1",
                                               description="",
                                               workbook=workbook_model)

    #add every variable within the model
    for study in program_model.study_set.filter(active=True):
        for var in study.user_feature_definitions_set.all():
            work_var = Worksheet_variable.objects.create(
                worksheet_id=worksheet_model.id,
                name=var.feature_name,
                url_code=var.bq_map_id,
                feature_id=var.id)
            work_var.save()

    redirect_url = reverse('workbook_detail',
                           kwargs={'workbook_id': workbook_model.id})
    return redirect(redirect_url)
示例#3
0
def workbook_create_with_cohort(request):
    cohort_id       = request.POST.get('cohort_id')
    cohort          = Cohort.objects.get(id=cohort_id)
    workbook_model  = Workbook.create(name="Untitled Workbook", description="This workbook was created with cohort \"" + cohort.name + "\" added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
    worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
    worksheet_model.add_cohort(cohort=cohort)

    redirect_url = reverse('workbook_detail', kwargs={'workbook_id':workbook_model.id})
    return redirect(redirect_url)
示例#4
0
def workbook_create_with_analysis(request):
    analysis_type   = request.POST.get('analysis')

    allowed_types = Analysis.get_types()
    redirect_url = reverse('sample_analyses')
    for type in allowed_types :
        if analysis_type == type['name'] :
            workbook_model  = Workbook.create(name="Untitled Workbook", description="this is an untitled workbook with a \"" + analysis_type + "\" plot added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
            worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
            worksheet_model.set_plot(type=analysis_type)
            redirect_url = reverse('workbook_detail', kwargs={'workbook_id':workbook_model.id})
            break

    return redirect(redirect_url)
示例#5
0
def workbook_create_with_cohort_list(request):
    cohort_ids = json.loads(request.body)['cohorts']
    if len(cohort_ids) > 0 :
        workbook_model  = Workbook.create(name="Untitled Workbook", description="This is a workbook created with cohorts added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
        worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
        for id in cohort_ids :
            cohort = Cohort.objects.get(id=id)
            worksheet_model.add_cohort(cohort=cohort)

        result = {'workbook_id'  : workbook_model.id,
                  'worksheet_id' : worksheet_model.id}
    else :
        result = {'error' : 'parameters are not correct'}

    return HttpResponse(json.dumps(result), status=200)
示例#6
0
def workbook_create_with_cohort(request):
    cohort_id = request.POST.get('cohort_id')
    cohort = Cohort.objects.get(id=cohort_id)
    workbook_model = Workbook.create(
        name="Untitled Workbook",
        description="This workbook was created with cohort \"" + cohort.name +
        "\" added to the first worksheet. Click Edit Details to change your workbook title and description.",
        user=request.user)
    worksheet_model = Worksheet.objects.create(name="worksheet 1",
                                               description="",
                                               workbook=workbook_model)
    worksheet_model.add_cohort(cohort=cohort)

    redirect_url = reverse('workbook_detail',
                           kwargs={'workbook_id': workbook_model.id})
    return redirect(redirect_url)
示例#7
0
def workbook_create_with_program(request):
    program_id = request.POST.get('program_id')
    program_model = Program.objects.get(id=program_id)

    workbook_model = Workbook.create(name="Untitled Workbook", description="this is an untitled workbook with all variables of program \"" + program_model.name + "\" added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
    worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)

    #add every variable within the model
    for study in program_model.study_set.all().filter(active=True) :
        for var in study.user_feature_definitions_set.all() :
            work_var = Worksheet_variable.objects.create(worksheet_id = worksheet_model.id,
                                              name         = var.feature_name,
                                              url_code     = var.bq_map_id,
                                              feature_id   = var.id)
            work_var.save()

    redirect_url = reverse('workbook_detail', kwargs={'workbook_id':workbook_model.id})
    return redirect(redirect_url)
示例#8
0
def workbook_create_with_variables(request):
    json_data = request.POST.get('json_data')
    if json_data:
        data = json.loads(json_data)
        # TODO: Refactor so that user can create using multiple variable lists
        var_list_id = data['variable_list_id'][0]
    else:
        var_list_id = request.POST.get('variable_list_id')

    var_list_model = VariableFavorite.objects.get(id=var_list_id)
    name = request.POST.get('name', var_list_model.name + ' workbook')
    workbook_model = Workbook.create(
        name=name,
        description=
        "this is an untitled workbook with all variables of variable favorite list \""
        + var_list_model.name +
        "\" added to the first worksheet. Click Edit Details to change your workbook title and description.",
        user=request.user)
    workbook_model.save()
    worksheet_model = Worksheet.objects.create(name="worksheet 1",
                                               description="",
                                               workbook=workbook_model)
    worksheet_model.save()

    print workbook_model.id
    for var in var_list_model.get_variables():
        work_var = Worksheet_variable.objects.create(
            worksheet_id=worksheet_model.id,
            name=var.name,
            url_code=var.code,
            type=var.type,
            feature_id=var.feature_id)

        work_var.save()

    redirect_url = reverse('workbook_detail',
                           kwargs={'workbook_id': workbook_model.id})
    if json_data:
        return JsonResponse({
            'workbook_id': workbook_model.id,
            'worksheet_id': worksheet_model.id
        })
    else:
        return redirect(redirect_url)
示例#9
0
def workbook_create_with_analysis(request):
    analysis_type = request.POST.get('analysis')

    allowed_types = Analysis.get_types()
    redirect_url = reverse('sample_analyses')
    for type in allowed_types:
        if analysis_type == type['name']:
            workbook_model = Workbook.create(
                name="Untitled Workbook",
                description="this is an untitled workbook with a \"" +
                analysis_type +
                "\" plot added to the first worksheet. Click Edit Details to change your workbook title and description.",
                user=request.user)
            worksheet_model = Worksheet.objects.create(name="worksheet 1",
                                                       description="",
                                                       workbook=workbook_model)
            worksheet_model.set_plot(type=analysis_type)
            redirect_url = reverse('workbook_detail',
                                   kwargs={'workbook_id': workbook_model.id})
            break

    return redirect(redirect_url)
示例#10
0
def workbook_create_with_cohort_list(request):
    cohort_ids = json.loads(request.body)['cohorts']
    if len(cohort_ids) > 0:
        workbook_model = Workbook.create(
            name="Untitled Workbook",
            description=
            "This is a workbook created with cohorts added to the first worksheet. Click Edit Details to change your workbook title and description.",
            user=request.user)
        worksheet_model = Worksheet.objects.create(name="worksheet 1",
                                                   description="",
                                                   workbook=workbook_model)
        for id in cohort_ids:
            cohort = Cohort.objects.get(id=id)
            worksheet_model.add_cohort(cohort=cohort)

        result = {
            'workbook_id': workbook_model.id,
            'worksheet_id': worksheet_model.id
        }
    else:
        result = {'error': 'parameters are not correct'}

    return HttpResponse(json.dumps(result), status=200)
示例#11
0
def worksheet_genes(request, workbook_id=0, worksheet_id=0, genes_id=0):
    command  = request.path.rsplit('/',1)[1];
    json_response = False
    result = {}

    if request.method == "POST" :
        if command == "delete" :
            Worksheet_gene.destroy(workbook_id=workbook_id, worksheet_id=worksheet_id, id=genes_id, user=request.user)
            result['message'] = "genes have been deleted from workbook"
        else :
            genes = []
            workbook_name = 'Untitled Workbook'
            #from Gene Edit Page
            if request.POST.get("genes-list") :
                # Get workbook name
                if request.POST.get('name'):
                    workbook_name = request.POST.get('name')

                name = request.POST.get("genes-name")
                gene_list = request.POST.get("genes-list")
                gene_list = [x.strip() for x in gene_list.split(' ')]
                gene_list = list(set(gene_list))
                GeneFavorite.create(name=name, gene_list=gene_list, user=request.user)
                messages.info(request, 'The gene favorite list \"' + name + '\" was created and added to your worksheet')
                for g in gene_list:
                    genes.append(g)

            #from Gene Details Page
            if request.POST.get("gene_list_id") :
                # Get workbook name
                if request.POST.get('name'):
                    workbook_name = request.POST.get('name')

                gene_id = request.POST.get("gene_list_id")
                try :
                    gene_fav = GeneFavorite.objects.get(id=gene_id)
                    names = gene_fav.get_gene_name_list()
                    for g in names:
                        if g not  in genes:
                            genes.append(g)
                except ObjectDoesNotExist:
                        None

            #from Gene List Page
            if "gene_fav_list" in request.body :
                json_response = True
                gene_fav_list = json.loads(request.body)['gene_fav_list']
                for id in gene_fav_list:
                    try:
                        fav = GeneFavorite.objects.get(id=id)
                        names = fav.get_gene_name_list()
                        for g in names:
                            if g not in genes:
                                genes.append(g)
                    except ObjectDoesNotExist:
                        None
            if len(genes) > 0:
                if workbook_id is 0:

                    workbook_model  = Workbook.create(name=workbook_name, description="This workbook was created with genes added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
                    worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
                else :
                    workbook_model = Workbook.objects.get(id=workbook_id)
                    workbook_model.save()
                    worksheet_model = Worksheet.objects.get(id=worksheet_id)

                Worksheet_gene.edit_list(workbook_id=workbook_model.id, worksheet_id=worksheet_model.id, gene_list=genes, user=request.user)
                result['genes'] = genes
            else :
                result['error'] = "no genes to add"

    else :
        result['error'] = "method not correct"

    if json_response :
        return HttpResponse(json.dumps(result), status=200)
    else :
        redirect_url = reverse('worksheet_display', kwargs={'workbook_id':workbook_model.id, 'worksheet_id': worksheet_model.id})
        return redirect(redirect_url)
示例#12
0
def worksheet_variables(request, workbook_id=0, worksheet_id=0, variable_id=0):
    command  = request.path.rsplit('/',1)[1];
    json_response = False
    workbook_name = "Untitled Workbook"
    result        = {}

    if request.method == "POST" :
        if command == "delete" :
            Worksheet_variable.destroy(workbook_id=workbook_id, worksheet_id=worksheet_id, id=variable_id, user=request.user)
            result['message'] = "variables have been deleted from workbook"
        else :
            variables = []
            #from Edit Page
            if "variables" in request.body :
                json_response = True
                name          = json.loads(request.body)['name']
                variable_list = json.loads(request.body)['variables']
                variable_favorite_result = VariableFavorite.create(name       = name,
                                                                   variables  = variable_list,
                                                                   user       = request.user)

                model = VariableFavorite.objects.get(id=variable_favorite_result['id'])
                messages.info(request, 'The variable favorite list \"' + model.name + '\" was created and added to your worksheet')
                variables = model.get_variables()

            #from Details Page or list page
            if request.POST.get("variable_list_id") :
                workbook_name = request.POST.get("name")
                variable_id   = request.POST.get("variable_list_id")
                try :
                    variable_fav = VariableFavorite.objects.get(id=variable_id)
                    variables = variable_fav.get_variables()
                except ObjectDoesNotExist:
                    result['error'] = "variable favorite does not exist"

            #from Select Page
            if "var_favorites" in request.body :
                variable_fav_list = json.loads(request.body)['var_favorites']
                json_response = True
                for fav in variable_fav_list:
                    try:
                        fav = VariableFavorite.objects.get(id=fav['id'])
                        variables = fav.get_variables()
                    except ObjectDoesNotExist:
                        result['error'] = "variable favorite does not exist"

            if len(variables) > 0:
                if workbook_id == 0:
                    workbook_model  = Workbook.create(name=workbook_name, description="This workbook was created with variables added to the first worksheet. Click Edit Details to change your workbook title and description.", user=request.user)
                    worksheet_model = Worksheet.objects.create(name="worksheet 1", description="", workbook=workbook_model)
                else :
                    workbook_model  = Workbook.objects.get(id=workbook_id)
                    workbook_model.save()
                    worksheet_model = Worksheet.objects.get(id=worksheet_id)

                Worksheet_variable.edit_list(workbook_id=workbook_model.id, worksheet_id=worksheet_model.id, variable_list=variables, user=request.user)
                result['workbook_id'] = workbook_model.id
                result['worksheet_id'] = worksheet_model.id
            else :
                result['error'] = "no variables to add"
    else :
        result['error'] = "method not correct"

    if json_response :
        return HttpResponse(json.dumps(result), status=200)
    else :
        redirect_url = reverse('worksheet_display', kwargs={'workbook_id':workbook_model.id, 'worksheet_id': worksheet_model.id})
        return redirect(redirect_url)
示例#13
0
def worksheet_genes(request, workbook_id=0, worksheet_id=0, genes_id=0):
    command = request.path.rsplit('/', 1)[1]
    json_response = False
    result = {}

    if request.method == "POST":
        if command == "delete":
            Worksheet_gene.destroy(workbook_id=workbook_id,
                                   worksheet_id=worksheet_id,
                                   id=genes_id,
                                   user=request.user)
            result['message'] = "genes have been deleted from workbook"
        else:
            genes = []
            workbook_name = 'Untitled Workbook'
            #from Gene Edit Page
            if request.POST.get("genes-list"):
                # Get workbook name
                if request.POST.get('name'):
                    workbook_name = request.POST.get('name')

                name = request.POST.get("genes-name")
                gene_list = request.POST.get("genes-list")
                gene_list = [x.strip() for x in gene_list.split(' ')]
                gene_list = list(set(gene_list))
                GeneFave = GeneFavorite.create(name=name,
                                               gene_list=gene_list,
                                               user=request.user)
                messages.info(
                    request, 'The gene favorite list \"' + name +
                    '\" was created and added to your worksheet')
                # Refetch the created gene list, because it will have the names correctly formatted
                for g in GeneFavorite.objects.get(
                        id=GeneFave['id']).get_genes_list():
                    genes.append(g)

            #from Gene Details Page
            if request.POST.get("gene_list_id"):
                # Get workbook name
                if request.POST.get('name'):
                    workbook_name = request.POST.get('name')

                gene_id = request.POST.get("gene_list_id")
                try:
                    gene_fav = GeneFavorite.objects.get(id=gene_id)
                    names = gene_fav.get_gene_name_list()
                    for g in names:
                        if g not in genes:
                            genes.append(g)
                except ObjectDoesNotExist:
                    None

            #from Gene List Page
            if "gene_fav_list" in request.body:
                json_response = True
                gene_fav_list = json.loads(request.body)['gene_fav_list']
                for id in gene_fav_list:
                    try:
                        fav = GeneFavorite.objects.get(id=id)
                        names = fav.get_gene_name_list()
                        for g in names:
                            if g not in genes:
                                genes.append(g)
                    except ObjectDoesNotExist:
                        None
            if len(genes) > 0:
                if workbook_id is 0:
                    workbook_model = Workbook.create(
                        name=workbook_name,
                        description=
                        "This workbook was created with genes added to the first worksheet. Click Edit Details to change your workbook title and description.",
                        user=request.user)
                    worksheet_model = Worksheet.objects.create(
                        name="worksheet 1",
                        description="",
                        workbook=workbook_model)
                else:
                    workbook_model = Workbook.objects.get(id=workbook_id)
                    workbook_model.save()
                    worksheet_model = Worksheet.objects.get(id=worksheet_id)

                Worksheet_gene.edit_list(workbook_id=workbook_model.id,
                                         worksheet_id=worksheet_model.id,
                                         gene_list=genes,
                                         user=request.user)
                result['genes'] = genes
            else:
                result['error'] = "no genes to add"

    else:
        result['error'] = "method not correct"

    if json_response:
        return HttpResponse(json.dumps(result), status=200)
    else:
        redirect_url = reverse('worksheet_display',
                               kwargs={
                                   'workbook_id': workbook_model.id,
                                   'worksheet_id': worksheet_model.id
                               })
        return redirect(redirect_url)
示例#14
0
def worksheet_variables(request, workbook_id=0, worksheet_id=0, variable_id=0):
    command = request.path.rsplit('/', 1)[1]
    json_response = False
    workbook_name = "Untitled Workbook"
    result = {}

    if request.method == "POST":
        if command == "delete":
            Worksheet_variable.destroy(workbook_id=workbook_id,
                                       worksheet_id=worksheet_id,
                                       id=variable_id,
                                       user=request.user)
            result['message'] = "variables have been deleted from workbook"
        else:
            variables = []
            #from Edit Page
            if "variables" in request.body:
                json_response = True
                name = json.loads(request.body)['name']
                variable_list = json.loads(request.body)['variables']
                variable_favorite_result = VariableFavorite.create(
                    name=name, variables=variable_list, user=request.user)

                model = VariableFavorite.objects.get(
                    id=variable_favorite_result['id'])
                messages.info(
                    request,
                    'The variable favorite list \"' + escape(model.name) +
                    '\" was created and added to your worksheet')
                variables = model.get_variables()

            #from Details Page or list page
            if request.POST.get("variable_list_id"):
                workbook_name = request.POST.get("name")
                variable_id = request.POST.get("variable_list_id")
                try:
                    variable_fav = VariableFavorite.objects.get(id=variable_id)
                    variables = variable_fav.get_variables()
                except ObjectDoesNotExist:
                    result['error'] = "variable favorite does not exist"

            #from Select Page
            if "var_favorites" in request.body:
                variable_fav_list = json.loads(request.body)['var_favorites']
                json_response = True
                for fav in variable_fav_list:
                    try:
                        fav = VariableFavorite.objects.get(id=fav['id'])
                        variables = fav.get_variables()
                    except ObjectDoesNotExist:
                        result['error'] = "variable favorite does not exist"

            if len(variables) > 0:
                if workbook_id == 0:
                    workbook_model = Workbook.create(
                        name=workbook_name,
                        description=
                        "This workbook was created with variables added to the first worksheet. Click Edit Details to change your workbook title and description.",
                        user=request.user)
                    worksheet_model = Worksheet.objects.create(
                        name="worksheet 1",
                        description="",
                        workbook=workbook_model)
                else:
                    workbook_model = Workbook.objects.get(id=workbook_id)
                    workbook_model.save()
                    worksheet_model = Worksheet.objects.get(id=worksheet_id)

                Worksheet_variable.edit_list(workbook_id=workbook_model.id,
                                             worksheet_id=worksheet_model.id,
                                             variable_list=variables,
                                             user=request.user)
                result['workbook_id'] = workbook_model.id
                result['worksheet_id'] = worksheet_model.id
            else:
                result['error'] = "no variables to add"
    else:
        result['error'] = "method not correct"

    if json_response:
        return HttpResponse(json.dumps(result), status=200)
    else:
        redirect_url = reverse('worksheet_display',
                               kwargs={
                                   'workbook_id': workbook_model.id,
                                   'worksheet_id': worksheet_model.id
                               })
        return redirect(redirect_url)