Esempio n. 1
0
def data_entry():

    employee_info = []

    # Check if the user is logged in, if not: back to login.
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))
    if session['manager'] is None:
        return redirect(url_for('index'))

    if (request.method == 'POST'):
        empid = request.form.get('empid')
        name = request.form.get('name')
        homeaddress = request.form.get('homeaddress')
        dateofbirth = request.form.get('dateofbirth')
        password = request.form.get('password')

        employee_info.append(int(empid))
        employee_info.append(name)
        employee_info.append(homeaddress)
        dt_dateofbirth = datetime.strptime(dateofbirth, '%Y-%m-%d').date()
        employee_info.append(dt_dateofbirth)
        employee_info.append(password)

        for info in employee_info:
            print(info)
            if info is None:
                page['bar'] = False
                flash('Invalid request')
                return redirect(url_for('data_entry'))

        res = database.add_employee(employee_info)

        if res[0]:
            page['bar'] = True
            flash('Employee successfully added to database.')
        else:
            page['bar'] = False
            flash(res[1])
        return redirect(url_for('data_entry'))

    elif (request.method == 'GET'):
        # Else they're looking at the page
        # Get the employees in the department (once chosen)
        employees = database.get_employees_in_department(session['manager'])

        if employees is None:
            page['bar'] = False
            flash('Error communicating with database')
            employees = []

        return render_template('entry.html',
                               page=page,
                               session=session,
                               employees=employees)
Esempio n. 2
0
def issue_device():
    # Check if the user is logged in, if not: back to login.
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))
    if session['manager'] is None:
        return redirect(url_for('index'))

    if (request.method == 'POST'):
        empid = request.form.get('empid')
        device_id = request.form.get('deviceid')

        if empid is None or device_id is None:
            page['bar'] = False
            flash('Invalid request')
            return redirect(url_for('issue_device'))

        # If it is a POST - they are sending an 'issue' request
        res = database.issue_device_to_employee(empid, device_id)
        if res[0]:
            page['bar'] = True
            flash('Device successfully issued')
        else:
            page['bar'] = False
            flash(res[1])
        return redirect(url_for('issue_device'))

    elif (request.method == 'GET'):
        # Else they're looking at the page.
        # 1. Get the list of models (Other parts will be async through ajax)
        models = database.get_department_models(session['manager'])

        if models is None:
            page['bar'] = False
            flash('Error communicating with database')
            models = []

        # 3. Get the employees in the department (once chosen)
        employees = database.get_employees_in_department(session['manager'])

        if employees is None:
            page['bar'] = False
            flash('Error communicating with database')
            employees = []

        return render_template('issue.html',
                               page=page,
                               session=session,
                               employees=employees,
                               models=models)
Esempio n. 3
0
def departmentemployees():
    """
    Return the list of employees that work in the
    department.
    """
    department = request.args.get('department')

    if department is None:
        flash('Error retrieving devices')
        return jsonify({'error': True})

    employees = database.get_employees_in_department(department)

    if employees is None:
        return jsonify({'error': True})

    return jsonify({'employees': employees})
Esempio n. 4
0
def remove_employee():
    """
    Remove employee.
    """
    # Check if the user is logged in, if not: back to login.
    if ('logged_in' not in session or not session['logged_in']):
        return redirect(url_for('login'))

    if (session['manager'] is None):
        return redirect(url_for('index'))

    if (request.method == 'POST'):
        empid = request.form.get('empid')
        print(empid)
        if empid is None:
            page['bar'] = False
            flash('Invalid request')
            return redirect(url_for('remove_employee'))
        res = database.remove_employee(empid)

        if res[0]:
            page['bar'] = True
            flash('Employee successfully removed')
        else:
            page['bar'] = False
            flash(res[1])
        return redirect(url_for('remove_employee'))

    elif (request.method == 'GET'):

        employees = database.get_employees_in_department(session['manager'])

        if employees is None:
            page['bar'] = False
            flash('Error communicating with database')
            employees = []

        return render_template(
            'remove_employee.html',
            page=page,
            session=session,
            employees=employees,
        )