summaryrefslogtreecommitdiff
path: root/maconomy/templates.py
diff options
context:
space:
mode:
Diffstat (limited to 'maconomy/templates.py')
-rw-r--r--maconomy/templates.py54
1 files changed, 33 insertions, 21 deletions
diff --git a/maconomy/templates.py b/maconomy/templates.py
index 05c3319..80cafbb 100644
--- a/maconomy/templates.py
+++ b/maconomy/templates.py
@@ -1,4 +1,5 @@
from string import Template
+from maconomy import utils
class BaseTemplate(object):
def __init__(self, template_file):
@@ -12,6 +13,9 @@ class BaseTemplate(object):
template_base = f.read()
self.template = Template(template_base)
+ def tag(self, tag, content):
+ return u"<{tag}>{content}</{tag}>".format(tag=tag, content=content)
+
class UnsubmittedEmailTemplate(BaseTemplate):
def __init__(self):
@@ -30,38 +34,46 @@ class MissingEmailTemplate(BaseTemplate):
class ManagerEmailTemplate(BaseTemplate):
def __init__(self):
self.set_template("templates/manager.html")
- self.status_template = EmployeeStatusTemplate()
+ self.status_template = EmployeeStatusListTemplate()
def build(self, timesheets, maconomyurl):
statuslist = self.build_statuslist(timesheets)
return self.template.substitute(statuslist=statuslist,maconomyurl=maconomyurl, amount=len(timesheets))
def build_statuslist(self, timesheets):
- statuslist = [self.status_template.build(timesheet) for timesheet in timesheets]
- return "\n".join(statuslist)
-
-class EmployeeStatusTemplate(BaseTemplate):
- def __init__(self, include_approver=False):
- self.set_template("templates/_employee_status.html")
- self.include_approver = include_approver
+ result = u""
+ unfinished = [timesheet for timesheet in timesheets if not timesheet.is_submitted()]
+ #Sort to get unsubmitted last
+ unfinished.sort(key=lambda t: t.status_summary())
+ if unfinished:
+ result += self.tag("h4","Unfinished:")+u"\n{}".format(self.status_template.build(unfinished))
+
+ notapproved = set(timesheets) - set(unfinished)
+ if notapproved:
+ result += self.tag("h4", "For approval:") + u"\n{}".format(self.status_template.build(notapproved))
+ return result
+
+class EmployeeStatusListTemplate(BaseTemplate):
+ def __init__(self):
+ pass
+ def build(self, timesheets):
+ statuslist = u"\n".join([self.status_summary(t) for t in timesheets])
+ return self.tag("ul", statuslist) if statuslist else ""
- def build(self, timesheet):
- employee = timesheet.employee
- submitted = '' if timesheet.is_submitted() else 'not'
- approver = timesheet.approver if self.include_approver else 'you'
- approved = '' if timesheet.is_approved() else 'not'
- return self.template.substitute(employee=employee.__unicode__(), submitted=submitted, approved=approved, approver=approver)
+ def status_summary(self, timesheet):
+ content = u"{}".format(timesheet.status_summary())
+ return self.tag("li", content)
class CEOEmailTemplate(BaseTemplate):
def __init__(self):
self.set_template("templates/ceo.html")
- self.status_template = EmployeeStatusTemplate(include_approver=True)
+ self.status_template = EmployeeStatusListTemplate()
def build(self, timesheets):
- statuslist = self.build_statuslist(timesheets)
+ per_manager = utils.per_manager(timesheets)
+ statuslist = u""
+ for manager_id, relevant_timesheets in per_manager.items():
+ relevant_timesheets.sort(key=lambda t: t.status_summary())
+ statuslist += self.tag("h4", u"Status for {} employees:".format(manager_id))
+ statuslist += self.status_template.build(relevant_timesheets)
return self.template.substitute(statuslist=statuslist)
-
- def build_statuslist(self, timesheets):
- statuslist = [self.status_template.build(timesheet) for timesheet in timesheets]
- return "\n".join(statuslist)
-