Exemple #1
0
def getCategoryComponentsList(name):
    """
    getCategoryComponentsList(name) -> Return a list filled with dictionaries 
                                with information of all components under 
                                the given category
    """
    category = models.Category.objects.get(pk=name)
    components = models.Component.objects.filter(category_id=category)
    cinf = []

    for c in components:
        cinfo = {
            "ref": c.ref,
            "name": c.name,
            "img": str(c.img),
            "avgprice": str(c.avgprice),
            "category": {"name": str(c.category), "link": getCategoryURL(c.category.name)},
            "manufacturer": {
                "name": str(c.manufacturer) if c.manufacturer else "",
                "link": getManufacturerURL(c.manufacturer.name) if c.manufacturer else "",
            },
            "link": {"rel": "self", "href": getComponentURL(c.ref)},
        }

        # Append info to the list
        cinf.append(cinfo)

    return cinf
Exemple #2
0
def getComponentsSummaryAsList():
    """
    getComponentsSummaryAsList() -> Return a list filled with dictionaries
                                containing component information
    """
    cinf = []

    for c in models.Component.objects.all():
        cinfo = {
            "ref": c.ref,
            "name": c.name,
            "img": str(c.img),
            "avgprice": str(c.avgprice),
            "category": {
                "name": str(c.category) if c.category else "",
                "link": getCategoryURL(c.category.name) if c.category else "",
            },
            "manufacturer": {
                "name": str(c.manufacturer) if c.manufacturer else "",
                "link": getManufacturerURL(c.manufacturer.name) if c.manufacturer else "",
            },
            "link": {"rel": "self", "href": getComponentURL(c.ref)},
        }

        # Append info to the list
        cinf.append(cinfo)

    return cinf
Exemple #3
0
 def get(self, request, *args, **kwargs):
     try:
         context = self.get_context_data(**kwargs)
         return self.render_to_response(context)
     except ObjectDoesNotExist, e:
         name = kwargs['name']
         return responseutils.getHttpResponseNotFoundHTML(
                                         '%s Not Found' % name,
                                         request.user,
                                         name,
                                         urlutils.getCategoryURL(name))
Exemple #4
0
def getComponentInfo(ref):
    """
    getComponentInfo(ref) -> Return a dictionary with all the information
                            of the specified component
    """
    comp = models.Component.objects.get(pk=ref)

    cinf = {
        "ref": comp.ref,
        "name": comp.name,
        "img": str(comp.img),
        "avgprice": str(comp.avgprice),
        "category": {
            "name": str(comp.category) if comp.category else "",
            "link": getCategoryURL(comp.category.name) if comp.category else "",
        },
        "desc": comp.desc,
        "manufacturer": {
            "name": str(comp.manufacturer) if comp.manufacturer else "",
            "link": getManufacturerURL(comp.manufacturer.name) if comp.manufacturer else "",
        },
        "supportedby": [],
        "createdby": str(comp.createdby),
        "link": {"rel": "self", "href": getComponentURL(comp.ref)},
    }

    # Add supported by list if exists (elements separed by ;)
    supportedby = getComponentSupportedBy(comp)

    if supportedby:
        for sb in supportedby:
            cinf["supportedby"].append(
                {
                    "id": sb["id"],
                    "name": sb["name"],
                    "link": getOperatingSystemURL(sb["name"]),
                    "minversion": sb["minversion"],
                    "maxversion": sb["maxversion"],
                }
            )

    # Add reviews
    cinf["reviews"] = getComponentReviews(comp)

    return cinf
Exemple #5
0
def getCategoriesInfoAsList():
    """
    getCategoriesInfoAsList() -> Return a list filled dictionaries containing
                                categories information
    """
    categories = []

    for cat in models.Category.objects.all():
        components = models.Component.objects.filter(category_id=cat)
        categories.append(
            {"name": cat.name, "itemcount": len(components), "link": {"rel": "self", "href": getCategoryURL(cat.name)}}
        )

    return categories