def libs(request): user_libs_qs = user_accessible_libs(request.user) # modalFormData = Library.getModalFormData() modalFormData = build_modal_form_data(Library) libs_filter = LibraryFilter( data=request.GET, request=request, queryset=user_libs_qs, filter_id='lib_filter', form_id='lib_filter_form' ) table = ModalEditLibrariesTable( data=libs_filter.qs.order_by('-modified_date'), order_by="id", data_target=modalFormData['edit']['modal_id'], a_class="btn btn-primary " + modalFormData['edit']['url_class'], table_id='lib_table', form_id='lib_table_form', form_action=reverse('modify_libs'), view_name='lib_edit') RequestConfig(request, paginate={'per_page': 5}).configure(table) buttons = [ {'id': 'delete_selected', 'text': 'Delete Selected','class': 'btn-danger btn-confirm'}, # modalFormData['new']['button'] {'id': 'new_lib_btn','text': 'New Library','class': 'btn-primary ' + 'lib_new_url', 'href':reverse('lib_new', kwargs={'form_class':"lib_new_form"})}, ] modals = [ modalFormData['edit'], modalFormData['new'], ] context = build_filter_table_context(libs_filter, table, modals, buttons) return render(request,'experiment/lib_templates/libraries.html', context)
def plates(request, pk_exp=None): modalFormData = build_modal_form_data(Plate) plateFilter = PlateFilter( data=request.GET, request=request, queryset=user_editable_plates(request.user), filter_id='proj_filter', form_id='proj_filter_form', ) table = ModalEditPlatesTable( data=plateFilter.qs.order_by('-modified_date'), data_target=modalFormData['edit']['modal_id'], a_class="btn btn-primary " + modalFormData['edit']['url_class'], table_id='plate_table', form_id='plate_table_form', form_action=reverse('modify_plates'), view_name='plate_edit', ) RequestConfig(request, paginate={'per_page': 20}).configure(table) buttons = [] modals = [ modalFormData['edit'], ] context = build_filter_table_context(plateFilter, table, modals, buttons) return render(request, 'experiment/proj_templates/projects.html', context)
def plate(request, pk_plate, pk_proj=None): from my_utils.constants import idx_to_letters_map, letters_to_idx_map p = get_object_or_404(Plate, pk=pk_plate) if p: plateForm = PlateForm(instance=p) ### Handle PlateForm() if request.method == "POST": if request.is_ajax(): pass else: plateForm = PlateForm(request.POST, instance=p) if plateForm.is_valid(): update_instance(p, plateForm.cleaned_data, plateForm.cleaned_data.keys()) messages.success(request, 'Plate ' + p.name + ' updated.') return redirect('plate', pk_plate=p.pk) else: wells_qs = p.wells.select_related( 'compound', 'soak').prefetch_related('subwells').order_by('name') wells = [w for w in wells_qs] well_form_map = {} subwells = [] for w in wells: subwells.extend([s for s in w.subwells.all()]) well_form_map[w.id] = WellPriorityForm(instance=w) reshaped_wells = reshape(wells, (p.numRows, p.numCols)) soaks_qs = Soak.objects.select_related( 'dest', 'src').filter(dest__in=subwells) soaks = [s for s in soaks_qs] subwellToSoakMap = dict([(s.dest.name, s) for s in soaks]) context = {} from lib.tables import CompoundsTable, ModalEditCompoundsTable from lib.filters import CompoundFilter compoundsFilter = CompoundFilter(request.GET, queryset=p.compounds.all(), filter_id='compounds_filter', form_id='compounds_filter_form') compoundsTable = ModalEditCompoundsTable( data=compoundsFilter.qs, table_id='compounds_table', ) RequestConfig(request, paginate={ 'per_page': 20 }).configure(compoundsTable) context = build_filter_table_context(compoundsFilter, compoundsTable, [], []) context.update({ 'wellMatrix': reshaped_wells, 'subwellToSoakMap': subwellToSoakMap, 'plate': p, 'idx_to_letters_map': idx_to_letters_map, 'canEdit': True, 'well_form_map': well_form_map, 'plateForm': plateForm, }) return render(request, 'experiment/exp_templates/plate.html', context)
def experiments(request, qs=None): exp_qs = user_editable_experiments(request.user) if qs: exp_qs = qs modalFormData = build_modal_form_data(Experiment) expFilter = ExperimentFilter( data=request.GET, request=request, queryset=exp_qs, filter_id='exp_filter', form_id='exp_filter_form', ) table = ModalEditExperimentsTable( data=expFilter.qs.order_by('-modified_date'), data_target=modalFormData['edit']['modal_id'], a_class="btn btn-primary " + modalFormData['edit']['url_class'], table_id='exp_table', form_id='exp_table_form', form_action=reverse('modify_exps'), view_name='exp_edit', ) RequestConfig(request, paginate={'per_page': 5}).configure(table) buttons = [ { 'id': 'delete_selected', 'text': 'Delete Selected', 'class': 'btn-danger btn-confirm' }, { 'id': 'new_exp_btn', 'text': 'New Experiment', 'class': 'btn-primary ' + 'exp_new_url', 'href': reverse('exp_new') }, ] modals = [ modalFormData['new'], modalFormData['edit'], ] context = build_filter_table_context(expFilter, table, modals, buttons) return render(request, 'experiment/exp_templates/experiments.html', context) #,{'experiments':})
def lib_compounds(request, pk_lib): lib_qs = Library.objects.filter(id=pk_lib) lib = lib_qs.first() expsTable = ExperimentsTable( data=lib.experiments.all(), exclude=['project', 'library', 'protein', 'owner', 'checked'], ) compounds = lib.compounds.filter() compounds_filter = CompoundFilter(data=request.GET, queryset=compounds, filter_id='compounds_filter', form_id='compounds_filter_form') table = ModalEditCompoundsTable( exclude=[ 'id', 'chemicalName', 'chemicalFormula', 'smiles', 'zincURL', ], data=compounds_filter.qs, table_id='compounds_table', form_id='compounds_table_form', form_action=reverse('modify_lib_compounds', kwargs={'pk_lib': pk_lib}), ) RequestConfig(request, paginate={'per_page': 10}).configure(table) url_class = "compounds_edit_url" modal_id = "compounds_edit_modal" exc = list(ModalEditLibrariesTable.Meta.fields) libTable = ModalEditLibrariesTable( data=lib_qs, data_target=modal_id, a_class="btn btn-primary " + url_class, exclude=exc, attrs={'th': { 'id': 'lib_table_header' }}) buttons = [ { 'id': 'remove_compounds', 'text': 'Remove Selected', 'class': 'btn-danger btn-confirm', 'msg': 'Remove selected compounds from library?' }, { 'id': 'deactivate_compounds', 'text': 'Deactivate Selected', 'class': 'btn-secondary btn-confirm' }, { 'id': 'activate_compounds', 'text': 'Activate Selected', 'class': 'btn-secondary btn-confirm' }, ] modals = [ { 'url_class': url_class, 'modal_id': modal_id, 'form_class': "compounds_edit_form" }, { 'url_class': 'update_compounds_from_file_url', 'modal_id': 'update_compounds_from_file_modal', 'form_class': "update_compounds_from_file_url_form" }, ] context = build_filter_table_context(compounds_filter, table, modals, buttons) context.update({ 'expsTable': expsTable, 'lib': lib, 'libTable': libTable, }) return render(request, 'experiment/lib_templates/library_compounds.html', context)