Пример #1
0
    def _render(self):
        self._clear_screen()
        if self.view == 'menu-view':
            self._render_main_menu()

        elif self.view == 'main-view':
            paginator = self.main_view['paginator']
            current_page = self.main_view['current_page']
            info = self.main_view['info']
            highlighted_item = self.main_view['highlighted_item']

            self._render_package_list(paginator, current_page, info,
                                      highlighted_item)

        elif self.view == 'category-choice-view':
            paginator = self.category_choice_view['paginator']
            info = self.main_view['info']
            current_page = self.category_choice_view['current_page']
            highlighted_item = self.category_choice_view['highlighted_item']

            self._render_category_choice_view(paginator, current_page, info,
                                              highlighted_item)

        elif self.view == 'update-view':
            self.update()
            self.view = 'menu-view'
            self._render()

        elif self.view == 'package-view':
            package = self.main_view['paginator'].current_page()[
                self.main_view['highlighted_item'] - 1]
            self._render_package_info(package)

            rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
            docs = rtd_bootstrap.check_if_docs_exist(package.pypi_package_name
                                                     or package.repo_name)
            if docs:
                self._render_package_info(package, docs=docs)

        elif self.view == 'about-view':

            file = open(os.path.join(PROJECT_DIR, 'templates', 'ABOUT.txt'))
            puts(file.read())
            file.close()

        elif self.view == 'help-view':

            file = open(os.path.join(PROJECT_DIR, 'templates', 'HELP.txt'))
            puts(file.read())
            file.close()
    def _render(self):
        self._clear_screen()
        if self.view == 'menu-view':
            self._render_main_menu()

        elif self.view == 'main-view':
            paginator = self.main_view['paginator']
            current_page = self.main_view['current_page']
            info = self.main_view['info']
            highlighted_item = self.main_view['highlighted_item']

            self._render_package_list(paginator, current_page, info, highlighted_item)

        elif self.view == 'category-choice-view':
            paginator = self.category_choice_view['paginator']
            info = self.main_view['info']
            current_page = self.category_choice_view['current_page']
            highlighted_item = self.category_choice_view['highlighted_item']

            self._render_category_choice_view(paginator, current_page, info, highlighted_item)

        elif self.view == 'update-view':
            self.update()
            self.view = 'menu-view'
            self._render()

        elif self.view == 'package-view':
            package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
            self._render_package_info(package)

            rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
            docs = rtd_bootstrap.check_if_docs_exist(package.pypi_package_name or package.repo_name)
            if docs:
                self._render_package_info(package, docs=docs)

        elif self.view == 'about-view':

            file = open(os.path.join(PROJECT_DIR, 'templates', 'ABOUT.txt'))
            puts(file.read())
            file.close()

        elif self.view == 'help-view':

            file = open(os.path.join(PROJECT_DIR, 'templates', 'HELP.txt'))
            puts(file.read())
            file.close()
