def hunt_status(hunt): from gonzo.webapp.templatetags.timesince import mytimesince, mytimeuntil state = hunt.get_state() if state == Hunt.State.FUTURE: return "Hunt begins in " + mytimeuntil(hunt.start_time) elif state == Hunt.State.CURRENT: return "Hunt ends in " + mytimeuntil(hunt.end_time) elif state == Hunt.State.VOTING: return "Voting ends in " + mytimeuntil(hunt.vote_end_time) elif state == Hunt.State.FINISHED: return "Hunt ended %s ago" % (mytimesince(hunt.vote_end_time),)
def mytimeuntil(value, arg=None): """Formats a date as the time until that date (i.e. "4 days, 6 hours").""" from gonzo.webapp.templatetags.timesince import mytimeuntil from datetime import datetime if not value: return u'' try: return mytimeuntil(value, arg) except (ValueError, TypeError): return u''