remove duplications
This commit is contained in:
@@ -12,13 +12,17 @@ from .get_period_times import (
|
||||
task_file,
|
||||
task_or_none,
|
||||
timezone,
|
||||
get_work_project_tasks,
|
||||
get_work_period_totals,
|
||||
)
|
||||
|
||||
|
||||
|
||||
class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
# def formatmonth(self, theyear, themonth, withyear=True):
|
||||
# self.dmmonth = themonth
|
||||
# super().formatmonth(self, theyear, themonth)
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.use_work_projects = False
|
||||
self.task = None
|
||||
|
||||
def setcalmonth(self, month):
|
||||
self.dmmonth = month
|
||||
@@ -29,6 +33,9 @@ class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
def settask(self, task):
|
||||
self.task = task
|
||||
|
||||
def set_work_projects_mode(self, enabled=True):
|
||||
self.use_work_projects = enabled
|
||||
|
||||
def oneday(self, month, day):
|
||||
current_year = datetime.today().year
|
||||
start = datetime(self.dmyear, month, day).replace(
|
||||
@@ -38,7 +45,10 @@ class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
hour=23, minute=59, second=59, tzinfo=timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end, self.task)
|
||||
if self.use_work_projects:
|
||||
rows = get_work_period_totals(start, end)
|
||||
else:
|
||||
rows = get_period_totals(start, end, self.task)
|
||||
|
||||
returnstr = "<table class='totaltable'>"
|
||||
for row in rows:
|
||||
@@ -75,7 +85,10 @@ class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
hour=23, minute=59, second=59, tzinfo=timezone
|
||||
)
|
||||
|
||||
rows = get_period_totals(start, end, self.task)
|
||||
if self.use_work_projects:
|
||||
rows = get_work_period_totals(start, end)
|
||||
else:
|
||||
rows = get_period_totals(start, end, self.task)
|
||||
|
||||
print(rows)
|
||||
|
||||
@@ -117,6 +130,28 @@ class DMHTMLCalendar(calendar.HTMLCalendar):
|
||||
)
|
||||
|
||||
|
||||
@dmbp.route("/workmonth")
|
||||
@dmbp.route("/workmonth/<int:month>")
|
||||
@dmbp.route("/workmonth/<int:month>/<int:year>")
|
||||
def workmonth(month=None, year=None):
|
||||
usemonth = datetime.today().month
|
||||
useyear = datetime.today().year
|
||||
|
||||
if month:
|
||||
usemonth = month
|
||||
|
||||
if year:
|
||||
useyear = year
|
||||
|
||||
cal = DMHTMLCalendar(calendar.SATURDAY)
|
||||
|
||||
cal.set_work_projects_mode(True)
|
||||
cal.setcalmonth(usemonth)
|
||||
cal.setcalyear(useyear)
|
||||
|
||||
return render_template("calendar.html", content=cal.formatmonth(useyear, usemonth))
|
||||
|
||||
|
||||
@dmbp.route("/month")
|
||||
@dmbp.route("/month/<int:month>")
|
||||
@dmbp.route("/month/<int:month>/<int:year>")
|
||||
|
||||
Reference in New Issue
Block a user