예제 #1
0
def edit_employee(request,id):
	userprofile=UserProfile.objects.get(user=request.user)
	try:
		employee=Employee.objects.get(pk=id)
	except Employee.DoesNotExist:
		raise Http404

	try:
		action=Action.objects.get(is_leave=False,status=1,update_log__employee=employee)
		messages.success(request, 'An update action is already pending')
		return redirect(reverse('action',args=(action.pk,)))
	except Action.DoesNotExist:
		pass



	form=EmployeeEditForm(initial={'new_name':employee.name,'new_dept':employee.dept
	,'new_email':employee.email,'new_is_active':employee.is_active})
	context={
	'employee':employee,
	'form':form,
	'user_type':userprofile.user_type
	}
	if request.method=='POST':
		form = EmployeeEditForm(request.POST)
		if form.is_valid():
			new_name=form.cleaned_data['new_name']
			new_dept=form.cleaned_data['new_dept']
			new_email=form.cleaned_data['new_email']
			new_is_active=form.cleaned_data['new_is_active']
			note=form.cleaned_data['note']
			if(new_name==employee.name and new_dept==employee.dept and
		 	new_email==employee.email and new_is_active==employee.is_active):
		 		messages.error(request,'No details updated')
		 		context['form']=form
		 	else:
			 	action=Action(note=note,is_leave=False)
			 	action.save()
			 	update=EmployeeUpdateLog(action=action,employee=employee,new_name=new_name,new_dept=new_dept,
			 	new_email=new_email,new_is_active=new_is_active,old_name=employee.name,old_dept=employee.dept,
			 	old_email=employee.email,old_is_active=employee.is_active)
			 	update.save()
				messages.success(request, 'Employee details update sent for approval')
				return redirect(reverse('action',args=(action.pk,)))
			
		else:
			messages.error(request,'Please correct incorrect fields')
			context['form']=form
		return render(request,'leave/edit_employee.html',context)
	
	else:	
		return render(request,'leave/edit_employee.html',context)
예제 #2
0
def new_employee(request):
    userprofile = UserProfile.objects.get(user=request.user)

    context = {
        'user_type': userprofile.user_type,
    }
    if request.method == 'POST':
        form = EmployeeNewForm(request.POST)
        code = form.data['code']

        try:
            employee = Employee.objects.filter(is_active=False).get(code=code)
            messages.success(
                request,
                'Employee code already exists ,Please update details Here')
            return redirect(reverse('edit_employee', args=(employee.pk, )))
        except Employee.DoesNotExist:
            if form.is_valid():

                new_employee = form.save()
                note = "Adding new employee"
                action = Action(note=note, is_leave=False)
                action.save()
                update = EmployeeUpdateLog(action=action,
                                           is_new=True,
                                           employee=new_employee,
                                           new_name=new_employee.name,
                                           new_dept=new_employee.dept,
                                           new_email=new_employee.email,
                                           new_is_active=True,
                                           old_name=new_employee.name,
                                           old_dept=new_employee.dept,
                                           old_email=new_employee.email,
                                           old_is_active=False)
                update.save()
                messages.success(
                    request, 'Request to add new employee sent for approval')
                return redirect(reverse('action', args=(action.pk, )))
            else:
                messages.error(request, 'Please correct incorrect fields')
                context['form'] = form
        return render(request, 'leave/new_employee.html', context)

    else:
        context['form'] = EmployeeNewForm()
        return render(request, 'leave/new_employee.html', context)
예제 #3
0
파일: views.py 프로젝트: HoneyAshthana/LMS
def new_employee(request):
    userprofile = UserProfile.objects.get(user=request.user)
    context = {
        'user_type': UserProfile.user_type,
    }
    if request.method == 'POST':
        form = EmployeeNewForm(request.POST)
        qci_id = form.data['qci_id']
        try:
            employee = Employee.objects.filter(is_active=False).get(
                qci_id=qci_id)
            messages.success(request,
                             'Employee Id already exits,upload details here')
            return redirect(reverse('edit_employee', args=(employee.pk, )))
        except Employee.DoesNotExist:
            if form.is_valid():
                new_employee = form.save()
                note = "Adding new Employee"
                action = Action(note=note, is_leave=False)
                action.save()
                update = EmployeeUpdateLog(action=action,
                                           is_new=True,
                                           employee=new_employee,
                                           new_name=new_employee.name,
                                           new_dept=new_employee.dept,
                                           new_email=new_employee.email,
                                           new_is_active=True)
                update.save()
                messages.success(request, 'New Employee is going to be added')
                return redirect(reverse('action', args=(action.pk, )))
            else:
                messages.error(request, 'Please correct,Incorrect fields')
                context['form'] = form
        return redirect(request, 'leave/new_employee.html', context)
    else:
        context['form'] = EmployeeNewForm()
        return render(request, 'leave/new_employee.html', context)
