Example #1
0
def expenditureForm():
    '''
    Route for exenditure form page. 
    On GET, renders blank form.
    On POST, collects and validates data and if valid, adds to database. 
       Renders form again with submission confirmation flashed.
    '''

    if request.method == 'GET':
        return render_template('expenditures.html')

    else:
        # Collect Expenditure Data
        expenditure = {
            'expenditure-category': request.form['expenditure-category'],
            'amount': request.form['expenditure-amount'],
            'expenditure-description': request.form['expenditure-description'],
            'date': date.today()
        }

        # Validate Expenditure Data
        validation_result = expenditureBackend.validate_expenditure(
            expenditure)
        if len(validation_result) != 0:
            for msg in validation_result:
                flash(msg)
            return (redirect(url_for('expenditureForm')))

        # Submit to Expenditure DB
        conn = get_conn()
        expend_id = expenditureBackend.add_expend(expenditure, conn)
        flash('Expenditure ID: ' + str(expend_id))
        return render_template('expenditures.html')
Example #2
0
def updateInventoryForm():
    '''Collects information from update inventory form
    passes this information to backend to update inventory table'''

    conn = get_conn()
    allItemTypes = search_inventory_history.getInventoryItemTypes(conn)

    if request.method == 'GET':
        return render_template('updateInventory.html', inventory=allItemTypes)

    else:
        updatedItem = {
            'item_id': request.form['inventoryItem'],
            'amount': request.form['new-amount'],
            'threshold': request.form['new-threshold'],
            'date': date.today()
        }

    #ensures an amount is entered for threshold if current value is none
    if updatedItem['threshold'] == "":
        currentStatus = search_inventory_history.getStatus(
            conn, updatedItem['item_id'])

        if (currentStatus[0]['status'] == "null"):
            flash("Please set a threshold for item " + updatedItem['item_id'])
            return (redirect(url_for('updateInventoryForm')))

    flash('Inventory item ' + updatedItem['item_id'] + ' Updated')
    search_inventory_history.updateInventory(conn, updatedItem['item_id'],
                                             updatedItem['amount'],
                                             updatedItem['threshold'])
    return render_template('updateInventory.html', inventory=allItemTypes)
Example #3
0
def sandbox():
    conn = get_conn()
    donor_list = donationBackend.get_donors(conn)
    donation_list = donationBackend.get_inventory_items(conn)
    return render_template('donation_form.html',
                           donor_list=donor_list,
                           donation_list=donation_list)
Example #4
0
def hint_widget(type_, widget_id, contents):
    conn = connection.get_conn()
    content_encoded = []
    for content in contents:
        content_encoded.append(base64.b64encode(content.encode('utf-8')))
    conn.send_event("Hint" + type_, widget_id, len(content_encoded),
                    *content_encoded)
Example #5
0
def join():
    '''allows user to join by creating a username and password, checks if username is
    unique, encyrpts passwords and stores it'''
    try:
        username = request.form['username']
        passwd1 = request.form['password1']
        passwd2 = request.form['password2']
        if passwd1 != passwd2:
            flash('passwords do not match')
            return redirect(url_for('index'))
        hashed = bcrypt.hashpw(passwd1.encode('utf-8'), bcrypt.gensalt())
        conn = get_conn()
        curs = conn.cursor(MySQLdb.cursors.DictCursor)
        curs.execute('SELECT username FROM userpass WHERE username = %s',
                     [username])
        row = curs.fetchone()
        if row is not None:
            flash('That username is taken')
            return redirect(url_for('index'))
        curs.execute('INSERT into userpass(username,hashed) VALUES(%s,%s)',
                     [username, hashed])
        session['username'] = username
        session['logged_in'] = True
        flash('successfully logged in as ' + username)
        return redirect(url_for('index'))
    except Exception as err:
        flash('form submission error ' + str(err))
        return redirect(url_for('index'))
