On Tue, Oct 28, 2008 at 10:13 AM, Ted Gifford <[EMAIL PROTECTED]> wrote:
>
>
> On Tue, Oct 28, 2008 at 5:16 AM, Martin S. <[EMAIL PROTECTED]>
> wrote:
>>
>> On Oct 28, 2:44 am, "Ted Gifford" <[EMAIL PROTECTED]> wrote:
>> > Random number,
>> > perhaps?http://www.python.org/doc/2.5.2/lib/module-random.html
>> A random number is much less unique than a incremented number, because
>> you have
>> the chance - even if it's a very small one - that you get the number
>> twice.
>>
>> > I'm wondering if you actually need the ID, or if it just makes it more
>> > convenient to write some javascript or something. How do you use it?
>> I need the ID for javascript, in order to call getElementById on it.
>> Because the macro could get used twice on the same wiki page I need
>> unique IDs.
>>
>> I now implemented it with a class integer variable which gets
>> incremented every time the macro is called - which works ok so far.
>> Because it isn't reset (as long trac isn't restarted) there might be
>> in theory an overrun after a long runtime, which should be ok.
>
> For the devil's advocate in me: If that risk is okay, have you calculated
> the risk of duplicate random numbers? It's probably just as small, .... or
> hold that thought, this is python so I think integers grow pretty much
> without bound (where your use case is concerned).
> But again, I'm not sure why you need to use getElementById. Trac ships with
> jQuery, which allows you to scope things very nicely, e.g.
> jQuery('.someContainerOfMyMacroClass .trigger').click(function(){
>   jQuery(this).parent().append("<p>You clicked the trigger</p>");
> });
> ..........
> <div class="someContainerOfMyMacroClass">
>   <a class="trigger" href="#">Click me!</a>
>   <!-- <p>You clicked the trigger</p> shows up here -->
> </div>
> It's better than adding IDs, at least for my aesthetics.
> Ted

I had a similar situation to this at one point, and my first attempt
to solve it did involve using unique, autoincremented ids for each
macro.  It's an ugly hack, but I got the job done by just using
req.args.  I had an argument in req.args like
req.args['__macro_count'] (but a little less vague in reality).  So
each time the macro is rendered in the course of a single request,
that value was incremented.

But like I said, it's a hack.  And I ended up doing exactly what Ted
suggested in the above message, which works fine.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to