Skip to content

Commit

Permalink
Add is_past_thirty_days check for date
Browse files Browse the repository at this point in the history
- If true, show dd/mm/yyyy vs. naturaltime
  • Loading branch information
smithellis committed Jun 4, 2024
1 parent 6b7b5b6 commit 047ef58
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion kitsune/products/jinja2/products/documents.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h2 class="sumo-card-heading">
</a>
</h2>
<p>{{ document['document_summary'] }}</p>
{{ document_metadata(document['created'], document['product_titles'], helpful_votes=None, metadata_type="list") }}
{{ document_metadata(document['created'], document['is_past_thirty_days'], document['product_titles'], helpful_votes=None, metadata_type="list") }}
</div>
</article>
{% endfor %}
Expand Down
9 changes: 9 additions & 0 deletions kitsune/products/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json

from datetime import datetime, timedelta

from django.http import HttpResponse
from django.shortcuts import get_object_or_404, redirect, render
from product_details import product_details
Expand Down Expand Up @@ -90,6 +92,13 @@ def document_listing(request, product_slug, topic_slug, subtopic_slug=None):
}

documents, fallback_documents = documents_for(request.user, **doc_kw)
documents = [
{
**document,
"is_past_thirty_days": document["created"] < (datetime.now() - timedelta(days=30)),
}
for document in documents
]

return render(
request,
Expand Down
2 changes: 1 addition & 1 deletion kitsune/wiki/jinja2/wiki/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<article class="wiki-doc">
{{ document_messages(document, redirected_from) }}
{% if not document.is_archived %}
{{ document_metadata(document.current_revision.created, product_titles, helpful_votes, metadata_type="document") }}
{{ document_metadata(document.current_revision.created, is_past_thirty_days, product_titles, helpful_votes, metadata_type="document") }}
{% endif %}
{{ document_content(document, fallback_reason, request, settings, document_css_class, any_localizable_revision, full_locale_name) }}

Expand Down
4 changes: 2 additions & 2 deletions kitsune/wiki/jinja2/wiki/includes/document_macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
<h1 class="sumo-page-heading">{{ document.title }}</h1>
{%- endmacro %}

{% macro document_metadata(created_date, product_titles, helpful_votes, metadata_type) -%}
{% macro document_metadata(created_date, is_past_thirty_days, product_titles, helpful_votes, metadata_type) -%}
{% set truncate_length = 25 if helpful_votes else 50 %}
<div id="document_metadata" class="{% if metadata_type=="list" %}has-border-top{% else %}has-border-bottom{% endif %}">
<span class="product tooltip-container">
{{ product_titles | truncate(truncate_length) }}
<span class="tooltip">{{ product_titles }}</span>
</span>
<span class="last-updated">
<img class="pencil" src="{{ webpack_static('sumo/img/pencil.svg') }}" /> <strong>{{ _("Last updated") }}:</strong> <span class="time">{{ created_date|naturaltime }}</span>
<img class="pencil" src="{{ webpack_static('sumo/img/pencil.svg') }}" /> <strong>{{ _("Last updated") }}:</strong> <span class="time">{% if is_past_thirty_days %}{{ created_date.strftime('%m/%d/%Y') }}{% else %}{{ created_date|naturaltime }}{% endif %}</span>
</span>
{% if helpful_votes %}
<span class="helpful-info">
Expand Down
5 changes: 4 additions & 1 deletion kitsune/wiki/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import logging
import time
from datetime import datetime, time as datetime_time
from datetime import datetime, time as datetime_time, timedelta
from functools import wraps

from django.conf import settings
Expand Down Expand Up @@ -281,8 +281,11 @@ def document(request, document_slug, document=None):
else 0
)

is_past_thirty_days = doc.current_revision.created < (datetime.now() - timedelta(days=30))

data = {
"document": doc,
"is_past_thirty_days": is_past_thirty_days,
"redirected_from": redirected_from,
"contributors": contributors,
"fallback_reason": fallback_reason,
Expand Down

0 comments on commit 047ef58

Please sign in to comment.