﻿
from web.frontend import app

@app.template_filter('datetimeformat')
def datetimeformat(value, format='%d, %b %Y %H:%M', blank_message=u"N/A"):
	if value:
		return value.strftime(format)
	else:
		return blank_message

@app.template_filter('length')
def length(obj):
	try:
		return len(obj)
	except:
		return 0

step_map = {
	"METALINGUISTIC" : "Metalinguistic signs",
	"STATIC" : "Static signs",
	"DYNAMIC" : "Dynamic signs"
}

@app.template_filter('stringfy_step')
def stringfy_step(step):
	return step_map[step.upper()]

step_type_map = {
	"STEP_TYPE.METALINGUISTIC" : "Metalinguistic",
	"STEP_TYPE.STATIC" : "Static",
	"STEP_TYPE.DYNAMIC" : "Dynamic"
}

@app.template_filter('stringfy_step_type')
def stringfy_step_type(step):
	return step_type_map[str(step)]

phase_map = {
	"PHASE.NON_INITIALIZED" : "Non initialized",
	"PHASE.INITIAL" : "Initial phase",
	"PHASE.METALINGUISTIC_READY" : "Metalinguistc ready",
	"PHASE.STATIC_READY" : "Static ready",
	"PHASE.DYNAMIC_READY" : "Dynamic ready",
	"PHASE.COMPARASION" : "Comparasion ready",
	"PHASE.FINAL" : "Complete"
}

@app.template_filter('stringfy_phase')
def stringfy_phase(phase):
	return phase_map[str(phase)]

status_map = {
	"STATUS.DRAFT" : "Draft",
	"STATUS.COMPLETE" : "Complete",
	"STATUS.PUBLISHED" : "Published"
}

@app.template_filter('stringfy_status')
def stringfy_status(status):
	return status_map[str(status)]


