From Import Import From Import From Import Try From Import Except Pass
From Import Import From Import From Import Try From Import Except Pass
import os
from core.settings import MEDIA_ROOT
from accounts.models import atmDevices
try:
from accounts import globalVariables
except:
pass
EJ_MEDIA_SUB_ROOT = 'ej/'
CBS_MEDIA_SUB_ROOT = 'cbsSt/'
VISA_MEDIA_SUB_ROOT = 'visa/'
MASTER_MEDIA_SUB_ROOT = 'master/'
UPI_MEDIA_SUB_ROOT = 'upi/'
SWITCH_MEDIA_SUB_ROOT = 'switch/'
banksCardBin = ['44380', '443832', '443834']
cardStartBIN = '4438'
MAX_FILE_SIZE = 50 * (1024**2)
validFormats = ['jrn', 'csv', 'txt', '']
class UploadMultipleFileForm(forms.Form):
fileTyes = {
'': 'Select',
'switchCW': 'Switch Cash Withdrawal LOG',
'cbsCwAcq': 'CBS Cash Withdrawal Acquiring',
'cbsCwIss': 'CBS Cash Withdrawal Issuing',
'visa745': 'VISA CW. Acquiring (EP745)',
'visa707': 'VISA CW. Issuing (EP707)',
'masterTT464T0': 'MasterCard CW. Acq. (TT464T0)',
'upiAcom': 'UPI Cw. Acq. (ACOM)'
}
fileTyes_list = list(fileTyes.items())
file_upload_type = forms.ChoiceField(
label='Select Report Type', choices=fileTyes_list, required=True)
upload_file = forms.FileField(widget=forms.FileInput(
attrs={'multiple': True}), required=True, label='Upload File(s)')
def clean(self):
uploadFiles = self.files.getlist('uploadfile')
try:
for uploadFile in uploadFiles:
if MAX_FILE_SIZE < uploadFile.size:
raise forms.ValidationError(
'File {} exceeds maximum allowed file size of 15 MB!'.format(uploadFile.name))
uploadFileFormat = os.path.splitext(
uploadFile.name)[1].lower()[1:]
if uploadFileFormat not in validFormats and \
uploadFileFormat.isdigit() is False:
raise forms.ValidationError(
'File {} has invalid file format!'.format(uploadFile.name))
# okay now i have one more part i.e. file validation validate which i will work on later
return uploadFiles
except Exception:
raise forms.ValidationError(
'File {} could not be validated!'.format(uploadFile.name))
class SyncATMForm(forms.Form):
atm_list = (('', ''),)
atm_id = forms.ChoiceField(
label='Select ATM', choices=atm_list, required=True)
self.fields['atm_id'].choices = atm_list