コード例 #1
0
def notification():
    # Initialize SDK
    username = "******"
    api_key = "1d988c1ab828a49631413ae985e9ee72d6533458d18cc3b9570033e398c261b0"
    africastalking.initialize(username, api_key)

    # Initialize a service
    sms = africastalking.SMS

    if request.method == 'POST':
        try:
            # fetch all records
            allRecords = Operators.fetch_all()

            # get the phone numbers(number.telephoneNo)
            for number in allRecords:
                # convert to a string
                newNumbers = str(number.telephoneNo)
                # add +254 to each number
                allNumbers = ['+254' + newNumbers]

                # send the message/Notification to all phone numbers
                for x in allNumbers:
                    message = request.form['message']
                    # send the message
                    response = sms.send(message, [x])
                    print(response)

            flash('Message sent successfully', 'success')

        except Exception as e:
            flash('Error! Unable to send message', 'danger')
            print(e)

    return redirect(url_for('dashboard'))
コード例 #2
0
def vehicles():
    displayAll = Vehicles.fetch_all()

    if request.method == 'POST':
        try:
            plateno = request.form['plateno']
            seats = request.form['seats']
            route = request.form['route']
            licenseNo = request.form['licenseNo']
            insuranceCompany = request.form['insuranceCompany']
            insuranceExpiryDate = request.form['expirydate']
            operatorId = request.form['operatorId']

            vehicle = Vehicles(plateNo=plateno,
                               seats=seats,
                               route=route,
                               licenseNo=licenseNo,
                               insuranceCompany=insuranceCompany,
                               insuranceExpiryDate=insuranceExpiryDate,
                               operatorId=operatorId)
            vehicle.create_vehicles()

            flash('Vehicle successfully added', 'success')
            return redirect(url_for('vehicles'))
        except Exception as e:
            print(e)

    operators = Operators.fetch_all()

    return render_template('vehicles.html',
                           operators=operators,
                           allvehicles=displayAll)
コード例 #3
0
def contributions():

    displayAll = Contributions.fetch_all()

    if request.method == 'POST':
        try:
            amount = request.form['amount']
            dateTime = request.form['dateTime']
            paymentForm = request.form['paymentForm']
            operator = request.form['operatorId']

            contributions = Contributions(amount=amount,
                                          dateTime=dateTime,
                                          paymentForm=paymentForm,
                                          operator_id=operator)
            contributions.create_contributions()

            flash('Monthly Contributions paid', 'success')
            return redirect(url_for('contributions'))
        except Exception as e:
            print(e)

    operators = Operators.fetch_all()

    return render_template('contributions.html',
                           operators=operators,
                           allContributions=displayAll)
コード例 #4
0
def deleteRecord(id):
    deleted = Operators.delete_by_id(id)
    if deleted:
        flash('Deleted Successfully')
        return redirect(url_for('operators'))
    else:
        flash('Record not found')
        return redirect(url_for('operators'))
コード例 #5
0
def loginOperator():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']

        # check if email exist
        if Operators.check_email_exist(email=email):
            # if the email exists check if password is correct
            if Operators.check_password(email=email, password=password):
                session['logged_in'] = True
                session['operator'] = Operators.fetch_by_email(email).firstname
                session['mail'] = Operators.fetch_by_email(email).email
                return redirect(request.form['next']
                                or url_for('operatorPage'))
            else:
                flash('Incorrect password', 'danger')
                return render_template('operatorlogin.html')
        else:
            flash('Email does not exist', 'danger')
    return render_template('operatorlogin.html')
コード例 #6
0
def operators():

    displayAll = Operators.fetch_all()

    if request.method == 'POST':
        try:
            email = request.form['email']
            password = request.form['password']
            firstname = request.form['firstName']
            lastname = request.form['lastName']
            gender = request.form['gender']
            telephoneno = request.form['telephoneNo']

            operator = Operators(firstname=firstname,
                                 lastname=lastname,
                                 gender=gender,
                                 telephoneNo=telephoneno,
                                 email=email,
                                 password=password)
            operator.create_operators()

            flash('Operator succesfully added', 'success')
            return redirect(url_for('operators'))
        except Exception as e:
            print(e)

    operators = Operators.fetch_all()
    return render_template('operators.html',
                           operators=operators,
                           allOperators=displayAll)
コード例 #7
0
def editRecord(id):
    newEmail = request.form['email']
    newPassword = request.form['password']
    newFirstname = request.form['firstName']
    newLastname = request.form['lastName']
    newGender = request.form['gender']
    newTelephoneNo = request.form['telephoneNo']
    update = Operators.update_by_id(id=id,
                                    newEmail=newEmail,
                                    newPassword=newPassword,
                                    newFirstname=newFirstname,
                                    newLastname=newLastname,
                                    newGender=newGender,
                                    newTelephoneNo=newTelephoneNo)

    if update:
        flash('Update Succesful', 'success')
        return redirect(url_for('operators'))
    else:
        flash('Record not found')
        return redirect(url_for('operators'))
コード例 #8
0
def operatorPage():
    try:
        if session:
            if session['operator']:
                operator = Operators.fetch_by_email(session['mail'])

                for each in operator.vehicles:
                    print(each.plateNo)

                totalcontribs = 0
                for each in operator.contributions:
                    totalcontribs += each.amount

                return render_template('operatorsusers.html',
                                       operator=operator,
                                       totalcontribs=totalcontribs)
            else:
                return redirect(url_for('loginOperator'))
        else:
            return redirect(url_for('loginOperator'))
    except KeyError:
        return redirect(url_for('loginOperator'))