コード例 #1
0
ファイル: views.py プロジェクト: Angiotension/ISB-CGC-Webapp
def gene_fav_save(request, gene_fav_id=0):
    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))

    if gene_fav_id :
        try:
            gene_fav_model = GeneFavorite.objects.get(id=gene_fav_id)
            if gene_fav_model.user == request.user :
                gene_fav_model.name = name
                gene_fav_model.save()
                gene_fav_model.edit_list(gene_list, request.user)
                redirect_url = reverse('gene_fav_detail', kwargs={'gene_fav_id':gene_fav_id})
            else :
                messages.error(request, 'You do not have permission to update this gene favorite list')
                redirect_url = reverse('genes')
        except ObjectDoesNotExist:
            messages.error(request, 'The gene list you want does not exist.')
            redirect_url = reverse('genes')
    else :
        GeneFavorite.create(name=name, gene_list=gene_list, user=request.user)
        redirect_url = reverse('genes')

    return redirect(redirect_url)
コード例 #2
0
ファイル: views.py プロジェクト: isb-cgc/ISB-CGC-Webapp
def gene_fav_list(request, workbook_id=0, worksheet_id=0, new_workbook=0):
    template = 'genes/genes_list.html'
    context  = {}

    gene_list = GeneFavorite.get_list(request.user)
    if len(gene_list) == 0 :
        gene_list = None
    context['gene_fav_list']=gene_list

    if workbook_id != 0 :
        try:
            workbook_model = Workbook.objects.get(id=workbook_id)
            context['workbook'] = workbook_model
            worksheet_model = Worksheet.objects.get(id=worksheet_id)
            context['worksheet'] = worksheet_model
            context['base_url']  = settings.BASE_URL

            template = 'genes/genes_select.html'
            if not gene_list :
                context['genes'] = []

        except ObjectDoesNotExist:
            messages.error(request, 'The workbook and worksheet you were referencing does not exist.')
            return redirect('genes')
    elif new_workbook :
        context['new_workbook'] = True
        if gene_list :
            template = 'genes/genes_select.html'
        else :
            template = 'genes/genes_edit.html'
            context['genes'] = []
            context['base_url'] = settings.BASE_URL

    return render(request, template, context)
コード例 #3
0
ファイル: views.py プロジェクト: Kryndex/ISB-CGC-Webapp
def gene_fav_list(request, workbook_id=0, worksheet_id=0, new_workbook=0):
    template = 'genes/genes_list.html'
    context  = {}

    gene_list = GeneFavorite.get_list(request.user)
    if len(gene_list) == 0 :
        gene_list = None
    context['gene_fav_list']=gene_list

    if workbook_id != 0 :
        try:
            workbook_model = Workbook.objects.get(id=workbook_id)
            context['workbook'] = workbook_model
            worksheet_model = Worksheet.objects.get(id=worksheet_id)
            context['worksheet'] = worksheet_model
            context['base_url']  = settings.BASE_URL

            template = 'genes/genes_select.html'
            if not gene_list :
                context['genes'] = []

        except ObjectDoesNotExist:
            messages.error(request, 'The workbook and worksheet you were referencing does not exist.')
            return redirect('genes')
    elif new_workbook :
        context['new_workbook'] = True
        if gene_list :
            template = 'genes/genes_select.html'
        else :
            template = 'genes/genes_edit.html'
            context['genes'] = []
            context['base_url'] = settings.BASE_URL

    return render(request, template, context)
コード例 #4
0
ファイル: views.py プロジェクト: isb-cgc/ISB-CGC-Webapp
def gene_fav_save(request, gene_fav_id=0):
    name = request.POST.get("genes-name")
    gene_list = request.POST.get("genes-list")

    gene_list = [x.strip().upper() for x in gene_list.split(' ')]
    gene_list = list(set(gene_list))

    whitelist = re.compile(WHITELIST_RE, re.UNICODE)
    match = whitelist.search(unicode(name))
    if match:
        # XSS risk, log and fail this cohort save
        match = whitelist.findall(unicode(name))
        logger.error('[ERROR] While saving a gene list, saw a malformed name: ' + name + ', characters: ' + match.__str__())
        messages.error(request, "Your gene list's name contains invalid characters; please choose another name.")
        redirect_url = reverse('genes') if not gene_fav_id else reverse('gene_fav_detail', kwargs={'gene_fav_id':gene_fav_id})
        return redirect(redirect_url)

    if gene_fav_id :
        try:
            gene_fav_model = GeneFavorite.objects.get(id=gene_fav_id)
            if gene_fav_model.user == request.user :
                gene_fav_model.name = name
                gene_fav_model.save()
                gene_fav_model.edit_list(gene_list, request.user)
                redirect_url = reverse('gene_fav_detail', kwargs={'gene_fav_id':gene_fav_id})
            else :
                messages.error(request, 'You do not have permission to update this gene favorite list')
                redirect_url = reverse('genes')
        except ObjectDoesNotExist:
            messages.error(request, 'The gene list you want does not exist.')
            redirect_url = reverse('genes')
    else :
        GeneFavorite.create(name=name, gene_list=gene_list, user=request.user)
        redirect_url = reverse('genes')

    return redirect(redirect_url)
コード例 #5
0
ファイル: views.py プロジェクト: Kryndex/ISB-CGC-Webapp
def gene_fav_save(request, gene_fav_id=0):
    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))

    whitelist = re.compile(WHITELIST_RE, re.UNICODE)
    match = whitelist.search(unicode(name))
    if match:
        # XSS risk, log and fail this cohort save
        match = whitelist.findall(unicode(name))
        logger.error('[ERROR] While saving a gene list, saw a malformed name: ' + name + ', characters: ' + match.__str__())
        messages.error(request, "Your gene list's name contains invalid characters; please choose another name.")
        redirect_url = reverse('genes') if not gene_fav_id else reverse('gene_fav_detail', kwargs={'gene_fav_id':gene_fav_id})
        return redirect(redirect_url)

    if gene_fav_id :
        try:
            gene_fav_model = GeneFavorite.objects.get(id=gene_fav_id)
            if gene_fav_model.user == request.user :
                gene_fav_model.name = name
                gene_fav_model.save()
                gene_fav_model.edit_list(gene_list, request.user)
                redirect_url = reverse('gene_fav_detail', kwargs={'gene_fav_id':gene_fav_id})
            else :
                messages.error(request, 'You do not have permission to update this gene favorite list')
                redirect_url = reverse('genes')
        except ObjectDoesNotExist:
            messages.error(request, 'The gene list you want does not exist.')
            redirect_url = reverse('genes')
    else :
        GeneFavorite.create(name=name, gene_list=gene_list, user=request.user)
        redirect_url = reverse('genes')

    return redirect(redirect_url)