Merge remote-tracking branch 'inventree/master'

This commit is contained in:
Oliver Walters 2019-09-14 00:19:17 +10:00
commit 5fde9777fb
14 changed files with 166 additions and 8 deletions

2
.gitignore vendored
View File

@ -36,6 +36,8 @@ InvenTree/media
InvenTree/static InvenTree/static
media media
static static
inventree_media
inventree_static
# Local config file # Local config file
config.yaml config.yaml

View File

@ -0,0 +1,27 @@
""" Custom fields used in InvenTree """
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from .validators import allowable_url_schemes
from django.forms.fields import URLField as FormURLField
from django.db import models as models
from django.core import validators
class InvenTreeURLFormField(FormURLField):
""" Custom URL form field with custom scheme validators """
default_validators = [validators.URLValidator(schemes=allowable_url_schemes())]
class InvenTreeURLField(models.URLField):
""" Custom URL field which has custom scheme validators """
default_validators = [validators.URLValidator(schemes=allowable_url_schemes())]
def formfield(self, **kwargs):
return super().formfield(**{
'form_class': InvenTreeURLFormField
})

View File

@ -213,6 +213,14 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
# Extra (optional) URL validators
# See https://docs.djangoproject.com/en/2.2/ref/validators/#django.core.validators.URLValidator
EXTRA_URL_SCHEMES = CONFIG.get('extra_url_schemes', [])
if not type(EXTRA_URL_SCHEMES) in [list]:
eprint("Warning: extra_url_schemes not correctly formatted")
EXTRA_URL_SCHEMES = []
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.10/topics/i18n/ # https://docs.djangoproject.com/en/1.10/topics/i18n/

View File

@ -2,10 +2,29 @@
Custom field validators for InvenTree Custom field validators for InvenTree
""" """
from django.conf import settings
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
def allowable_url_schemes():
""" Return the list of allowable URL schemes.
In addition to the default schemes allowed by Django,
the install configuration file (config.yaml) can specify
extra schemas """
# Default schemes
schemes = ['http', 'https', 'ftp', 'ftps']
extra = settings.EXTRA_URL_SCHEMES
for e in extra:
if e.lower() not in schemes:
schemes.append(e.lower())
return schemes
def validate_part_name(value): def validate_part_name(value):
""" Prevent some illegal characters in part names. """ Prevent some illegal characters in part names.
""" """

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.5 on 2019-09-13 14:07
import InvenTree.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('build', '0005_auto_20190604_2217'),
]
operations = [
migrations.AlterField(
model_name='build',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL'),
),
]

View File

@ -17,6 +17,7 @@ from django.db.models import Sum
from django.core.validators import MinValueValidator from django.core.validators import MinValueValidator
from InvenTree.status_codes import BuildStatus from InvenTree.status_codes import BuildStatus
from InvenTree.fields import InvenTreeURLField
from stock.models import StockItem from stock.models import StockItem
from part.models import Part, BomItem from part.models import Part, BomItem
@ -89,7 +90,7 @@ class Build(models.Model):
related_name='builds_completed' related_name='builds_completed'
) )
URL = models.URLField(blank=True, help_text='Link to external URL') URL = InvenTreeURLField(blank=True, help_text='Link to external URL')
notes = models.TextField(blank=True, help_text='Extra build notes') notes = models.TextField(blank=True, help_text='Extra build notes')
""" Notes attached to each build output """ """ Notes attached to each build output """

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.5 on 2019-09-13 14:07
import InvenTree.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('company', '0007_remove_supplierpart_lead_time'),
]
operations = [
migrations.AlterField(
model_name='company',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external company information'),
),
migrations.AlterField(
model_name='supplierpart',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='URL for external supplier part link'),
),
]

View File

@ -19,6 +19,7 @@ from django.urls import reverse
from django.conf import settings from django.conf import settings
from django.contrib.staticfiles.templatetags.staticfiles import static from django.contrib.staticfiles.templatetags.staticfiles import static
from InvenTree.fields import InvenTreeURLField
from InvenTree.status_codes import OrderStatus from InvenTree.status_codes import OrderStatus
from common.models import Currency from common.models import Currency
@ -85,7 +86,7 @@ class Company(models.Model):
contact = models.CharField(max_length=100, contact = models.CharField(max_length=100,
blank=True, help_text='Point of contact') blank=True, help_text='Point of contact')
URL = models.URLField(blank=True, help_text='Link to external company information') URL = InvenTreeURLField(blank=True, help_text='Link to external company information')
image = models.ImageField(upload_to=rename_company_image, max_length=255, null=True, blank=True) image = models.ImageField(upload_to=rename_company_image, max_length=255, null=True, blank=True)
@ -238,7 +239,7 @@ class SupplierPart(models.Model):
MPN = models.CharField(max_length=100, blank=True, help_text='Manufacturer part number') MPN = models.CharField(max_length=100, blank=True, help_text='Manufacturer part number')
URL = models.URLField(blank=True, help_text='URL for external supplier part link') URL = InvenTreeURLField(blank=True, help_text='URL for external supplier part link')
description = models.CharField(max_length=250, blank=True, help_text='Supplier part description') description = models.CharField(max_length=250, blank=True, help_text='Supplier part description')

