Skip to content

Commit

Permalink
Simplify context assignment of TO/FROM dates.
Browse files Browse the repository at this point in the history
Removed redundant checks and bugfixes for context keys before assignment, directly setting date-related values in the context. This reduces complexity and ensures consistent behavior across methods.
  • Loading branch information
elarroba committed Jan 7, 2025
1 parent 515b3ad commit 0ed634a
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions django_ledger/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,8 @@ def get_context_data(self, **kwargs) -> dict:
quarter_end = self.get_quarter_end_date(year=year, quarter=quarter)
context['quarter_start'] = quarter_start
context['quarter_end'] = quarter_end

if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = quarter_start
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = quarter_end

context[self.get_from_date_context_name()] = quarter_start
context[self.get_to_date_context_name()] = quarter_end
context['has_quarter'] = True
return context

Expand Down Expand Up @@ -217,12 +213,8 @@ def get_context_data(self, **kwargs):
month_end = self.get_month_end_date(year=year, month=month)
context['month_start'] = month_start
context['month_end'] = month_end

if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = month_start
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = month_end

context[self.get_from_date_context_name()] = month_start
context[self.get_to_date_context_name()] = month_end
context['has_month'] = True
return context

Expand All @@ -236,12 +228,8 @@ def get_context_data(self, **kwargs):
context['next_day'] = view_date + timedelta(days=1)
context['previous_day'] = view_date - timedelta(days=1)
context['view_date'] = view_date

if self.get_from_date_context_name() not in context:
context[self.get_from_date_context_name()] = view_date
if self.get_to_date_context_name() not in context:
context[self.get_to_date_context_name()] = view_date

context[self.get_from_date_context_name()] = view_date
context[self.get_to_date_context_name()] = view_date
return context

def get_date(self) -> date:
Expand Down

0 comments on commit 0ed634a

Please sign in to comment.