Permalink
Browse files

passing start and end dates to view

  • Loading branch information...
snarlygoster committed May 21, 2012
1 parent 2e570e9 commit d825e3f3c284bbcf1e10921f24a24d90b3a1227c
Showing with 97 additions and 6 deletions.
  1. +18 −4 jobclock.bbprojectd/Scratchpad.txt
  2. +48 −0 templates/timeclock/work_totals.html
  3. +3 −2 timeclock/urls.py
  4. +27 −0 timeclock/views.py
  5. +1 −0 urls.py
@@ -46,13 +46,27 @@ http://www.b-list.org/weblog/2007/nov/04/working-models/
bindery manager marks job as complete, system moves job data to next report and archive.
-for wp in wpa:
-... if wp.worker in total:
-... total[wp.worker] = total[wp.worker] + wp.duration
+>>> worker_total = {}
+>>> for wp in wpall:
+... if wp.worker in worker_total:
+... worker_total[wp.worker] = worker_total[wp.worker] + wp.duration
... else:
-... total[wp.worker] = wp.duration
+... worker_total[wp.worker] = wp.duration
...
+>>> job_total = {}
+>>> for wp in wpall:
+... if wp.job in job_total:
+... job_total[wp.job] = job_total[wp.job] + wp.duration
+... else:
+... job_total[wp.job] = wp.duration
+...
+
+
+
+>>> for jt in job_total:
+... secs = job_total[jt].seconds + job_total[jt].days * 24 * 3600
+... "%s - %d:%02d" % (job_total[jt] , secs/3600, secs%3600/60)
import datetime
@@ -0,0 +1,48 @@
+<html>
+<head>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+ <title>Work Totals</title>
+</head>
+<body>
+
+
+<ul>
+
+{% for name,value in params.items %}
+ <li> {{ name }}: {{ value }}</li>
+{% endfor %}
+
+{% for name,value in bugs.items %}
+ <li>bug {{ name }}: {{ value }}</li>
+{% endfor %}
+
+</ul>
+<h1>Work Totals</h1>
+<h2>By Job</h2>
+
+
+
+
+
+<table>
+{% for job, total_time in job_total.items %}
+ <tr>
+ <td>{{ job.ticket }}</td>
+ <td>{{ job.description }}</td>
+ <td>{{ total_time}}</td>
+ </tr>
+{% endfor %}
+</table>
+
+
+<h2>By Person</h2>
+<table>
+{% for worker, total_time in worker_total.items %}
+ <tr>
+ <td>{{ worker.name }}</td>
+ <td>{{ total_time }}</td>
+ </tr>
+{% endfor %}
+</table>
+</body>
+</html>
View
@@ -2,14 +2,15 @@
# Our stuff
-from timeclock.views import ClockPunchView, ClockPunchSums, WorkPeriodView
+from timeclock.views import ClockPunchView, ClockPunchSums, WorkPeriodView, WorkTotals
urlpatterns = patterns('',
url(r'^$', ClockPunchView.as_view(), name='clockpunch_view'),
url(r'summary', ClockPunchSums.as_view(), name='clockpunchsums'),
url(r'workperiods/(?P<workername>\w*)/$', WorkPeriodView.as_view(), name='workperiods'),
url(r'workperiods/(?P<workername>\w*)/(?P<startdate>\d{8}/$)', WorkPeriodView.as_view(), name='workperiod_startdate'),
- url(r'worker/$', WorkerSums.as_view(), name='worker_view'),
+ url(r'work_totals/$', WorkTotals.as_view(), name='work_totals_view'),
+ url(r'work_totals/(?P<startyear>\d{4})/(?P<startmonth>\d{1,2})/(?P<startday>\d{1,2})/(?P<endyear>\d{4})/(?P<endmonth>\d{1,2})/(?P<endday>\d{1,2})/$', WorkTotals.as_view(), name='work_totals_view'),
# Examples:
# url(r'^$', 'jobclockproj.views.home', name='home'),
# url(r'^jobclockproj/', include('jobclockproj.foo.urls')),
View
@@ -66,3 +66,30 @@ def get_context_data(self, **kwargs):
context['workername'] = self.kwargs['workername']
context['work_periods'] = self._get_work_periods() #workername=self.kwargs['workername'])
return context
+
+class WorkTotals(TemplateView):
+ template_name='timeclock/work_totals.html'
+ work_periods=WorkPeriod.objects.all()
+
+ def _get_work_periods(self, **kwargs):
+ pass #### START HERE
+
+ def get_context_data(self, **kwargs):
+ context = super(WorkTotals, self).get_context_data(**kwargs)
+ params = context['params']
+ context['bugs'] = params
+ worker_total = {}
+ job_total = {}
+ for wp in self.work_periods:
+ if wp.worker in worker_total:
+ worker_total[wp.worker] = worker_total[wp.worker] + wp.duration
+ else:
+ worker_total[wp.worker] = wp.duration
+ if wp.job in job_total:
+ job_total[wp.job] = job_total[wp.job] + wp.duration
+ else:
+ job_total[wp.job] = wp.duration
+ context['worker_total'] = worker_total
+ context['job_total'] = job_total
+ return context
+
View
@@ -8,4 +8,5 @@
url(r'^jobclock/', include('timeclock.urls')),
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls)),
+ # url(r'^$', ),
)

0 comments on commit d825e3f

Please sign in to comment.