This file explains what to do and how to approach each task. Follow the steps in order.
- Clone the repo.
- Create a virtual environment and activate it.
- Install Python packages:
flaskflask_sqlalchemypsycopg2-binaryflask-wtf
- Create a PostgreSQL database named
admin. - Update the DB connection string if your user/password/host is different.
- Apply
database.sqlto the database. - Run one app:
- ORM version:
python app.py - Raw SQL version:
python user.py
- ORM version:
Goal: Learn common UI tooling and template patterns.
References:
- Bootstrap Modals: https://getbootstrap.com/docs/4.6/components/modal/
- SweetAlert2: https://sweetalert2.github.io/
- Flask-WTF: https://flask-wtf.readthedocs.io/en/stable/
- Jinja2 Templates: https://jinja.palletsprojects.com/en/3.1.x/templates/
- jQuery: https://api.jquery.com/
Steps:
- Inspect templates under
templates/to see current forms and tables. - Add a Bootstrap modal for delete confirmation (or edit) in the User view.
- Replace default browser confirm() with SweetAlert:
- Use SweetAlert on delete buttons.
- Add Flask-WTForms:
- Create a form class for User.
- Use the form in create/update routes.
- Render the form fields in Jinja2 templates.
- Ensure jQuery is included and used where needed for modals and alerts.
Deliverable:
- User create/edit pages use WTForms and SweetAlert for delete.
Goal: Build a new feature end-to-end and connect it with User.
References:
- SQLAlchemy ORM: https://docs.sqlalchemy.org/en/20/orm/
- Flask-SQLAlchemy: https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/
- PostgreSQL Docs: https://www.postgresql.org/docs/
Steps:
- Create a new
Rolemodel (or SQL table if using raw SQL). - Add a foreign key from
UsertoRole. - Create role routes:
- List roles
- Add role
- Edit role
- Delete role
- Build templates for role CRUD (list, add, edit, delete).
- Update User create/edit:
- Replace user_type text input with a role dropdown.
- Load roles from DB and show them in the select.
Deliverable:
- Roles can be created and assigned to users.
Goal: Learn pagination and async loading on big data.
References:
- DataTables: https://datatables.net/
- DataTables Server-side: https://datatables.net/manual/server-side
- Select2: https://select2.org/
- Select2 AJAX: https://select2.org/data-sources/ajax
Steps:
- Add DataTables to Users list and Roles list.
- Start with client-side DataTables on small data.
- Then add server-side pagination (lazy load):
- Create an endpoint that returns JSON data for DataTables.
- Use page number / limit to return chunks.
- Replace the Role dropdown on user forms with Select2:
- Load roles via AJAX.
- Support searching and pagination in Select2.
Deliverable:
- Users and Roles list pages are paginated.
- Role select is async with Select2.
Goal: Organize code into clean modules.
References:
- Flask Blueprints: https://flask.palletsprojects.com/en/3.0.x/blueprints/
- Flask App Factories (optional): https://flask.palletsprojects.com/en/3.0.x/patterns/appfactories/
Steps:
- Create a folder structure like:
users/(blueprint)roles/(blueprint)
- Inside each feature folder, create:
models.pyforms.pyviews.py(routes)
- Register blueprints in the main app file.
- Update imports and templates to match the new routes.
Deliverable:
- User and Role logic separated into modules and blueprints.
Goal: Polish UX and handle updates cleanly.
References:
- Flask-WTF: https://flask-wtf.readthedocs.io/en/stable/
- SweetAlert2: https://sweetalert2.github.io/
- DataTables Searching: https://datatables.net/examples/api/regex.html
Steps:
- Create WTForms for edit/update for both User and Role.
- Use SweetAlert for delete confirmation (User and Role).
- Add filter/search inputs above list tables:
- For Users: filter by username, email, role, active status.
- For Roles: filter by role name.
- Connect filters to the backend or DataTables search.
Deliverable:
- Edit forms exist for both entities.
- Filters work and delete is confirmed with SweetAlert.
- Flask app structure and blueprints
- SQLAlchemy ORM basics
- Jinja2 templating
- Flask-WTForms
- DataTables pagination and filtering
- Select2 lazy loading
- Bootstrap modals
- SweetAlert confirmations
- jQuery for UI behavior