def timetrack(request, group_slug=None, template_name="djime/timetrack.html", bridge=None): if request.method == 'GET': form = TimeSliceBaseForm(request.user) elif request.method == 'POST': post = request.POST form = TimeSliceBaseForm(request.user, request.POST) if form.is_valid(): active_slices = TimeSlice.objects.filter(user=request.user, duration=None) # there should only be at most one active timeslice at any # time but incase some error has occured, we want to stop # all active timeslices whenever a new one is started. for timeslice in active_slices: timeslice.calculate_duration() timeslice.save() cd = form.cleaned_data new_slice = TimeSlice( task=cd['task'], user=request.user, note=cd['note'], ) new_slice.save() if request.POST.has_key('destination'): project = Project.objects.get(pk=cd['project']) return HttpResponseRedirect(reverse(request.POST['destination'], kwargs={'group_slug': project.slug })) return render_to_response(template_name, { 'timestrack_timeslice_form': form }, context_instance=RequestContext(request))
def timesheet_date(request, end_date, start_date, group_slug=None, template_name="djime/timesheet.html", bridge=None): if request.method == 'GET': form = TimeSliceSheetForm(request.user) elif request.method == 'POST': form = TimeSliceSheetForm(request.user, request.POST) if form.is_valid(): cd = form.cleaned_data timeslice = TimeSlice( task=cd['task'], user=request.user, duration=cd['duration'], note=cd['note'], ) timeslice.save() headline = '%s to %s' % (start_date, end_date) s_date = datetime.strptime(start_date, '%Y-%m-%d').date() e_date = datetime.strptime(end_date, '%Y-%m-%d').date() + \ timedelta(days=1) timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__range=(s_date, e_date)) return render_to_response(template_name, { 'slice_list': timesheet_timeslice_handler(timeslices), 'timesheet_timeslice_form': form, 'headline': headline }, context_instance=RequestContext(request))
def timesheet(request, method=None, year=None, method_value=0, group_slug=None, template_name="djime/timesheet.html", bridge=None): if request.method == 'GET': form = TimeSliceSheetForm(request.user) elif request.method == 'POST': form = TimeSliceSheetForm(request.user, request.POST) if form.is_valid(): cd = form.cleaned_data timeslice = TimeSlice( task=cd['task'], user=request.user, duration=cd['duration'], note=cd['note'], ) timeslice.save() today = date.today() if not method: headline = 'today' timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__day=today.day, begin__month=today.month, begin__year=today.year) elif method == 'week': week = int(method_value) if year: year = int(year) headline = 'week %s - %s' % (week, year) elif week: year = today.year headline = 'week %s - %s' % (week, year) else: headline = 'this week' week = today.isocalendar()[1] year = today.year start_date = date(year, 1, 1) + timedelta(days=(week-2)*7) while start_date.isocalendar()[1] != week: start_date += timedelta(days=1) end_date = start_date + timedelta(days=7) timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__range=(start_date, end_date)) elif method == 'month': month = int(method_value) if year: headline = '%s - %s' % (datetime(2000, month, 1).strftime('%B'), year) elif month: year = today.year headline = '%s - %s' % (datetime(2000, month, 1).strftime('%B'), year) else: headline = 'this month' month = today.month year = today.year timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__month=month, begin__year=year) elif method == 'quarter': quarter = int(method_value) quarter_suffix = ['1st', '2nd', '3rd', '4th'] quarter_end = [31, 30, 30, 31] if year: year = int(year) headline = '%s quarter - %s' % (quarter_suffix[quarter-1], year) elif quarter: year = today.year headline = '%s quarter - %s' % (quarter_suffix[quarter-1], year) else: headline = 'this quarter' quarter = (today.month - 1) / 3 + 1 year = today.year start_date = date(year, quarter * 3 - 2, 1) end_date = date(year, quarter * 3, quarter_end[quarter-1]) + \ timedelta(days=1) timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__range=(start_date, end_date)) elif method == 'year': year = int(method_value) if not year: year = today.year if year == today.year: headline = 'this year' else: headline = year timeslices = TimeSlice.objects.select_related().filter( user=request.user, begin__year=year) return render_to_response(template_name, { 'slice_list': timesheet_timeslice_handler(timeslices), 'timesheet_timeslice_form': form, 'headline': headline }, context_instance=RequestContext(request))