Thanks Ken
This puts me on the right direction and I think I can achieve what I’m trying to do.
Bit of a noob issue here. I created my model, which I want to populate from the form and send it to the DB, but I must not be understanding something as I keep getting a KeyData() got an unexpected keyword argument ‘dataSize’
Only thing of note is that KDBParser.getKeys() returns a list of dictionaries where each key is parsed out of the uploaded file, that part works fine as I can dump all the content into the console.
Here is my model:
class KeyData(models.Model):
dataSize = models.IntegerField
version = models.IntegerField
keyUsageFlag = models.IntegerField
pubExp = models.BinaryField(max_length=4)
keyId = models.BinaryField(max_length=16, primary_key=True, unique=True)
keySize = models.IntegerField
# Must be all zeros
reserved = models.BinaryField(max_length=44)
modulus = models.BinaryField
and what I try to do with it in views.py
class FileFieldFormView(generic.FormView):
form_class = fileUploadForm
template_name = 'dbparser/keyDBUpload.html'
success_url = 'keyDBHome'
def post(self, request, *args, **kwargs):
form_class = self.get_form_class()
form = self.get_form(form_class)
files = request.FILES.getlist('file_field')
if form.is_valid():
for f in files:
hexdata = f.read()
validateKeyDBImage(hexdata)
kdb = KDBHeaderParser(hexdata)
for key in kdb.getKeys():
k = KeyData(dataSize=key['DataSize'], version=key['Version'],\
keyUsageFlag = key['KeyUsageFlag'], pubExp=key['PubExp'], keyId=key['KeyId'],\
keySize=key['KeySize'], reserved=key['Reserved'], modulus=key['Modulus'])
k.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
and finally the error that I get:
Traceback (most recent call last):
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\user1\Desktop\signsrv\dbparser\views.py", line 58, in post
k = KeyData(dataSize=key['DataSize'], version=key['Version'],\
File "C:\Users\user1\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\models\base.py", line 503, in __init__
raise TypeError("%s() got an unexpected keyword argument '%s'" % (cls.__name__, kwarg))
Exception Type: TypeError at /dbparser/upload
Exception Value: KeyData() got an unexpected keyword argument 'dataSize'
I tried several variations of this, but I don’t know how the model fields are supposed to get populated here, if I don’t supply any names, it seems to take the arguments, but, I don’t think that is right.
Appreciate any help.
Thank you
xp