diff --git a/euth/projects/templates/euth_projects/includes/project_hero_unit.html b/euth/projects/templates/euth_projects/includes/project_hero_unit.html index eb6049134..c34b56233 100644 --- a/euth/projects/templates/euth_projects/includes/project_hero_unit.html +++ b/euth/projects/templates/euth_projects/includes/project_hero_unit.html @@ -1,4 +1,4 @@ -{% load thumbnail react_follows project_tags i18n rules %} +{% load thumbnail react_follows project_class_tags i18n rules %}
- {% get_days project.days_left as days %} + {% get_days project as days %}

{% if project.is_private %} {% trans 'private' %} diff --git a/euth/projects/templates/euth_projects/includes/project_list_item.html b/euth/projects/templates/euth_projects/includes/project_list_item.html index 5707f96a5..c8c30a1d0 100644 --- a/euth/projects/templates/euth_projects/includes/project_list_item.html +++ b/euth/projects/templates/euth_projects/includes/project_list_item.html @@ -1,9 +1,9 @@ -{% load i18n project_tags thumbnail follow_tags %} +{% load i18n project_class_tags thumbnail follow_tags %} {% get_class project as class %}

- {% get_days project.days_left as days %} + {% get_days project as days %}

{% if project.is_private %} {% trans 'private' %} diff --git a/euth/projects/templates/euth_projects/includes/project_tile.html b/euth/projects/templates/euth_projects/includes/project_tile.html index 0b81b5185..ca3200437 100644 --- a/euth/projects/templates/euth_projects/includes/project_tile.html +++ b/euth/projects/templates/euth_projects/includes/project_tile.html @@ -1,4 +1,4 @@ -{% load i18n project_tags project_class_tags thumbnail static %} +{% load i18n project_class_tags thumbnail static %} {% get_class project as class %}

@@ -6,7 +6,7 @@ style="background-image: url('{% if project.image %} {{ project.image|thumbnail_url:'project_thumbnail' }} {% else %}{% static "images/placeholder.png" %}{% endif %}');" {% if open_in_new_tab %}target="_blank"{% endif %}> - {% get_days project.days_left as days %} + {% get_days project as days %} {% if project.is_archived %}

{% trans 'archived' %}

{% elif project.is_private %} diff --git a/euth/projects/templatetags/project_class_tags.py b/euth/projects/templatetags/project_class_tags.py index c62bce96c..f3eb1fea8 100644 --- a/euth/projects/templatetags/project_class_tags.py +++ b/euth/projects/templatetags/project_class_tags.py @@ -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 ''