Skip to content

Commit

Permalink
apps/projects: do not use deprecated property days_left from a4 - fix…
Browse files Browse the repository at this point in the history
…es part of #2590
  • Loading branch information
fuzzylogic2000 authored and philli-m committed Feb 20, 2023
1 parent 7dc17c8 commit 42bbf30
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load thumbnail react_follows project_tags i18n rules %}
{% load thumbnail react_follows project_class_tags i18n rules %}

<header class="herounit" style="{% if project.image %}
background-image: url({{ project.image |thumbnail_url:'heroimage' }});
Expand All @@ -7,7 +7,7 @@
<div class="container-narrow">
<div class="herounit-header">

{% get_days project.days_left as days %}
{% get_days project as days %}
<p>
{% if project.is_private %}
<span class="badge badge-private">{% trans 'private' %}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% load i18n project_tags thumbnail follow_tags %}
{% load i18n project_class_tags thumbnail follow_tags %}
{% get_class project as class %}
<div class="teaserlist-item {{ class }} {% if not project.image %} no-image {% endif %}"
style="{% if project.image %}background-image: url({{ project.image|thumbnail_url:'heroimage_preview' }}){% endif %}">
<div class="teaserlist-body">
{% get_days project.days_left as days %}
{% get_days project as days %}
<p>
{% if project.is_private %}
<span class="badge badge-private">{% trans 'private' %}</span>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{% load i18n project_tags project_class_tags thumbnail static %}
{% load i18n project_class_tags thumbnail static %}
{% get_class project as class %}

<div class="project-tile project-tile-{{ class }} {% if not project.image %} project-tile-no-image {% endif %}">
<a href="{% url 'project-detail' project.slug %}" class="project-tile-image-link"
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 %}>
<img src="{% if project.image %} {{ project.image|thumbnail_url:'project_thumbnail' }} {% else %}{% static "images/placeholder.png" %}{% endif %}" class="project-tile-image img-fluid">

{% get_days project.days_left as days %}
{% get_days project as days %}
{% if project.is_archived %}
<p class="badge badge-archived">{% trans 'archived' %}</p>
{% elif project.is_private %}
Expand Down
38 changes: 36 additions & 2 deletions euth/projects/templatetags/project_class_tags.py
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 ''

0 comments on commit 42bbf30

Please sign in to comment.