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
def getManufacturerInfo(name): """ getManufacturerInfo(name) -> Return a dictionary with all the information related to the specified manufacturer """ manufacturer = models.Manufacturer.objects.get(pk=name) manu_info = { "name": manufacturer.name, "desc": manufacturer.desc, "link": {"rel": "self", "href": getManufacturerURL(manufacturer.name)}, "makes": [], } # Try to add links of made components components = getManufacturerComponents(manufacturer) for c in components: manu_info["makes"].append({"name": c.name, "link": getComponentURL(c.name)}) # Try to add links of made operating systems operating_systems = getManufacturerOperatingSystems(manufacturer) for os in operating_systems: manu_info["makes"].append({"name": os.name, "link": getOperatingSystemURL(os.name)}) return manu_info
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
def get(self, request, *args, **kwargs): try: context = self.get_context_data(**kwargs) return self.render_to_response(context) except ObjectDoesNotExist: name = kwargs['name'] return responseutils.getHttpResponseNotFoundHTML( '%s Not Found' % name, request.user, name, urlutils.getManufacturerURL(name))
def getManufacturersInfoAsList(): """ getManufacturersInfoAsList() -> Return a list filled with dictionaries containing manufacturers information """ manu_info = [] for m in models.Manufacturer.objects.all(): single_manu_info = {"name": m.name, "link": {"rel": "self", "href": getManufacturerURL(m.name)}} manu_info.append(single_manu_info) return manu_info
def getOSInfo(name): """ getOSInfo(name) -> Return a dictionary with all the information of the specified OS """ print name os = models.OperatingSystem.objects.get(pk=name) os_info = {"name": os.name, "manufacturer": "", "link": {"rel": "self", "href": getOperatingSystemURL(os.name)}} manufacturer = getOSManufacturer(os) if manufacturer: os_info["manufacturer"] = {"name": manufacturer.name, "link": getManufacturerURL(manufacturer.name)} return os_info
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