Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed title of /query page to manage navigation menu #217

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .TRACFREEZE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# generated by traccheck.py on 2024-04-18 14:36:14 with Trac version 1.6
# generated by traccheck.py on 2024-10-12 11:43:25 with Trac version 1.6
trac.admin.api.admincommandmanager
trac.admin.console.tracadminhelpmacro
trac.admin.web_ui.adminmodule
Expand Down Expand Up @@ -66,7 +66,6 @@ trac.ticket.notification.ticketownersubscriber
trac.ticket.notification.ticketpreviousupdaterssubscriber
trac.ticket.notification.ticketreportersubscriber
trac.ticket.notification.ticketupdatersubscriber
trac.ticket.query.querymodule
trac.ticket.query.ticketquerymacro
trac.ticket.roadmap.defaultticketgroupstatsprovider
trac.ticket.roadmap.milestonemodule
Expand Down Expand Up @@ -106,6 +105,7 @@ tracdjangoplugin.plugins.customtheme
tracdjangoplugin.plugins.customwikimodule
tracdjangoplugin.plugins.githubbrowserwithsvnchangesets
tracdjangoplugin.plugins.plainlogincomponent
tracdjangoplugin.plugins.renamequerytitlecomponent
tracdjangoplugin.plugins.reservedusernamescomponent
tracdragdrop.web_ui.tracdragdropmodule
tracext.github.githubloginmodule
Expand Down
13 changes: 13 additions & 0 deletions DjangoPlugin/tracdjangoplugin/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from trac.web.api import IRequestFilter, IRequestHandler, RequestDone
from trac.web.auth import LoginModule
from trac.wiki.web_ui import WikiModule
from trac.ticket.query import QueryModule
from trac.util.html import tag
from tracext.github import GitHubLoginModule, GitHubBrowser

Expand Down Expand Up @@ -190,3 +191,15 @@ def force_logout_and_redirect(self, req):

def post_process_request(self, req, template, data, metadata):
return template, data, metadata # required by Trac to exist


class RenameQueryTitleComponent(QueryModule):
"""
Change the title of the /query page so that the navmenu entry matches the
page's <h1>.
"""

def display_html(self, req, query):
template_name, context = super().display_html(req, query)
context["title"] = "View Tickets"
return template_name, context
65 changes: 65 additions & 0 deletions DjangoPlugin/tracdjangoplugin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
ReStructuredTextRenderer, # noqa: needed for RSTWikiTestCase to work
)
from trac.test import EnvironmentStub, MockRequest
from trac.ticket.web_ui import TicketModule # Imported for side effects
from trac.ticket.query import QueryModule # Imported for side effects
from trac.web.api import RequestDone
from trac.web.main import RequestDispatcher

from tracdjangoplugin.middlewares import DjangoDBManagementMiddleware
from tracdjangoplugin.plugins import PlainLoginComponent, ReservedUsernamesComponent
Expand Down Expand Up @@ -258,3 +261,65 @@ def test_wiki_can_render_rst(self):
str(output),
'<div class="document" id="test"><h1 class="title">TEST</h1></div>',
)


class _TracRequestWrapper:
"""
Wrap a Trac request object to make it look like a Django response (so it
can be used with assertContains)
"""

streaming = False
charset = "utf8"

def __init__(self, request):
self._request = request

@property
def status_code(self):
status_str, _ = self._request._status.split(" ", 1)
return int(status_str)

@property
def content(self):
return self._request.response_sent.getvalue()


class RenameQueryTitleComponentTestCase(TestCase):
def setUp(self):
self.env = EnvironmentStub(
enable=[
"trac.ticket.*",
"trac.ticket.query.*",
"trac.web.*",
"tracdjangoplugin.plugins.renamequerytitlecomponent",
],
disable=[
"trac.ticket.query.querymodule",
],
)
self.request_factory = partial(MockRequest, self.env)
self.dispatcher = RequestDispatcher(self.env)

def get_response(self, **kwargs):
"""
Build a request using the given kwargs and return a Django-like
response object.
"""
request = self.request_factory(**kwargs)
self.assertRaises(RequestDone, self.dispatcher.dispatch, request)
return _TracRequestWrapper(request)

def test_new_title(self):
response = self.get_response(path_info="/query")

self.assertContains(
response,
'<h1>View Tickets <span class="numrows">(0 matches)</span></h1>',
html=True,
)
self.assertNotContains(
response,
'<h1>Custom Query <span class="numrows">(0 matches)</span></h1>',
html=True,
)
3 changes: 2 additions & 1 deletion trac-env/conf/trac.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ wiki_format_messages = enabled
trac.about.* = disabled
trac.admin.web_ui.PluginAdminPanel = disabled
trac.ticket.query.* = enabled
trac.ticket.query.querymodule = enabled
# replaced by tracdjangoplugin.plugins.RenameQueryTitleComponent
trac.ticket.query.querymodule = disabled
trac.ticket.query.ticketquerymacro = enabled
trac.ticket.report.* = disabled
trac.ticket.report.reportmodule = disabled
Expand Down
Loading