Пример #3
0
    def packages(self, category_name=None):
        """
        Commands

        n = next page
        p = prev page
        q = quit

        """
        self.view = "menu-view"
        category = "All"

        # MENU VIEW
        self.menu_view = {
            'highlighted_item': 1,
            'options': {
                'Packages': 'main-view',
                'Categories': 'category-choice-view',
                'Virtual Environments': 'virtual-env-view',
                'Help': 'help-view',
                'Update': 'update-view',
                'About': 'about-view',
            }
        }

        self.session = Session()
        #self.session = session

        categories = self.session.query(Category).order_by(
            Category.title).all()
        self.category_choice_view = {
            'categories': categories,
            'paginator': Paginator(objects=categories, pagination=10),
            'current_page': 1,
            'highlighted_item': 1,
            'ordering': 'name',
        }

        self.category_choice_view['category_paginator'] = Paginator(
            objects=categories, pagination=10)
        self.category_choice_view['current_page'] = 1
        self.category_choice_view['highlighted_item'] = 1
        self.category_choice_view['info'] = {}

        if category_name:
            category = self.session.query(Category).filter(
                Category.slug == category_name)
            if not category:
                category = "All"
                puts_err("Could not find specified category.")

                self.view = 'category-choice-view'

        packages_query = self.session.query(Package).order_by(
            Package.pypi_downloads.desc())
        packages = packages_query.all()

        puts("")

        self.main_view = {}
        self.main_view['paginator'] = Paginator(packages, pagination=10)
        self.main_view['paginator'].base_query = self.session.query(Package)
        self.main_view['current_page'] = 1
        self.main_view['highlighted_item'] = 1
        self.main_view['info'] = {
            'Category': category_name or 'All',
            'Package count': self.session.query(Package).count(),
        }
        self.main_view['ordering'] = 'downloads'

        self._render()

        while True:
            key = listen_for_cli_command()

            if key == 'q':
                quit()

            if self.view == "menu-view":
                # MAIN MENU
                if ord(key) == 80:
                    # UP key
                    if not self.menu_view['highlighted_item'] >= len(
                            self.menu_view['options']):
                        self.menu_view['highlighted_item'] += 1

                    self._render_main_menu()

                elif ord(key) == 72:
                    # DOWN key
                    if not self.menu_view['highlighted_item'] <= 1:
                        self.menu_view['highlighted_item'] -= 1

                    self._render_main_menu()

                elif ord(key) == 13:
                    # ENTER key
                    index = self.menu_view['highlighted_item'] - 1
                    self.view = self.menu_view['options'].values()[index]
                    print "going to %s..." % self.view

                    self._render()

            elif self.view == "virtual-env-list-view":
                pass

            elif self.view == 'main-view':
                if key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.main_view['current_page'] >= self.main_view[
                            'paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.main_view['current_page'] += 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.main_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.main_view['current_page'] -= 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'u':
                    # SORT BY USING
                    self.main_view['ordering'] = 'people using library'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'c':
                    self.view = "category-choice-view"
                    self._render_category_choice_view(
                        self.category_choice_view['category_paginator'],
                        self.category_choice_view['current_page'],
                        self.main_view['info'],
                        self.category_choice_view['highlighted_item'])

                elif key == 'g':
                    # UPDATE
                    self.view = 'update-view'
                    self.update()
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])
                    self.view = 'main-view'

                elif key == 'w':
                    # SORT BY WATCHING
                    self.main_view['ordering'] = 'people wathcing repository'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.repo_watchers.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'd':
                    # SORT by Downloads
                    self.main_view['ordering'] = 'PYPI downloads'
                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.pypi_downloads.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package
                    self.view = 'package-view'
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    self._render_package_info(package)

                    rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
                    docs = rtd_bootstrap.check_if_docs_exist(
                        package.pypi_package_name or package.repo_name)
                    if docs:
                        self._render_package_info(package, docs=docs)

                elif ord(key) == 72:
                    # pressed UP
                    if not self.main_view['highlighted_item'] <= 1:
                        self.main_view['highlighted_item'] -= 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.main_view['highlighted_item'] >= 10:
                        self.main_view['highlighted_item'] += 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

            elif self.view == 'package-view':

                if key == 'i':
                    #INSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Installing..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    result = self.install(
                        package_names=[package.install_string])
                    if not result:
                        package.update_installed_info()
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render()
                    #self._render_package_info(package)

                elif key == 'u':
                    # UNINSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Uninstalling..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    result = self.uninstall(package_names=[
                        package.pypi_package_name or package.repo_name
                    ])
                    if result:
                        puts(result)

                    if not result:
                        package.installed = False
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render_package_info(package)

                elif ord(key) == 8:
                    # BACKSPACE
                    self.view = 'main-view'
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

                elif key == 'p':
                    # PYPI webpage
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    webbrowser.open(package.pypi_url)

                elif key == 'r':
                    # REPO page
                    package = self.main_view['paginator'].current_page()[
                        self.main_view['highlighted_item'] - 1]
                    webbrowser.open(package.repo_url)

            elif self.view == 'installed-view':
                pass

            elif self.view == 'category-choice-view':
                if key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.category_choice_view[
                            'current_page'] >= self.category_choice_view[
                                'category_paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.category_choice_view['current_page'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.category_choice_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.category_choice_view['current_page'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package

                    category = self.category_choice_view[
                        'category_paginator'].current_page()[
                            self.category_choice_view['highlighted_item'] - 1]

                    packages_base_query = self.session.query(Package).filter(
                        Package.categories.any(id=category.id))
                    self.main_view['paginator'] = Paginator(
                        objects=packages_base_query.order_by(
                            Package.pypi_downloads.desc()).all())
                    self.main_view[
                        'paginator'].base_query = packages_base_query

                    self.main_view['current_page'] = 1
                    self.main_view['highlighted_item'] = 1
                    self.main_view['info'] = {
                        'Category': category and category.title or 'All',
                        'Package count': len(category.packages),
                    }

                    self.view = 'main-view'
                    self._render()
                    #self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 72:
                    # pressed UP
                    if not self.category_choice_view['highlighted_item'] <= 1:
                        self.category_choice_view['highlighted_item'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.category_choice_view['highlighted_item'] >= 10:
                        self.category_choice_view['highlighted_item'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

                elif key == 'k':
                    # ORDERING by Package count
                    self.category_choice_view['ordering'] = 'package count'
                    #self.category_choice_view['paginator'] = self.category_choice_view['paginator'].base_query.order_by(Category.package.desc()).all()

                    self.main_view['paginator'].objects = self.main_view[
                        'paginator'].base_query.order_by(
                            Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(
                        self.main_view['paginator'],
                        self.main_view['current_page'], self.main_view['info'],
                        self.main_view['highlighted_item'])

            elif self.view in ['about-view', 'help-view']:

                if ord(key) == 8:
                    self.view = "menu-view"
                    self._render()
    def packages(self, category_name=None):
        """
        Commands

        n = next page
        p = prev page
        q = quit

        """
        self.view = "menu-view"
        category = "All"

        # MENU VIEW
        self.menu_view = {
            'highlighted_item': 1,
            'options': {
                'Packages': 'main-view',
                'Categories': 'category-choice-view',
                'Virtual Environments': 'virtual-env-view',
                'Help': 'help-view',
                'Update': 'update-view',
                'About': 'about-view',
            }
        }

        self.session = Session()
        #self.session = session

        categories = self.session.query(Category).order_by(Category.title).all()
        self.category_choice_view = {
            'categories': categories,
            'paginator' : Paginator(objects=categories, pagination=10),
            'current_page' : 1,
            'highlighted_item' : 1,
            'ordering': 'name',
        }

        self.category_choice_view['category_paginator'] = Paginator(objects=categories, pagination=10)
        self.category_choice_view['current_page'] = 1
        self.category_choice_view['highlighted_item'] = 1
        self.category_choice_view['info'] = {}

        if category_name:
            category = self.session.query(Category).filter(Category.slug == category_name)
            if not category:
                category = "All"
                puts_err("Could not find specified category.")

                self.view = 'category-choice-view'


        packages_query = self.session.query(Package).order_by(Package.pypi_downloads.desc())
        packages = packages_query.all()

        puts("")


        self.main_view = {}
        self.main_view['paginator'] = Paginator(packages, pagination=10)
        self.main_view['paginator'].base_query = self.session.query(Package)
        self.main_view['current_page'] = 1
        self.main_view['highlighted_item'] = 1
        self.main_view['info'] = {
            'Category': category_name or 'All',
            'Package count': self.session.query(Package).count(),
            }
        self.main_view['ordering'] = 'downloads'

        self._render()

        while True:
            key = listen_for_cli_command()

            if key == 'q':
                quit()


            if self.view == "menu-view":
                # MAIN MENU
                if ord(key) == 80:
                    # UP key
                    if not self.menu_view['highlighted_item'] >= len(self.menu_view['options']):
                        self.menu_view['highlighted_item'] += 1

                    self._render_main_menu()

                elif ord(key) == 72:
                    # DOWN key
                    if not self.menu_view['highlighted_item'] <= 1:
                        self.menu_view['highlighted_item'] -= 1

                    self._render_main_menu()

                elif ord(key) == 13:
                    # ENTER key
                    index = self.menu_view['highlighted_item']-1
                    self.view = self.menu_view['options'].values()[index]
                    print "going to %s..." %self.view

                    self._render()

            elif self.view == "virtual-env-list-view":
                pass



            elif self.view == 'main-view':
                if   key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.main_view['current_page'] >= self.main_view['paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.main_view['current_page'] += 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.main_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.main_view['current_page'] -= 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'u':
                    # SORT BY USING
                    self.main_view['ordering'] = 'people using library'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'c':
                    self.view = "category-choice-view"
                    self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])


                elif key == 'g':
                    # UPDATE
                    self.view = 'update-view'
                    self.update()
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])
                    self.view = 'main-view'

                elif key == 'w':
                    # SORT BY WATCHING
                    self.main_view['ordering'] = 'people wathcing repository'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.repo_watchers.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'd':
                    # SORT by Downloads
                    self.main_view['ordering'] = 'PYPI downloads'
                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.pypi_downloads.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package
                    self.view = 'package-view'
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    self._render_package_info(package)

                    rtd_bootstrap = ReadTheDocsBootstrap(proxy=self.proxy)
                    docs = rtd_bootstrap.check_if_docs_exist(package.pypi_package_name or package.repo_name)
                    if docs:
                        self._render_package_info(package, docs=docs)


                elif ord(key) == 72:
                    # pressed UP
                    if not self.main_view['highlighted_item'] <= 1:
                        self.main_view['highlighted_item'] -= 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.main_view['highlighted_item'] >= 10:
                        self.main_view['highlighted_item'] += 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

            elif self.view == 'package-view':

                if key == 'i':
                    #INSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Installing..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    result = self.install(package_names=[package.install_string])
                    if not result:
                        package.update_installed_info()
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render()
                    #self._render_package_info(package)


                elif key == 'u':
                    # UNINSTALL
                    self.view = "install-view"

                    self._clear_screen()

                    puts(colored.magenta("Uninstalling..."))
                    puts()

                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    result = self.uninstall(package_names=[package.pypi_package_name or package.repo_name])
                    if result:
                        puts(result)

                    if not result:
                        package.installed = False
                        self.session.commit()

                    self.main_view['paginator'].refresh_objects()

                    puts()
                    puts(colored.magenta("Press ENTER to continue..."))
                    s = raw_input()

                    self.view = 'package-view'
                    self._render_package_info(package)

                elif ord(key) == 8:
                    # BACKSPACE
                    self.view = 'main-view'
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

                elif key == 'p':
                    # PYPI webpage
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    webbrowser.open(package.pypi_url)

                elif key == 'r':
                    # REPO page
                    package = self.main_view['paginator'].current_page()[self.main_view['highlighted_item']-1]
                    webbrowser.open(package.repo_url)

            elif self.view == 'installed-view':
                pass

            elif self.view == 'category-choice-view':
                if   key == 'n' or ord(key) == 77:
                    # N = Next page
                    if self.category_choice_view['current_page'] >= self.category_choice_view['category_paginator'].num_pages:
                        puts_err("You are already at the last page")
                        continue

                    self.category_choice_view['current_page'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif key == 'p' or ord(key) == 75:
                    # P = Previous page
                    if self.category_choice_view['current_page'] <= 1:
                        puts_err("You are already at the first page")
                        continue

                    self.category_choice_view['current_page'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 13:
                    # Pressed ENTER onto package

                    category = self.category_choice_view['category_paginator'].current_page()[self.category_choice_view['highlighted_item']-1]

                    packages_base_query = self.session.query(Package).filter(Package.categories.any(id=category.id))
                    self.main_view['paginator'] = Paginator(objects=packages_base_query.order_by(Package.pypi_downloads.desc()).all())
                    self.main_view['paginator'].base_query = packages_base_query

                    self.main_view['current_page'] = 1
                    self.main_view['highlighted_item'] = 1
                    self.main_view['info'] = {
                        'Category': category and category.title or 'All',
                        'Package count': len(category.packages),
                    }

                    self.view = 'main-view'
                    self._render()
                    #self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])


                elif ord(key) == 72:
                    # pressed UP
                    if not self.category_choice_view['highlighted_item'] <= 1:
                        self.category_choice_view['highlighted_item'] -= 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 80:
                    # pressed DOWN
                    if not self.category_choice_view['highlighted_item'] >= 10:
                        self.category_choice_view['highlighted_item'] += 1
                    self._render()
                    #self._render_category_choice_view(self.category_choice_view['category_paginator'], self.category_choice_view['current_page'], self.main_view['info'], self.category_choice_view['highlighted_item'])

                elif ord(key) == 8:
                    # BACKSPACE key
                    self.view = 'menu-view'
                    self._render()

                elif key == 'k':
                    # ORDERING by Package count
                    self.category_choice_view['ordering'] = 'package count'
                    #self.category_choice_view['paginator'] = self.category_choice_view['paginator'].base_query.order_by(Category.package.desc()).all()

                    self.main_view['paginator'].objects = self.main_view['paginator'].base_query.order_by(Package.usage_count.desc()).all()
                    self.main_view['current_page'] = 1
                    self._render_package_list(self.main_view['paginator'], self.main_view['current_page'], self.main_view['info'], self.main_view['highlighted_item'])

            elif self.view in ['about-view', 'help-view']:

                if ord(key) == 8:
                    self.view = "menu-view"
                    self._render()