View unanswered posts | View active topics It is currently Mon May 20, 2013 11:09 pm



Reply to topic  [ 2 posts ] 
 strange behaviour in Python template code 
Author Message

Joined: Jul 01, 2007
Posts: 17
Post strange behaviour in Python template code
I've spent many hours trying to figure out a mysterious control page behavior, without success. I wonder if someone else can spot what I'm doing wrong?

Here's some background. There are browsers connected to Indigo control pages running on several Nokia N-770 internet tablets scattered around the house. Each location shows the same control pages, except that there's one page customized for each location.

Every control page has buttons at the bottom to select other control pages such as timers, security, HVAC, etc. However, there's also a LOCAL button on each page, which goes to the control page customized for the location of each browser. Rather than make up several sets of control pages, identical except for the links associated with the page-selection buttons, I wanted to do this programatically.

With Matt's guidance, I modified the "actionType == 1015" section of _pageelem.html (see code excerpt below) to look at a "browserId" parameter in the URL and dispatch appropriately. (This is the code that creates the target URL for onClick events.) This works just as intended. If the target control page is "Local", the code changes the URL target to the name in browserId. If browserId = unknown, the template runs the original un-modified code (this should never occur, in practice). If the browserId is anything else, it's just passed on in the URL.

However, there's a strange side effect. When running the modified code, the displays for page elements showing variables mostly (but not always) do not update. I.e., if a variable value changes, its state on the web page does not change until the page is manually refreshed. When this failure happens, the spinning-gear refresh icon spins forever, indicating that the browser failed to render the whole page. Firefox's Javascipt Console says
Code: Select all
Error: no element found
Source File: http://localhost:8176/_getupdatedcontrols?name=Timers&changeCount=248&serverState=idle&hash=14793&_=
Line: 1, Column: 1

Revert to the original code by changing the "#if False ...#, and the pages update reliably, although, of course, my browserId modifications are no longer in place.

In the following code excerpt, "if False" skips the original code and executes my modified code. Changing that to "if True" executes the original code instead. What's really peculiar is that the "browserId == unknown" option also runs the original code. (It was carefully copied and pasted in place to make sure there were no typos.) It should work just as when "#if True". However, this is not the case. The same problem of not updating variable-referenced display items occurs when running the identical code--just in a slighty different place.

I've confirmed that "if" statements are going through the expected branches with debugging statements. So, two questions: why don't variables update reliably when using the modified code, and why does this behavior occur when the original code (which works reliably) is moved into an "if" statement, which is confirmed to be executing only the branch with the original code?

I'm not a Python person, so perhaps there's something obvious I'm doing wrong. Any ideas would be appreciated--I've been struggling with this for quite a while. Thanks.

Jeff

Code: Select all
#else if $pageElem.actionType == 1015
 #if False
  <!-- original code -->
  <a href="controlpage?name=${pageElem.actionLinkTarget, entityEncoding='URL'}" ${pageElem.actionLinkHrefTarget, entityEncoding='skip'}>#slurp
 #else
  <!-- modified code -->
  #if $pageElem.actionLinkTarget == "Local"
    <!-- if LOCAL button clicked, go to controlpage = browserId value -->
    <a href="controlpage?name=${browserId, entityEncoding='URL'}&browserId=${browserId, entityEncodeing='URL'}" ${pageElem.actionLinkHrefTarget, entityEncoding='skip'}>#slurp     
  #else if $browserId == "unknown"
    <!-- if no browserId parameter supplied, execute original code -->
     <a href="controlpage?name=${pageElem.actionLinkTarget, entityEncoding='URL'}" ${pageElem.actionLinkHrefTarget, entityEncoding='skip'}>#slurp
  #else
    <!-- if browserId is anything else, just pass it on in the URL -->
    <a href="controlpage?name=${pageElem.actionLinkTarget, entityEncoding='URL'}&browserId=${browserId, entityEncodeing='URL'}" ${pageElem.actionLinkHrefTarget, entityEncoding='skip'}>#slurp
  #end if
 #end if


Mon Aug 06, 2007 8:09 am
Profile
Site Admin
User avatar

Joined: Jan 27, 2003
Posts: 11689
Location: Texas
Post Re: strange behaviour in Python template code
Hi Jeff,

Try adding a test to both of your conditionals to make sure the variables are not None first:

Code: Select all
  #if $pageElem.actionLinkTarget and $pageElem.actionLinkTarget == "Local"

Code: Select all
  #else if $browserId and $browserId == "unknown"

I'm not positive that will help, but I think it might.

Regards,
Matt


Mon Aug 06, 2007 1:33 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.   Template designed by STSoftware.