Skip to content

Commit

Permalink
[CHG] Renamed model 'IndexPage' to 'MainMenuEntry' and adapted every …
Browse files Browse the repository at this point in the history
…other mentions
  • Loading branch information
sveetch committed Sep 19, 2024
1 parent e963369 commit 8e181ff
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ superuser: ## Create an admin user with password "admin"

test-back: ## run back-end tests, or specific test like `make test-back tests/apps/core/test_web_analytics.py`
@args="$(filter-out $@,$(MAKECMDGOALS))" && \
DB_PORT=$(DB_PORT) bin/pytest --reuse-db $${args:-${1}}
DB_PORT=$(DB_PORT) bin/pytest $${args:-${1}}
.PHONY: test-back

# -- Internationalization
Expand Down
4 changes: 2 additions & 2 deletions sandbox/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura

# Wheither you can create PageIndex extension on page through toolbar if true or
# just editing existing extension if false
RICHIE_PAGEINDEX_ALLOW_CREATION = False
RICHIE_MAINMENUENTRY_ALLOW_CREATION = False

# Define which node level can be processed to search for pageindex extension
RICHIE_PAGEINDEX_MENU_ALLOWED_LEVEL = 0
RICHIE_MAINMENUENTRY_MENU_ALLOWED_LEVEL = 0

@classmethod
def _get_environment(cls):
Expand Down
6 changes: 3 additions & 3 deletions src/richie/apps/courses/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ def snapshot(self, request, course_id, *args, **kwargs):
return JsonResponse({"id": new_page.course.id})


class IndexPageAdmin(PageExtensionAdmin):
class MainMenuEntryAdmin(PageExtensionAdmin):
"""
Admin class for the IndexPage model
Admin class for the MainMenuEntry model
"""

list_display = ["title", "allow_submenu"]
Expand Down Expand Up @@ -364,7 +364,7 @@ class LicenceAdmin(TranslatableAdmin):
admin.site.register(models.Course, CourseAdmin)
admin.site.register(models.CourseRun, CourseRunAdmin)
admin.site.register(models.Licence, LicenceAdmin)
admin.site.register(models.IndexPage, IndexPageAdmin)
admin.site.register(models.MainMenuEntry, MainMenuEntryAdmin)
admin.site.register(models.Organization, OrganizationAdmin)
admin.site.register(models.PageRole, PageRoleAdmin)
admin.site.register(models.Person, PersonAdmin)
18 changes: 9 additions & 9 deletions src/richie/apps/courses/cms_menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
from menus.base import Modifier
from menus.menu_pool import menu_pool

from .models import IndexPage
from .models import MainMenuEntry


class MenuWithIndexPage(Modifier):
class MenuWithMainMenuEntry(Modifier):
"""
Menu modifier to include IndexPage extension data in menu template context.
Menu modifier to include MainMenuEntry extension data in menu template context.
In menu template you will be able to reach possible extension data from node
attribute ``menu_extension``. If node page has no extension it will have an empty
dict. Only a specific node level is processedn nodes with a different level won't
have the attribute ``menu_extension`` at all.
dict. Only a specific node level is processed and nodes with a different level
won't have the attribute ``menu_extension`` at all.
"""

