mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
eecb26676e
* Adds configurable setting for maximum remote image size * Add helper function for downloading image from remote URL - Will replace existing function - Performs more thorough sanity checking * Replace existing image downloading code - part image uses new generic function - company image uses new generic function * Rearrange settings * Refactor and cleanup existing views / forms * Add unit testing for image downloader function * Refactor image downloader forms - Part image download now uses the API - Company image download now uses the API - Remove outdated forms / views / templates * Increment API version * Prevent remote image download via API if the setting is not enabled * Do not attempt to validate or extract image from blank URL * Fix custom save() serializer methods
50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""Django Forms for interacting with Part objects."""
|
|
|
|
from django import forms
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from common.forms import MatchItemForm
|
|
from InvenTree.helpers import clean_decimal
|
|
|
|
from .models import Part
|
|
|
|
|
|
class BomMatchItemForm(MatchItemForm):
|
|
"""Override MatchItemForm fields."""
|
|
|
|
def get_special_field(self, col_guess, row, file_manager):
|
|
"""Set special fields."""
|
|
# set quantity field
|
|
if 'quantity' in col_guess.lower():
|
|
return forms.CharField(
|
|
required=False,
|
|
widget=forms.NumberInput(attrs={
|
|
'name': 'quantity' + str(row['index']),
|
|
'class': 'numberinput',
|
|
'type': 'number',
|
|
'min': '0',
|
|
'step': 'any',
|
|
'value': clean_decimal(row.get('quantity', '')),
|
|
})
|
|
)
|
|
|
|
return super().get_special_field(col_guess, row, file_manager)
|
|
|
|
|
|
class PartPriceForm(forms.Form):
|
|
"""Simple form for viewing part pricing information."""
|
|
|
|
quantity = forms.IntegerField(
|
|
required=True,
|
|
initial=1,
|
|
label=_('Quantity'),
|
|
help_text=_('Input quantity for price calculation')
|
|
)
|
|
|
|
class Meta:
|
|
"""Metaclass defines fields for this form"""
|
|
model = Part
|
|
fields = [
|
|
'quantity',
|
|
]
|