todonotifier.models
This module defines the standard models used in the application.
Standard format for todo item is as follows. todo has to be in capital letters Format: TODO [YYYY-MM-DD] @user_name inline_msg Date format must be YYYY-MM-DD Only one todo item is allowed per line. If more than one is in one line, the first one is considered as todo item and the rest are considered as message. No. of spaces between todo, date, user, message is NOT important.
1"""This module defines the standard models used in the application. 2 3Standard format for todo item is as follows. 4todo has to be in capital letters 5Format: TODO [YYYY-MM-DD] @user_name inline_msg 6Date format must be YYYY-MM-DD 7Only one todo item is allowed per line. If more than one is in one line, the first one 8is considered as todo item and the rest are considered as message. 9No. of spaces between todo, date, user, message is NOT important. 10""" 11 12from datetime import datetime 13from typing import TypeVar 14 15from dateutil import parser 16 17from todonotifier.constants import DEFAULT_COMPLETION_DATE 18 19T = TypeVar("T") 20 21 22class USER: 23 def __init__(self, user_name: str) -> None: 24 """Initializer for class `USER` 25 26 Args: 27 user_name (str): User name 28 """ 29 self._user_name = user_name 30 31 @property 32 def user_name(self) -> str: 33 """Getter for `user_name` 34 35 Returns: 36 str: Returns username 37 """ 38 return self._user_name 39 40 def __str__(self) -> str: 41 """Defines str representation of `USER` class object 42 43 Returns: 44 str: Returns string representation of the class object 45 """ 46 return f"User: {repr(self)} user_name: {self.user_name}" 47 48 49class POSITION: 50 def __init__(self, line_no: int) -> None: 51 """Initializer for position of a text in file 52 53 Args: 54 line_no (int): Shows line_no no. of the text 55 """ 56 self._line_no = line_no 57 58 @property 59 def line_no(self) -> int: 60 """Getter for `line_no` 61 62 Returns: 63 int: Integer representing the line_no no. in respective module 64 """ 65 return self._line_no 66 67 def __str__(self) -> str: 68 """Defines str representation of `POSITION` class object 69 70 Returns: 71 str: Returns string representation of the class object 72 """ 73 return f"Position: {repr(self)} line_no: {self.line_no}" 74 75 76class TODO: 77 def __init__( 78 self, 79 msg: str, 80 user: USER, 81 completion_date_str: str, 82 module: str, 83 position: POSITION, 84 ) -> None: 85 """Initializer for `todo.upper()` class 86 87 Args: 88 msg (str): Inline message in the todo 89 user (USER): User in the todo item 90 completion_date_str (str): Date by which the respective `todo` item is supposed to be completed 91 module (str): Module in which todo item is present 92 position (POSITION): Represents the position of the respective todo 93 94 Raises: 95 InvalidDateFormatException: Raised if the `completion_date_str` is not valid or doesn't conform to expected format of "YYYY-MM-DD" 96 """ 97 self._msg = msg 98 self._user = user 99 try: 100 self._completion_date = parser.parse(completion_date_str).date() 101 except Exception: 102 self._completion_date = parser.parse(DEFAULT_COMPLETION_DATE).date() 103 self._module = module 104 self._position = position 105 106 @property 107 def msg(self) -> str: 108 """Getter for `msg` 109 110 Returns: 111 str: Message of todo item 112 """ 113 return self._msg 114 115 @property 116 def user(self) -> USER: 117 """Getter for `user` 118 119 Returns: 120 USER: user object of the respective todo item 121 """ 122 return self._user 123 124 @property 125 def completion_date(self) -> datetime.date: 126 """Getter for `datetime` representation of `completion_date_str` 127 128 Returns: 129 datetime: datetime object representing `completion_date_str` 130 """ 131 return self._completion_date 132 133 @property 134 def module(self) -> str: 135 """Getter for `module` 136 137 Returns: 138 str: Module name/address of the respective todo item 139 """ 140 return self._module 141 142 @property 143 def position(self) -> POSITION: 144 """Getter for `position` 145 146 Returns: 147 POSITION: Position of respective todo item in code 148 """ 149 return self._position 150 151 def __str__(self) -> str: 152 """str representation of `todo` object 153 154 Returns: 155 str: String representation of the respective todo object 156 """ 157 return f"""TODO: {repr(self)} msg: {self.msg} user: {str(self.user)} completion date: {self.completion_date} module: {self.module} position: {str(self.position)}""" # noqa
class
USER:
23class USER: 24 def __init__(self, user_name: str) -> None: 25 """Initializer for class `USER` 26 27 Args: 28 user_name (str): User name 29 """ 30 self._user_name = user_name 31 32 @property 33 def user_name(self) -> str: 34 """Getter for `user_name` 35 36 Returns: 37 str: Returns username 38 """ 39 return self._user_name 40 41 def __str__(self) -> str: 42 """Defines str representation of `USER` class object 43 44 Returns: 45 str: Returns string representation of the class object 46 """ 47 return f"User: {repr(self)} user_name: {self.user_name}"
class
POSITION:
50class POSITION: 51 def __init__(self, line_no: int) -> None: 52 """Initializer for position of a text in file 53 54 Args: 55 line_no (int): Shows line_no no. of the text 56 """ 57 self._line_no = line_no 58 59 @property 60 def line_no(self) -> int: 61 """Getter for `line_no` 62 63 Returns: 64 int: Integer representing the line_no no. in respective module 65 """ 66 return self._line_no 67 68 def __str__(self) -> str: 69 """Defines str representation of `POSITION` class object 70 71 Returns: 72 str: Returns string representation of the class object 73 """ 74 return f"Position: {repr(self)} line_no: {self.line_no}"
POSITION(line_no: int)
51 def __init__(self, line_no: int) -> None: 52 """Initializer for position of a text in file 53 54 Args: 55 line_no (int): Shows line_no no. of the text 56 """ 57 self._line_no = line_no
Initializer for position of a text in file
Arguments:
- line_no (int): Shows line_no no. of the text
class
TODO:
77class TODO: 78 def __init__( 79 self, 80 msg: str, 81 user: USER, 82 completion_date_str: str, 83 module: str, 84 position: POSITION, 85 ) -> None: 86 """Initializer for `todo.upper()` class 87 88 Args: 89 msg (str): Inline message in the todo 90 user (USER): User in the todo item 91 completion_date_str (str): Date by which the respective `todo` item is supposed to be completed 92 module (str): Module in which todo item is present 93 position (POSITION): Represents the position of the respective todo 94 95 Raises: 96 InvalidDateFormatException: Raised if the `completion_date_str` is not valid or doesn't conform to expected format of "YYYY-MM-DD" 97 """ 98 self._msg = msg 99 self._user = user 100 try: 101 self._completion_date = parser.parse(completion_date_str).date() 102 except Exception: 103 self._completion_date = parser.parse(DEFAULT_COMPLETION_DATE).date() 104 self._module = module 105 self._position = position 106 107 @property 108 def msg(self) -> str: 109 """Getter for `msg` 110 111 Returns: 112 str: Message of todo item 113 """ 114 return self._msg 115 116 @property 117 def user(self) -> USER: 118 """Getter for `user` 119 120 Returns: 121 USER: user object of the respective todo item 122 """ 123 return self._user 124 125 @property 126 def completion_date(self) -> datetime.date: 127 """Getter for `datetime` representation of `completion_date_str` 128 129 Returns: 130 datetime: datetime object representing `completion_date_str` 131 """ 132 return self._completion_date 133 134 @property 135 def module(self) -> str: 136 """Getter for `module` 137 138 Returns: 139 str: Module name/address of the respective todo item 140 """ 141 return self._module 142 143 @property 144 def position(self) -> POSITION: 145 """Getter for `position` 146 147 Returns: 148 POSITION: Position of respective todo item in code 149 """ 150 return self._position 151 152 def __str__(self) -> str: 153 """str representation of `todo` object 154 155 Returns: 156 str: String representation of the respective todo object 157 """ 158 return f"""TODO: {repr(self)} msg: {self.msg} user: {str(self.user)} completion date: {self.completion_date} module: {self.module} position: {str(self.position)}""" # noqa
TODO( msg: str, user: todonotifier.models.USER, completion_date_str: str, module: str, position: todonotifier.models.POSITION)
78 def __init__( 79 self, 80 msg: str, 81 user: USER, 82 completion_date_str: str, 83 module: str, 84 position: POSITION, 85 ) -> None: 86 """Initializer for `todo.upper()` class 87 88 Args: 89 msg (str): Inline message in the todo 90 user (USER): User in the todo item 91 completion_date_str (str): Date by which the respective `todo` item is supposed to be completed 92 module (str): Module in which todo item is present 93 position (POSITION): Represents the position of the respective todo 94 95 Raises: 96 InvalidDateFormatException: Raised if the `completion_date_str` is not valid or doesn't conform to expected format of "YYYY-MM-DD" 97 """ 98 self._msg = msg 99 self._user = user 100 try: 101 self._completion_date = parser.parse(completion_date_str).date() 102 except Exception: 103 self._completion_date = parser.parse(DEFAULT_COMPLETION_DATE).date() 104 self._module = module 105 self._position = position
Initializer for todo.upper()
class
Arguments:
- msg (str): Inline message in the todo
- user (USER): User in the todo item
- completion_date_str (str): Date by which the respective
todo
item is supposed to be completed - module (str): Module in which todo item is present
- position (POSITION): Represents the position of the respective todo
Raises:
- InvalidDateFormatException: Raised if the
completion_date_str
is not valid or doesn't conform to expected format of "YYYY-MM-DD"
user: todonotifier.models.USER
completion_date: <method 'date' of 'datetime.datetime' objects>
Getter for datetime
representation of completion_date_str
Returns:
datetime: datetime object representing
completion_date_str
position: todonotifier.models.POSITION