Skip to content

Commit 78812c9

Browse files
committed
refactor: fix: project and contract status
* Fixed bug - getting active status * Removed unnecessary call to get_filter_button_label
1 parent 50b1862 commit 78812c9

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

app/contracts/view.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,8 @@ class ContractStates(Enum):
150150
COMPLETED = 3
151151
UPCOMING = 4
152152

153-
154-
def get_filter_button_label(state: ContractStates):
155-
"""Returns the label for the given state"""
156-
if state.value == ContractStates.ACTIVE.value:
157-
return "Active"
158-
elif state.value == ContractStates.UPCOMING.value:
159-
return "Upcoming"
160-
elif state.value == ContractStates.COMPLETED.value:
161-
return "Completed"
162-
else:
163-
return "All"
153+
def __str__(self):
154+
return self.name.capitalize()
164155

165156

166157
def get_filter_button_tooltip(state: ContractStates):
@@ -224,7 +215,7 @@ def set_filter_buttons(self):
224215
"""Sets all the filter buttons"""
225216
for state in ContractStates:
226217
button = self.filter_button(
227-
label=get_filter_button_label(state),
218+
label=state.__str__(),
228219
state=state,
229220
onClick=self.on_filter_button_clicked,
230221
tooltip=get_filter_button_tooltip(state),

app/projects/view.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,8 @@ class ProjectStates(Enum):
205205
COMPLETED = 3
206206
UPCOMING = 4
207207

208-
209-
def get_filter_button_label(state: ProjectStates):
210-
"""returns the label for the filter button"""
211-
if state.value == ProjectStates.ACTIVE.value:
212-
return "Active"
213-
elif state.value == ProjectStates.UPCOMING.value:
214-
return "Upcoming"
215-
elif state.value == ProjectStates.COMPLETED.value:
216-
return "Completed"
217-
else:
218-
return "All"
208+
def __str__(self):
209+
return self.name.capitalize()
219210

220211

221212
def get_filter_button_tooltip(state: ProjectStates):
@@ -279,7 +270,7 @@ def set_filter_buttons(self):
279270
"""sets the filter buttons for each project state"""
280271
for state in ProjectStates:
281272
button = self.filter_button(
282-
label=get_filter_button_label(state),
273+
label=state.__str__(),
283274
state=state,
284275
onClick=self.on_filter_button_clicked,
285276
tooltip=get_filter_button_tooltip(state),

tuttle/model.py

+4
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ def is_active(self) -> bool:
350350
"""Check if contract is active.A contract is active if it is not completed and the end date is in the future."""
351351
if self.is_completed:
352352
return False
353+
if self.is_upcoming():
354+
return False
353355
if self.end_date:
354356
today = datetime.date.today()
355357
return self.end_date > today
@@ -440,6 +442,8 @@ def is_active(self) -> bool:
440442
"""Is the project active? A project is active if it is not completed and if the end date is in the future."""
441443
if self.is_completed:
442444
return False
445+
if self.is_upcoming():
446+
return False
443447
if self.end_date:
444448
today = datetime.date.today()
445449
return self.end_date >= today

0 commit comments

Comments
 (0)