mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add generic method for retriving GET or POST params
This commit is contained in:
parent
e5fc43a00f
commit
cd438f0569
@ -69,6 +69,22 @@ class AjaxMixin(object):
|
||||
ajax_form_action = ''
|
||||
ajax_form_title = ''
|
||||
|
||||
def get_param(self, name, method='GET'):
|
||||
""" Get a request query parameter value from URL e.g. ?part=3
|
||||
|
||||
Args:
|
||||
name: Variable name e.g. 'part'
|
||||
method: Request type ('GET' or 'POST')
|
||||
|
||||
Returns:
|
||||
Value of the supplier parameter or None if parameter is not available
|
||||
"""
|
||||
|
||||
if method == 'POST':
|
||||
return self.request.POST.get(name, None)
|
||||
else:
|
||||
return self.request.GET.get(name, None)
|
||||
|
||||
def get_data(self):
|
||||
""" Get extra context data (default implementation is empty dict)
|
||||
|
||||
|
@ -92,6 +92,8 @@ class EditBomItemForm(HelperForm):
|
||||
'quantity',
|
||||
'note'
|
||||
]
|
||||
|
||||
# Prevent editing of the part associated with this BomItem
|
||||
widgets = {'part': forms.HiddenInput()}
|
||||
|
||||
|
||||
|
@ -406,6 +406,7 @@ class SupplierPartCreate(AjaxCreateView):
|
||||
ajax_form_title = 'Create new Supplier Part'
|
||||
context_object_name = 'part'
|
||||
|
||||
|
||||
def get_initial(self):
|
||||
""" Provide initial data for new SupplierPart:
|
||||
|
||||
@ -414,18 +415,21 @@ class SupplierPartCreate(AjaxCreateView):
|
||||
"""
|
||||
initials = super(SupplierPartCreate, self).get_initial().copy()
|
||||
|
||||
supplier_id = self.request.GET.get('supplier', None)
|
||||
part_id = self.request.GET.get('part', None)
|
||||
supplier_id = self.get_param('supplier')
|
||||
part_id = self.get_param('part')
|
||||
|
||||
if supplier_id:
|
||||
initials['supplier'] = get_object_or_404(Company, pk=supplier_id)
|
||||
# TODO
|
||||
# self.fields['supplier'].disabled = True
|
||||
try:
|
||||
initials['supplier'] = Company.objects.get(pk=supplier_id)
|
||||
except Company.DoesNotExist:
|
||||
initials['supplier'] = None
|
||||
|
||||
if part_id:
|
||||
initials['part'] = get_object_or_404(Part, pk=part_id)
|
||||
# TODO
|
||||
# self.fields['part'].disabled = True
|
||||
|
||||
try:
|
||||
initials['part'] = Part.objects.get(pk=part_id)
|
||||
except Part.DoesNotExist:
|
||||
initials['part'] = None
|
||||
|
||||
return initials
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user