Exemplo n.º 1
0
def power_supplies():
    psu_search_form = search.PSUSearch()
    psu_search_form.efficiency.choices = [
        (i, i) for i in search.get_choices("psus", "efficiency")
    ]
    psu_search_form.form_factor.choices = [
        (i, i) for i in search.get_choices("psus", "form factor")
    ]
    psu_search_form.wattage.choices = [
        (i, i) for i in search.get_choices("psus", "wattage")
    ]
    psu_search_form.modular.choices = [
        (i, i) for i in search.get_choices("psus", "modular")
    ]
    if psu_search_form.validate_on_submit():
        query = psu_search_form.query
        sort = psu_search_form.sort
        postcode = psu_search_form.postcode
        max_distance = psu_search_form.max_distance
        condition = psu_search_form.condition
        efficiency = psu_search_form.efficiency
        wattage = psu_search_form.wattage
        modular = psu_search_form.modular
        form_factor = psu_search_form.form_factor
        filters = json.dumps({
            "query": query.data,
            "sort": sort.data,
            "postcode": postcode.data.replace(" ", "").upper(),
            "max distance": max_distance.data,
            "condition": condition.data,
            "specific": {
                "efficiency": efficiency.data,
                "wattage": wattage.data,
                "modular": modular.data,
                "form factor": form_factor.data
            }
        })
        return flask.redirect(flask.url_for("power_supplies", filters=filters))
    try:
        filters = json.loads(flask.request.args.get('filters', None))
        displayed_posts = display_posts(posts,
                                        component_dict,
                                        "psus",
                                        query_param=filters["query"],
                                        sort=filters["sort"],
                                        postcode=filters["postcode"],
                                        max_distance=filters["max distance"],
                                        conditions_param=filters["condition"],
                                        filters_param=filters["specific"])
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    except:
        displayed_posts = display_posts(posts, component_dict, "psus")
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    return flask.render_template("psu_posts.html",
                                 title="Power Supply Posts",
                                 displayed_posts=displayed_posts,
                                 psu_search_form=psu_search_form)
Exemplo n.º 2
0
def memory():
    ram_search_form = search.RAMSearch()
    ram_search_form.module_type.choices = [
        (i, i) for i in search.get_choices("ram", "type")
    ]
    ram_search_form.speed.choices = [
        (i, i) for i in search.get_choices("ram", "speed")
    ]
    ram_search_form.size.choices = [(i, i)
                                    for i in search.get_choices("ram", "size")]
    ram_search_form.form_factor.choices = [
        (i, i) for i in search.get_choices("ram", "form factor")
    ]
    if ram_search_form.validate_on_submit():
        query = ram_search_form.query
        sort = ram_search_form.sort
        postcode = ram_search_form.postcode
        max_distance = ram_search_form.max_distance
        condition = ram_search_form.condition
        module_type = ram_search_form.module_type
        speed = ram_search_form.speed
        size = ram_search_form.size
        form_factor = ram_search_form.form_factor
        filters = json.dumps({
            "query": query.data,
            "sort": sort.data,
            "postcode": postcode.data.replace(" ", "").upper(),
            "max distance": max_distance.data,
            "condition": condition.data,
            "specific": {
                "type": module_type.data,
                "speed": speed.data,
                "size": size.data,
                "form factor": form_factor.data
            }
        })
        return flask.redirect(flask.url_for("memory", filters=filters))
    try:
        filters = json.loads(flask.request.args.get('filters', None))
        displayed_posts = display_posts(posts,
                                        component_dict,
                                        "ram",
                                        query_param=filters["query"],
                                        sort=filters["sort"],
                                        postcode=filters["postcode"],
                                        max_distance=filters["max distance"],
                                        conditions_param=filters["condition"],
                                        filters_param=filters["specific"])
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    except:
        displayed_posts = display_posts(posts, component_dict, "ram")
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    return flask.render_template("ram_posts.html",
                                 title="Memory Posts",
                                 displayed_posts=displayed_posts,
                                 ram_search_form=ram_search_form)
Exemplo n.º 3
0
def cpus():
    cpu_search_form = search.CPUSearch()
    cpu_search_form.brand.choices = [
        (i, i) for i in search.get_choices("cpus", "brand")
    ]
    if cpu_search_form.validate_on_submit():
        query = cpu_search_form.query
        sort = cpu_search_form.sort
        postcode = cpu_search_form.postcode
        max_distance = cpu_search_form.max_distance
        condition = cpu_search_form.condition
        brand = cpu_search_form.brand
        filters = json.dumps({
            "query": query.data,
            "sort": sort.data,
            "postcode": postcode.data.replace(" ", "").upper(),
            "max distance": max_distance.data,
            "condition": condition.data,
            "specific": {
                "brand": brand.data
            }
        })
        return flask.redirect(flask.url_for("cpus", filters=filters))
    try:
        filters = json.loads(flask.request.args.get('filters', None))
        displayed_posts = display_posts(posts, component_dict, "cpus",
                                        filters["query"], filters["sort"],
                                        filters["postcode"],
                                        filters["max distance"],
                                        filters["condition"],
                                        filters["specific"])
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    except:
        displayed_posts = display_posts(posts, component_dict, "cpus")
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    return flask.render_template("cpu_posts.html",
                                 title="CPU Posts",
                                 displayed_posts=displayed_posts,
                                 cpu_search_form=cpu_search_form)
