Esempio n. 1
0
def my_tasks(request,datefrom=None,dateto=None):

	# Get all tasks for this user
	aliases = TaskAlias.objects.filter( task__isnull = False ).filter( interval__importevent__user = request.user ).distinct()

	# Filter aliases if there is some datetimes
	if datefrom and dateto:		
		try:	
			datefrom, dateto = str2dt(datefrom), str2dt(dateto)		
		except ValueError:
			dateto, datefrom = False, False
			# Show all
			return HttpResponseRedirect( reverse('my_tasks') )
	
	# Empty list for each task to send to the template
	tasks = []

	# Loop thru aliases for this user, 
	# and find via all aliases for that (proper) task, find total time (for this user)
	for a in aliases:

		# Get all intervals for this task for this user
		intervals = Interval.objects.filter( alias__task = a.task ).filter( importevent__user = request.user )

		# Filter by date if datetimes are present
		if datefrom and dateto:
			intervals = intervals.filter( start__gte = datefrom, end__lte = dateto )

		# Sum timedeltas for all the intervals for this task in this time period
		total = sum_tds( [ i.duration for i in intervals ] )

		# Append this task, and total time to the list for the template
		tasks.append({ 'name':a.task.name, 'total':total })

	# JSON List of Task names
	categories = simplejson.dumps( [ i['name'] for i in tasks ] )
	# JSON List of values
	values = simplejson.dumps( [ float(i['total'].seconds / 60 ) for i in tasks ] )

	# Get list of last 12 months for the selectbox, see helpers.py
	months = month_list( datefrom=datefrom, dateto=dateto )

	return render(request,'graph.html', { 
		'title' : 'My projects', 
		'tasks' : tasks,
		'categories' : categories,
		'values' : values,
		'date' : { 'from' : datefrom, 'to' : dateto },
		'base_url' : reverse( my_tasks ),
		'months'	: months,
		'datefrom' : datefrom.strftime('%Y-%m-%d') if datefrom else False,
		'dateto' : dateto.strftime('%Y-%m-%d') if dateto else False
		})
Esempio n. 2
0
def all_tasks(request,datefrom=None,dateto=None):

	# Try to get date info
	if datefrom and dateto:		
		try:	
			datefrom, dateto = str2dt(datefrom), str2dt(dateto)			
		except ValueError:
			# Show all
			return HttpResponseRedirect( reverse('all_tasks') )

	# Get all proper task objects
	mtasks = Task.objects.all()

	# Empty list for each task to send to the template
	tasks = []

	for t in mtasks:
		# Get all intervals for this task
		intervals = Interval.objects.filter( alias__task = t )

		# Filter by date if datetimes are present
		if datefrom and dateto:
			intervals = intervals.filter( start__gte = datefrom, end__lte = dateto )

		# Sum timedeltas for all the intervals for this task in this time period
		total = sum_tds( [ i.duration for i in intervals ] )

		# Append this task, and total time to the list for the template
		tasks.append({ 'name':t.name, 'total':total })

	# JSON List of Task names
	categories = simplejson.dumps( [ i['name'] for i in tasks ] )
	# JSON List of values
	values = simplejson.dumps( [ float(i['total'].seconds / 60 ) for i in tasks ] )

	# Get list of last 12 months for the selectbox, see helpers.py
	months = month_list( datefrom=datefrom, dateto=dateto )


	return render(request,'graph.html', { 
		'title' : 'All projects', 
		'tasks' : tasks,
		'categories' : categories,
		'values' : values,
		'date' : { 'from' : datefrom, 'to' : dateto },
		'base_url' : reverse( all_tasks ),
		'months' : months,
		'datefrom' : datefrom.strftime('%Y-%m-%d') if datefrom else False,
		'dateto' : dateto.strftime('%Y-%m-%d') if dateto else False
		})
Esempio n. 3
0
def people_tasks(request,datefrom=None,dateto=None):

	# Try to get date info
	if datefrom and dateto:		
		try:	
			datefrom, dateto = str2dt(datefrom), str2dt(dateto)		
		except ValueError:
			dateto, datefrom = False, False
			# Show all events
			return HttpResponseRedirect( reverse('my_tasks') )
		else:
			mtasks = Task.objects.filter( taskalias__interval__start__gte = datefrom, taskalias__interval__end__lte = dateto ).distinct()
	else:
		mtasks = Task.objects.all().distinct()

	# All users
	users = User.objects.filter( importevent__isnull = False ).distinct()
	
	# List of string task names (categories)
	task_names = [ t.name for t in mtasks ]

	# list to append for each user a dict with their name and a list of all the total times for all tasks
	data = []

	# each user, all tasks
	for u in users:
		# List of time (totals) for this user for every task in mtasks
		series = []

		for t in mtasks:
			# collect intervals for this user for this task
			intervals = Interval.objects.filter( alias__task = t ).filter( importevent__user = u )
			
			# Date filter
			if datefrom and dateto:
				intervals = intervals.filter( start__gte = datefrom, end__lte = dateto )

			if intervals:
				# Sum intervals for this task, to create total time this user has spent on it
				total = sum_tds( [ i.duration for i in intervals ] )
				total_mins = float( total.seconds / 60 )
				series.append(total_mins)
			else:
				# No intervals recorded so send 0 to keep list lined up
				series.append(0)

		data.append( { 'name' : str(u), 'data' : series } )

	# Get list of last 12 months for the selectbox, see helpers.py
	months = month_list( datefrom=datefrom, dateto=dateto )

		
	
	return render(request,'graph_people.html', { 
		'title' : 'Projects', 
		'tasks' : mtasks,
		'series' : simplejson.dumps(data),
		'categories' : simplejson.dumps(task_names),
		'date' : { 'from' : datefrom, 'to' : dateto },
		'base_url' : reverse( people_tasks ),
		'months' : months,
		'datefrom' : datefrom.strftime('%Y-%m-%d') if datefrom else False,
		'dateto' : dateto.strftime('%Y-%m-%d') if dateto else False
		})