예제 #1
0
def remove_employee(request, employee_id):
    if request.method == 'DELETE':
        with connect() as conn:
            dbemployees = Employees(conn)
            dbemployees.remove(employee_id)
        return HttpResponse(status=200)
    return HttpResponse(status=400)
예제 #2
0
def get_employees(request):
    if request.method == 'GET':
        with connect() as conn:
            dbemployees = Employees(conn)
            employees = dbemployees.readall()
        return JsonResponse(employees, safe=False, encoder=ModelsJSONEncoder, json_dumps_params={'indent': 2})
    return HttpResponse(status=400)
예제 #3
0
def search_employee(request):
    if request.method == 'GET':
        with connect() as conn:
            dbemployees = Employees(conn)
            characteristicssearch = request.GET.get('characteristics', None)  # FULLTEXT search
            fullnamesearch = request.GET.get('full_name', None)  # LIKE search
            isinternsearch = request.GET.get('is_intern', None)  # WHERE search
            employees = dbemployees.search(characteristicssearch, fullnamesearch, isinternsearch)
        return JsonResponse(employees, safe=False, encoder=ModelsJSONEncoder)
    return HttpResponse(status=400)
예제 #4
0
def update_employee(request, employee_id):
    if request.method == 'PUT':
        try:
            employee = _req_body_to_employee(request)
        except (TypeError, KeyError) as e:
            print(e)
            return HttpResponse(status=400)
        with connect() as conn:
            dbemployees = Employees(conn)
            dbemployees.update(employee, employee_id)
        return HttpResponse(status=200)
    return HttpResponse(status=400)
예제 #5
0
def add_employee(request):
    if request.method == 'POST':
        try:
            employee = _req_body_to_employee(request)
        except (TypeError, KeyError) as e:
            print(e)
            return HttpResponse(status=400)
        with connect() as conn:
            dbemployees = Employees(conn)
            dbemployees.add(employee)
        return HttpResponse(status=200)
    return HttpResponse(status=400)
예제 #6
0
def import_employees(request):
    if request.method == 'POST':
        req_body = request.FILES['file'].read()
        employees_dict = simplexml.loads(req_body)['employees']
        employees = []
        for e in employees_dict:
            e_is_intern = 1 if '1' in e['is_intern'] else 0
            employees.append(Employee(
                0, e['full_name'], e['characteristics'], e_is_intern
            ))
        with connect() as conn:
            dbemployees = Employees(conn)
            dbemployees.importall(employees)
        return HttpResponse(status=200)
    return HttpResponse(status=400)
예제 #7
0
def export_employees(request):
    with connect() as conn:
        dbemployees = Employees(conn)
        employees = dbemployees.readall()
    return export(request, employees, 'employees')