displaying custom warning message on new ticket page.

5 views
Skip to first unread message

pierre...@gmail.com

unread,
Jan 28, 2008, 6:04:19 AM1/28/08
to Trac Users
Hi,

When accessing the new ticket page of the Trac web site :
http://trac.edgewall.org/newticket , a warning window is displayed on
top of the new ticket description "You are about to file a ticket
against Trac (...) "
I would like to implement the same on my system based on Trac 0.11b1.
Where do I have to add this warning ? Templates ?

thanks a lot for your help !

Pierre

osimons

unread,
Jan 28, 2008, 8:49:05 AM1/28/08
to Trac Users
There is an example snippet for including in a project templates/
site.html at:

http://trac.edgewall.org/wiki/TracInterfaceCustomization#SiteAppearance


:::simon

https://www.coderesort.com

pierre...@gmail.com

unread,
Jan 28, 2008, 12:05:55 PM1/28/08
to Trac Users
Ok thanks a lot Simon. I followed your link explanations : the warning
is welle displayed but on top of the page (before logo !) and not
under the "Create new ticket" label. I 've never used templates...
Could you please tell me how to do ? Is it a css property to set up
(I d'ont think so) ....

THanks a lot !
Pierre

On 28 jan, 14:49, osimons <oddsim...@gmail.com> wrote:
> pierrerot...@gmail.com wrote:
> > Hi,
>
> > When accessing the new ticket page of the Trac web site :
> >http://trac.edgewall.org/newticket, a warning window is displayed on

osimons

unread,
Jan 28, 2008, 1:33:02 PM1/28/08
to Trac Users
The basic principle is that the site.html is one file to contain all
your modifications. It usually works by the py:match (element of
attribute), and it allows you to modify the page as it renders - the
matches hook onto specific sections depending on what it tries to find
and modify. A site.html can contain any number of such py:match
sections for whatever you need to modify. This is all Genshi, so the
docs on the templating system can be found there.

Save the following content as 'site.html' inside your projects
templates directory (each Trac project can have their own site.html),
or in a shared location as specified by the '[inherit] templates_dir
=' setting in the project trac.ini:

==== Start cut

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">

<!--! Add modification sections below -->

<form py:match="div[@id='content' and @class='ticket']/form"
py:attrs="select('@*')"
py:if="req.environ['PATH_INFO']=='/newticket' and not 'preview' in
req.args">
<!-- Custom new ticket text goes here - example: -->
<p>Please make sure to search for existing tickets
before reporting a new one!</p>
${select('*')}
</form>

</html>

===== End cut

As a very quick intro to the templating details, here is what happens
on a general level:
- templates are just named, and will be pulled in where they are first
located on template path
- the main layout.html renders and 'pulls in' the specific template
(like ticket.html) to make the full page
- as it gets to the bottom of layout.html, it does an include call for
site.html
- site.html contains modification(s) that change the almost-completed
html page (stream)
- at the end the page is finished and sent to the user.

Now to the details of what this modification does:
- py:if = it is only interested in ticket.html template, and not
diplay in preview
- py:match = XPath query find the position of modification start - it
grabs the form on the page
- the newticket modification is itself a form, and gets inserted into
the page instead of the existing form
- this new form has information text, but is otherwise an empty form
(not very useful)
- py:attrs = select and use in new form all the orgininal <form>
attributes
- ${select('*')} = insert all elements (wildcard, so all content) from
original form

=> So, basically you have a new form replacing the orginal form, but
it pulls in the original attributes and the original content, but
manages to insert some informational text in the process.

Once you grasp the basics, it makes perfect sense. It is an incredibly
poweful way of doing page modifications - anything can be changed,
added and removed; all without the need to modify any of the default
Trac templates directly. And, it works just the same for any plugin
templates for that matter.


:::simon

https://www.coderesort.com

osimons

unread,
Jan 29, 2008, 6:35:53 AM1/29/08
to Trac Users


On Jan 28, 7:33 pm, osimons <oddsim...@gmail.com> wrote:
> pierrerot...@gmail.com wrote:
>
> > On 28 jan, 14:49, osimons <oddsim...@gmail.com> wrote:
> > > There is an example snippet for including in a project templates/
> > > site.html at:
>
> > >http://trac.edgewall.org/wiki/TracInterfaceCustomization#SiteAppearance
> Save the following content as 'site.html' inside your projects
> templates directory (each Trac project can have their own site.html),
> or in a shared location as specified by the '[inherit] templates_dir
> =' setting in the project trac.ini:
>
> ==== Start cut
>
> <html xmlns="http://www.w3.org/1999/xhtml"
> xmlns:py="http://genshi.edgewall.org/"
> xmlns:xi="http://www.w3.org/2001/XInclude"
> py:strip="">
>
> <!--! Add modification sections below -->
>
> </html>
>
> ===== End cut
>

Oops. Seems I shortened and changed the orgiginal from
TracInterfaceCustomisation a bit too much... I also chops the Ticket
properties form when viewing tickets... :-)

For reference, here is the full (working) section as found on t.e.o -
put this inside the site.html <html> tag instead:

<form py:match="div[@id='content' and @class='ticket']/form"
py:attrs="select('@*')">
<py:if test="req.environ['PATH_INFO'] == '/newticket' and (not
'preview' in req.args)">
<p>Please make sure to search for existing tickets before
reporting a new one!</p>
</py:if>
${select('*')}
</form>


:::simon

https://www.coderesort.com

pierre...@gmail.com

unread,
Jan 29, 2008, 9:17:10 AM1/29/08
to Trac Users
Hi again Simon,

Thanks a lot for your time and your usefull comments. I will dig into
template engines very soon as I heard about them but never look at
them closely.
I tried your update but there is still a problem :
The Trac Logo and "Powered by Trac 0.11b1 ...By Edgewall Software."
label are located on top of "Create a new ticket" : the footer seems
to be before the form...
I would be very interested in teo's site.html ...

Thanks again for your precious help

Pierre

osimons

unread,
Jan 29, 2008, 9:58:56 AM1/29/08
to Trac Users


On Jan 29, 3:17 pm, "pierrerot...@gmail.com" <pierrerot...@gmail.com>
wrote:
> I tried your update but there is still a problem :
> The Trac Logo and "Powered by Trac 0.11b1 ...By Edgewall Software."
> label are located on top of "Create a new ticket" : the footer seems
> to be before the form...

That is... impossible :-) I have no idea how that snippet could ever
manage that. Is your Genshi up-to-date - from trunk? Any other
modifications or plugins that change the layout and ordering of that
page?

I've used it for a long time without issues. Anyone else using the
snippet: feel free to chime in with your experience of using it.

> I would be very interested in teo's site.html ...
>

t.e.o is still on 0.10, so that is the old way of site_newticket.cs in
templates folder.


:::simon

https://www.coderesort.com

pierre...@gmail.com

unread,
Jan 29, 2008, 10:08:13 AM1/29/08
to Trac Users
Impossible.... :-) ... I've just washed my glasses and still see what
I described before...
Here's my "trac about" :
Trac: 0.11b1
Python: 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)]
setuptools: 0.6c7
SQLite: 3.3.4
pysqlite: 2.3.2
Genshi: 0.5dev-r789
Pygments: 0.9
Subversion: 1.4.6 (r28521)
jQuery: 1.2.1

And I'm using only one additional plugin which is AccountManager...
Can't understand what happens then...
Reply all
Reply to author
Forward
0 new messages