<commit_before>########## Module wrapping menus and their creation ##########
from psbackend import context
from flask.ext.login import current_user

##
# @brief A class wrapping the menu objects.
#
# Note: These ARE the menus that go in the nav
class Menu:
    ##
    # @brief Create a new menu object
    #
    # @param name Actual string for the appearing menu
    # @param routeFuncName Route to the view for the given menuentry.
    # @param submenus Option arg: array of submenus of this menu
    #
    # @return 
    def __init__(self, name, routeFuncName, visible=True, submenus=[]):
        self._name = name
        self._routeFuncName = routeFuncName
        self._submenus = submenus
        self._visible = visible
    
    def addToContext(self):
        context.projectVars["menus"].append(self)

    # Properties
    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @property
    def routeFuncName(self):
        return self._routeFuncName

    @routeFuncName.setter
    def routeFuncName(self, routeFuncName):
        self._routeFuncName = routeFuncName

    @property
    def visible(self):
        print("Menu.visible() called")
        return self._visible
    
    @visible.setter
    def visible(self, isVis):
        self._visible = isVis

    @property
    def submenus(self):
        return self._submenus

    @submenus.setter
    def submenus(self, subs):
        self._submenus = subs

class UserMenu(Menu):
    def __init__(self, name, routeFuncName, visible=True, submenus=[]):
        self.logoutMenu = Menu("Logout", "logout", False)
        submenus.append(self.logoutMenu)
        super().__init__(name, routeFuncName, visible, submenus)

    def isAuthenticated(self):
        return current_user and \
                current_user.is_authenticated()

    # Lets override visible() as a pseudo-hook
    @Menu.visible.getter
    def visible(self):
        print("UserMenu.visible() called")
        # Change the names if we have auth
        if self.isAuthenticated():
            self.name = current_user.get_id()
            self.routeFuncName = "user"

            # Turn on the logout submenu
            self.logoutMenu.visible = True
        else:
            self.name = "Login"
            self.routeFuncName = "login"

            # Turn off the logout submenu
            self.logoutMenu.visible = False
        return super().visible


def createApplicationMenus():
    menus = context.projectVars["menus"]

    menus.append(Menu("Home", "index"))
    menus.append(Menu("About", "about"))

    # Add the user menu
    users = UserMenu("Login", "login")

    menus.append(users)

<commit_msg>Got rid of some print() debug statements<commit_after>########## Module wrapping menus and their creation ##########
from psbackend import context
from flask.ext.login import current_user

##
# @brief A class wrapping the menu objects.
#
# Note: These ARE the menus that go in the nav
class Menu:
    ##
    # @brief Create a new menu object
    #
    # @param name Actual string for the appearing menu
    # @param routeFuncName Route to the view for the given menuentry.
    # @param submenus Option arg: array of submenus of this menu
    #
    # @return 
    def __init__(self, name, routeFuncName, visible=True, submenus=[]):
        self._name = name
        self._routeFuncName = routeFuncName
        self._submenus = submenus
        self._visible = visible
    
    def addToContext(self):
        context.projectVars["menus"].append(self)

    # Properties
    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, name):
        self._name = name

    @property
    def routeFuncName(self):
        return self._routeFuncName

    @routeFuncName.setter
    def routeFuncName(self, routeFuncName):
        self._routeFuncName = routeFuncName

    @property
    def visible(self):
        return self._visible
    
    @visible.setter
    def visible(self, isVis):
        self._visible = isVis

    @property
    def submenus(self):
        return self._submenus

    @submenus.setter
    def submenus(self, subs):
        self._submenus = subs

class UserMenu(Menu):
    def __init__(self, name, routeFuncName, visible=True, submenus=[]):
        self.logoutMenu = Menu("Logout", "logout", False)
        submenus.append(self.logoutMenu)
        super().__init__(name, routeFuncName, visible, submenus)

    def isAuthenticated(self):
        return current_user and \
                current_user.is_authenticated()

    # Lets override visible() as a pseudo-hook
    @Menu.visible.getter
    def visible(self):
        # Change the names if we have auth
        if self.isAuthenticated():
            self.name = current_user.get_id()
            self.routeFuncName = "user"

            # Turn on the logout submenu
            self.logoutMenu.visible = True
        else:
            self.name = "Login"
            self.routeFuncName = "login"

            # Turn off the logout submenu
            self.logoutMenu.visible = False
        return super().visible


def createApplicationMenus():
    menus = context.projectVars["menus"]

    menus.append(Menu("Home", "index"))
    menus.append(Menu("About", "about"))

    # Add the user menu
    users = UserMenu("Login", "login")

    menus.append(users)


{'fraction_non_alphanumeric': 0.09998141609366289, 'fraction_numerical': 0.0, 'mean_word_length': 2.483495145631068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5242746', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1547, 'n_words': 436}