Пример #1
0
def employee_update(request, pk):
    employee= get_object_or_404(Employee, pk=pk)
    form = EmployeeForm(request.POST or None, instance=employee)
    if form.is_valid():
        form.save()
        return redirect('employee_list')
    return render(request, 'employee_form.html', {'form':form})
Пример #2
0
def edit(request, slug):
    employee = get_object_or_404(Employee, slug=slug)
    if request.method == 'POST':
        form = EmployeeForm(request.POST, instance=employee)
        if form.is_valid():
            employee = form.save()
            # Process image
            image = request.FILES.get('image')
            if image:
                employee.image = image
                employee.save()
                s3_upload(employee)
                remove_local_images()
            messages.success(request, 'Employee updated')
            return HttpResponseRedirect(reverse('employees.views.detail', 
                args=[employee.slug]))
    else:
        form = EmployeeForm(instance=employee)
    d = {
        'employee': employee,
        'form'    : form,
        'title'   : 'Edit Employee',
    }
    return render_to_response('employees/new.html', add_csrf(request, d), 
        context_instance=RequestContext(request))
Пример #3
0
def employee_create(request, template_name='employees/employee_form.html'):
    form = EmployeeForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('employees:employee-list')
    context = {'form': form, 'title': 'Add Employee'}
    return render(request, template_name, context)
Пример #4
0
def employee_update(request, pk, template_name='employees/employee_form.html'):
    employee = get_object_or_404(Employee, pk=pk)
    form = EmployeeForm(request.POST or None, instance=employee)
    if form.is_valid():
        form.save()
        return redirect('employees:employee-list')
    return render(request, template_name, {
        'form': form,
        'title': 'Edit Employee'
    })
Пример #5
0
 def create(self, request, *args, **kwargs):
     """
     View to be used (by companies) to create an employee
     TODO : authenticate company
     """
     model_form = EmployeeForm(request.data)
     schema_name = get_schema_from_request(request)
     with schema_context(schema_name):
         if model_form.is_valid():
             model_form.save()
             return render(request, 'success.html',
                           {'data': model_form.cleaned_data})
         else:
             return render(request, 'errors.html',
                           {'errors': model_form.errors})
Пример #6
0
 def update(self, request, *args, **kwargs):
     """
     View to be used by Employee (or company) to edit employee information, like role, team etc
     TODO : authenticate company/employee
     """
     model_form = EmployeeForm(request.data)
     schema_name = get_schema_from_request(request)
     with schema_context(schema_name):
         if model_form.is_valid():
             model_form.save()
             return render(request, 'success.html',
                           {'data': model_form.cleaned_data})
         else:
             return render(request, 'errors.html',
                           {'error': model_form.errors})
Пример #7
0
def new(request):
    if request.method == 'POST':
        form = EmployeeForm(request.POST)
        print '%s' % form.is_valid()
        if form.is_valid():
            employee = form.save()
            messages.success(request, 'Employee created')
            return HttpResponseRedirect(reverse('employees.views.detail', 
                args=[employee.slug]))
    else:
        form = EmployeeForm()
    d = {
        'form'    : form,
        'title'   : 'New Employee',
    }
    return render_to_response('employees/new.html', add_csrf(request, d), 
        context_instance=RequestContext(request))
Пример #8
0
def update_emp(request, emp_id=None):
    employee_form = EmployeeForm(request.POST or None)
    employee_data = Users.objects.filter(is_employee=True)

    emp_obj = get_object_or_404(Users, id=emp_id)
    update_emp_form = EmployeeForm(request.POST or None, instance=emp_obj)

    # if form.is_valid():
    #     form.save()
    # else:
    #     print(form.errors)
    context = {
        'update_emp_form': update_emp_form,
        'employee_form': employee_form,
        'employee': employee_data,
        'emp_obj': emp_obj
    }
    return render(request, 'dashboard.html', context)
Пример #9
0
def create(request):
    if request.method == "POST":
        empForm = EmployeeForm(data=request.POST)
        if empForm.is_valid():
            empForm.save()
        return HttpResponse("Employee saved")
    else:
        empForm = EmployeeForm()
        return render(request, 'employees/create.html', {'form': empForm})
Пример #10
0
def apply_job(request, job_id):
	# if this is a POST request we need to process the form data
	job = get_object_or_404(Job, pk=job_id)
	
	if request.method == 'POST':
        # create a form instance and populate it with data from the request:
		employee_form = EmployeeForm(request.POST,request.FILES)
        # check whether it's valid:
		if employee_form.is_valid():
            
			new_employee = employee_form.save(commit=False)			
			new_employee.job = job
			#new_employee.resume = request.FILES['resume']
			
			new_employee.save()
			
			#send email to employee
			new_employee.send_job_application_email(new_employee)
			
			#notify employer of new application
			message = new_employee.first_name+" has applied for "+job.title
			Notification.objects.create(message=message,employer=job.employer)
			
				
			# redirect to a new URL:
			return render(request,'jobs/application_successful.html',{'company_name': job.employer.company_name,"job_position":job.title})

    # if a GET (or any other method) we'll create a blank form
	else:
		employee_form = EmployeeForm()
		
	return render(request, 'jobs/apply_job.html', {'form': employee_form,'job':job})
Пример #11
0
def employee_update(request, user_id):
    # pdb.set_trace()
    employee = Employee.objects.get(id=user_id)
    my_dict = {'employee': employee}
    # form = EmployeeForm(request.POST, instance = employee)
    if request.method == "POST":
        form = EmployeeForm(request.POST or None, instance=employee)
        # for key in request.POST:
        #     print(key)
        #     value = request.POST["ename"]
        #     print(value)

        if form.is_valid():
            try:
                form.save()
                return redirect('/employees/')
            except:
                raise ("Form is not valid")
        else:
            return render(request, 'employees/edit.html', my_dict)
    else:
        return render(request, 'employees/edit.html', my_dict)
