def image_category(request, category): tuples = [] f = open(settings.BASE_DIR_IMAGE_CATEGORIES + '/' + category, 'r') rows = f.readlines() for row in rows: experiment_plate_id, tile = row.split('_') tile = tile.split('.')[0] well = tile_to_well(tile) experiment = get_object_or_404(Experiment, plate=experiment_plate_id, well=well) tuples.append((experiment, tile)) f.close() display_tuples = get_paginated(request, tuples, IMAGES_PER_PAGE) context = { 'category': category, 'tuples': tuples, 'display_tuples': display_tuples, } return render(request, 'image_category.html', context)
def change_experiment_plates(request, pks): """ Render the page to update bulk experiment plates. When bulk updating experiment plates, the corresponding experiment wells might change too. """ split_pks = pks.split(',') experiment_plates = ExperimentPlate.objects.filter(pk__in=split_pks) display_plates = get_paginated(request, experiment_plates, EXPERIMENT_PLATES_PER_PAGE) if request.POST: form = ChangeExperimentPlatesForm(request.POST) if form.is_valid(): for plate in experiment_plates: process_ChangeExperimentPlatesForm_data(plate, form.cleaned_data) return redirect('change_experiment_plates_url', pks) else: form = ChangeExperimentPlatesForm() context = { 'experiment_plates': experiment_plates, 'display_plates': display_plates, 'form': form, } return render(request, 'change_experiment_plates.html', context)
def change_experiment_plates(request, pks): """ Render the page to update bulk experiment plates. When bulk updating experiment plates, the corresponding experiment wells might change too. """ split_pks = pks.split(',') experiment_plates = ExperimentPlate.objects.filter(pk__in=split_pks) display_plates = get_paginated(request, experiment_plates, EXPERIMENT_PLATES_PER_PAGE) if request.POST: form = ChangeExperimentPlatesForm(request.POST) if form.is_valid(): for plate in experiment_plates: process_ChangeExperimentPlatesForm_data( plate, form.cleaned_data) return redirect('change_experiment_plates_url', pks) else: form = ChangeExperimentPlatesForm() context = { 'experiment_plates': experiment_plates, 'display_plates': display_plates, 'form': form, } return render(request, 'change_experiment_plates.html', context)
def library_plates(request): """Render the page listing all library plates.""" screen_stage = request.GET.get('screen_stage') library_plates = LibraryPlate.get_screening_plates( screen_stage=screen_stage) display_plates = get_paginated(request, library_plates, PLATES_PER_PAGE) context = { 'library_plates': library_plates, 'display_plates': display_plates, } return render(request, 'library_plates.html', context)
def get_context_data(self, **kwargs): context_ = super().get_context_data(**kwargs) empe_filter, empr_filter = self.request.GET.get( 'empe_srch'), self.request.GET.get('empr_srch') vac_filters = (self.request.GET.get('vac_srch'), self.request.GET.get('vac_pos')) employees = Employee.objects.order_by('user__created', 'name') if empe_filter: employees = employees.filter(name__icontains=empe_filter) employers = Employer.objects.order_by('user__created', 'name') if empr_filter: employers = employers.filter(name__icontains=empr_filter) vacancies = Vacancy.objects.filter(is_active=True).order_by( 'employer__user__created', 'title') if any(vac_filters): if vac_filters[0]: vacancies = vacancies.filter(title__icontains=vac_filters[0]) if vac_filters[1] and vac_filters[1] != '*': vacancies = vacancies.filter(position_id__exact=vac_filters[1]) context_['employees'] = get_paginated(self.request, employees, page_query='page_empe') context_['employers'] = get_paginated(self.request, employers, page_query='page_empr') context_['vacancies'] = get_paginated(self.request, vacancies, page_query='page_vac') context_['positions'] = Position.objects.all() context_.update({'vac_filterss': vac_filters}) return context_
def clones(request): """Render the page listing all RNAi clones.""" if "clone_query" in request.GET: form = CloneSearchForm(request.GET) if form.is_valid(): data = form.cleaned_data clones = data["clone_query"] else: clones = [] else: form = CloneSearchForm() clones = Clone.objects.all() display_clones = get_paginated(request, clones, CLONES_PER_PAGE) context = {"clones": clones, "display_clones": display_clones, "form": form} return render(request, "clones.html", context)
def find_experiment_wells(request): """Render the page to find experiment wells based on filters.""" experiments = None display_experiments = None if request.GET: form = FilterExperimentWellsForm(request.GET) if form.is_valid(): experiments = form.process() display_experiments = get_paginated(request, experiments, EXPERIMENT_WELLS_PER_PAGE) else: form = FilterExperimentWellsForm() context = { 'form': form, 'experiments': experiments, 'display_experiments': display_experiments, } return render(request, 'find_experiment_wells.html', context)
def clones(request): """Render the page listing all RNAi clones.""" if 'clone_query' in request.GET: form = CloneSearchForm(request.GET) if form.is_valid(): data = form.cleaned_data clones = data['clone_query'] else: clones = [] else: form = CloneSearchForm() clones = Clone.objects.all() display_clones = get_paginated(request, clones, CLONES_PER_PAGE) context = { 'clones': clones, 'display_clones': display_clones, 'form': form, } return render(request, 'clones.html', context)
def score_experiment_wells(request): """ Render the page to score experiment wells. TODO: create base class to capture commonality between this and find_experiment_wells TODO: better handle case of invalid filter_form """ post_experiments = [] redo_post = False # If there was a previous submit if request.POST: exp = '^[0-9]+_[A-H][0-1][0-9]-.*_scores?$' pattern = re.compile(exp) pks = [k.split('-')[0] for k in request.POST if pattern.match(k)] # Check if all POSTs are valid for experiment in Experiment.objects.filter(pk__in=pks): f = get_score_form(request.GET.get('score_form_key')) experiment.score_form = f(request.POST, user=request.user, prefix=experiment.pk) post_experiments.append(experiment) if not experiment.score_form.is_valid(): redo_post = True # If all POSTs valid, process and redirect if not redo_post: for experiment in post_experiments: # This actually submits the scores to the database experiment.score_form.process() url = build_url('score_experiment_wells_url', get=request.GET) return HttpResponseRedirect(url) # Bind filter form with GET params if request.GET: filter_form = FilterExperimentWellsToScoreForm( request.GET, user=request.user) else: filter_form = FilterExperimentWellsToScoreForm() if (not request.GET or not filter_form.is_valid()): return render(request, 'score_experiment_wells_setup.html', { 'filter_form': filter_form }) # At this point, filter form is valid and cleaned filter_data = filter_form.process() experiments = filter_data['experiments'] unscored_by_user = filter_data['unscored_by_user'] if redo_post: # These already have attached and bound score forms display_experiments = post_experiments else: per_page = filter_data['images_per_page'] if unscored_by_user: display_experiments = experiments[:per_page] else: display_experiments = get_paginated(request, experiments, per_page) # Attach a score form to each experiment score_form = filter_data['score_form'] for experiment in display_experiments: experiment.score_form = score_form(prefix=experiment.pk) context = { 'experiments': experiments, 'display_experiments': display_experiments, 'unscored_by_user': filter_data['unscored_by_user'], 'do_not_display': ['images_per_page', 'score_form_key', 'is_junk'] } return render(request, 'score_experiment_wells.html', context)
def score_experiment_wells(request): """ Render the page to score experiment wells. TODO: create base class to capture commonality between this and find_experiment_wells TODO: better handle case of invalid filter_form """ post_experiments = [] # list that stores all submitted scores per exp redo_post = False # If there was a previous submit # post is submitting the database # This is passing through all the same get paramters (the filtering params) # keeping him on the same page # GET and POST both happen every time if request.POST: exp = '^[0-9]+_[A-H][0-1][0-9]-.*_scores?$' pattern = re.compile(exp) pks = [k.split('-')[0] for k in request.POST if pattern.match(k)] # Check if all POSTs are valid for experiment in Experiment.objects.filter(pk__in=pks): # gets the form from either enhancer or Suppressor f = get_score_form(request.GET.get('score_form_key')) experiment.score_form = f(request.POST, user=request.user, prefix=experiment.pk) post_experiments.append(experiment) if not experiment.score_form.is_valid(): redo_post = True # If all POSTs valid, process and redirect # this saves scores and brings back to the same page and # resets the POST data so that there's not a double submit if not redo_post: for experiment in post_experiments: # This actually submits the scores to the database experiment.score_form.process() url = build_url('score_experiment_wells_url', get=request.GET) return HttpResponseRedirect(url) # Bind filter form with GET params # If there's stuff to limit on # .GET parameters is taken from the input form if request.GET: filter_form = FilterExperimentWellsToScoreForm(request.GET, user=request.user) else: filter_form = FilterExperimentWellsToScoreForm() if (not request.GET or not filter_form.is_valid()): return render(request, 'score_experiment_wells_setup.html', {'filter_form': filter_form}) # At this point, filter form is valid and cleaned filter_data = filter_form.process() experiments = filter_data['experiments'] unscored_by_user = filter_data['unscored_by_user'] if redo_post: # These already have attached and bound score forms display_experiments = post_experiments else: per_page = filter_data['images_per_page'] if unscored_by_user: display_experiments = experiments[:per_page] else: display_experiments = get_paginated(request, experiments, per_page) # Attach a score form to each experiment # the prefix attaches the experiment's pk to each form field which makes it queryable # when posting # This sets the class attribute 'score_form' to the secondary enhacer score forms # which is then called and rendered in the template score_form = filter_data['score_form'] for experiment in display_experiments: experiment.score_form = score_form(prefix=experiment.pk) context = { 'experiments': experiments, 'display_experiments': display_experiments, 'unscored_by_user': filter_data['unscored_by_user'], # 'do_not_display': ['images_per_page', 'score_form_key', 'is_junk'] 'do_not_display': ['images_per_page', 'score_form_key'] } return render(request, 'score_experiment_wells.html', context)