Exemplo n.º 1
0
def third_computer(id):
    dbwrapper = db_queries.DBWrapper(session['type'])
    concdevices = dbwrapper.concdevices_by_device_id(id)
    big_pretty_comp = pretty_data.big_computer(id, dbwrapper)
    small_pretty_comp = pretty_data.small_devices([id], [0], dbwrapper)[0]
    return render_template('Comp.html', big_comp=big_pretty_comp,
                                small_comp=small_pretty_comp,
                                conccomps=concdevices)
Exemplo n.º 2
0
def second():
    # need refactor dbwrapper calls
    dbwrapper = db_queries.DBWrapper(DEFFAULT_DEVICE_TYPE)
    # getting computers id:
    if "type" in request.args.keys():
        session["type"] = request.args["type"]
        dbwrapper = db_queries.DBWrapper(request.args["type"])
        devices_id, devices_dss, dss_dict = filtered_devices_id(FILTERS[dbwrapper.device], request.args, dbwrapper)
        if "user_id" in session:
            db_queries.delete_user(session["user_id"])
            del session["user_id"]
        user_id = db_queries.add_user(devices_id, devices_dss)
        session["user_id"] = user_id
    else:
        # first page (without_question)
        devices_id, devices_dss, dss_dict = None, None, {}  # nothing to return
        return render_template(
            "QandA.html",
            computers=[],
            filters=FILTERS[u"all"],
            pagination_pages=[],
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=True,
            prom=PROM,
        )

    if devices_id:
        last_page = int(round(float(len(devices_id)) / COMPUTERS_ON_PAGE + 0.49))
        first_comp_index = 0
        last_comp_index = min(COMPUTERS_ON_PAGE, len(devices_id))
        devices_id_on_page = devices_id[first_comp_index:last_comp_index]
        devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]
        pretty_devices = pretty_data.small_devices(devices_id_on_page, devices_dss_on_page, dbwrapper)
        return render_template(
            "QandA.html",
            computers=pretty_devices,
            filters=FILTERS[u"all"],
            pagination_pages=pretty_data.pagination_pages(last_page),
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM,
        )
    else:
        return render_template(
            "QandA.html",
            computers=[],
            filters=FILTERS[u"all"],
            pagination_pages=[],
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM,
        )
Exemplo n.º 3
0
def second():
    #need refactor dbwrapper calls
    dbwrapper = db_queries.DBWrapper(DEFFAULT_DEVICE_TYPE)
    #getting computers id:
    if 'type' in request.args.keys():
        session['type'] = request.args['type']
        dbwrapper = db_queries.DBWrapper(request.args['type'])
        devices_id, devices_dss, dss_dict = filtered_devices_id(
            FILTERS[dbwrapper.device], request.args, dbwrapper)
        if 'user_id' in session:
            db_queries.delete_user(session['user_id'])
            del session['user_id']
        user_id = db_queries.add_user(devices_id, devices_dss)
        session['user_id'] = user_id
    else:
        # first page (without_question)
        devices_id, devices_dss, dss_dict = None, None, {}  # nothing to return
        return render_template('QandA.html',
                               computers=[],
                               filters=FILTERS[u'all'],
                               pagination_pages=[],
                               dss_dict=dss_dict,
                               tooltips=TOOLTIPS_DICT,
                               without_question=True,
                               prom=PROM)

    if devices_id:
        last_page = int(
            round(float(len(devices_id)) / COMPUTERS_ON_PAGE + 0.49))
        first_comp_index = 0
        last_comp_index = min(COMPUTERS_ON_PAGE, len(devices_id))
        devices_id_on_page = devices_id[first_comp_index:last_comp_index]
        devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]
        pretty_devices = pretty_data.small_devices(devices_id_on_page,
                                                   devices_dss_on_page,
                                                   dbwrapper)
        return render_template(
            'QandA.html',
            computers=pretty_devices,
            filters=FILTERS[u'all'],
            pagination_pages=pretty_data.pagination_pages(last_page),
            dss_dict=dss_dict,
            tooltips=TOOLTIPS_DICT,
            without_question=False,
            prom=PROM)
    else:
        return render_template('QandA.html',
                               computers=[],
                               filters=FILTERS[u'all'],
                               pagination_pages=[],
                               dss_dict=dss_dict,
                               tooltips=TOOLTIPS_DICT,
                               without_question=False,
                               prom=PROM)
Exemplo n.º 4
0
def third_notebook(id, dss):
    dbwrapper = db_queries.DBWrapper("notebook")
    concdevices = dbwrapper.concdevices_by_device_id(id)
    big_pretty_notebook = pretty_data.big_notebook(id, dbwrapper)
    small_pretty_notebook = pretty_data.small_devices([id], [float(dss)],
                                                      dbwrapper)[0]
    return render_template('Comp.html',
                           big_comp=big_pretty_notebook,
                           small_comp=small_pretty_notebook,
                           tooltips=TOOLTIPS_DICT,
                           conccomps=concdevices,
                           prom=PROM)