예제 #4
0
def new_employee(request):
	userprofile=UserProfile.objects.get(user=request.user)

	context={
	'user_type':userprofile.user_type,
	}
	if request.method=='POST':
		form = EmployeeNewForm(request.POST)
		code=form.data['code']
		
		try:
			employee=Employee.objects.filter(is_active=False).get(code=code)
			messages.success(request, 'Employee code already exists ,Please update details Here')
			return redirect(reverse('edit_employee',args=(employee.pk,)))
		except Employee.DoesNotExist:
			if form.is_valid():
					
					new_employee=form.save()
					note="Adding new employee"
					action=Action(note=note,is_leave=False)
				 	action.save()
				 	update=EmployeeUpdateLog(action=action,is_new=True,employee=new_employee,new_name=new_employee.name,
				 	new_dept=new_employee.dept,new_email=new_employee.email,new_is_active=True,
				 	old_name=new_employee.name,old_dept=new_employee.dept,
				 	old_email=new_employee.email,old_is_active=False)
				 	update.save()
					messages.success(request, 'Request to add new employee sent for approval')
					return redirect(reverse('action',args=(action.pk,)))
			else:
				messages.error(request,'Please correct incorrect fields')
				context['form']=form
		return render(request,'leave/new_employee.html',context)
	
	
	else:	
		context['form']=EmployeeNewForm()
		return render(request,'leave/new_employee.html',context)
예제 #5
0
def edit_employee(request, id):
    userprofile = UserProfile.objects.get(user=request.user)
    try:
        employee = Employee.objects.get(pk=id)
    except Employee.DoesNotExist:
        raise Http404

    try:
        action = Action.objects.get(is_leave=False,
                                    status=1,
                                    update_log__employee=employee)
        messages.success(request, 'An update action is already pending')
        return redirect(reverse('action', args=(action.pk, )))
    except Action.DoesNotExist:
        pass

    form = EmployeeEditForm(
        initial={
            'new_name': employee.name,
            'new_dept': employee.dept,
            'new_email': employee.email,
            'new_is_active': employee.is_active
        })
    context = {
        'employee': employee,
        'form': form,
        'user_type': userprofile.user_type
    }
    if request.method == 'POST':
        form = EmployeeEditForm(request.POST)
        if form.is_valid():
            new_name = form.cleaned_data['new_name']
            new_dept = form.cleaned_data['new_dept']
            new_email = form.cleaned_data['new_email']
            new_is_active = form.cleaned_data['new_is_active']
            note = form.cleaned_data['note']
            if (new_name == employee.name and new_dept == employee.dept
                    and new_email == employee.email
                    and new_is_active == employee.is_active):
                messages.error(request, 'No details updated')
                context['form'] = form
            else:
                action = Action(note=note, is_leave=False)
                action.save()
                update = EmployeeUpdateLog(action=action,
                                           employee=employee,
                                           new_name=new_name,
                                           new_dept=new_dept,
                                           new_email=new_email,
                                           new_is_active=new_is_active,
                                           old_name=employee.name,
                                           old_dept=employee.dept,
                                           old_email=employee.email,
                                           old_is_active=employee.is_active)
                update.save()
                messages.success(request,
                                 'Employee details update sent for approval')
                return redirect(reverse('action', args=(action.pk, )))

        else:
            messages.error(request, 'Please correct incorrect fields')
            context['form'] = form
        return render(request, 'leave/edit_employee.html', context)

    else:
        return render(request, 'leave/edit_employee.html', context)