Exemplo n.º 4
0
def storage():
    storage_search_form = search.StorageSearch()
    storage_search_form.storage_type.choices = [
        (i, i) for i in search.get_choices("storage", "type")
    ]
    storage_search_form.rpm.choices = [
        (i, i) for i in search.get_choices("storage", "rpm")
    ]
    storage_search_form.size.choices = [
        (i, i) for i in search.get_choices("storage", "size")
    ]
    storage_search_form.form_factor.choices = [
        (i, i) for i in search.get_choices("storage", "form factor")
    ]
    storage_search_form.interface.choices = [
        (i, i) for i in search.get_choices("storage", "interface")
    ]
    if storage_search_form.validate_on_submit():
        query = storage_search_form.query
        sort = storage_search_form.sort
        postcode = storage_search_form.postcode
        max_distance = storage_search_form.max_distance
        condition = storage_search_form.condition
        storage_type = storage_search_form.storage_type
        rpm = storage_search_form.rpm
        size = storage_search_form.size
        form_factor = storage_search_form.form_factor
        interface = storage_search_form.interface
        filters = json.dumps({
            "query": query.data,
            "sort": sort.data,
            "postcode": postcode.data.replace(" ", "").upper(),
            "max distance": max_distance.data,
            "condition": condition.data,
            "specific": {
                "type": storage_type.data,
                "rpm": rpm.data,
                "size": size.data,
                "form factor": form_factor.data,
                "interface": interface.data
            }
        })
        return flask.redirect(flask.url_for("storage", filters=filters))
    try:
        filters = json.loads(flask.request.args.get('filters', None))
        displayed_posts = display_posts(posts,
                                        component_dict,
                                        "storage",
                                        query_param=filters["query"],
                                        sort=filters["sort"],
                                        postcode=filters["postcode"],
                                        max_distance=filters["max distance"],
                                        conditions_param=filters["condition"],
                                        filters_param=filters["specific"])
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    except:
        displayed_posts = display_posts(posts, component_dict, "storage")
        for post in displayed_posts:
            post["readable time"] = get_time_created(post["time created"])
    return flask.render_template("storage_posts.html",
                                 title="Storage Posts",
                                 displayed_posts=displayed_posts,
                                 storage_search_form=storage_search_form)
Exemplo n.º 5
0
def display_posts(posts,
                  parts,
                  category=None,
                  query_param=None,
                  sort="t",
                  postcode=None,
                  max_distance=None,
                  conditions_param=None,
                  filters_param=None):
    if conditions_param == []:
        conditions = ["New", "Good", "Slightly Faulty", "Not working at all"]
    else:
        conditions = conditions_param
    if filters_param:
        filters = filters_param
        for key, value in filters.items():
            if value == []:
                filters[key] = get_choices(category, key)
    if query_param == "":
        query = None
    else:
        query = query_param
    if category:
        ids = []
        if postcode:  #if postcode is passed as a parameter then others wont be empty
            for part in parts[category]:
                id_valid = True
                for key, value in filters.items():
                    filter_valid = False
                    for item in value:
                        if part[key] == item:
                            filter_valid = True
                            break
                    if filter_valid == False:
                        id_valid = False
                        break
                if id_valid:
                    ids.append(part["id"])
            post_matches = []
            for condition in conditions:
                condition_matches = get_posts(posts,
                                              ids=ids,
                                              search=query,
                                              condition=condition)
                for p in condition_matches:
                    if p not in post_matches and (
                            get_distance(p["location"], postcode) <=
                            max_distance or max_distance
                            == 200):  #add distance condition and function here
                        post_matches.append(p)
        else:
            try:
                for part in parts[category]:
                    ids.append(part["id"])
            except:
                ids.append(parts[category]["id"])
            post_matches = get_posts(posts, ids)
    else:
        if postcode:
            post_matches = []
            for condition in conditions:
                condition_matches = get_posts(posts,
                                              search=query,
                                              condition=condition)
                for p in condition_matches:
                    if p not in post_matches and (
                            get_distance(p["location"], postcode) <=
                            max_distance or max_distance
                            == 200):  #add distance condition and function here
                        post_matches.append(p)
        else:
            post_matches = get_posts(posts)
    if sort == "t":  #sort by time added
        post_matches = sorted(post_matches,
                              key=lambda i: i['time created'],
                              reverse=True)
    elif sort == "p":  #sort by price
        post_matches = sorted(post_matches, key=lambda i: i['price'])
    elif sort == "d":  #sort by distance
        post_matches = sorted(
            post_matches, key=lambda i: get_distance(i["location"], postcode)
        )  #will do a similar thing to the above calling a to be created 'get distance' function that compares the postcode on the post to the postcode in params
    return post_matches