Exemple #1
0
def countries():
    if 'username' in session:

        system = System()
        countries = system.countries()
        login_user = system.getUser(session.get('username'))
        error = None
        if request.method == 'POST':

            country = request.form['country']
            region = request.form['region']

            if len(country) < 1:
                abort(400, 'No country entered')
            elif len(region) < 1:
                abort(400, 'No region selected')

            email = session.get('username')
            response = User(email).createCountry(region,country)
            if response == 0:
                error = country + ' added to region ' + region+', refresh browser to see update'
                flash("Country added Successfully")
                countries = system.countries()
                return render_template('country.html', login_user=login_user, error=error,countries=countries)
            if response == 506:

                abort(400,'No data insertion was made, please check Internet connectivity')
            if response == 1:
                error = country + ' already exist'
                return render_template('country.html', login_user=login_user, error=error,countries=countries)
        return render_template('country.html', login_user=login_user, error=error,countries=countries)

    return redirect(url_for("Index"))
Exemple #2
0
def countries():
    if 'username' in session:

        system = System()
        countries = system.countries()
        login_user = system.getUser(session.get('username'))
        error = None
        if request.method == 'POST':

            country = request.form['country']
            region = request.form['region']

            if len(country) < 1:
                abort(400, 'No country entered')
            elif len(region) < 1:
                abort(400, 'No region selected')

            email = session.get('username')
            response = User(email).createCountry(region, country)
            if response == 0:
                error = country + ' added to region ' + region + ', refresh browser to see update'
                flash("Country added Successfully")
                countries = system.countries()
                return render_template('country.html',
                                       login_user=login_user,
                                       error=error,
                                       countries=countries)
            if response == 506:

                abort(
                    400,
                    'No data insertion was made, please check Internet connectivity'
                )
            if response == 1:
                error = country + ' already exist'
                return render_template('country.html',
                                       login_user=login_user,
                                       error=error,
                                       countries=countries)
        return render_template('country.html',
                               login_user=login_user,
                               error=error,
                               countries=countries)

    return redirect(url_for("Index"))
Exemple #3
0
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"))
Exemple #4
0
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"))
Exemple #5
0
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"))
Exemple #6
0
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"))