add task feature
This commit is contained in:
@@ -1,125 +1,140 @@
|
||||
import calendar
|
||||
from datetime import datetime
|
||||
from pprint import pprint
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
import pytz
|
||||
|
||||
import calendar
|
||||
|
||||
|
||||
from dmweb.dm import dmbp, get_period_totals, local_date
|
||||
|
||||
from flask import Blueprint, render_template
|
||||
|
||||
|
||||
class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
|
||||
|
||||
# def formatmonth(self, theyear, themonth, withyear=True):
|
||||
# self.dmmonth = themonth
|
||||
# super().formatmonth(self, theyear, themonth)
|
||||
|
||||
|
||||
def setcalmonth(self, month):
|
||||
self.dmmonth = month
|
||||
|
||||
def setcalyear(self, year):
|
||||
self.dmyear = year
|
||||
|
||||
def oneday(self,month,day):
|
||||
def settask(self, task):
|
||||
self.task = task
|
||||
|
||||
def oneday(self, month, day):
|
||||
current_year = datetime.today().year
|
||||
start = datetime(self.dmyear, month, day).replace(hour=0,
|
||||
minute=0,
|
||||
second=0)
|
||||
start = datetime(self.dmyear, month, day).replace(hour=0, minute=0, second=0)
|
||||
|
||||
end = datetime(self.dmyear, month, day).replace (hour=23,
|
||||
minute=59,
|
||||
second=59)
|
||||
end = datetime(self.dmyear, month, day).replace(hour=23, minute=59, second=59)
|
||||
|
||||
rows = get_period_totals( local_date(start),
|
||||
local_date(end))
|
||||
rows = get_period_totals(local_date(start), local_date(end), self.task)
|
||||
|
||||
returnstr = "<table class='totaltable'>"
|
||||
for row in rows:
|
||||
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(row["ws"],row["total"])
|
||||
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
|
||||
row["ws"], row["total"]
|
||||
)
|
||||
|
||||
returnstr += "</table>"
|
||||
return returnstr
|
||||
|
||||
|
||||
def oneweek(self,month,week):
|
||||
return returnstr
|
||||
|
||||
def oneweek(self, month, week):
|
||||
start_day = None
|
||||
end_day = None
|
||||
|
||||
for (d, wd) in week:
|
||||
for d, wd in week:
|
||||
if d == 0:
|
||||
continue
|
||||
else:
|
||||
start_day = d
|
||||
break
|
||||
|
||||
|
||||
for (d, wd) in reversed(week):
|
||||
for d, wd in reversed(week):
|
||||
if d == 0:
|
||||
continue
|
||||
else:
|
||||
end_day = d
|
||||
break
|
||||
|
||||
start = datetime(self.dmyear, month, start_day).replace(
|
||||
hour=0, minute=0, second=0
|
||||
)
|
||||
|
||||
start = datetime(self.dmyear, month, start_day).replace(hour=0,
|
||||
minute=0,
|
||||
second=0)
|
||||
end = datetime(self.dmyear, month, end_day).replace(
|
||||
hour=23, minute=59, second=59
|
||||
)
|
||||
|
||||
end = datetime(self.dmyear, month, end_day).replace (hour=23,
|
||||
minute=59,
|
||||
second=59)
|
||||
|
||||
rows = get_period_totals( local_date(start),
|
||||
local_date(end))
|
||||
rows = get_period_totals(local_date(start), local_date(end))
|
||||
|
||||
returnstr = "<table class='totaltable'>"
|
||||
for row in rows:
|
||||
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(row["ws"],row["total"])
|
||||
returnstr += "<tr><td>{}</td><td>{}</td></tr>".format(
|
||||
row["ws"], row["total"]
|
||||
)
|
||||
|
||||
returnstr += "</table>"
|
||||
return returnstr
|
||||
|
||||
return returnstr
|
||||
|
||||
def formatweekheader(self):
|
||||
"""
|
||||
Return a header for a week as a table row.
|
||||
"""
|
||||
s = ''.join(self.formatweekday(i) for i in self.iterweekdays())
|
||||
s = "".join(self.formatweekday(i) for i in self.iterweekdays())
|
||||
s += "<td>Week Totals</td>"
|
||||
return '<tr>%s</tr>' % s
|
||||
|
||||
|
||||
return "<tr>%s</tr>" % s
|
||||
|
||||
def formatweek(self, theweek):
|
||||
"""
|
||||
Return a complete week as a table row.
|
||||
"""
|
||||
s = ''.join(self.formatday(d, wd) for (d, wd) in theweek)
|
||||
s = "".join(self.formatday(d, wd) for (d, wd) in theweek)
|
||||
s += "<td>{}</td>".format(self.oneweek(self.dmmonth, theweek))
|
||||
return '<tr>%s</tr>' % s
|
||||
|
||||
return "<tr>%s</tr>" % s
|
||||
|
||||
def formatday(self, day, weekday):
|
||||
"""
|
||||
Return a day as a table cell.
|
||||
"""
|
||||
if day == 0:
|
||||
return '<td class="noday"> </td>' # day outside month
|
||||
else:
|
||||
return '<td class="%s">%s</td>' % (self.cssclasses[weekday], self.oneday(self.dmmonth, day))
|
||||
"""
|
||||
Return a day as a table cell.
|
||||
"""
|
||||
if day == 0:
|
||||
return '<td class="noday"> </td>' # day outside month
|
||||
else:
|
||||
return '<td class="%s">%s</td>' % (
|
||||
self.cssclasses[weekday],
|
||||
self.oneday(self.dmmonth, day),
|
||||
)
|
||||
|
||||
|
||||
@dmbp.route("/month")
|
||||
@dmbp.route("/month/<int:month>")
|
||||
@dmbp.route("/month/<int:month>/<int:year>")
|
||||
@dmbp.route("/month/task/<string:task>")
|
||||
@dmbp.route("/month/<int:month>/task/<string:task>")
|
||||
@dmbp.route("/month/<int:month>/<int:year>/task/<string:task>")
|
||||
def month(month=None, year=None, task=None):
|
||||
usemonth = datetime.today().month
|
||||
useyear = datetime.today().year
|
||||
|
||||
@dmbp.route("/calendar")
|
||||
@dmbp.route("/calendar/<int:month>")
|
||||
def calmain(month=None):
|
||||
if month:
|
||||
usemonth = month
|
||||
|
||||
if year:
|
||||
useyear = year
|
||||
|
||||
cal = DMHTMLCalendar(calendar.SATURDAY)
|
||||
|
||||
cal.settask(None)
|
||||
if task:
|
||||
cal.settask(task)
|
||||
|
||||
cal.setcalmonth(usemonth)
|
||||
cal.setcalyear(useyear)
|
||||
|
||||
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth))
|
||||
|
||||
|
||||
@dmbp.route("/week")
|
||||
@dmbp.route("/week/<int:week>")
|
||||
def week(month=None):
|
||||
usemonth = datetime.today().month
|
||||
useyear = datetime.today().year
|
||||
if month:
|
||||
@@ -129,6 +144,5 @@ def calmain(month=None):
|
||||
|
||||
cal.setcalmonth(usemonth)
|
||||
cal.setcalyear(useyear)
|
||||
|
||||
return render_template("calendar.html", content=cal.formatmonth(useyear,usemonth))
|
||||
|
||||
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth))
|
||||
|
||||
Reference in New Issue
Block a user