Edgewall Software
Modify

Opened 17 years ago

Closed 16 years ago

#6033 closed defect (fixed)

The "context" object is missing from within several templates

Reported by: ilias@… 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)

comment:1 by ThurnerRupert, 17 years ago

Resolution: invalid
Status: newclosed

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.

in reply to:  1 comment:2 by ilias@…, 17 years ago

Resolution: invalid
Status: closedreopened

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 ilias@…, 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)?

comment:4 by Christian Boos, 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).

in reply to:  4 comment:5 by ilias@…, 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 either context() (the toplevel context), or context(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 ilias@…, 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:7 by ilias@…, 17 years ago

correction:

${w2h('Test WikiStart', env, req)}

comment:8 by ilias@…, 17 years ago

related: #6144

comment:9 by Christian Boos, 16 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.

comment:10 by Christian Boos, 16 years ago

Resolution: fixed
Status: reopenedclosed

Now in trunk (r6139).

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.