This was originally a test assignment written (mainly) on Flask + SQLAlchemyORM. It complies with the following requirements:
Create a webpage that displays an employee hierarchy as a tree structure containing the following data:
- Name
- Position
- Date of hire
- Salary
- Each employee has only 1 supervisor
- The database must contain at least 50,000 employees and 5 levels of hierarchy.
- Create the database using Flask migrations.
- Use Twitter Bootstrap to create basic styles for your page.
- Create a separate page to display a list of employees with all the employees’ information.
- Extend task #3 with the ability to sort and search by any field without reloading the page (e.g. by using ajax).
- Using standard Flask functions, add user authentication and create a section available only for registered users.
- Transfer the functionality developed in tasks 3 and 6 to a section accessible only to registered users.
- In the section accessible only to registered users, implement the remaining CRUD operations for employee records, including changing the superviosr.
- Implement lazy loading for the employees tree.
Run following commands (in that order recommended)
With Python PIP installed run:
pip install -r requirements.txt
If used with MySQL as opposed to the default SQLite, also requires MySQL client:
pip install -r optional-requirements.txt
Please checl SQLalchemy documentation on requirements for running other SQL dialects.
With NPM installed:
npm install
This installs the bower package manager to handle the UI necessary components. Then run:
node_modules/bower/bin/bower install
The application uses the 'DATABASE_URL' environment variable to connect to the database. If unspecified, the application will be using the deafult SQLite database in the 'app.db' file in the root directory of the app.
This package uses flask-Migrate. To upgrade an empty schema run these commands:
flask db upgrade
Package includes a seeder which relies on the seeding/positions.txt
file data that follows following format:
top_lvl_position_name, number_of_employees, salary
2_lvl_position_name, number_of_employees, salary
...
Posiitons are evaluated top down, with each employee on a level getting as many subordinates as is indicated on the next level down. E.g. in the example provided file (that wil lresult in 65843 employees generated by default), each Country Manager gets 8 Regional Managers in their subordination, each of which gets 8 Branch managers in turn, and so on. Names of the employees are generated randomly as provided by the Faker package (included in the requirements.txt.).
To seed the DB, please use the flask shell
command to run interpreter with necessary context already in place and then execute following code:
seeder = DbSeeder()
seeder.seed()
db.session.commit()
This will populate the Database with the entire hierarchy structure as provided in the seeding/positions.txt
file.
Alternatively, you can set an arbitrary number of levels to be processed from the top, if you would like a smaller hierarchy without having to change the positions file, like so:
seeder = DbSeeder()
seeder.seed(4)
db.session.commit()
This will result in seeding only the top 4 levels of the file.
You can run the application locally with the following command:
flask run
Which (by default) will start serving the application at http://127.0.0.1:5000/