def load_registry_object(cls, context, handle): """Load contact of the handle and append it into the context.""" try: contact = WHOIS.get_contact_by_handle(handle) birthday = None if contact.identification.value.identification_type == "BIRTHDAY": try: birthday = datetime.datetime.strptime( contact.identification.value.identification_data, '%Y-%m-%d').date() except ValueError: birthday = contact.identification.value.identification_data context[cls._registry_objects_key]["contact"] = { "detail": contact, "birthday": birthday, "label": _("Contact"), } except OBJECT_NOT_FOUND as error: raise WebwhoisError( 'OBJECT_NOT_FOUND', title=_("Contact not found"), message=cls.message_with_handle_in_html( _("No contact matches %s handle."), handle), ) from error except INVALID_HANDLE as error: raise WebwhoisError( **cls.message_invalid_handle(handle)) from error
def _get_object(self, handle: str) -> Any: objects = {} with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['contact'] = WHOIS.get_contact_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['nsset'] = WHOIS.get_nsset_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['keyset'] = WHOIS.get_keyset_by_handle(handle) with suppress(OBJECT_NOT_FOUND, INVALID_HANDLE): objects['registrar'] = WHOIS.get_registrar_by_handle(handle) if not handle.startswith("."): with suppress(OBJECT_NOT_FOUND, UNMANAGED_ZONE, INVALID_LABEL, TOO_MANY_LABELS, idna.IDNAError): idna_handle = idna.encode(handle).decode() try: objects['domain'] = WHOIS.get_domain_by_handle(idna_handle) except OBJECT_DELETE_CANDIDATE: objects['domain'] = None if not objects: raise WebwhoisError( code="OBJECT_NOT_FOUND", title=_("Record not found"), message=self.message_with_handle_in_html( _("%s does not match any record."), handle), object_not_found=True, ) return objects
def _get_object(self, handle: str) -> Any: try: return WHOIS.get_contact_by_handle(handle) except OBJECT_NOT_FOUND as error: raise WebwhoisError( 'OBJECT_NOT_FOUND', title=_("Contact not found"), message=self.message_with_handle_in_html( _("No contact matches %s handle."), handle), ) from error except INVALID_HANDLE as error: raise WebwhoisError( **self.message_invalid_handle(handle)) from error
def load_related_objects(self, context): """Load objects related to the domain and append them into the context.""" descriptions = self._get_status_descriptions( "domain", WHOIS.get_domain_status_descriptions) data = context[self._registry_objects_key][ "domain"] # detail, type, label, href if data is None: # Domain is a delete candidate return registry_object = data["detail"] data["status_descriptions"] = [ descriptions[key] for key in registry_object.statuses ] if STATUS_DELETE_CANDIDATE in registry_object.statuses: return data.update({ "registrant": WHOIS.get_contact_by_handle(registry_object.registrant_handle), "registrar": WHOIS.get_registrar_by_handle(registry_object.registrar_handle), "admins": [ WHOIS.get_contact_by_handle(handle) for handle in registry_object.admin_contact_handles ], }) if registry_object.nsset_handle: data["nsset"] = { "detail": WHOIS.get_nsset_by_handle(registry_object.nsset_handle) } NssetDetailMixin.append_nsset_related(data["nsset"]) if registry_object.keyset_handle: data["keyset"] = { "detail": WHOIS.get_keyset_by_handle(registry_object.keyset_handle) } KeysetDetailMixin.append_keyset_related(data["keyset"])
def append_nsset_related(cls, data): """Load objects related to the nsset and append them into the data context.""" descriptions = cls._get_status_descriptions( "nsset", WHOIS.get_nsset_status_descriptions) registry_object = data["detail"] data.update({ "admins": [ WHOIS.get_contact_by_handle(handle) for handle in registry_object.tech_contact_handles ], "registrar": WHOIS.get_registrar_by_handle(registry_object.registrar_handle), "status_descriptions": [descriptions[key] for key in registry_object.statuses], })