def go_to_subject_visit_schedule_dashboard( self, visit_schedule_name=None, schedule_name=None, visit_code=None, save_only=None, screenshot=True, ): """Add screening, add subject consent, proceed to dashboard and update appointment to in_progress. """ if not save_only: url_name = url_names.get("screening_listboard_url") url = reverse(url_name) self.selenium.get("%s%s" % (self.live_server_url, url)) if screenshot: self.selenium.save_screenshot( os.path.join(settings.BASE_DIR, "screenshots", "new_subject1.png")) element = self.wait_for("Add Subject Screening") element.click() # add a subject screening form subject_screening = self.fill_subject_screening(save_only=save_only) if screenshot: self.selenium.save_screenshot( os.path.join(settings.BASE_DIR, "screenshots", "new_subject2.png")) if not save_only: # add a subject consent for the newly screened subject element = self.wait_for( text= f"subjectconsent_add_{subject_screening.screening_identifier}", by=By.ID, ) element.click() subject_consent = self.fill_subject_consent(subject_screening, save_only=save_only) if screenshot: self.selenium.save_screenshot( os.path.join(settings.BASE_DIR, "screenshots", "new_subject3.png")) subject_identifier = subject_consent.subject_identifier self.complete_previous_visits( subject_identifier=subject_identifier, visit_schedule_name=visit_schedule_name, schedule_name=schedule_name, visit_code=visit_code, ) # set appointment in progress appointment = self.fill_appointment_in_progress(subject_identifier, save_only=save_only) if screenshot: self.selenium.save_screenshot( os.path.join(settings.BASE_DIR, "screenshots", "new_subject4.png")) return appointment
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) url_kwargs = copy(self.url_kwargs) url_kwargs["position"] = 1 url_kwargs["action_name"] = "verify" context.update(verify_box_listboard_url_reversed=reverse( url_names.get(self.verify_box_listboard_url), kwargs=url_kwargs)) return context
def get_context_data(self, **kwargs): context = super().get_context_data() context = self.add_url_to_context(new_key="ae_home_url", existing_key=self.url_name, context=context) context.update(ADVERSE_EVENT_ADMIN_SITE=ADVERSE_EVENT_ADMIN_SITE) context.update(ADVERSE_EVENT_APP_LABEL=ADVERSE_EVENT_APP_LABEL) app_list_url = f"{ADVERSE_EVENT_ADMIN_SITE}:app_list" ae_listboard_url = url_names.get(self.ae_listboard_url) death_report_listboard_url = url_names.get( self.death_report_listboard_url) context.update( app_list_url=app_list_url, ae_listboard_url=ae_listboard_url, death_report_listboard_url=death_report_listboard_url, ) return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update( new_manifest=ManifestModelWrapper(Manifest()), print_manifest_url_name=url_names.get(self.print_manifest_url), SHIPPED=SHIPPED, ) return context
def view_on_site(self, obj): url_name = url_names.get("subject_dashboard_url") try: return reverse( url_name, kwargs=dict(subject_identifier=obj.subject_identifier)) except NoReverseMatch: return super().view_on_site(obj)
def box_href(self): url_name = url_names.get(self.post_action_url) return reverse( url_name, kwargs={ "box_identifier": self.box_identifier, "action_name": "manage" }, )
def url_name(self, value): try: self._url_name = url_names.get(value) except InvalidUrlName: self._url_name = value.split( ":")[1] if self.no_url_namespace else value if not self._url_name: raise NavbarItemError( f"'url_name' not specified. See {repr(self)}")
def __init__(self, url_name=None, url_args=None): try: # assume this is a key in global `url_names` self.url_name = url_names.get(url_name) except InvalidUrlName: if not url_name: raise NextUrlError(f"Invalid url_name. Got {url_name}.") # assume not a key but an explicitly declared `url_name` self.url_name = url_name self.url_args = url_args
def get_action_item_reason(self): try: url = url_names.get("subject_dashboard_url") except InvalidUrlName: visit_href = "#" else: try: visit = get_subject_visit_model_cls().objects.get( subject_identifier=self.registered_subject. subject_identifier, visit_schedule_name=self.visit_schedule. visit_schedule_name, schedule_name=self.visit_schedule.schedule_name, visit_code=self.visit_schedule.visit_code, visit_code_sequence=self.visit_code_sequence, ) except ObjectDoesNotExist: visit_href = "#" except AttributeError as e: if ("visit_schedule_name" not in str(e) and "schedule_name" not in str(e) and "visit_code" not in str(e)): raise visit_href = "#" else: visit_href = reverse( url, kwargs=dict( appointment=str(visit.appointment.id), subject_identifier=self.registered_subject. subject_identifier, ), ) template_name = (f"edc_data_manager/bootstrap{settings.EDC_BOOTSTRAP}/" f"columns/query_text.html") context = dict( form_and_numbers=self.form_and_numbers_to_string(), query_priority=self.query_priority, query_priority_display=self.get_query_priority_display(), query_text=self.query_text, questions=self.data_dictionaries.all().order_by("model", "number"), report_datetime=self.report_datetime, requisition_panel=self.requisition_panel, resolved_datetime=self.resolved_datetime, site_resolved_datetime=self.site_resolved_datetime, site_response_text=self.site_response_text, site_response_status=self.get_site_response_status_display(), status=self.status, dm_user=self.dm_user, title=self.title, visit_schedule=self.visit_schedule, visit_href=visit_href, ) return render_to_string(template_name, context=context)
def get_post_url_on_delete(self, request, obj): try: url_name = url_names.get(self.post_url_on_delete_name) except InvalidUrlName: if self.post_url_on_delete_name: raise url_name = None if url_name: kwargs = self.post_url_on_delete_kwargs(request, obj) post_url_on_delete = reverse(url_name, kwargs=kwargs) return post_url_on_delete return None
def post(self, request, *args, **kwargs): """Process the form "action" then redirect.""" action = slugify(self.request.POST.get("action", "").lower()) if action not in self.valid_form_actions: raise InvalidPostError(f"Invalid form action in POST. Got {action}") else: self.action = action self.process_form_action(request=request) url_name = url_names.get(self.post_action_url) url = reverse(url_name, kwargs=self.url_kwargs) if self.redirect_querystring: url = f"{url}?{urllib.parse.urlencode(self.redirect_querystring)}" return HttpResponseRedirect(url)
def clean(self: forms.ModelForm) -> dict: cleaned_data = super().clean() # type:ignore r = re.compile(UUID_PATTERN) if (self.instance.id and self.instance.subject_identifier and not r.match(self.instance.subject_identifier)): url_name = url_names.get("subject_dashboard_url") url = reverse( url_name, kwargs={ "subject_identifier": self.instance.subject_identifier }, ) msg = mark_safe( "Not allowed. Subject has already consented. " f'See subject <A href="{url}">{self.instance.subject_identifier}</A>' ) raise forms.ValidationError(msg) return cleaned_data
def dashboard(self, obj=None, label=None): try: url = reverse( self.get_subject_dashboard_url_name(), kwargs=self.get_subject_dashboard_url_kwargs(obj), ) except NoReverseMatch: url = reverse(url_names.get("screening_listboard_url"), kwargs={}) context = dict( title=_("Go to screening listboard"), url=f"{url}?q={obj.screening_identifier}", label=label, ) else: context = dict(title=_("Go to subject dashboard"), url=url, label=label) return render_to_string("dashboard_button.html", context=context)
def clean(self): cleaned_data = super().clean() screening_identifier = cleaned_data.get("screening_identifier") if screening_identifier: subject_screening = SubjectScreening.objects.get( screening_identifier=screening_identifier ) if not subject_screening.eligible: url_name = url_names.get("screening_listboard_url") url = reverse( url_name, kwargs={"screening_identifier": self.instance.screening_identifier}, ) msg = mark_safe( "Not allowed. Subject is not eligible. " f'See subject <A href="{url}?q={screening_identifier}">' f"{screening_identifier}</A>" ) raise forms.ValidationError(msg) return cleaned_data
def clean(self): cleaned_data = super().clean() try: obj = RegisteredSubject.objects.get( screening_identifier=self.instance.screening_identifier ) except ObjectDoesNotExist: pass else: url_name = url_names.get("subject_dashboard_url") url = reverse( url_name, kwargs={"subject_identifier": obj.subject_identifier}, ) msg = mark_safe( "Not allowed. Subject has already consented. " f'See subject <A href="{url}">{obj.subject_identifier}</A>' ) raise forms.ValidationError(msg) return cleaned_data
def verify_box_listboard_url_reversed(self): url_kwargs = copy(self.url_kwargs) url_kwargs["position"] = 1 url_kwargs["action_name"] = "verify" return reverse(url_names.get(self.verify_box_listboard_url), kwargs=url_kwargs)
def get_success_url(self): success_url = url_names.get(self.success_url_name) return success_url
def empty_queryset_message(self): href = reverse(url_names.get("pack_listboard_url")) return mark_safe("All specimens have been processed. Continue to " f'<a href="{href}" class="alert-link">packing</a>')
def form_action_url_reversed(self): form_action_url = url_names.get(self.form_action_url) return reverse(form_action_url, kwargs=self.form_action_url_kwargs)
def dashboard_button(model_wrapper): subject_dashboard_url = url_names.get("subject_dashboard_url") return dict( subject_dashboard_url=subject_dashboard_url, subject_identifier=model_wrapper.subject_identifier, )
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context.update({"subject_dashboard_url": url_names.get("subject_dashboard_url")}) if self.kwargs.get("subject_identifier"): context.update({"q": self.kwargs.get("subject_identifier")}) return context
def dashboard_url(self): return url_names.get(self.dashboard_url_name)
def manage_box_listboard_url_reversed(self): url_kwargs = copy(self.url_kwargs) url_kwargs.pop("position") url_kwargs["action_name"] = "manage" return reverse(url_names.get(self.manage_box_listboard_url), kwargs=url_kwargs)
def get_subject_listboard_url_name(self): return url_names.get(self.subject_listboard_url_name)