Skip to content

williskneeland/django-bom

 
 

Repository files navigation

BOM

BOM is a simple Django app to manage a bill of materials. It supports multiple part numbering schemes, tracking component sourcing information, estimates costs, and contains smart integrations with Mouser to pull in the latest component pricing and Google Drive for part file management. BOM is written in Python 3 and Django 3.

See a live example.

BOM can be added to an existing (or new) Django project, or stand alone on its own, which can be more convenient if you're interested in tweaking the tool.

If you already have a django project, you can skip to Add Django Bom To Your App, otherwise Start From Scratch: Add to new Django project to add it to a new django project, or Start From Scratch: Use as standalone Django project.

Table of contents

Start From Scratch: Add to a new Django project

  1. To start from scratch we recommend setting up a virtual environment
virtualenv -p python3 mysite
cd mysite
source bin/activate
  1. From here install django, and set up your project.
pip install django
django-admin startproject mysite
cd mysite
python manage.py migrate
python manage.py createsuperuser # make a user for your development environment
  1. Continue on to Add Django Bom To Your App.

Add Django Bom To Your App

django-bom is a reusable django application. If you don't already have a django project, you can follow some quick steps below to get up and running, or read about creating your first django app here. Note that django-bom currently supports python 2.7.

pip install django-bom

Alternatively, to gain access to the new features contained in this fork, use the following install instead

pip install git+https://github.com/williskneeland/django-bom
  1. Add "bom" to your INSTALLED_APPS setting like this::
INSTALLED_APPS = [
    ...
    'bom',
    'social_django', # to enable google drive sync in bom
    'djmoney', # for currency
    'djmoney.contrib.exchange', # for currency
    'materializecssform',
]
  1. Update your URLconf in your project urls.py like this::
path('bom/', include('bom.urls')),

And don't forget to import include:

from django.conf.urls import include
  1. Update your settings.py to add the bom context processor 'bom.context_processors.bom_config', to your TEMPLATES variable, and create a new empty dictionary BOM_CONFIG.
TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'bom.context_processors.bom_config',
            ],
        },
    },
]

and

BOM_CONFIG = {}
  1. Run python manage.py migrate to create the bom models.

  2. Start the development server python manage.py runserver and visit http://127.0.0.1:8000/admin/ to manage the bom (you'll need the Admin app enabled).

  3. Visit http://127.0.0.1:8000/bom/ to begin.

Start From Scratch: Use as a standalone Django project

  1. To start from scratch we recommend setting up a virtual environment
virtualenv -p python3 mysite
cd mysite
source bin/activate
  1. From here install django, and set up your project.
git clone https://github.com/mpkasp/django-bom.git
pip install -r requirements.txt
python manage.py migrate
cp bom/local_settings.py.example bom/local_settings.py
python manage.py runserver

Setting up email notifications for part workflows

Each time a user is assigned to a new task in a workflow, they can be notified via email. The email will contain details about the workflow, as well as any previous comments from the last step in the workflow. To get this working, we'll need to configure Django to connect to a SMTP server domain.

  1. Add the following settings to the end of the settings.py file of your project:
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = ''
EMAIL_PORT = 587 # Default port for most SMTP servers
EMAIL_USE_TLS = True # Mandatory for personal email providers
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''

The EMAIL_HOST variable refers to the SMTP server domain to use. Three common providers are:

Provider SMTP Host
Gmail 'smtp.gmail.com'
Outlook 'smtp-mail.outlook.com'
Yahoo 'smtp.yahoo.com'

For this example, we'll be using Gmail (smtp.gmail.com), however the setup should be similar for other providers.

Leave both the EMAIL_HOST_USER and EMAIL_HOST_PASSWORD blank for now. We'll use Django Environ to avoid setting these credentials directly in the code.

  1. Get a Gmail app password

You can do this by going to myaccount.google.com, navigating to Security, and selecting App passwords. You must also have two-factor authentication set up, since it's required to get an app password. Then click on select app, choose a custom name for the app password, for example "Django Email", and hit Generate.

  1. Hiding user and password credentials with Django Environ

Customize Base Template

The base template can be customized to your pleasing. Just add the following configuration to your settings.py:

BOM_CONFIG = {
    'base_template': 'base.html',
}

where base.html is your base template.

Integrations

Mouser Integration

For part matching, make sure to add your Mouser api key. You can get your key here.

Google Drive Integration

Make sure to add the following to your settings.py:

AUTHENTICATION_BACKENDS = (
    'social_core.backends.google.GoogleOpenId',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.google.GoogleOAuth',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = ['email', 'profile', 'https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/plus.login']
SOCIAL_AUTH_GOOGLE_OAUTH2_AUTH_EXTRA_ARGUMENTS = {
    'access_type': 'offline',
    'approval_prompt': 'auto'
}

And if you're using https on production add:

SOCIAL_AUTH_REDIRECT_IS_HTTPS = not DEBUG

FIXER

Fixer.io is used to handle exchange rate calculations. This is helpful if you may be purchasing parts from another currency (especially via Mouser) and you still need to estimate your part costs.

To set this up you just need to add your API key to local_settings.py as shown in the example.

To update rates, migrate and run python manage.py update_rates. Some day we will need to add a (celerybeat?) task to update rates on a schedule. Explained more here.

Contributing

Contributions welcome! Before contributing your work please read the contributing readme.

Also reach out to mike@indabom.com to discuss features, and join our slack channel.

Installation Pitfalls

Windows

Sqlite

You may get an error during your pip install -r requirements.txt related to sqlite. This may be fixed by installing Visual C++ for python...

Cryptography

Sometimes you'll have issues installing cryptography, if this is the case you may just need to set up some environment variables. This stackoverflow may help.

About

A simple bill of materials app built using the django web framework.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 59.3%
  • HTML 37.1%
  • JavaScript 2.0%
  • CSS 1.6%