From 0d5fd0ae155d0201962101a61a08ed521dd91e65 Mon Sep 17 00:00:00 2001 From: vitaliypopel Date: Fri, 20 Sep 2024 14:21:26 +0300 Subject: [PATCH] Made string representation of Router --- src/django_routify/_abstraction.py | 16 ++++++++++++++++ src/django_routify/router.py | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/django_routify/_abstraction.py b/src/django_routify/_abstraction.py index 10ed44b..7474f39 100644 --- a/src/django_routify/_abstraction.py +++ b/src/django_routify/_abstraction.py @@ -111,3 +111,19 @@ def route(self, url_path: str, name: str = None): :return: Any ''' ... + + @abstractmethod + def __str__(self) -> str: + ''' + Router string representation + :return: str + ''' + ... + + @abstractmethod + def __repr__(self) -> str: + ''' + Router string representation + :return: str + ''' + ... diff --git a/src/django_routify/router.py b/src/django_routify/router.py index 3647d61..ee04214 100644 --- a/src/django_routify/router.py +++ b/src/django_routify/router.py @@ -94,3 +94,13 @@ def register(view: FUNC_VIEW | View) -> FUNC_VIEW | View: return view return register + + def __str__(self) -> str: + return f'Router(\n' \ + f'\tapp_name:\t"{self.__app_name}"\n' \ + f'\turl_prefix:\t"{self.__prefix}"\n' \ + f'\turls:\t\t{self.__urls}\n' \ + f')' + + def __repr__(self) -> str: + return str(self)