# pylint: disable=too-many-arguments
def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
"""
Patch navigation nodes to include data from possible extension
``IndexPage``.
``MainMenuEntry``.
For performance:
Expand All @@ -47,7 +47,7 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
page_ids = [
node.id
for node in nodes
if node.level == settings.RICHIE_PAGEINDEX_MENU_ALLOWED_LEVEL
if node.level == settings.RICHIE_MAINMENUENTRY_MENU_ALLOWED_LEVEL
]

# No need to continue if we don't have any valid node
Expand All @@ -56,7 +56,7 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):

# We directly get the extensions from their related page id and serialized
# as a dict instead of model object
extension_queryset = IndexPage.objects.filter(
extension_queryset = MainMenuEntry.objects.filter(
extended_object_id__in=page_ids
).values("extended_object_id", "allow_submenu", "menu_color")

Expand All @@ -76,4 +76,4 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
return nodes


menu_pool.register_modifier(MenuWithIndexPage)
menu_pool.register_modifier(MenuWithMainMenuEntry)
20 changes: 10 additions & 10 deletions src/richie/apps/courses/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from cms.utils.urlutils import admin_reverse

from .defaults import PAGE_EXTENSION_TOOLBAR_ITEM_POSITION
from .models import Category, Course, IndexPage, Organization, Person
from .models import Category, Course, MainMenuEntry, Organization, Person


class BaseExtensionToolbar(ExtensionToolbar):
Expand Down Expand Up @@ -135,21 +135,21 @@ class PersonExtensionToolbar(BaseExtensionToolbar):


@toolbar_pool.register
class IndexPageExtensionToolbar(BaseExtensionToolbar):
class MainMenuEntryExtensionToolbar(BaseExtensionToolbar):
"""
This extension class customizes the toolbar for the IndexPage page extension.
This extension class customizes the toolbar for the MainMenuEntry page extension.
"""

model = IndexPage
model = MainMenuEntry

def populate(self):
"""
Specific extension populate method.
This extension entry only appears in toolbar if page already have extension or
if setting ``RICHIE_PAGEINDEX_ALLOW_CREATION`` is true. Finally the page level
must also match the allowed level from setting
``RICHIE_PAGEINDEX_MENU_ALLOWED_LEVEL``.
if setting ``RICHIE_MAINMENUENTRY_ALLOW_CREATION`` is true. Finally the page
level must also match the allowed level from setting
``RICHIE_MAINMENUENTRY_MENU_ALLOWED_LEVEL``.
"""
# always use draft if we have a page
self.page = get_page_draft(self.request.current_page)
Expand All @@ -167,16 +167,16 @@ def populate(self):
level = self.page.node.get_depth() - 1
allowed = page_extension is not None or (
page_extension is None
and settings.RICHIE_PAGEINDEX_ALLOW_CREATION is True
and settings.RICHIE_MAINMENUENTRY_ALLOW_CREATION is True
)
if (
allowed
and level == settings.RICHIE_PAGEINDEX_MENU_ALLOWED_LEVEL
and level == settings.RICHIE_MAINMENUENTRY_MENU_ALLOWED_LEVEL
and admin_url
):
# Adds a toolbar item in position 0 (at the top of the menu)
page_menu.add_modal_item(
_("Index Page settings"),
_("Main menu settings"),
url=admin_url,
disabled=not self.toolbar.edit_mode_active,
position=PAGE_EXTENSION_TOOLBAR_ITEM_POSITION,
Expand Down
9 changes: 2 additions & 7 deletions src/richie/apps/courses/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
"reverse_id": "organizations",
"template": "courses/cms/organization_detail.html",
}
INDEXES_PAGE = {
MENUENTRIES_PAGE = {
"reverse_id": None,
"template": "richie/single_column.html",
}
Expand Down Expand Up @@ -344,11 +344,6 @@
"in_navigation": True,
"template": "search/search.html",
},
INDEXES_PAGE["reverse_id"]: {
"title": "Indexes",
"in_navigation": True,
"template": "richie/single_column.html",
},
ORGANIZATIONS_PAGE["reverse_id"]: {
"title": "Organizations",
"in_navigation": True,
Expand Down Expand Up @@ -392,7 +387,7 @@
# The additional runs can be viewed by clicking on `View more` link.
RICHIE_MAX_ARCHIVED_COURSE_RUNS = 10

# Define possible hover color that can be choosen for an IndexPage and to apply on
# Define possible hover color that can be choosen for an MainMenuEntry and to apply on
# its menu item
INDEX_MENU_COLOR_CLASSES = getattr(
settings,
Expand Down
8 changes: 4 additions & 4 deletions src/richie/apps/courses/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,14 +912,14 @@ def fill_excerpt(self, create, extracted, **kwargs):
)


class IndexPageFactory(BLDPageExtensionDjangoModelFactory):
class MainMenuEntryFactory(BLDPageExtensionDjangoModelFactory):
"""
A factory to automatically generate random yet meaningful index page extensions
A factory to automatically generate random yet meaningful menu entry page extensions
and their related page in our tests.
"""

class Meta:
model = models.IndexPage
model = models.MainMenuEntry
exclude = [
"page_in_navigation",
"page_languages",
Expand All @@ -930,6 +930,6 @@ class Meta:
]

# fields concerning the related page
page_template = models.IndexPage.PAGE["template"]
page_template = models.MainMenuEntry.PAGE["template"]
allow_submenu = False
menu_color = ""
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Generated by Django 4.2.14 on 2024-09-09 15:06
# Generated by Django 4.2.16 on 2024-09-19 00:24

import django.db.models.deletion
from django.db import migrations, models

from ..defaults import INDEX_MENU_COLOR_CLASSES


class Migration(migrations.Migration):

Expand All @@ -15,7 +13,7 @@ class Migration(migrations.Migration):

operations = [
migrations.CreateModel(
name="IndexPage",
name="MainMenuEntry",
fields=[
(
"id",
Expand All @@ -38,9 +36,13 @@ class Migration(migrations.Migration):
"menu_color",
models.CharField(
blank=True,
choices=INDEX_MENU_COLOR_CLASSES,
choices=[
("", "None"),
("primary", "Primary"),
("warning", "Warning"),
],
default="",
help_text="A color used to display page in menu",
help_text="A color used to display page entry in menu.",
max_length=10,
verbose_name="Color in menu",
),
Expand All @@ -60,14 +62,14 @@ class Migration(migrations.Migration):
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="draft_extension",
to="courses.indexpage",
to="courses.mainmenuentry",
),
),
],
options={
"verbose_name": "index",
"verbose_name_plural": "indexes",
"db_table": "richie_index",
"verbose_name": "main menu entry",
"verbose_name_plural": "main menu entries",
"db_table": "richie_menuentry",
"ordering": ["-pk"],
},
),
Expand Down
2 changes: 1 addition & 1 deletion src/richie/apps/courses/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .blog import *
from .category import *
from .course import *
from .index import *
from .menuentry import *
from .organization import *
from .person import *
from .program import *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Declare and configure the models for the index part
Declare and configure the models for the menu entry part
"""