View File

@ -47,7 +47,16 @@ media_root: '../inventree_media'
# By default it is stored in a directory named 'static' local to the InvenTree directory # By default it is stored in a directory named 'static' local to the InvenTree directory
static_root: '../inventree_static' static_root: '../inventree_static'
# Optional URL schemes to allow in URL fields
# By default, only the following schemes are allowed: ['http', 'https', 'ftp', 'ftps']
# Uncomment the lines below to allow extra schemes
#extra_url_schemes:
# - mailto
# - git
# - ssh
# Logging options # Logging options
# If debug mode is enabled, set log_queries to True to show aggregate database queries in the debug console
log_queries: False log_queries: False
# Backup options # Backup options

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.5 on 2019-09-13 14:01
import InvenTree.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('part', '0022_auto_20190908_0918'),
]
operations = [
migrations.AlterField(
model_name='part',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to extenal URL'),
),
]

View File

@ -34,6 +34,7 @@ import hashlib
from InvenTree import helpers from InvenTree import helpers
from InvenTree import validators from InvenTree import validators
from InvenTree.models import InvenTreeTree from InvenTree.models import InvenTreeTree
from InvenTree.fields import InvenTreeURLField
from InvenTree.status_codes import BuildStatus, StockStatus, OrderStatus from InvenTree.status_codes import BuildStatus, StockStatus, OrderStatus
@ -353,7 +354,7 @@ class Part(models.Model):
revision = models.CharField(max_length=100, blank=True, help_text='Part revision or version number') revision = models.CharField(max_length=100, blank=True, help_text='Part revision or version number')
URL = models.URLField(blank=True, help_text='Link to extenal URL') URL = InvenTreeURLField(blank=True, help_text='Link to extenal URL')
image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True) image = models.ImageField(upload_to=rename_part_image, max_length=255, null=True, blank=True)

View File

@ -0,0 +1,24 @@
# Generated by Django 2.2.5 on 2019-09-13 14:07
import InvenTree.fields
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('stock', '0014_auto_20190908_0918'),
]
operations = [
migrations.AlterField(
model_name='stockitem',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, max_length=125),
),
migrations.AlterField(
model_name='stockitemtracking',
name='URL',
field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external page for further information'),
),
]

View File

@ -23,6 +23,7 @@ from InvenTree import helpers
from InvenTree.status_codes import StockStatus from InvenTree.status_codes import StockStatus
from InvenTree.models import InvenTreeTree from InvenTree.models import InvenTreeTree
from InvenTree.fields import InvenTreeURLField
from part.models import Part from part.models import Part
@ -308,7 +309,7 @@ class StockItem(models.Model):
serial = models.PositiveIntegerField(blank=True, null=True, serial = models.PositiveIntegerField(blank=True, null=True,
help_text='Serial number for this item') help_text='Serial number for this item')
URL = models.URLField(max_length=125, blank=True) URL = InvenTreeURLField(max_length=125, blank=True)
batch = models.CharField(max_length=100, blank=True, null=True, batch = models.CharField(max_length=100, blank=True, null=True,
help_text='Batch code for this stock item') help_text='Batch code for this stock item')
@ -715,7 +716,7 @@ class StockItemTracking(models.Model):
notes = models.CharField(blank=True, max_length=512, help_text='Entry notes') notes = models.CharField(blank=True, max_length=512, help_text='Entry notes')
URL = models.URLField(blank=True, help_text='Link to external page for further information') URL = InvenTreeURLField(blank=True, help_text='Link to external page for further information')
user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True) user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)

View File

@ -7,7 +7,7 @@ clean:
rm -rf .tox rm -rf .tox
rm -f .coverage rm -f .coverage
update: backup install migrate update: backup install migrate static
# Perform database migrations (after schema changes are made) # Perform database migrations (after schema changes are made)
migrate: migrate:
@ -15,6 +15,9 @@ migrate:
cd InvenTree && python3 manage.py migrate cd InvenTree && python3 manage.py migrate
cd InvenTree && python3 manage.py migrate --run-syncdb cd InvenTree && python3 manage.py migrate --run-syncdb
cd InvenTree && python3 manage.py check cd InvenTree && python3 manage.py check
# Collect static files into the correct locations
static:
cd InvenTree && python3 manage.py collectstatic cd InvenTree && python3 manage.py collectstatic
# Install all required packages # Install all required packages
@ -64,4 +67,4 @@ backup:
cd InvenTree && python3 manage.py dbbackup cd InvenTree && python3 manage.py dbbackup
cd InvenTree && python3 manage.py mediabackup cd InvenTree && python3 manage.py mediabackup
.PHONY: clean migrate superuser install mysql postgresql style test coverage docreqs docs backup update .PHONY: clean migrate superuser install mysql postgresql static style test coverage docreqs docs backup update