Пример #1
0
def leave_request_cancel(request, id):
	leave_request = get_object_or_404(LeaveRequest, id=id)
	success = process.get_processor(leave_request, request.employee).cancel()
	if not success:
		set_warning_msg(request, leave_request)
	else:
		messages.add_message(request, messages.INFO, "%s's leave request has been canceled successfully!" % leave_request.employee.display_name)
		LeaveRequestProcesses(leave_request=leave_request,
						who=request.employee.display_name,
						do='Canceled').save()
	return redirect(leave_request)
Пример #2
0
def leave_request_view(request, id):
	leave_request = get_object_or_404(LeaveRequest, id=id)
	
	lrps = LeaveRequestProcesses.objects.filter(leave_request=leave_request).order_by('at')
	actions = process.get_processor(leave_request, request.employee).actions()
		
	context = {
		'leaverequest': leave_request,
		'actions': actions,
		'lrps': lrps,
	}
	return render_to_response('leave/leave_request.html',
							  RequestContext(request, context))
Пример #3
0
def leave_request_reject(request, id):
	leave_request = get_object_or_404(LeaveRequest, id=id)
	reason = request.POST.get('reason', '')
	success = process.get_processor(leave_request, request.employee).reject(reason)
	if success:
		LeaveRequestProcesses(leave_request=leave_request,
						who=request.employee.display_name,
						do='Rejected',
						reason=reason).save()
		
	
		messages.add_message(request, messages.INFO, "%s's leave request has been rejected successfully!" % leave_request.employee.display_name)
	else:
		set_warning_msg(request, leave_request)
	
	return redirect(leave_request)
Пример #4
0
def leave_request_approve(request, id):
	leave_request = get_object_or_404(LeaveRequest, id=id)
	success = process.get_processor(leave_request, request.employee).approve()
	if success:
		LeaveRequestProcesses(leave_request=leave_request,
						who=request.employee.display_name,
						do='Approved').save()

	shortcut = int(request.GET.get('shortcut', '0'))
	if not shortcut:
		if success:
			messages.add_message(request, messages.SUCCESS, "%s's leave request has been approved successfully!" % leave_request.employee.display_name)
		else:
			set_warning_msg(request, leave_request)
		return redirect(leave_request)
	else:
		return HttpResponse(leave_request.status)
Пример #5
0
def leave_request(request, id=None, edit=False):
	form = periods = leave_request = availableDays = None
	if request.method == 'POST':
		if edit and request.POST.has_key('leave_request_id'):
			lr = get_object_or_404(LeaveRequest, id=request.POST.get('leave_request_id'))
			if not can_edit_leave_request(request, lr): return redirect(lr)
			form = CreateLeaveRequestForm(request.POST, instance=lr)
		else:
			form = CreateLeaveRequestForm(request.POST)			
		
		if form.is_valid():
			current_lr = form.save()
			if current_lr:
				Period.objects.filter(leave_request=current_lr).delete()
				
				periods_str = request.POST.get('periods')
				periods = periods_str.rstrip("b").split('b')
				for p in periods:
					start, end = p.split(',')
					
					Period(leave_request=current_lr,
						   start=datetime.datetime.strptime(start, '%Y-%m-%d-%H'),
						   end=datetime.datetime.strptime(end, '%Y-%m-%d-%H')
						).save()
				
			if not request.POST.has_key('modify'):
				process.get_processor(current_lr, request.employee).submit()
				messages.add_message(request, messages.INFO, 'You leave request has been submitted successfully!')
			else:
				do = 'modified'
				if request.employee.is_mine(current_lr):
					success_resubmit = process.get_processor(current_lr, request.employee).resubmit()
					if success_resubmit:
						messages.add_message(request, messages.INFO, current_lr.employee.display_name + "'s leave request has been modified and resubmitted!")
						do += ' and resubmited'
						LeaveRequestProcesses(leave_request=current_lr,
									  who=request.employee.display_name,
									  do=do).save()
					else:
						set_warning_msg(request, current_lr)
				else:
					success_edit = process.get_processor(current_lr, request.employee).edit()
					if success_edit:
						messages.add_message(request, messages.INFO, current_lr.employee.display_name + "'s leave request has been modified successfully!")
						LeaveRequestProcesses(leave_request=current_lr,
									  who=request.employee.display_name,
									  do=do).save()
					else: set_warning_msg(request, current_lr)
				
			return redirect(current_lr)
	elif id and edit:
		leave_request = get_object_or_404(LeaveRequest, id=id)
		
		if not have_can_view_permission(request.employee, leave_request):
			return render_to_response('can_not_view.html', RequestContext(request, {}))
		
		if not can_edit_leave_request(request, leave_request): return redirect(leave_request)
		
		form = CreateLeaveRequestForm(instance=leave_request)
		periods = Period.objects.filter(leave_request__id=leave_request.id)
		availableDays = leave_request.employee.days_available()
		for k, v in availableDays.items():
			if k == leave_request.leave_type.name.lower().replace(' ', '_'):
				v['available_days'] = v['total_days'] - v['used_days']
				if v['available_days'] < 0: v['available_days'] = 0
	else:
		form = CreateLeaveRequestForm()
		availableDays = request.employee.days_available()
	
	context = {
		'form': form,
		'leaverequest': leave_request,
		'periods': periods,
		'edit': edit,
		'availableDays': availableDays,
		'nav': 'new_leave_request'
	}
	return render_to_response('leave/new_leave_request.html',
							  RequestContext(request, context))