class AddonsGet(Service): def __init__(self, context, request): super(AddonsGet, self).__init__(context, request) self.params = [] self.addons = Addons(context, request) def publishTraverse(self, request, name): # Consume any path segments after /@addons as parameters self.params.append(name) return self def reply(self): all_addons = self.addons.get_addons() if self.params: if self.params[0] in all_addons: return self.addons.serializeAddon(all_addons[self.params[0]]) else: return [] result = { "items": {"@id": "{}/@addons".format(self.context.absolute_url())}, } addons_data = [] for addon in all_addons.values(): addons_data.append(self.addons.serializeAddon(addon)) result["items"] = addons_data self.request.response.setStatus(200) return result
class AddonsPost(Service): """Performs install/upgrade/uninstall functions on an addon.""" def __init__(self, context, request): super(AddonsPost, self).__init__(context, request) self.params = [] self.errors = {} self.addons = Addons(context, request) def publishTraverse(self, request, name): # Consume any path segments after /@addons as parameters self.params.append(name) return self def reply(self): addon, action = self.params # Disable CSRF protection if "IDisableCSRFProtection" in dir(plone.protect.interfaces): alsoProvides(self.request, plone.protect.interfaces.IDisableCSRFProtection) if action == "install": result = self.addons.install_product(addon) elif action == "uninstall": result = self.addons.uninstall_product(addon) elif action == "upgrade": result = self.addons.upgrade_product(addon) else: raise Exception("Unknown action {}".format(action)) prefer = self.request.getHeader("Prefer") if prefer == "return=representation": control_panel = getMultiAdapter( (self.context, self.request), name="prefs_install_products_form" ) all_addons = control_panel.get_addons() result = { "items": {"@id": "{}/@addons".format(self.context.absolute_url())} } addons_data = [] for a in all_addons.values(): addons_data.append(self.addons.serializeAddon(a)) result["items"] = addons_data self.request.response.setStatus(200) return result else: self.request.response.setStatus(204) return None
class AddonsGet(Service): def __init__(self, context, request): super().__init__(context, request) self.params = [] self.addons = Addons(context, request) self.query = self.request.form.copy() def publishTraverse(self, request, name): # Consume any path segments after /@addons as parameters self.params.append(name) return self def reply(self): all_addons = self.addons.get_addons() if self.params: if self.params[0] in all_addons: return self.addons.serializeAddon(all_addons[self.params[0]]) else: return [] result = { "items": { "@id": f"{self.context.absolute_url()}/@addons" }, } addons_data = [] for addon in all_addons.values(): addons_data.append(self.addons.serializeAddon(addon)) if len(self.query) > 0 and len(self.params) == 0: upgradeables = self.query.get("upgradeable", "") if upgradeables: addons_data = [ addon for addon in addons_data if addon.get("upgrade_info", False) and addon["upgrade_info"].get("available", False) ] result["items"] = addons_data self.request.response.setStatus(200) return result
def __init__(self, context, request): super().__init__(context, request) self.params = [] self.addons = Addons(context, request) self.query = self.request.form.copy()
def __init__(self, context, request): super().__init__(context, request) self.params = [] self.errors = {} self.addons = Addons(context, request)
def __init__(self, context, request): super(AddonsGet, self).__init__(context, request) self.params = [] self.addons = Addons(context, request)