-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apps/projects: do not use deprecated property days_left from a4 - fix…
…es part of #2590
- Loading branch information
1 parent
7dc17c8
commit dc2c712
Showing
4 changed files
with
42 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
euth/projects/templates/euth_projects/includes/project_list_item.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
euth/projects/templates/euth_projects/includes/project_tile.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
from django import template | ||
from django.utils import timezone | ||
from django.utils.translation import gettext as _ | ||
from django.utils.translation import ngettext | ||
|
||
from adhocracy4.projects.enums import Access | ||
|
||
register = template.Library() | ||
|
||
|
||
def days_left(project): | ||
""" | ||
Replaces the project property days_left that was removed from a4. | ||
Still uses the active_phase property, which is deprecated. | ||
""" | ||
active_phase = project.active_phase | ||
if active_phase: | ||
today = timezone.now().replace(hour=0, minute=0, second=0) | ||
time_delta = active_phase.end_date - today | ||
return time_delta.days | ||
return None | ||
|
||
|
||
@register.simple_tag | ||
def get_class(project): | ||
if project.is_archived: | ||
return 'archived' | ||
elif project.access == Access.PRIVATE: | ||
elif (project.access == Access.PRIVATE | ||
or project.access == Access.SEMIPUBLIC): | ||
return 'private' | ||
elif project.has_finished: | ||
return 'finished' | ||
elif project.days_left is not None and project.days_left <= 5: | ||
elif days_left(project) is not None and days_left(project) <= 5: | ||
return 'running-out' | ||
else: | ||
return 'public' | ||
|
||
|
||
@register.simple_tag | ||
def get_days(project): | ||
number = days_left(project) | ||
if number and number >= 1 and number <= 5: | ||
text = ngettext( | ||
'%(number)d day left', | ||
'%(number)d days left', | ||
number) % { | ||
'number': number, | ||
} | ||
return text | ||
elif number == 0: | ||
return _('a few hours left') | ||
else: | ||
return '' |