Example #6
0
def login():
    '''allows user to login, confirms username and password combination are valid'''
    try:
        username = request.form['username']
        passwd = request.form['password']
        conn = get_conn()
        curs = conn.cursor(MySQLdb.cursors.DictCursor)
        curs.execute('SELECT hashed FROM userpass WHERE username = %s',
                     [username])
        row = curs.fetchone()
        if row is None:
            # Same response as wrong password, so no information about what went wrong
            flash('login incorrect. Try again or join')
            return redirect(url_for('index'))
        hashed = row['hashed']
        # strings always come out of the database as unicode objects
        if bcrypt.hashpw(passwd.encode('utf-8'),
                         hashed.encode('utf-8')) == hashed:
            flash('successfully logged in as ' + username)
            session['username'] = username
            session['logged_in'] = True
            return redirect(url_for('index'))
        else:
            flash('login incorrect. Try again or join')
            return redirect(url_for('index'))
    except Exception as err:
        flash('form submission error ' + str(err))
        return redirect(url_for('index'))
Example #7
0
def notify_intent(intent):
    assert 'activity' in intent
    (args, nargs) = intentlib.obtain_intent_args(intent)
    args.append('comp')
    args.append(intent['activity']['name'])
    nargs += 1
    conn = connection.get_conn()
    conn.send_event("AddIntent", 0.01, 1, nargs, *args)
Example #8
0
def notify_intent(intent):
    assert 'activity' in intent
    (args, nargs) = intentlib.obtain_intent_args(intent)
    args.append('comp')
    args.append(intent['activity']['name'])
    nargs += 1
    conn = connection.get_conn()
    conn.send_event("AddIntent", 0.01, 1, nargs, *args)
Example #9
0
def list_all() -> list[Ox]:
    with get_conn() as conn:
        cursor = conn.cursor()
        cursor.execute("SELECT identificador, raca, peso FROM boi;")

        return [
            Ox(identifier=line[0], breed=line[1], weight=line[2])
            for line in cursor.fetchall()
        ]
Example #10
0
def get_view_by_class(cls):
    conn = connection.get_conn()
    event_id = conn.send_event("FindViewByClass", cls)
    result = conn.wait_result(event_id)
    try:
        int(result[0], 16)
        return result[0]
    except:
        return None
Example #11
0
def dump_view(widget_id):
    conn = connection.get_conn()
    event_id = conn.send_event("GetViewGeo", widget_id)
    result = conn.wait_result(event_id)
    xresult = []
    for i in result:
        xresult += [int(i)]

    return xresult
Example #12
0
def get_view_by_class(cls):
    conn = connection.get_conn()
    event_id = conn.send_event("FindViewByClass", cls)
    result = conn.wait_result(event_id)
    try:
        int(result[0], 16)
        return result[0]
    except:
        return None
Example #13
0
def get_view_child(view_id, entry):
    conn = connection.get_conn()
    event_id = conn.send_event("GetViewChild", view_id, entry)
    result = conn.wait_result(event_id)
    try:
        int(result[0], 16)
        return result[0]
    except:
        return None
Example #14
0
def get_view_child(view_id, entry):
    conn = connection.get_conn()
    event_id = conn.send_event("GetViewChild", view_id, entry)
    result = conn.wait_result(event_id)
    try:
        int(result[0], 16)
        return result[0]
    except:
        return None
Example #15
0
def dump_view(widget_id):
    conn = connection.get_conn()
    event_id = conn.send_event("GetViewGeo", widget_id)
    result = conn.wait_result(event_id)
    xresult = []
    for i in result:
        xresult += [int(i)]

    return xresult
Example #16
0
def get(identifier: int) -> Ox:
    with get_conn() as conn:
        cursor = conn.cursor()
        cursor.execute(
            "SELECT identificador, raca, peso FROM boi WHERE identificador = ?;",
            (identifier, ))

        line = cursor.fetchone()

        return Ox(identifier=line[0], breed=line[1], weight=line[2])
