forked from django/code.djangoproject.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move plugins to dedicated module to be able to import django at toplevel
Without that, an AppRegistryNotReady would be thrown when trying to run the wsgi file.
- Loading branch information
Showing
3 changed files
with
95 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +0,0 @@ | ||
from trac.core import Component, implements | ||
from trac.web.chrome import INavigationContributor | ||
from trac.web.api import IRequestFilter, IRequestHandler | ||
from trac.wiki.web_ui import WikiModule | ||
from trac.util import Markup | ||
from trac.util.html import tag | ||
from tracext.github import GitHubBrowser | ||
|
||
|
||
class CustomTheme(Component): | ||
implements(IRequestFilter) | ||
|
||
def pre_process_request(self, req, handler): | ||
return handler | ||
|
||
def post_process_request(self, req, template, data, metadata): | ||
req.chrome["theme"] = "django_theme.html" | ||
return template, data, metadata | ||
|
||
|
||
class CustomWikiModule(WikiModule): | ||
"""Works in combination with the CustomNavigationBar and replaces | ||
the default wiki module. Has a different logic for active item | ||
handling. | ||
""" | ||
|
||
def get_active_navigation_item(self, req): | ||
pagename = req.args.get("page") | ||
if pagename == "Reports": | ||
return "custom_reports" | ||
return "wiki" | ||
|
||
|
||
class CustomNewTicket(Component): | ||
"""Hide certain options for the new ticket page""" | ||
|
||
implements(IRequestFilter, IRequestHandler) | ||
hidden_fields = frozenset( | ||
["stage", "needs_tests", "needs_docs", "needs_better_patch"] | ||
) | ||
|
||
def match_request(self, req): | ||
return req.path_info == "/simpleticket" | ||
|
||
def process_request(self, req): | ||
req.redirect(req.href.newticket()) | ||
|
||
def pre_process_request(self, req, handler): | ||
return handler | ||
|
||
def post_process_request(self, req, template, data, metadata): | ||
if data is None: | ||
data = {} | ||
if req.path_info == "/newticket" and not data.get("preview_mode", False): | ||
simple_interface = "TICKET_BATCH_MODIFY" not in req.perm | ||
if simple_interface and "fields" in data: | ||
data["fields"] = [ | ||
f for f in data["fields"] if f["name"] not in self.hidden_fields | ||
] | ||
data["simple_interface"] = simple_interface | ||
template = "custom_ticket.html" | ||
return template, data, metadata | ||
|
||
|
||
class CustomNavigationBar(Component): | ||
"""Implements some more items for the navigation bar.""" | ||
|
||
implements(INavigationContributor) | ||
|
||
def get_active_navigation_item(self, req): | ||
return "custom_reports" | ||
|
||
def get_navigation_items(self, req): | ||
return [ | ||
( | ||
"mainnav", | ||
"custom_reports", | ||
Markup('<a href="%s">Reports</a>' % req.href.wiki("Reports")), | ||
), | ||
] | ||
|
||
|
||
class GitHubBrowserWithSVNChangesets(GitHubBrowser): | ||
def _format_changeset_link(self, formatter, ns, chgset, label, fullmatch=None): | ||
# Dead-simple version for SVN changesets. | ||
if chgset.isnumeric(): | ||
href = formatter.href.changeset(chgset, None, "/") | ||
return tag.a(label, class_="changeset", href=href) | ||
|
||
# Fallback to the default implementation. | ||
return super(GitHubBrowserWithSVNChangesets, self)._format_changeset_link( | ||
formatter, ns, chgset, label, fullmatch | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
from trac.core import Component, implements | ||
from trac.web.chrome import INavigationContributor | ||
from trac.web.api import IRequestFilter, IRequestHandler | ||
from trac.wiki.web_ui import WikiModule | ||
from trac.util import Markup | ||
from trac.util.html import tag | ||
from tracext.github import GitHubBrowser | ||
|
||
|
||
class CustomTheme(Component): | ||
implements(IRequestFilter) | ||
|
||
def pre_process_request(self, req, handler): | ||
return handler | ||
|
||
def post_process_request(self, req, template, data, metadata): | ||
req.chrome["theme"] = "django_theme.html" | ||
return template, data, metadata | ||
|
||
|
||
class CustomWikiModule(WikiModule): | ||
"""Works in combination with the CustomNavigationBar and replaces | ||
the default wiki module. Has a different logic for active item | ||
handling. | ||
""" | ||
|
||
def get_active_navigation_item(self, req): | ||
pagename = req.args.get("page") | ||
if pagename == "Reports": | ||
return "custom_reports" | ||
return "wiki" | ||
|
||
|
||
class CustomNewTicket(Component): | ||
"""Hide certain options for the new ticket page""" | ||
|
||
implements(IRequestFilter, IRequestHandler) | ||
hidden_fields = frozenset( | ||
["stage", "needs_tests", "needs_docs", "needs_better_patch"] | ||
) | ||
|
||
def match_request(self, req): | ||
return req.path_info == "/simpleticket" | ||
|
||
def process_request(self, req): | ||
req.redirect(req.href.newticket()) | ||
|
||
def pre_process_request(self, req, handler): | ||
return handler | ||
|
||
def post_process_request(self, req, template, data, metadata): | ||
if data is None: | ||
data = {} | ||
if req.path_info == "/newticket" and not data.get("preview_mode", False): | ||
simple_interface = "TICKET_BATCH_MODIFY" not in req.perm | ||
if simple_interface and "fields" in data: | ||
data["fields"] = [ | ||
f for f in data["fields"] if f["name"] not in self.hidden_fields | ||
] | ||
data["simple_interface"] = simple_interface | ||
template = "custom_ticket.html" | ||
return template, data, metadata | ||
|
||
|
||
class CustomNavigationBar(Component): | ||
"""Implements some more items for the navigation bar.""" | ||
|
||
implements(INavigationContributor) | ||
|
||
def get_active_navigation_item(self, req): | ||
return "custom_reports" | ||
|
||
def get_navigation_items(self, req): | ||
return [ | ||
( | ||
"mainnav", | ||
"custom_reports", | ||
Markup('<a href="%s">Reports</a>' % req.href.wiki("Reports")), | ||
), | ||
] | ||
|
||
|
||
class GitHubBrowserWithSVNChangesets(GitHubBrowser): | ||
def _format_changeset_link(self, formatter, ns, chgset, label, fullmatch=None): | ||
# Dead-simple version for SVN changesets. | ||
if chgset.isnumeric(): | ||
href = formatter.href.changeset(chgset, None, "/") | ||
return tag.a(label, class_="changeset", href=href) | ||
|
||
# Fallback to the default implementation. | ||
return super(GitHubBrowserWithSVNChangesets, self)._format_changeset_link( | ||
formatter, ns, chgset, label, fullmatch | ||
) |