def Did(): if session.get('username'): system = System() login_user = system.getUser(session.get('username')) pins = system.pins() countries = system.countries() dids = system.dids() error = None if request.method == 'POST': file = request.files['did_file'] if not file: phone = request.form['phone'] cost = request.form['cost'] country = request.form['country'] capacity = request.form['capacity'] provider = request.form['provider'] mode = request.form['mode'] pin = request.form['pin'] if len(phone) < 1: abort(400, 'The phone number is invalid') elif len(cost) < 1: abort(400,'Invalid cost specified') elif len(country) < 1: abort(400, 'Invalid country code') elif len(capacity) < 1: abort(400, 'Please select capacity') elif len(provider) < 1: abort(400, 'Please select provider') elif len(mode) < 1: abort(400, 'Please select mode') elif len(pin) < 1: abort(400, 'Please select pin') email = session.get('username') response = User(email).createDid(phone,provider,cost,country,capacity,mode,pin) if response == 0: flash('DID Successfully created') error = 'DID Successfully created with pin '+pin return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries) elif response == 1: abort(400, 'DID %s already exist'%(phone)) else: abort(400, 'DID is not created') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_dids = System().readCSV(fileUrl) insert_dids = System().insertDids(data_list_dids) error = str(insert_dids) + ' DIDs has been uploaded and saved' except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' return render_template('did.html', login_user=login_user, error=error, did_file=file, dids=dids,pins=pins,countries=countries) return render_template('did.html', login_user=login_user, error=error, pins=pins, dids=dids,countries=countries) return redirect(url_for("Index"))
def Own(): if session.get('username'): system = System() login_user = system.getUser(session.get('username')) dids = system.dids() owns = system.owns() error = None if request.method == 'POST': file = request.files['own_file'] if not file: sim = request.form['sim'] did = request.form['did'] if len(sim) < 1: abort(400, 'Please enter a SIM number') elif len(did) < 1: abort(400,'Please select a did') email = session.get('username') response = User(email).createSim(sim,did) if response == 0: flash('OWN Successfully created') error = 'OWN Successfully created with did '+did return render_template('own.html', login_user=login_user, error=error,owns=owns) elif response == 1: abort(400, 'OWN %s already exist with SIM '%(sim)) elif response == 506: abort(400, 'Error:'+response+', Data insertion error') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_owns = system.readCSV(fileUrl) insert_owns = system.insertOwns(data_list_owns) error = str(insert_owns) + ' OWN has been uploaded and saved' #error = data_list_owns except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' return render_template('own.html', login_user=login_user, error=error, own_file=file, owns=owns) return render_template('own.html', login_user=login_user, error=error, dids=dids, owns=owns) return redirect(url_for("Index"))
def Did(): if 'username' in session: db.session.commit() ###### commit to the database system = System() login_user = system.getUser(session.get('username')) pins = system.available_pins() countries = system.countries() dids = system.dids() count_available_dids = system.count_available_dids() error = None if request.method == 'POST': file = request.files['did_file'] if not file: phone = request.form['phone'] cost = request.form['cost'] country = request.form['country'] capacity = request.form['capacity'] provider = request.form['provider'] mode = request.form['mode'] pin = request.form['pin'] if len(phone) < 1: abort(400, 'The phone number is invalid') elif len(cost) < 1: abort(400, 'Invalid cost specified') elif len(country) < 1: abort(400, 'Invalid country code') elif len(capacity) < 1: abort(400, 'Please select capacity') elif len(provider) < 1: abort(400, 'Please select provider') elif len(mode) < 1: abort(400, 'Please select mode') elif mode == 'PIN-DIALING' and len(pin) < 1: abort(400, 'Please select pin') elif mode == 'DIRECT-DIALING': pin = None email = session.get('username') response = User(email).createDid(phone, provider, cost, country, capacity, mode, pin) if response == 0: flash('DID Successfully created') dids = system.dids() pins = system.available_pins() error = 'DID Successfully created ' + phone #return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries) return redirect('/did') elif response == 1: abort(400, 'DID %s already exist' % (phone)) elif response == 506: abort( 400, 'A technical error occured, this has to do with the application program the mode for the pin in the (PIN) table' ) else: abort(400, 'DID is not created') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] + filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_dids = System().readCSV(fileUrl) insert_dids = System().insertDids(data_list_dids) error = str( insert_dids['insertnum'] ) + ' DIDs has been uploaded in total of ' + str( insert_dids['total']) except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' ###### After the browsers refresh when uploading from a file dids = system.dids() pins = system.available_pins() count_available_dids = system.count_available_dids() return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, did_file=file, dids=dids, pins=pins, countries=countries) ###### When the browser is using other method apart from GET db.session.rollback() dids = system.dids() pins = system.available_pins() count_available_dids = system.count_available_dids() return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, pins=pins, dids=dids, countries=countries) return redirect(url_for("Index"))
def Own(): if 'username' in session: db.session.commit() ###### commit to the database system = System() login_user = system.getUser(session.get('username')) dids = system.dids() owns = system.owns() error = None if request.method == 'POST': file = request.files['own_file'] if not file: sim = request.form['sim'] did = request.form['did'] if len(sim) < 1: abort(400, 'Please enter a SIM number') elif len(did) < 1: abort(400, 'Please select a did') email = session.get('username') response = User(email).createSim(sim, did) if response == 0: flash('OWN Successfully created') error = 'OWN Successfully created with did ' + did owns = system.owns() return redirect('/own') elif response == 1: abort(400, 'OWN %s already exist with SIM ' % (sim)) elif response == 506: abort(400, 'Error:' + response + ', Data insertion error') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] + filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_owns = system.readCSV(fileUrl) insert_owns = system.insertOwns(data_list_owns) error = error = str( insert_owns['insertnum'] ) + ' Owns has been uploaded in total of ' + str( insert_owns['total']) #error = data_list_owns except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' owns = system.owns() return render_template('own.html', login_user=login_user, error=error, own_file=file, owns=owns) db.session.commit() ###### commit to the database dids = system.dids() owns = system.owns() return render_template('own.html', login_user=login_user, error=error, dids=dids, owns=owns) return redirect(url_for("Index"))
def Did(): if session.get('username'): system = System() login_user = system.getUser(session.get('username')) pins = system.pins() countries = system.countries() dids = system.dids() error = None if request.method == 'POST': file = request.files['did_file'] if not file: phone = request.form['phone'] cost = request.form['cost'] country = request.form['country'] capacity = request.form['capacity'] provider = request.form['provider'] mode = request.form['mode'] pin = request.form['pin'] if len(phone) < 1: abort(400, 'The phone number is invalid') elif len(cost) < 1: abort(400, 'Invalid cost specified') elif len(country) < 1: abort(400, 'Invalid country code') elif len(capacity) < 1: abort(400, 'Please select capacity') elif len(provider) < 1: abort(400, 'Please select provider') elif len(mode) < 1: abort(400, 'Please select mode') elif len(pin) < 1: abort(400, 'Please select pin') email = session.get('username') response = User(email).createDid(phone, provider, cost, country, capacity, mode, pin) if response == 0: flash('DID Successfully created') error = 'DID Successfully created with pin ' + pin return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries) elif response == 1: abort(400, 'DID %s already exist' % (phone)) else: abort(400, 'DID is not created') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save( os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER'] + filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_dids = System().readCSV(fileUrl) insert_dids = System().insertDids(data_list_dids) error = str( insert_dids) + ' DIDs has been uploaded and saved' except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' return render_template('did.html', login_user=login_user, error=error, did_file=file, dids=dids, pins=pins, countries=countries) return render_template('did.html', login_user=login_user, error=error, pins=pins, dids=dids, countries=countries) return redirect(url_for("Index"))
def Did(): if 'username' in session: db.session.commit() ###### commit to the database system = System() login_user = system.getUser(session.get('username')) pins = system.available_pins() countries = system.countries() dids = system.dids() count_available_dids = system.count_available_dids() error = None if request.method == 'POST': file = request.files['did_file'] if not file: phone = request.form['phone'] cost = request.form['cost'] country = request.form['country'] capacity = request.form['capacity'] provider = request.form['provider'] mode = request.form['mode'] pin = request.form['pin'] if len(phone) < 1: abort(400,'The phone number is invalid') elif len(cost) < 1: abort(400,'Invalid cost specified') elif len(country) < 1: abort(400,'Invalid country code') elif len(capacity) < 1: abort(400,'Please select capacity') elif len(provider) < 1: abort(400,'Please select provider') elif len(mode) < 1: abort(400,'Please select mode') elif mode == 'PIN-DIALING' and len(pin) < 1: abort(400,'Please select pin') elif mode == 'DIRECT-DIALING': pin = None email = session.get('username') response = User(email).createDid(phone,provider,cost,country,capacity,mode,pin) if response == 0: flash('DID Successfully created') dids = system.dids() pins = system.available_pins() error = 'DID Successfully created '+phone #return render_template('did.html', login_user=login_user, error=error, dids=dids, pins=pins, countries=countries) return redirect('/did') elif response == 1: abort(400,'DID %s already exist'%(phone)) elif response == 506: abort(400,'A technical error occured, this has to do with the application program the mode for the pin in the (PIN) table') else: abort(400,'DID is not created') if System().allowed_file(file.filename): filename = secure_filename(file.filename) try: file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) fileUrl = os.path.abspath(app.config['UPLOAD_FOLDER']+filename) #fileUrl = path(app.config['UPLOAD_FOLDER']+filename).abspath() error = 'File uploaded : Path -> ' + fileUrl data_list_dids = System().readCSV(fileUrl) insert_dids = System().insertDids(data_list_dids) error = str(insert_dids['insertnum']) + ' DIDs has been uploaded in total of '+ str(insert_dids['total']) except: error = 'File not uploaded Successfully' else: error = 'File format is not allowed' ###### After the browsers refresh when uploading from a file dids = system.dids() pins = system.available_pins() count_available_dids = system.count_available_dids() return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, did_file=file, dids=dids,pins=pins,countries=countries) ###### When the browser is using other method apart from GET db.session.rollback() dids = system.dids() pins = system.available_pins() count_available_dids = system.count_available_dids() return render_template('did.html', login_user=login_user, countdids=count_available_dids, error=error, pins=pins, dids=dids,countries=countries) return redirect(url_for("Index"))