Example #17
0
def get_leaner() -> Ox:
    with get_conn() as conn:
        cursor = conn.cursor()
        cursor.execute(
            "SELECT identificador, raca, peso FROM boi ORDER BY peso ASC limit 1;"
        )

        line = cursor.fetchone()

        return Ox(identifier=line[0], breed=line[1], weight=line[2])
Example #18
0
def filter_by_breed(breed) -> list[Ox]:
    with get_conn() as conn:
        cursor = conn.cursor()
        cursor.execute(
            "SELECT identificador, raca, peso FROM boi WHERE raca = ?  ORDER BY identificador ASC;",
            (breed, ))

        return [
            Ox(identifier=line[0], breed=line[1], weight=line[2])
            for line in cursor.fetchall()
        ]
Example #19
0
def run(input_path, output_path):
    with open(output_path, "w") as f:
        # Check whether we can write to output_path before doing any work.
        pass

    with open(input_path) as f:
        sql = f.read()

    conn = get_conn()
    cursor = conn.cursor()
    cursor.execute(sql)

    with open(output_path, "w") as f:
        writer = csv.writer(f)
        writer.writerow([col[0] for col in cursor.description])
        writer.writerows(cursor)
Example #20
0
def filterDonations():
    '''Route that deals with all sorting and filtering of donations table'''
    conn = get_conn()
    dropdownType = request.form.get("menu-tt")
    print dropdownType
    checkboxType = request.form.get("type")
    donationByType = search_donation_history.getDonationByType(
        conn, checkboxType)
    allDonations = search_donation_history.getAllDonationHistoryInfo(conn)

    if dropdownType == "none":  #No drop down selected
        #No drop down or checkboxes are selected
        if checkboxType is None:
            return render_template('donations.html', allDonations=allDonations)

        else:  #No drop down selected but at least one checkbox selected
            if (len(donationByType) == 0):  #No items of checkboxType
                flash("There are no donations of type: " + checkboxType)
            return render_template('donations.html',
                                   allDonations=donationByType)

    else:  # Drop down is selected
        #Drop down selected but not checkbox
        if checkboxType is None:
            if (dropdownType == "Most Recent Donation"):
                donationsOrdered = search_donation_history.sortDonationByDateDescending(
                    conn)
                return render_template('donations.html',
                                       allDonations=donationsOrdered)
            elif (dropdownType == "Oldest Donation First"):
                donationsOrdered = search_donation_history.sortDonationByDateAscending(
                    conn)
                return render_template('donations.html',
                                       allDonations=donationsOrdered)
            else:
                donationsOrdered = search_donation_history.sortDonationType(
                    conn)
                return render_template('donations.html',
                                       allDonations=donationsOrdered)
        #Drop down and checkbox both selected!
        else:
            filtered = search_donation_history.combineFilters(
                conn, checkboxType, dropdownType)
            return render_template('donations.html', allDonations=filtered)
Example #21
0
def filterInventory():
    '''Route that deals with all sorting and filtering of inventory table'''
    conn = get_conn()
    dropdownType = request.form.get("menu-tt")
    print dropdownType
    checkboxType = request.form.get("type")
    inventoryByType = search_inventory_history.getInventoryByType(
        conn, checkboxType)
    allInventory = search_inventory_history.getInventoryItemTypes(conn)

    if dropdownType == "none":  #No drop down selected
        #No drop down or checkboxes are selected
        if checkboxType is None:
            return render_template('inventory.html', allInventory=allInventory)

        else:  #No drop down selected but at least one checkbox selected
            if (len(inventoryByType) == 0):  #No items of checkboxType
                flash("There are no inventory items of type: " + checkboxType)
            return render_template('inventory.html',
                                   allInventory=inventoryByType)

    else:  # Drop down is selected
        #Drop down selected but not checkbox
        if checkboxType is None:
            if dropdownType == "Status (Low to High)":
                sortInventory = search_inventory_history.sortInventoryStatus(
                    conn)
                return render_template('inventory.html',
                                       allInventory=sortInventory)
            else:
                sortInventory = search_inventory_history.sortInventoryType(
                    conn)
                return render_template('inventory.html',
                                       allInventory=sortInventory)
        #Drop down and checkbox both selected!
        else:
            filtered = search_inventory_history.combineFilters(
                conn, checkboxType, dropdownType)
            return render_template('inventory.html', allInventory=filtered)