Пример #12
0
def update(request, id):
    if request.method == "POST":
        emp = Employees.objects.get(pk=id)
        empForm = EmployeeForm(request.POST, instance=emp)
        if empForm.is_valid():
            empForm.save()
            return redirect(request.path)
    else:
        emp = Employees.objects.get(pk=id)
        empForm = EmployeeForm(instance=emp)
        return render(request, 'employees/update.html', {'form': empForm})
Пример #13
0
def edit_staff(request, staff_id):
    if request.method == "POST":

        try:
            employee = get_object_or_404(Employee, id=staff_id)
            form = EmployeeForm(request.POST, request.FILES, instance=employee)
            if form.is_valid():  # To check whether the fields are
                form.save()
                messages.success(request, "Staff data updated successfully")
                return redirect("employees:staff_profile",
                                staff_id=employee.id)
            else:
                print(form.errors)
                messages.error(request, "Update Empty Fields")
                return redirect("employees:staff_profile",
                                staff_id=employee.id)

        except ValueError:
            employee = get_object_or_404(Employee, id=staff_id)
            messages.error(request, "Update Failed Bad Data")
            return redirect("employees:staff_profile", staff_id=employee.id)
    else:
        pass
Пример #14
0
def add(request):
    if request.method == "POST":
        form = EmployeeForm(request.POST)
        if form.is_valid():
            try:
                form.save()
                return redirect('/employees/')
            except:
                pass
    else:
        form = EmployeeForm()
        my_dict = {'form': form}
        return render(request, 'employees/index.html', my_dict)
Пример #15
0
def save_employee(request):
    signup_form = EmployeeForm(request.POST)
    password = request.POST.get('password')
    if signup_form.is_valid():
        instance = signup_form.save(commit=False)
        instance.set_password(password)
        instance.is_employee = True
        instance.save()
        messages.success(request, 'Success! Account Created.')
        return redirect('/dashboard/')
    else:
        print(signup_form.errors)
        signup_form = EmployeeForm(request.POST)
        context = {'employee_form': signup_form}
        return render(request, 'dashboard.html', context)
Пример #16
0
def add_employee(request):
    button_title = "Create Employee"
    if request.method == "POST":
        form = EmployeeForm(request.POST)
        files = request.FILES.getlist('file_field')

        if form.is_valid():
            employee_obj = form.save()
            for f in files:
                handle_uploaded_file(f, employee_obj)
            return redirect(f"/employees/show/{employee_obj.id}")
        else:
            return render(request, 'employees/add.html', {'form': form, 'button_title': button_title })        
    else:
        form = EmployeeForm()
    return render(request, 'employees/add.html', {'form': form, 'button_title': button_title})
Пример #17
0
def edit_employee(request, id=None):
    button_title = "Update Employee"
    if id is not None:
        employee = Employee.objects.get(id=id)
        if request.method == "POST":
            form = EmployeeForm(request.POST, instance=employee)
            files = request.FILES.getlist('file_field')

            if form.is_valid():
                employee_obj = form.save()
                for f in files:
                    handle_uploaded_file(f, employee_obj)
                return redirect(f"/employees/show/{employee_obj.id}")
        else:
            form = EmployeeForm(instance=employee)
            images = get_images(employee)
            return render(request, 'employees/add.html', {'form': form, 'images': images, 'button_title': button_title})
Пример #18
0
def save_update_emp(request, emp_id=None):
    emp_obj = get_object_or_404(Users, id=emp_id)
    update_emp_form = EmployeeForm(request.POST or None, instance=emp_obj)
    employee_form = EmployeeForm(request.POST or None)
    employee_data = Users.objects.filter(is_employee=True)

    if update_emp_form.is_valid():
        update_emp_form.save()
        messages.success(request, 'Employee updated.')
        return redirect('/dashboard/')
    else:
        print(update_emp_form.errors)
        context = {
            'update_emp_form': update_emp_form,
            'employee_form': employee_form,
            'employee': employee_data,
        }
        return render(request, 'dashboard.html', context)
Пример #19
0
def add_staff(request):
    if request.method == "GET":
        departments = Department.objects.all()
        donors = Donor.objects.all()
        dictionary = {
            "title": "Add Employee",
            "active_nav": "red-text",
            "countries": countries,
            "departments": departments,
            "donors": donors,
        }
        return render(request, 'employees/add-employee.html', dictionary)
    else:
        try:
            form = EmployeeForm(request.POST, request.FILES)

            if form.is_valid:
                form.save()
                messages.success(request, "Staff Added Successfully")
                return redirect(home)
            else:
                print(form.errors)
                messages.error(request, "Please fill all the fields")
                return redirect(add_staff)
        except Exception as e:
            print(e)
            form = EmployeeForm(request.POST, request.FILES)
            print(form.errors)
            messages.error(request, "Data is not correct")
            departments = Department.objects.all()
            donors = Donor.objects.all()
            dictionary = {
                "title": "Add Employee",
                "countries": countries,
                "departments": departments,
                "donors": donors
            }
            return render(request, 'employees/add-employee.html', dictionary)
Пример #20
0
 def list(self, request, *args, **kwargs):
     form = EmployeeForm()
     return render(request, 'employee.html', {'form': form})
Пример #21
0
def employee_create(request):
    form = EmployeeForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect('employee_list')
    return render(request, 'employee_form.html', {'form':form})
Пример #22
0
def dashboard(request):
    employee_form = EmployeeForm(request.POST or None)
    employee_data = Users.objects.filter(is_employee=True)
    context = {'employee_form': employee_form, 'employee': employee_data}
    return render(request, 'dashboard.html', context)