from django.db import models
Expand All @@ -11,21 +11,21 @@
from .. import defaults


class IndexPage(BasePageExtension):
class MainMenuEntry(BasePageExtension):
"""
The IndexPage extension defines some options for a page entry in the main menu.
The MainMenuEntry extension defines some options for a page entry in the main menu.
"""

PAGE = defaults.INDEXES_PAGE
PAGE = defaults.MENUENTRIES_PAGE

class Meta:
db_table = "richie_index"
db_table = "richie_menuentry"
ordering = ["-pk"]
verbose_name = _("index")
verbose_name_plural = _("indexes")
verbose_name = _("main menu entry")
verbose_name_plural = _("main menu entries")

def __str__(self):
"""Human representation of an index page"""
"""Human representation of an main menu entry page"""
model = self._meta.verbose_name.title()
name = self.extended_object.get_title()
return f"{model:s}: {name:s}"
Expand All @@ -44,8 +44,8 @@ def __str__(self):
default="",
blank=True,
choices=defaults.INDEX_MENU_COLOR_CLASSES,
help_text=_("A color used to display page in menu"),
help_text=_("A color used to display page entry in menu."),
)


extension_pool.register(IndexPage)
extension_pool.register(MainMenuEntry)
10 changes: 5 additions & 5 deletions src/richie/apps/courses/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,11 +580,11 @@ def richie_placeholder_conf(name):

# If true the toolbar item will already be showed. If false only a page which already
# have the extension will have the toolbar item and users won't be able to add
# pageindex extension on existing page, only create new page with index extension
# MainMenuEntry extension on existing page, only create new page with index extension
# through the wizard.
RICHIE_PAGEINDEX_ALLOW_CREATION = False
RICHIE_MAINMENUENTRY_ALLOW_CREATION = False

# Define which node level can be processed to search for pageindex extension. You can
# set it to 'None' for never processing any node.
# Define which node level can be processed to search for MainMenuEntry extension. You
# can set it to 'None' for never processing any node.
# This is a limit against performance issues to avoid making querysets for nothing.
RICHIE_PAGEINDEX_MENU_ALLOWED_LEVEL = 0
RICHIE_MAINMENUENTRY_MENU_ALLOWED_LEVEL = 0
Loading

0 comments on commit 8e181ff

Please sign in to comment.