Example #22
0
def index():
    conn = get_conn()
    inventoryTotal = search_inventory_history.countInventoryTotal(conn)
    lowList = search_inventory_history.listLowItems(conn)
    lastWeekDonations = search_donation_history.donationsPastWeek(conn)
    lowCount = search_inventory_history.statusCount(conn, "low")
    highCount = search_inventory_history.statusCount(conn, "high")
    donationTotal = search_donation_history.countDonationTotal(conn)
    donorTotal = search_donation_history.countDonorTotal(conn)
    expenditureTotal = expenditureBackend.countExpenditureTotal(conn)
    mostSpent = expenditureBackend.mostExpensiveType(conn)
    leastSpent = expenditureBackend.leastExpensiveType(conn)
    return render_template('index.html',
                           inventoryTotal=inventoryTotal,
                           lowList=lowList,
                           lowCount=lowCount,
                           highCount=highCount,
                           lastWeekDonations=lastWeekDonations,
                           donationTotal=donationTotal,
                           donorTotal=donorTotal,
                           expenditureTotal=expenditureTotal,
                           mostSpent=mostSpent,
                           leastSpent=leastSpent)
Example #23
0
def start():
    result = None
    exc = None
    for i in range(START_ATTEMPT):
        try:
            conn = connection.get_conn()
            result = conn.wait_result(conn.send_event("Start"))
            break
        except exception.ConnectionBroken as e:
            exc = e
            if "reset" in e.message:
                logger.info("start failed: conn. reset. retry %d" % i)
                connection.close_conn()
                time.sleep(START_INTERVAL)
            else:
                raise e
    if result is None:
        raise exc

    ins_path = result[0]
    ins_path = base64.b64decode(ins_path)
    wait_for_idle()

    return ins_path
Example #24
0
def start():
    result = None
    exc = None
    for i in range(START_ATTEMPT):
        try:
            conn = connection.get_conn()
            result = conn.wait_result(conn.send_event("Start"))
            break
        except exception.ConnectionBroken as e:
            exc = e
            if "reset" in e.message:
                logger.info("start failed: conn. reset. retry %d" % i)
                connection.close_conn()
                time.sleep(START_INTERVAL)
            else:
                raise e
    if result is None:
        raise exc

    ins_path = result[0]
    ins_path = base64.b64decode(ins_path)
    wait_for_idle()

    return ins_path
Example #25
0
def hint_widget(type_, widget_id, contents):
    conn = connection.get_conn()
    content_encoded = []
    for content in contents:
        content_encoded.append(base64.b64encode(content.encode('utf-8')))
    conn.send_event("Hint" + type_, widget_id, len(content_encoded), *content_encoded)
Example #26
0
def add_checker(cls, checker):
    conn = connection.get_conn()
    conn.send_event("AddChecker", cls, checker)
Example #27
0
def change_dpi(dpi):
    conn = connection.get_conn()
    conn.send_event("ChangeDpi", dpi)
Example #28
0
def menu_click(menu_id):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("MenuClick", menu_id))
Example #29
0
def rotate():
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("Rotate"))
Example #30
0
def mouse_click(x, y):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("PointerClickOnPoint", x, y))
Example #31
0
def mouse_up(widget_id, x, y):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("MouseUp", x, y))
Example #32
0
def collect():
    conn = connection.get_conn()
    return conn.wait_result(conn.send_event("Collect"))
Example #33
0
def key_up(key):
    conn = connection.get_conn()
    conn.send_event("KeyUp", key)
