This guide will help you set up the Testomatic Dashboard.
uWSGI Emperor manages the processes using ini files in /etc/uwsgi-emperor/vassals/.
There are two apps: register (production) and register-test.
To restart an app, touch its ini file — Emperor detects the change and reloads it:
# Restart production
sudo touch /etc/uwsgi-emperor/vassals/register.ini
# Restart test
sudo touch /etc/uwsgi-emperor/vassals/register-test.iniThe Emperor process itself is managed by systemd:
sudo systemctl restart uwsgi-emperorSupplier pricing/stock for Parts (erp.PartSourceVariant) is kept up to date by the
refresh_part_sources management command, which is not run automatically by the
app itself — add an hourly crontab entry for it on each production host:
0 * * * * cd /path/to/register/pyproj && /path/to/register/pyproj/venv/bin/python manage.py refresh_part_sources >> /var/log/register/refresh_part_sources.log 2>&1Each run only refreshes a bounded, oldest-first slice of variants (roughly
1/24th of the total) so a day's worth of supplier API calls is spread across 24
runs rather than firing all at once. See python manage.py refresh_part_sources --help
for the --max-per-run and --dry-run options.
Note:
manage.pyreads.envfresh on every invocation, but the running uWSGI worker only read it once at startup — so if you change any DigiKey-related.envvalue (see DigiKey API Integration for the failure modes this causes), restart the relevant uWSGI vassal (above) too, or the cron job and the web app will silently disagree about DigiKey config.
Todo
The instructions below are for local setup on MacOS.
- Python 3.8+ (check with
python3 --version) - pip (Python package manager)
- Git (if cloning the repository)
cd /Users/jon/src/register/pyprojpython3 -m venv venv
source venv/bin/activateYou should see (venv) in your terminal prompt. Keep this terminal open and
the virtual environment activated for all subsequent steps.
pip install --upgrade pip
pip install -r requirements.txtCreate conf/local_settings.py from the template:
cp conf/local_settings.py.template conf/local_settings.pyThen edit conf/local_settings.py and keep only the SQLite configuration
(the first section, lines 1-28). Remove or comment out the MySQL section below.
Create a .env file in the pyproj directory:
cd /Users/jon/src/register/pyproj
touch .envAdd the following to .env:
SECRET_KEY=your-secret-key-here-change-this-in-production
DEPLOY_TYPE=dev
DEMO_MODE=False
API_ALLOW_IPV4_SUBNET=Important: Generate a secure SECRET_KEY. You can use this command:
python3 -c "from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())"Copy the output and paste it as the value for SECRET_KEY in your .env file.
python manage.py migrateThis will create the SQLite database file (db.sqlite3) and set up all
the database tables.
python manage.py createsuperuserFollow the prompts to create an admin account. You'll use this to log into the admin interface.
python manage.py runserverThe server will start at http://127.0.0.1:8000/
- Main application: http://127.0.0.1:8000/device/
- Admin interface: http://127.0.0.1:8000/office/
- API documentation: http://127.0.0.1:8000/api/v1/docs (requires staff login)
To test the Excel import command you just modified:
- Prepare an Excel file with the required sheets (see the import command for format)
- Run the import command:
python manage.py import-xlsx /path/to/your/file.xlsxTo run the test suite:
pytestOr with Django's test runner:
python manage.py testIf you get import errors, make sure:
- Your virtual environment is activated (
source venv/bin/activate) - All dependencies are installed (
pip install -r requirements.txt)
If you get database errors:
- Make sure migrations are run:
python manage.py migrate - Check that
conf/local_settings.pyexists and has the correct database configuration
If static files (CSS, images) don't load:
- In development, Django serves static files automatically
- Make sure
DEBUG = Truein yourlocal_settings.py
When you're done working, you can deactivate the virtual environment:
deactivate- Create some test data through the admin interface
- Create clients, designs, and devices
- Test the Excel import functionality
- Explore the API endpoints