Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apps/projects: do not use deprecated property days_left from a4 - fix… #2592

Merged
merged 2 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ''
Loading