def add_family_group_submit(request, project_id): project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): return HttpResponse('unauthorized') error = None form = AddFamilyGroupForm(project, request.POST) if form.is_valid(): # todo: move to sample_anagement family_group = FamilyGroup.objects.create( project=project, slug=form.cleaned_data['family_group_slug'], name=form.cleaned_data['name'], description=form.cleaned_data['description'], ) for family in form.cleaned_data['families']: family_group.families.add(family) else: error = server_utils.form_error_string(form) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return server_utils.JSONResponse({ 'is_error': False, 'new_url': reverse('family_group_home', args=(project.project_id, family_group.slug)) })
def add_family_group(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied form = AddFamilyGroupForm(project, request.POST) if form.is_valid(): # todo: move to sample_anagement family_group = FamilyGroup.objects.create( project=project, slug=form.cleaned_data['family_group_slug'], name=form.cleaned_data['name'], description=form.cleaned_data['description'], ) for family in form.cleaned_data['families']: family_group.families.add(family) else: error = server_utils.form_error_string(form) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return redirect('family_group_home', project.project_id, family_group.slug)
def add_phenotype(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied form = AddPhenotypeForm(project, request.POST) if form.is_valid(): phenotype = ProjectPhenotype( project=project, slug=form.cleaned_data['slug'], name=form.cleaned_data['name'], category=form.cleaned_data['category'], datatype=form.cleaned_data['datatype'], ) phenotype.save() return redirect('edit_individuals', project.project_id) else: error = server_utils.form_error_string(form) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return redirect('edit_individuals', project.project_id)
def delete_individuals(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied indiv_id_list = request.POST.get('to_delete').split('|') to_delete = [] for indiv_id in indiv_id_list: i = Individual.objects.get(project=project, indiv_id=indiv_id) to_delete.append(i) for individual in to_delete: individual.delete() try: settings.EVENTS_COLLECTION.insert({ 'event_type': 'delete_individuals', 'date': timezone.now(), 'project_id': project_id, 'individuals': ", ".join([i.indiv_id for i in to_delete]), 'username': request.user.username, 'email': request.user.email, }) except Exception as e: logging.error("Error while logging add_variant_tag event: %s" % e) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return redirect('edit_individuals', project.project_id)
def save_one_individual(request, project_id): error = None project = Project.objects.get(project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied indiv_json = json.loads(request.POST.get('individual_json')) save_individual_from_json_dict(project, indiv_json) if not error: ret = { 'is_error': False, } return server_utils.JSONResponse(ret) else: ret = {'is_error': True, 'error': error} return server_utils.JSONResponse(ret)
def add_individuals(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied indiv_id_list = json.loads(request.POST.get('indiv_id_list'), '[]') for indiv_id in indiv_id_list: if Individual.objects.filter(project=project, indiv_id=indiv_id).exists(): error = "Indiv ID %s already exists" % indiv_id if not error: for indiv_id in indiv_id_list: Individual.objects.create(project=project, indiv_id=indiv_id) if True: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return server_utils.JSONResponse({'is_error': False})
def save_all_individuals(request, project_id): error = None # todo: validation project = Project.objects.get(project_id=project_id) if not project.can_admin(request.user): return HttpResponse('unauthorized') individuals_json = json.loads(request.POST.get('individuals_json')) for indiv_obj in individuals_json: save_individual_from_json_dict(project, indiv_obj) if not error: ret = { 'is_error': False, } return server_utils.JSONResponse(ret) else: ret = {'is_error': True, 'error': error} return server_utils.JSONResponse(ret)
def add_family_group_submit(request, project_id): project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied error = None form = AddFamilyGroupForm(project, request.POST) if form.is_valid(): # todo: move to sample_anagement family_group, created = get_or_create_xbrowse_model( FamilyGroup, project=project, slug=form.cleaned_data['family_group_slug'], ) update_xbrowse_model(family_group, name=form.cleaned_data['name'], description=form.cleaned_data['description']) seqr_analysis_group = find_matching_seqr_model(family_group) for family in form.cleaned_data['families']: family_group.families.add(family) seqr_analysis_group.families.add(find_matching_seqr_model(family)) else: error = server_utils.form_error_string(form) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return server_utils.JSONResponse({ 'is_error': False, 'new_url': reverse('family_group_home', args=(project.project_id, family_group.slug)) })
def delete_individuals(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied indiv_id_list = request.POST.get('to_delete').split('|') to_delete = [] for indiv_id in indiv_id_list: for i in Individual.objects.filter(project=project, indiv_id=indiv_id): to_delete.append(i) family_ids = set() for individual in to_delete: family_ids.add(individual.family.family_id) delete_xbrowse_model(individual) for family_id in family_ids: if len(Individual.objects.filter(family__family_id=family_id)) == 0: families = Family.objects.filter(family_id=family_id) if families: delete_xbrowse_model(families[0]) try: settings.EVENTS_COLLECTION.insert({ 'event_type': 'delete_individuals', 'date': timezone.now(), 'project_id': project_id, 'individuals': ", ".join([i.indiv_id for i in to_delete]), 'username': request.user.username, 'email': request.user.email, }) except Exception as e: logging.error("Error while logging add_variant_tag event: %s" % e) if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return redirect('edit_individuals', project.project_id)
def delete_individuals(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied indiv_id_list = request.POST.get('to_delete').split('|') to_delete = [] for indiv_id in indiv_id_list: i = Individual.objects.get(project=project, indiv_id=indiv_id) to_delete.append(i) for individual in to_delete: individual.delete() if error: return server_utils.JSONResponse({'is_error': True, 'error': error}) else: return redirect('edit_individuals', project.project_id)
def update_project_from_fam(request, project_id): error = None project = get_object_or_404(Project, project_id=project_id) if not project.can_admin(request.user): raise PermissionDenied form = FAMFileForm(request.POST, request.FILES) if form.is_valid(): sample_management.update_project_from_individuals(project, form.cleaned_data['individuals']) return redirect('edit_individuals', project.project_id) else: error = "File error" if error: ret = {'is_error': True, 'error': error} else: ret = {'is_error': False} return server_utils.JSONResponse(ret)