Ejemplo n.º 1
0
def add(request):
    error = None
    if request.method == 'POST':
	t = Task()
        t.caption = request.POST.get('Caption:')
	t.elaboration = request.POST.get('Full Description:')
	t.priority = int(request.POST.get('Priority(0 highest):'))
        
	t.save();
        
        if not t.caption or not t.elaboration or t.priority == '':
		error = 'Fill out all fields!'
            
    return render_to_response('add.html', {'error' : error}, context_instance=RequestContext(request))
Ejemplo n.º 2
0
def add(request, userID):
	user = User.objects.get(code=userID)
	error = None
	
	times = []
	kinds = set([t.kind for t in user.tasks.all()])
	for i in range(24):
		times.append(str(i)+':00')
		times.append(str(i)+':30')
	defaultKinds = [k for k in user.defaultKinds.all()]

	if request.method == 'POST':
		t = Task()
		t.caption = request.POST.get('Caption:')
		t.elaboration = request.POST.get('notes')
		t.priority = int(request.POST.get('priority'))
		time = request.POST.get('time')
		
	
		if(time):
			hourmin = time.split(':')
			time = [int(hourmin[0]), int(hourmin[1]), 0, 0]
		else:
			time = [23,59,59,0] #if no time specified, assume end of day(23:59)
		moretime = timedelta(0);
		if(request.POST.get('usecal')=="0"):
			year = datetime.now().year
			month = datetime.now().month
			day = datetime.now().day
			ezdate = int(request.POST.get('radio2'))-1
			if(ezdate==0 or ezdate==1):
				moretime = timedelta(ezdate)
			if(ezdate==2):
				moretime = timedelta((4-datetime.today().weekday())%7) #day difference to friday
			#else if(ezdate==4):
			#	t.isGoal = true
		else:
			caldate = request.POST.get('caldate').split('/')
			month = int(caldate[0])
			day = int(caldate[1])
			year = int(caldate[2])
		t.dateDue = datetime(year, month, day, time[0], time[1], time[2], time[3]) + moretime
			

			
		kindtype = request.POST.get('oldkind')
		if kindtype != '0':
			t.kind = kindtype;
			#t.kind = Kind.objects.get(pk=kindtype).name
		else:
			t.kind = request.POST.get('newkind')		
		
		if(not t.kind or not t.caption):
			return render_to_response('add3.html', {'error' : "fill out all fields!", 'times' : times, 'kinds' : kinds, 'defaultKinds': defaultKinds, 'userID': userID}, context_instance=RequestContext(request))		
		else: 
			t.save()
			user.tasks.add(t)
			user.save() 
			dispTasks(request,userID,None,True)

        
	return render_to_response('add3.html', {'error' : error, 'times' : times, 'kinds' : kinds, 'defaultKinds': defaultKinds, 'userID' : userID}, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def add(request, userID):
	user = User.objects.get(code=userID)
	error = None
	
	if request.method == 'POST':
		t = Task()
		t.caption = request.POST.get('Caption:')
		t.elaboration = request.POST.get('notes')
		t.priority = int(request.POST.get('priority'))
		if request.POST.get('today') == '1':
			t.dateDue = datetime(datetime.now().year, datetime.now().month, datetime.now().day, 23, 59, 59, 0)
		else:
			month = int(request.POST.get('month'))
			day = int(request.POST.get('day'))
			time = request.POST.get('time').split(':')
			#t.dateDue = datetime(datetime.now.year 
			t.dateDue = datetime(datetime.now().year, int(request.POST.get('month')), int(request.POST.get('day')), int(request.POST.get('time').split(':')[0]), int(request.POST.get('time').split(':')[1]), 0, 0)
			if t.dateDue - datetime.now() < timedelta(0):
				t.dateDue = datetime(t.dateDue + timedelta(1))
			
		kindtype = request.POST.get('oldkind')
		if kindtype != '0':
			t.kind = Kind.objects.get(pk=kindtype).name
		else:
			t.kind = request.POST.get('New kind:')		

		t.save()
		user.tasks.add(t)
		user.save() 
        
		if not t.caption or not t.dateDue or not  t.priority:
			error = 'Fill out all fields!'
        
	months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
	times = []
	monthlist = range(1,13)
	days = range(1,32)
	kinds = set([t.kind for t in user.tasks.all()])
	for i in range(24):
		times.append(str(i)+':00')
		times.append(str(i)+':30')
	defaultKinds = [k for k in user.defaultKinds.all()]
	return render_to_response('add.html', {'error' : error, 'months' : months, 'monthlist' : monthlist, 'days' : days, 'times' : times, 'kinds' : kinds, 'defaultKinds': defaultKinds, 'userID' : userID}, context_instance=RequestContext(request))