Example #34
0
def get_text(widget_id):
    conn = connection.get_conn()
    conn.send_event("get_text", widget_id)
Example #35
0
def long_click(widget_id):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("LongClick", widget_id))
Example #36
0
def enable_checker():
    conn = connection.get_conn()
    conn.send_event("EnableChecker")
Example #37
0
def unhint_edit(edit_id):
    conn = connection.get_conn()
    conn.send_event("UnhintEdit", edit_id)
Example #38
0
def key_up(key):
    conn = connection.get_conn()
    conn.send_event("KeyUp", key)
Example #39
0
def mouse_down(widget_id, x, y):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("MouseDown", x, y))
Example #40
0
def enable_lcc():
    conn = connection.get_conn()
    conn.send_event("EnableLifeCycleChecker")
Example #41
0
def wait_for_idle():
    conn = connection.get_conn()
    event_id = conn.send_event("WaitForIdle")
    conn.wait_result(event_id)
Example #42
0
def select(op):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("Select", op))
Example #43
0
def crawl():
    conn = connection.get_conn()
    conn.send_event("Crawl")
Example #44
0
def notify_broadcast(intent):
    assert 'receiver' in intent
    (args, nargs) = intentlib.obtain_intent_args(intent)
    conn = connection.get_conn()
    conn.send_event("AddBroadcast", 0.01, 1, nargs, *args)
Example #45
0
def get_widget_id(name):
    conn = connection.get_conn()
    result = conn.wait_result(conn.send_event("GetViewId", name))
    int(result[0], 16)
    return result[0]
Example #46
0
def long_click(widget_id):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("LongClick", widget_id))
Example #47
0
def enter(widget_id, text):
    conn = connection.get_conn()
    click(widget_id)
    conn.send_event_sync("Input", base64.b64encode(text))
Example #48
0
def get_text(widget_id):
    conn = connection.get_conn()
    conn.send_event("get_text", widget_id)
Example #49
0
def purge_checkers():
    conn = connection.get_conn()
    conn.send_event("RemoveAllCheckers", "View")
    conn.send_event("RemoveAllCheckers", "General")
    conn.send_event("RemoveAllCheckers", "Orientation")
Example #50
0
def key_down(key):
    conn = connection.get_conn()
    conn.send_event("KeyDown", key)
Example #51
0
def enable_lcc():
    conn = connection.get_conn()
    conn.send_event("EnableLifeCycleChecker")
Example #52
0
def disable_checker():
    conn = connection.get_conn()
    conn.send_event("DisableChecker")
Example #53
0
def notify_broadcast(intent):
    assert 'receiver' in intent
    (args, nargs) = intentlib.obtain_intent_args(intent)
    conn = connection.get_conn()
    conn.send_event("AddBroadcast", 0.01, 1, nargs, *args)
Example #54
0
def should_change_dpi():
    conn = connection.get_conn()
    return True if conn.wait_result(conn.send_event("ShouldChangeDpi"))[0] == "YES" else False
Example #55
0
def enter(widget_id, text):
    conn = connection.get_conn()
    click(widget_id)
    conn.send_event_sync("Input", base64.b64encode(text))
Example #56
0
def change_dpi(dpi):
    conn = connection.get_conn()
    conn.send_event("ChangeDpi", dpi)
Example #57
0
def key_down(key):
    conn = connection.get_conn()
    conn.send_event("KeyDown", key)
Example #58
0
def purge_checkers():
    conn = connection.get_conn()
    conn.send_event("RemoveAllCheckers", "View")
    conn.send_event("RemoveAllCheckers", "General")
    conn.send_event("RemoveAllCheckers", "Orientation")
Example #59
0
def mouse_down(widget_id, x, y):
    conn = connection.get_conn()
    conn.wait_result(conn.send_event("MouseDown", x, y))
Example #60
0
def add_checker(cls, checker):
    conn = connection.get_conn()
    conn.send_event("AddChecker", cls, checker)