return value menu

This commit is contained in:
Valentin CZERYBA 2023-07-26 19:18:18 +02:00
parent eee14e08f1
commit 8de7485775

View File

@ -262,7 +262,6 @@ class WPMenu:
exit(0)
def _createItemMenu(self, idMenu, itemMenu, parent): def _createItemMenu(self, idMenu, itemMenu, parent):
idItemMenu = 0 idItemMenu = 0
@ -285,10 +284,17 @@ class WPMenu:
if objectt == "tag": if objectt == "tag":
objectt = "post_tag" objectt = "post_tag"
data = {"title": itemMenu["title"], "status": "publish", "parent":parent, "menus":idMenu, "object":objectt, "object_id":itemMenu["id"]} data = {"title": itemMenu["title"], "status": "publish", "parent":parent, "menus":idMenu, "object":objectt, "object_id":itemMenu["id"]}
page = self._request_wordpress.post(url, auth=self._basic, headers=self._headers_json, data=json.dumps(data)) page = self._request_wordpress.post(url, auth=self._basic, headers=self._headers_json, data=json.dumps(data))
if page.status_code == 201: if page.status_code == 201:
result = page.json()
idItemMenu = result["id"]
self._logger.info("{0} : create item menu : {1}".format(self._name, itemMenu["title"])) self._logger.info("{0} : create item menu : {1}".format(self._name, itemMenu["title"]))
elif page.status_code == 200: elif page.status_code == 200:
result = page.json()
for i in result:
if result["title"]["rendered"] == itemMenu["title"]:
idItemMenu = i["id"]
self._logger.info("{0} : update item menu : {1}".format(self._name, itemMenu["title"])) self._logger.info("{0} : update item menu : {1}".format(self._name, itemMenu["title"]))
else: else:
self._logger.error("{0} : Create menu items didn't get due status code : {1}".format(self._name, page.status_code)) self._logger.error("{0} : Create menu items didn't get due status code : {1}".format(self._name, page.status_code))
@ -356,3 +362,8 @@ class WPMenu:
exit(1) exit(1)
except Exception as err: except Exception as err:
self._logger.error("{0} : Exception error for get menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menus".format(self._wordpress, self._protocol_wordpress), err)) self._logger.error("{0} : Exception error for get menu {1} : {2}".format(self._name, "{1}://{0}/wp-json/wp/v2/menus".format(self._wordpress, self._protocol_wordpress), err))
def addItemMenu(self, menu, idMenu):
self._logger.info("{0} : add item to menu : {1}".format(self._name, idMenu))