Exemplo n.º 5
0
def third_notebook(id, dss):
    dbwrapper = db_queries.DBWrapper("notebook")
    concdevices = dbwrapper.concdevices_by_device_id(id)
    big_pretty_notebook = pretty_data.big_notebook(id, dbwrapper)
    small_pretty_notebook = pretty_data.small_devices([id], [float(dss)], dbwrapper)[0]
    return render_template(
        "Comp.html",
        big_comp=big_pretty_notebook,
        small_comp=small_pretty_notebook,
        tooltips=TOOLTIPS_DICT,
        conccomps=concdevices,
        prom=PROM,
    )
Exemplo n.º 6
0
def second():
    #need refactor dbwrapper calls
    dbwrapper = db_queries.DBWrapper(DEFFAULT_DEVICE_TYPE)
    #getting computers id:
    print request.args
    if 'type' in request.args.keys():
        session['type'] = request.args['type']
        dbwrapper = db_queries.DBWrapper(request.args['type'])
        devices_id, devices_dss, dss_dict = filtered_devices_id(FILTERS[dbwrapper.device], request.args, dbwrapper)
        if 'user_id' in session:
            dbwrapper.delete_user(session['user_id'])
            del session['user_id']
        user_id = dbwrapper.add_user(devices_id, devices_dss)
        session['user_id'] = user_id
    else:
        if 'user_id' in session:
            dbwrapper = db_queries.DBWrapper(session['type'])
            user = dbwrapper.get_user(session['user_id'])
            if user:
                devices_id, devices_dss = user.devices_id, user.devices_dss
                dss_dict = {}  # ????
            else:  # there is no such user in our db
                del session['user_id']
                devices_id, devices_dss, dss_dict = [], [], {}  # nothing to return
        else:
            devices_id, devices_dss, dss_dict = [], [], {}  # nothing to return

    last_page = int(round(float(len(devices_id)) / COMPUTERS_ON_PAGE + 0.49))
    # pagination test(if bad or wrong page) - REWRITE!!!
    try:
        page = int(request.args.get('page', '')) if 'page' in request.args else 1
    except ValueError:
        abort(404)
    # if page > last_page or page < 1:
    #     abort(404)

    first_comp_index = (page - 1) * COMPUTERS_ON_PAGE
    last_comp_index = min(page * COMPUTERS_ON_PAGE, len(devices_id))
    devices_id_on_page = devices_id[first_comp_index: last_comp_index]
    devices_dss_on_page = devices_dss[first_comp_index: last_comp_index]

    pretty_devices = pretty_data.small_devices(devices_id_on_page, devices_dss_on_page, dbwrapper)

    return render_template('QandA.html', computers=pretty_devices, filters=FILTERS[u'all'],
        current_page=page, pagination_pages=pretty_data.pagination_pages(page, last_page), dss_dict=dss_dict)
Exemplo n.º 7
0
def getPage(page, type):
    dbwrapper = db_queries.DBWrapper(type)
    user = db_queries.get_user(session["user_id"])
    if user:
        devices_id, devices_dss = user["devices_id"], user["devices_dss"]
        dss_dict = {}  # ????
    else:  # there is no such user in our db
        del session["user_id"]
        devices_id, devices_dss, dss_dict = [], [], {}  # nothing to return
    first_comp_index = (int(page) - 1) * COMPUTERS_ON_PAGE
    last_comp_index = min(int(page) * COMPUTERS_ON_PAGE, len(devices_id))
    devices_id_on_page = devices_id[first_comp_index:last_comp_index]
    devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]

    pretty_devices = pretty_data.small_devices(devices_id_on_page, devices_dss_on_page, dbwrapper)
    resp = jsonify({"pretty_devices": pretty_devices})
    resp.status_code = 200
    return resp
Exemplo n.º 8
0
def getPage(page, type):
    dbwrapper = db_queries.DBWrapper(type)
    user = db_queries.get_user(session['user_id'])
    if user:
        devices_id, devices_dss = user['devices_id'], user['devices_dss']
        dss_dict = {}  # ????
    else:  # there is no such user in our db
        del session['user_id']
        devices_id, devices_dss, dss_dict = [], [], {}  # nothing to return
    first_comp_index = (int(page) - 1) * COMPUTERS_ON_PAGE
    last_comp_index = min(int(page) * COMPUTERS_ON_PAGE, len(devices_id))
    devices_id_on_page = devices_id[first_comp_index:last_comp_index]
    devices_dss_on_page = devices_dss[first_comp_index:last_comp_index]

    pretty_devices = pretty_data.small_devices(devices_id_on_page,
                                               devices_dss_on_page, dbwrapper)
    resp = jsonify({"pretty_devices": pretty_devices})
    resp.status_code = 200
    return resp