Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

Commit

Permalink
Replaced all of the date formatting lines with a call to the formatDa…
Browse files Browse the repository at this point in the history
…te function in utils.py
  • Loading branch information
Anusha Ranganathan committed Jun 25, 2012
1 parent 91d5855 commit b3dc6be
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 25 deletions.
8 changes: 6 additions & 2 deletions rdfdatabank/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,12 @@ def extract_metadata(item):
return dict(m)

def formatDate(dt):
dt_obj = parse(dt, dayfirst=True, yearfirst=False)
dt_human = dt_obj.strftime("%B %d %Y, %I:%M %p")
dt_human = dt
try:
dt_obj = parse(dt, dayfirst=True, yearfirst=False)
dt_human = dt_obj.strftime("%B %d %Y, %I:%M %p")
except:
return dt
return dt_human

def getSiloModifiedDate(silo_name):
Expand Down
16 changes: 7 additions & 9 deletions rdfdatabank/templates/datasetview.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,13 @@ <h3>View other versions:</h3><ul class="versions">
<h2>Access Information</h2>
<div class="dataset_info">
% if c.embargos and c.current in c.embargos and c.embargos[c.current]:
<%
from dateutil.parser import parse
from time import strftime
c.emb = c.embargos[c.current]
dt_human = c.emb[1]
if c.emb[1] and c.emb[1].strip():
dt_obj = parse(c.emb[1].strip(), dayfirst=True, yearfirst=False)
dt_human = dt_obj.strftime('%B %d %Y, %I:%M %p')
%>
<%
from rdfdatabank.lib.utils import formatDate
c.emb = c.embargos[c.current]
dt_human = c.emb[1]
if dt_human and dt_human.strip():
dt_human = formatDate(dt_human)
%>
% if c.emb[0] == True or c.emb[0] == 1 or (isinstance(c.emb[0], basestring) and c.emb[0].strip().lower() in ['true', '1']):
% if (isinstance(c.emb[1], basestring) and c.emb[1].strip()):
Data package is embargoed until ${dt_human}. Only the metadata is openly accessible.
Expand Down
6 changes: 1 addition & 5 deletions rdfdatabank/templates/embargo_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
% if c.embargos[c.current][1]:
<%
from rdfdatabank.lib.utils import formatDate
##dateutil.parser import parse
##from time import strftime
dt_human = c.embargos[c.current][1]
if c.embargos[c.current][1].strip():
##dt_obj = parse(c.embargos[c.current][1].strip(), dayfirst=True, yearfirst=False)
##dt_human = dt_obj.strftime('%Y-%m-%d %H:%M:%S')
if dt_human and dt_human.strip():
dt_human = formatDate(dt_human)
%>
<label for="emu">Embargoed until (date)</label>
Expand Down
16 changes: 7 additions & 9 deletions rdfdatabank/templates/list_of_datasets.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,13 @@
<td><ul><li><a href="/${c.silo_name}/datasets/${item}"> ${item}</a></li></ul></td>
<td>
% if c.embargos and item in c.embargos and c.embargos[item]:
<%
c.emb = c.embargos[item]
from dateutil.parser import parse
from time import strftime
dt_human = c.emb[1]
if c.emb[1] and c.emb[1].strip():
dt_obj = parse(c.emb[1].strip(), dayfirst=True, yearfirst=False)
dt_human = dt_obj.strftime('%B %d %Y, %I:%M %p')
%>
<%
from rdfdatabank.lib.utils import formatDate
c.emb = c.embargos[item]
dt_human = c.emb[1]
if dt_human and dt_human.strip():
dt_human = formatDate(dt_human)
%>
% if c.emb[0] == True or c.emb[0] == 1 or (isinstance(c.emb[0], basestring) and c.emb[0].strip().lower() in ['true', '1']):
% if (isinstance(c.emb[1], basestring) and c.emb[1].strip()):
Data package is embargoed until ${dt_human}
Expand Down

0 comments on commit b3dc6be

Please sign in to comment.