Commit fe1ee806 authored by svilayphiou's avatar svilayphiou
Browse files

Added Jinja filter "datetime" to format dates in templates.

Usage:
    {{ committed_date|datetime("%d/%m/%Y, %H:%M") }}
parent de32ea16
import api
from jinja2 import Environment, FileSystemLoader, select_autoescape
import time
import datetime, time
from models import Group
from settings import GROUP_ID, TEMPLATE_DIR, OUTPUT_DIR, CACHE_DIR, STATIC_DIR
import os.path
from os import makedirs, mkdir
import shutil
env = Environment(
loader=FileSystemLoader(TEMPLATE_DIR),
autoescape=select_autoescape(['html', 'xml'])
)
STRPTIME_FORMAT = '%Y-%m-%dT%H:%M:%S'
def format_datetime(value, format="%d/%m/%Y, %H:%M"):
date = datetime.datetime.strptime(value[:-10], STRPTIME_FORMAT)
return date.strftime(format)
env.filters['datetime'] = format_datetime
print('Starting generation')
......@@ -22,7 +30,7 @@ if not os.path.exists(CACHE_DIR):
group = Group(GROUP_ID)
# For now invalidate group cache on every call
group.invalidate_cache()
#group.invalidate_cache()
group.get()
# print(group)
# for project in group.projects:
......@@ -83,4 +91,4 @@ print('Generation finished')
# def update_project(project_id):
# call = get_commits(project_id)
# call.invalidate_cache()
# call.get()
\ No newline at end of file
# call.get()
......@@ -18,6 +18,43 @@
//})
Vue.filter('date', {
read: function (val) {
return formatDate(parseDate(val));
},
write: function (val, oldVal) {
var d = parseDate(val);
return d ? formatDate(d) : val
}
});
new Vue({
el: document.body,
data: { mydate: new Date() },
})
// super simple pt-BR date parser
function parseDate(str) {
if(str === null || isDate(str)) return str || null;
var p = str.match(/^(\d{1,2})\/?(\d{1,2})?\/?(\d{2,4})?$/);
if(!p) return null;
return new Date(parseInt(p[3] || new Date().getFullYear()), parseInt(p[2] || (new Date().getMonth() + 1)) - 1, parseInt(p[1]), 0, 0, 0, 0);
}
// super simple pt-BR date format
function formatDate(dt) {
if(dt == null) return '';
var f = function(d) { return d < 10 ? '0' + d : d; };
return f(dt.getDate()) + '/' + f(dt.getMonth() + 1) + '/' + dt.getFullYear();
}
// is object a date?
function isDate(d) {
return Object.prototype.toString.call(d) === '[object Date]';
}
......
......@@ -24,9 +24,7 @@
<section id="images" class="repo-views">
<div id="iceberg">
<h3>Iceberg</h3>
<div v-for="image in icebergList">
<img v-bind:src="image.src">
</div>
<img v-bind:src="image.src" v-for="image in icebergList">
</div>
<div id="processus">
......@@ -67,7 +65,7 @@
{% for commit in project.commits %}
<li class="commit-item">
<a href="https://gitlab.constantvzw.org/osp/{{ project.name }}/-/commit/{{ commit.id }}">
<time class="commit-time">{{ commit.committed_date }}</time>
<time class="commit-time">{{ commit.committed_date|datetime("%d/%m/%Y, %H:%M") }}</time>
</a>
<p class="commit-author">{{ commit.author_name }}:</p>
<p class="commit-message">{{ commit.message }}</p>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment