Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: django/code.djangoproject.com
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: bmispelon/code.djangoproject.com
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: query-page-title-rename
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 4 files changed
  • 1 contributor

Commits on Oct 12, 2024

  1. Copy the full SHA
    9f8e4f7 View commit details
Showing with 82 additions and 3 deletions.
  1. +2 −2 .TRACFREEZE.txt
  2. +13 −0 DjangoPlugin/tracdjangoplugin/plugins.py
  3. +65 −0 DjangoPlugin/tracdjangoplugin/tests.py
  4. +2 −1 trac-env/conf/trac.ini
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
@@ -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
@@ -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
13 changes: 13 additions & 0 deletions DjangoPlugin/tracdjangoplugin/plugins.py
Original file line number Diff line number Diff line change
@@ -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

@@ -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
@@ -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
@@ -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
@@ -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