0% found this document useful (0 votes)
40 views2 pages

From Import Import From Import From Import Try From Import Except Pass

This document defines forms for uploading multiple files and syncing ATM devices in Django. It imports necessary modules, defines constants for media sub-folders and valid file formats. The UploadMultipleFileForm allows selecting a report type and uploading multiple files, validating the file size and format. The SyncATMForm dynamically populates the ATM dropdown based on available devices, for selecting an ATM to sync.

Uploaded by

ritesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

From Import Import From Import From Import Try From Import Except Pass

This document defines forms for uploading multiple files and syncing ATM devices in Django. It imports necessary modules, defines constants for media sub-folders and valid file formats. The UploadMultipleFileForm allows selecting a report type and uploading multiple files, validating the file size and format. The SyncATMForm dynamically populates the ATM dropdown based on available devices, for selecting an ATM to sync.

Uploaded by

ritesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

from django import forms

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)

def __init__(self, *args, **kwargs):


super(self.__class__, self).__init__(*args, **kwargs)
try:
atm_list = globalVariables.atm_listFunc()
except Exception as e:
print(e)
atm_list = (('', ''),)

self.fields['atm_id'].choices = atm_list

You might also like