def get_event_object_context(event_content_object, event_type): # Deleted objects don't have a content object any more if not event_content_object: return EventContextSpec(name=None, url=None, object_id=None) event_subject = get_event_subject(event_type) object_id = None object_url = None object_name = None if hasattr(event_content_object, 'id'): object_id = event_content_object.id if hasattr(event_content_object, 'unique_name'): object_name = event_content_object.unique_name if event_subject == event_subjects.PROJECT: object_url = unique_urls.get_project_url(object_name) elif event_subject == event_subjects.EXPERIMENT: object_url = unique_urls.get_experiment_url(object_name) elif event_subject == event_subjects.EXPERIMENT_GROUP: object_url = unique_urls.get_experiment_group_url(object_name) elif event_subject == event_subjects.BUILD_JOB: object_url = unique_urls.get_build_url(object_name) elif event_subject == event_subjects.JOB: object_url = unique_urls.get_job_url(object_name) elif hasattr(event_content_object, 'name'): object_name = event_content_object.name elif hasattr(event_content_object, 'username'): object_name = event_content_object.username object_url = unique_urls.get_user_url(event_content_object.username) return EventContextSpec(name=object_name, url=object_url, object_id=object_id)
def test_get_build_url(self): unique_name = self.build.unique_name self.assertEqual( unique_name, '{}.{}.builds.{}'.format(self.build.project.user.username, self.build.project.name, self.build.id)) self.assertEqual( get_build_url(unique_name=unique_name), '/{}/{}/builds/{}'.format(self.build.project.user.username, self.build.project.name, self.build.id))
def get_event_object_context( event_content_object: Any, event_type: str) -> Optional['EventItemContextSpec']: # Deleted objects don't have a content object any more if not event_content_object: return EventItemContextSpec(name=None, url=None, object_id=None) event_subject = get_event_subject(event_type) object_id = None object_url = None object_name = None if hasattr(event_content_object, 'id'): object_id = event_content_object.id if hasattr(event_content_object, 'unique_name'): object_name = event_content_object.unique_name if event_subject == event_subjects.PROJECT: object_url = unique_urls.get_project_url(object_name) elif event_subject == event_subjects.EXPERIMENT: object_url = unique_urls.get_experiment_url(object_name) elif event_subject == event_subjects.EXPERIMENT_GROUP: object_url = unique_urls.get_experiment_group_url(object_name) elif event_subject == event_subjects.BUILD_JOB: object_url = unique_urls.get_build_url(object_name) elif event_subject == event_subjects.JOB: object_url = unique_urls.get_job_url(object_name) elif hasattr(event_content_object, 'name'): object_name = event_content_object.name elif hasattr(event_content_object, 'username'): object_name = event_content_object.username object_url = unique_urls.get_user_url(event_content_object.username) # Set proper url object_url = absolute_uri('app{}'.format(object_url)) return EventItemContextSpec(name=object_name, url=object_url, object_id=object_id)