def get_context_data(self, **kwargs): """ Get context data passes arguments into the template context for the view, in this case, the link to be followed :param kwargs: :return: """ context = super(BaseTemplateView, self).get_context_data(**kwargs) person_id = self.request.GET['person_id'] context['link_url'] = build_url(self.success_url_name, get={'person_id': person_id}) return context
def get_context_data(self, **kwargs): """ Returns the person id and the success url for the template :param kwargs: :return: """ context = super().get_context_data() context['person_id'] = self.request.GET.get('person_id') context['thank_you_url'] = build_url( 'Health-Check-Thank-You', get={'person_id': context['person_id']}) return context
def get_success_url(self): """ Get success url is called whenever a successful form submission occurs, it generates a url based off of success_url and success_parameters as defined in the class definition :return: a full url for the next page """ if self.success_url: # If not none, run the build url util function url = build_url(self.success_url, get=self.get_success_parameters()) else: raise ImproperlyConfigured( "No URL to redirect to. Provide a success_url.") return url
def get(self, request=None): """ Handle get requests made to the SeriousIllnessView page. :return: response; HttpResponse containing information to be rendered. """ response = super().get(request=self.request) person_id = self.request.GET.get('person_id') person_record = AdultInHome.objects.get(pk=person_id) if self.request.GET.get('action') == 'Delete': HealthCheckSerious.objects.filter(pk=self.request.GET.get('illness_id')).delete() if not HealthCheckSerious.objects.filter(person_id=person_record).exists(): return HttpResponseRedirect(build_url('Health-Check-Serious-Start', get={'person_id': person_id})) return response
def get(self, request=None): """ If a get request is performed, this checks to see if a 'delete' hyperlink was followed, and removes the associated record if so :param request: :return: """ response = super().get(request=self.request) person_id = self.request.GET.get('person_id') person_record = AdultInHome.objects.get(pk=person_id) if self.request.GET.get('action') == 'Delete': HealthCheckHospital.objects.filter( pk=self.request.GET.get('illness_id')).delete() if not HealthCheckHospital.objects.filter( person_id=person_record).exists(): return HttpResponseRedirect( build_url('Health-Check-Hospital-Start', get={'person_id': person_id})) return response
def get_context_data(self, **kwargs): context = super().get_context_data() context['person_id'] = self.request.GET.get('person_id') person_object = AdultInHome.objects.get( pk=self.request.GET.get('person_id')) context['declaration_url'] = build_url( 'Health-Check-Declaration', get={'person_id': context['person_id']}) context['current_treatment_set'] = HealthCheckCurrent.objects.filter( person_id=self.request.GET.get('person_id')) context['serious_illness_set'] = HealthCheckSerious.objects.filter( person_id=person_object) context['hospital_admission_set'] = HealthCheckHospital.objects.filter( person_id=person_object) context['current_treatment_bool'] = person_object.current_treatment context['serious_illness_bool'] = person_object.serious_illness context['hospital_admission_bool'] = person_object.hospital_admission return context
def validate_magic_link(request, id): """ Method to verify that the URL matches a magic link :param request: request to display a magic link page :param id: magic link ID :return: HttpResponse, directing to the correct page """ try: person = AdultInHome.objects.get(token=id) if person.validated is not True: # As they've now used their link, set to true person.validated = True person.save() application = Application.objects.get(pk=person.application_id.pk) try: applicant_name = ApplicantName.objects.get(application_id=application.pk) name = ' '.join([applicant_name.first_name, applicant_name.middle_names, applicant_name.last_name]) except: name = 'An applicant' dob_url = build_url('Health-Check-Dob', get={'person_id': person.pk}) context = { 'name': name, 'dob_url': dob_url, } response = render(request, 'other_people_health_check/start.html', context) CustomAuthenticationHandler.create_session(response, person.email) return response else: return render(request, 'bad-link.html') except Exception as ex: exception_data = traceback.format_exc().splitlines() exception_array = [exception_data[-3:]] log.error(exception_array) return render(request, 'bad-link.html')