Download seed.py from ed29/xertify: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/ed29/xertify/resolve/main/seed.py
- Command line
-
hf download hf://spaces/ed29/xertify/seed.py
-
curl -L -o seed.py https://huggingface.co/spaces/ed29/xertify/resolve/main/seed.py
1.56 kB
| """Seed script for QR_ccp | |
| Creates a sample Entity and an admin user if they don't exist. | |
| Usage (PowerShell): | |
| python seed.py | |
| """ | |
| from werkzeug.security import generate_password_hash | |
| from app import create_app | |
| from app_pkg.models import db | |
| from app_pkg.models.entity import Entity | |
| from app_pkg.models.user import User | |
| def seed(): | |
| app = create_app() | |
| with app.app_context(): | |
| db.create_all() | |
| # Create a sample entity | |
| entity_name = "Entidad Ejemplo" | |
| entity = Entity.query.filter_by(name=entity_name).first() | |
| if not entity: | |
| entity = Entity(name=entity_name) | |
| db.session.add(entity) | |
| db.session.commit() | |
| print(f"Created entity '{entity_name}' with id={entity.id}") | |
| else: | |
| print(f"Entity '{entity_name}' already exists with id={entity.id}") | |
| # Create an admin user | |
| admin_email = "edfego591@gmail.com" | |
| admin = User.query.filter_by(email=admin_email).first() | |
| if not admin: | |
| admin = User( | |
| name="Admin", | |
| email=admin_email, | |
| password=generate_password_hash("Adminp@s5@fedgoX"), | |
| role="admin", | |
| status="active", | |
| entity_id=entity.id, | |
| ) | |
| db.session.add(admin) | |
| db.session.commit() | |
| print(f"Created admin user '{admin_email}' with password 'Adminp@s5@fedgoX'") | |
| else: | |
| print(f"Admin user '{admin_email}' already exists") | |
| if __name__ == "__main__": | |
| seed() | |