Skip to content
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
Empty file added scancodeio/formats/__init__.py
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions scancodeio/formats/en/formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/aboutcode-org/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/scancode.io for support and download.

DATE_FORMAT = "M d, Y"
DATETIME_FORMAT = "Y-m-d H:i"
48 changes: 48 additions & 0 deletions scancodeio/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# SPDX-License-Identifier: Apache-2.0
#
# http://nexb.com and https://github.com/aboutcode-org/scancode.io
# The ScanCode.io software is licensed under the Apache License version 2.0.
# Data generated with ScanCode.io is provided as-is without warranties.
# ScanCode is a trademark of nexB Inc.
#
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
# ScanCode.io should be considered or used as legal advice. Consult an Attorney
# for any legal advice.
#
# ScanCode.io is a free software code scanning tool from nexB Inc. and others.
# Visit https://github.com/aboutcode-org/scancode.io for support and download.

import zoneinfo

from django.utils import timezone


def validate_timezone(tz):
"""Return a valid timezone or None if invalid."""
try:
return zoneinfo.ZoneInfo(tz).key
except (zoneinfo.ZoneInfoNotFoundError, TypeError, ValueError):
return


class TimezoneMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
tz = validate_timezone(request.COOKIES.get("client_timezone"))

if tz:
timezone.activate(zoneinfo.ZoneInfo(tz))
else:
timezone.deactivate()

return self.get_response(request)
3 changes: 3 additions & 0 deletions scancodeio/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"scancodeio.middleware.TimezoneMiddleware",
]

ROOT_URLCONF = "scancodeio.urls"
Expand Down Expand Up @@ -348,6 +349,8 @@

LANGUAGE_CODE = "en-us"

FORMAT_MODULE_PATH = ["scancodeio.formats"]

TIME_ZONE = env.str("TIME_ZONE", default="UTC")

USE_I18N = True
Expand Down
8 changes: 8 additions & 0 deletions scancodeio/static/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,14 @@ document.addEventListener('DOMContentLoaded', function () {
});
}

// Timezone
// Detects the user's current timezone using the browser's API
// and stores it in a cookie to be used by the backend for localization.
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
if (timezone) {
document.cookie = `client_timezone=${timezone}; path=/; SameSite=Lax`;
}

});

// Toasts (requires bulma-toast.js)
Expand Down
13 changes: 12 additions & 1 deletion scanpipe/templates/scanpipe/includes/project_list_table.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load humanize %}
{% now "Y-m-d" as today %}
<table class="table is-bordered is-striped is-hoverable is-fullwidth">
{% include 'scanpipe/includes/list_view_thead.html' with select_all=True %}
<tbody>
Expand All @@ -12,7 +13,17 @@
<div>
{% include 'scanpipe/includes/project_labels.html' with labels=project.labels.all only %}
</div>
<span class="has-text-grey is-size-7 is-block" title="{{ project.created_date|date:'N j, Y, P T' }}">Created {{ project.created_date|naturaltime }}</span>
<span class="has-text-grey is-size-7 is-block">
{% if project.created_date|date:"Y-m-d" == today %}
<span title="{{ project.created_date }}">
Created {{ project.created_date|naturaltime }}
</span>
{% else %}
<span title="{{ project.created_date|naturaltime }}">
Created {{ project.created_date }}
</span>
{% endif %}
</span>
</th>
<td>
{% if project.discoveredpackages_count %}
Expand Down
6 changes: 3 additions & 3 deletions scanpipe/templates/scanpipe/modals/run_modal_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,22 @@
<div class="control">
<div class="tags has-addons">
<span class="tag is-dark">Created date</span>
<span class="tag is-info">{{ run.created_date|date:'N j, Y, P T' }}</span>
<span class="tag is-info">{{ run.created_date }}</span>
</div>
</div>
{% if run.task_start_date %}
<div class="control">
<div class="tags has-addons">
<span class="tag is-dark">Start date</span>
<span class="tag is-info">{{ run.task_start_date|date:'N j, Y, P T' }}</span>
<span class="tag is-info">{{ run.task_start_date }}</span>
</div>
</div>
{% endif %}
{% if run.task_end_date %}
<div class="control">
<div class="tags has-addons">
<span class="tag is-dark">End date</span>
<span class="tag is-info">{{ run.task_end_date|date:'N j, Y, P T' }}</span>
<span class="tag is-info">{{ run.task_end_date }}</span>
</div>
</div>
{% endif %}
Expand Down
13 changes: 10 additions & 3 deletions scanpipe/templates/scanpipe/project_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@
</nav>
<div class="subtitle is-size-6">
<span class="has-text-grey">
<span title="{{ project.created_date|date:'N j, Y, P T' }}">
Created {{ project.created_date|naturaltime }}
</span>
{% now "Y-m-d" as today %}
{% if project.created_date|date:"Y-m-d" == today %}
<span title="{{ project.created_date }}">
Created {{ project.created_date|naturaltime }}
</span>
{% else %}
<span title="{{ project.created_date|naturaltime }}">
Created {{ project.created_date }}
</span>
{% endif %}
</span>
{% include 'scanpipe/includes/project_labels.html' with labels=labels only %}
<a class="modal-button is-size-7" data-target="add-labels-modal" aria-haspopup="true">
Expand Down