Opened 17 years ago
Closed 17 years ago
#6033 closed defect (fixed)
The "context" object is missing from within several templates
Reported by: | Owned by: | Christian Boos | |
---|---|---|---|
Priority: | normal | Milestone: | 0.11 |
Component: | wiki system | Version: | devel |
Severity: | normal | Keywords: | context |
Cc: | Branch: | ||
Release Notes: | |||
API Changes: | |||
Internal Changes: |
Description
Problem:
A call to "wiki_to_html" needs the "context" object as a first parameter.
The context object is missing from within several templates, e.g. the "timeline", thus "wiki_to_html" cannot be used within those.
Reproduction:
add the following to "timeline.html"
${wiki_to_html(context, "WikiStart test")
clicking on "timeline" results in an error.
Trac detected an internal error: UndefinedError: "context" not defined
Trac should create a default "context" object, thus calls to wiki_to_html work fine (note that in other places the same happens, e.g. "admin")
For the case this will not fix: Is there any simple way to obtain a default context-object (e.g. the wiki root) within a template, thus "wiki_to_html" works?
Attachments (0)
Change History (10)
follow-up: 2 comment:1 by , 17 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
comment:2 by , 17 years ago
Resolution: | invalid |
---|---|
Status: | closed → reopened |
Replying to ThurnerRupert:
why would you need to call wiki_to_html in a template, i thought you write html directly there?
pls reopen if i am wrong.
With all respect: "Thinking" something about the trac design is no a valid reason to close a ticket as 'invalid' (see the TracTicketTriage).
As to your question: One standard use-case of "wiki_to_html" within the standard trac-templates (ticket/templates/report-view.html):
<div py:if="report.description" id="description" xml:space="preserve"> ${wiki_to_html(context, report.description)} </div>
You will see that "wiki_to_html" is used in many different standard templates, but where it's not used, a "context" object is missing, which makes template customization difficult (especially an overall customization within "layout.html").
comment:3 by , 17 years ago
Keywords: | context added |
---|
I've noticed the document TracDev/ContextRefactoring, but I am still not able to create a workaround.
How can I obtain a default root-context object within a template programatically (if context is not provided)?
follow-up: 5 comment:4 by , 17 years ago
For now, you can't, as this would require to do Context(env, req)
and the "Context" symbol is not available.
With the new proposal, it will always be possible to create a RenderingContext
easily from within a template, by doing either context()
(the toplevel context), or context(resource)
(for some resource).
comment:5 by , 17 years ago
Replying to cboos:
For now, you can't, as this would require to do
Context(env, req)
and the "Context" symbol is not available.
I understand. I may have missunderstood something, but shouldnt it be possible to do something like (pseudo code)
<?python> import trac.context.Context as Context if not (defined context): context = Context(env, req) <?> # usage of context
With the new proposal, it will always be possible to create a
RenderingContext
easily from within a template, by doing eithercontext()
(the toplevel context), orcontext(resource)
(for some resource).
ok, sounds good.
As I'm currently within a dead-lock situation:
would it be possible to make "wiki_to_html" use the root context by default? (e.g. passing and undefined "context" makes "wiki_to_html" create internally the wiki root object.
As said, I may have missunderstood something of the current design. I use wiki_to_html just for template customization.
comment:6 by , 17 years ago
After some problems with genshi (see genshi:#153 and genshi:#154 ) I'm able to have full access to code within the templates.
So, I have the context symbol available now.
I place this code before the body tag (of the wiki_view.html template):
<?python from trac.context import Context as C def w2h(wikitext,env, req): ctxx = C(env, req)('wiki','WikiStart') return wiki_to_html(ctxx, wikitext) ?> ${w2h('Test WikiStart',trac.xenv,req)}
but I get an error:
AttributeError: 'Context' object has no attribute 'id'
Most possibly I've overseen a detail.
If not, isn't at this point any lower level function available, which converts wiki to html, without any need to pass a context? Such a simpler function would be useful.
comment:9 by , 17 years ago
Milestone: | → 0.11 |
---|
After the context-refactoring, there will actually be a context
object (trac.mimeview.api.Context) available in the data dictionary.
why would you need to call wiki_to_html in a template, i thought you write html directly there?
pls reopen if i am wrong.