def destination_new(user_id): if session.get('username'): system = System() dids = system.available_dids() owns = system.owns() login_user = system.getUser(session.get('username')) user = system.getUserById(user_id) error = None if not user: return redirect('/customers') if request.method == 'POST': did = request.form['did'] own = request.form['own'] record = request.form['record'] auth_gw = request.form['auth_gw'] auth_did = request.form['auth_did'] gateway = request.form['gateway'] channel = request.form['channel'] number = request.form['number'] day = request.form['day'] month = request.form['month'] year = request.form['year'] string_date = year + '-' + month + '-' + day + ' 12:00:00' end_date = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S") email = session.get('username') response = User(email).destination_new(user_id, did, number, record, auth_did, auth_gw, gateway, channel, own, end_date) if response == 0: error = "Destination created for origin " if response == 1: error = " Destination number already exist with origin " return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns) return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns) return redirect('/')
def destination_new(user_id): if 'username' in session: db.session.commit() ####### Make a recent call to the database system = System() dids = system.available_dids() owns = system.owns() login_user = system.getUser(session.get('username')) user = system.getUserById(user_id) error = None if not user: return redirect('/customers') if request.method == 'POST': did = request.form['did'] own = request.form['own'] gateway = request.form['gateway'] channel = request.form['channel'] number = request.form['number'] day = request.form['day'] month = request.form['month'] year = request.form['year'] string_date = year + '-' + month + '-' + day + ' 12:00:00' end_date = datetime.datetime.strptime(string_date, "%Y-%m-%d %H:%M:%S") email = session.get('username') if not request.form.get('auth_did'): auth_did = "0" else: auth_did = request.form['auth_did'] if not request.form.get('auth_gw'): auth_gw = "0" else: auth_gw = request.form['auth_gw'] if not request.form.get('record'): record = "0" else: record = request.form['record'] response = User(email).destination_new(user_id,did,number,record,auth_did,auth_gw,gateway,channel,own,end_date) if response == 0: error = "Destination " + str(number) + " created successfully" if response == 1: error = " Destination number already exist with origin " db.session.commit() ####### Make a recent call to the database system = System() dids = system.available_dids() return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns) return render_template('destination-new.html', login_user=login_user, user=user, error=error, dids=dids, owns=owns) return redirect('/')
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 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"))