def get_insert_position(admin_menu, item_name):
"""
Ensures that there is a SHORTCUTS_BREAK and returns a position for an
alphabetical position against all items between SHORTCUTS_BREAK, and
the ADMINISTRATION_BREAK.
"""
start = admin_menu.find_first(Break, identifier=SHORTCUTS_BREAK)
if not start:
end = admin_menu.find_first(Break, identifier=ADMINISTRATION_BREAK)
admin_menu.add_break(SHORTCUTS_BREAK, position=end.index)
start = admin_menu.find_first(Break, identifier=SHORTCUTS_BREAK)
end = admin_menu.find_first(Break, identifier=ADMINISTRATION_BREAK)
items = admin_menu.get_items()[start.index + 1: end.index]
for idx, item in enumerate(items):
try:
if force_text(item_name.lower()) < force_text(item.name.lower()):
return idx + start.index + 1
except AttributeError:
# Some item types do not have a 'name' attribute.
pass
return end.index
评论列表
文章目录