lundi 29 juin 2015

Django : HTML Table with iterative lists values

I am using Django framework and trying to build a table based on the values i have in a list:

list : [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [3, 3, 3, 3]] The table should be as shown below:

The code I have used is :

  html = "<html><body><br>" \
           "<table border=1 ><thead> <tr><th>result 1</th><th>result 2</th><th>result 3</th><th>result 4</th></tr><thead>{% for item in matrix %} {% for secitem in item %} <tr> <td> {{secitem[0]}} </td>  <td> {{secitem[1]}} </td><td> {{secitem[2]}} </td><td> {{secitem[3]}} </td>  </tr>    {% endfor %}{% endfor %} " \
           "</table></body></html>"

I am not able to get the exact table with the required rows in it. Any help is highly appreciated.![enter image description here][1]

Radiobuttons in a HTML form to remain editable when exporting to PDF

Running into a problem when generating an editable PDF form a html form.

I have a html form with text input fields and radio button selections. When user submits, it will generate an editable PDF (with user-entered data) to the server.

I am able to get the text input fields to remain editable in the PDF but not the radio button selections. These radio buttons automatically rasterized to images.

Is there a solution to this problem? Thanks!

Starting IE 11 from batch file - keeps previous tabs

I am using a batch file to kill all instances of internet explorer, and then start it again using a shortcut that is on the hard drive. The shortcut is a HTML file that has a URL & Login information in it. The IE version is IE 11. The site requires the browser to be Internet Explorer. The batch file is as follows:

taskkill /f /t /im iexplore.exe
start /max "iexplore.exe" "C:\Users\Public\Documents\mysite.htm"

The HTML file has:

<html>
<body onload='f1.submit();'>
<form id=f1 action="http://ift.tt/1IGI68z" method=post>
<input id=uid name=uid type=text value=user1 style="visibility: hidden">
<input id=pwd name=pwd type=text value=pass1 style="visibility: hidden">
<input type=submit style="visibility: hidden">
</form>
</body>
</html>

The problem is, if I X out of the browser, the next time the batch file is run, it opens it in a new tab. So, even though the "new" tab is logged in, the other old tabs are still retained when IE starts again.

How can you make IE 11 forget the last page it had open & force this to open in the first tab of a new browser each time?

Python extract info from a local html file [duplicate]

This question already has an answer here:

I have this local website and I want to extract each line after

<font color='000000'> <u>PATTERN:</font>

Here is the page source, it's an output from the program ApproxMAP on google code:

<! Created by program ApproxMAP by Hye-Chung(Monica) Kum>
<HTML><font size=5 face='Helvetica-Narrow'><b>
<font color='000000'> Cluster Support= [Pattern=</font>
<font color='000000'> 50</font>
<font color='000000'> % : Variation=</font>
<font color='000000'> 20</font>
<font color='000000'> %]; Database Support= [Min= </font>
<font color='000000'> 1</font>
<font color='000000'>  seq: Max=</font>
<font color='000000'> 50</font>
<font color='000000'> %]</font>
<BR>
<font color='a9a9a9'> cluster=0 size=3</font>
<font color='000000'>   =<100:</font>
<font color='434343'> 85:</font>
<font color='767676'> 70:</font>
<font color='a9a9a9'> 50:</font>
<font color='c8c8c8'> 35:</font>
<font color='e1e1e1'> 20></font>
<BR>
<font color='000000'> <u>PATTERN:</font>
<font color='000000'> {1,} {2,3,} {4,5,} 
</font>
<font color='000000'> =</font>
<font color='000000'> 5</font>
<font color='000000'> </u></font>
<BR>
<font color='000000'> {</font>
<font color='000000'> 1</font>
<font color='cbcbcb'> 12</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='cbcbcb'> 24</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='7f7f7f'> 2</font>
<font color='7f7f7f'> 3</font>
<font color='cbcbcb'> 25</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='cbcbcb'> 1</font>
<font color='7f7f7f'> 4</font>
<font color='7f7f7f'> 5</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='cbcbcb'> 26</font>
<font color='000000'> }</font>
<BR>
<font color='000000'> <u>PATTERN:</font>
<font color='000000'> {9,10,} {11,} {12,13,} 
</font>
<font color='000000'> =</font>
<font color='000000'> 5</font>
<font color='000000'> </u></font>
<BR>
<font color='000000'> {</font>
<font color='717171'> 9</font>
<font color='989898'> 10</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='d3d3d3'> 11</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='404040'> 11</font>
<font color='000000'> }</font>
<font color='000000'> {</font>
<font color='404040'> 12</font>
<font color='989898'> 13</font>
<font color='000000'> }</font>
<BR>
<font color='000000'> TOTAL LEN=</font>
<font color='000000'> 10</font>
<BR>
<BR>
</b></font></html>

In this case, I want to extract the following:

{1,} {2,3,} {4,5,} 
{9,10,} {11,} {12,13,} 

Here are some code I tried but none of them worked:

# First try
soup = BeautifulSoup('file:///H:/Approx_google_code/tiny20.html')
soup.findall('PATTERN:')

# Second try
re.search( "PATTERN:", 'file:///H:/Approx_google_code/tiny20.html')

# Third try
soup.body.findAll(text='PATTERN:')

# Forth try
soup.body.findAll(text=re.compile('PATTERN:'))

I've been stuck on this easy problem for so long that I started to wonder whether BeautifulSoup is the right direction. I'm totally new to HTML so any easy explanations / suggestions are welcomed, thanks.

document.getElementById is not working (Object doesn't support property or method 'getElementById')

The element that im trying to get is a checkbox, the content of the page is dynamically created by using ASP.Net.

here is the line where IE11 breaks;

<TD>
    <span id="spnFaxSelected" style="HEIGHT: 100%">
        <span class="">
            <input onclick="document.getElementById(&quot;COIÑAPPÑfax&quot;).checked=this.checked;document.getElementById(&quot;COIÑAPPÑfax&quot;).value=(this.checked)?&#39;on&#39;:&#39;off&#39;;OpenTransaction(this);"
                type="checkbox" id="COIÑAPPÑfax~chk" disabled="disabled" style="BACKGROUND-COLOR:#e4e4e4;" />
            <label for="COIÑAPPÑfax~chk">Fax</label>
            <input id="COIÑAPPÑfax" name="COIÑAPPÑfax" type="hidden" value="off" CAType="CACheckBox" onpropertychange="caCheck()" />
        </span>
    </span>
</TD>

the error that im getting in IE11 debugger is

Object doesn't support property or method 'getElementById'

Any one encountered this problem before?

EDIT: The code works fine in IE9, doesnt work in IE11

scrolltofixed - limit next item

scrolltofixed plugin does not seem to be changing to the next item in the list. See code below: http://ift.tt/1HtOSDZ

var learningObjectives = $('.learning-objective-header');
learningObjectives.each(function(i) {
  var learningObjective = $(learningObjectives[i]);
  var next = learningObjectives[i + 1];

  learningObjective.scrollToFixed({
    marginTop: 137,
    limit: function() {
      var limit = 0;
      if (next) {
        limit = $(next).offset().top - $(this).outerHeight(true);
      }
      return limit;
    }
  });
});

Using HTML5 Drag and Drop for list elements

I have HTML:

 <li class='has-sub'><a href='#'>Registration</a>
            <ul ondragstart="drag(event)" draggable="true">
               <li><a href='1'>Register for Classes</a></li>
               <li><a href='2'>Retake a Course (Academic Forgiveness)</a></li>
               <li><a href='3'>View Your Holds</a></li>

and so on. It's a menu that displays some links. I also have another menu that should allow the user to drop "favorite links" into it:

 <div id="myFavorites" ondrop="drop(event)" ondragover="allowDrop(event)">
    <ul>
        <li class='has-sub'><a href='#'>My Favorites</a>
             <ul id="favoritesList">
                <li><a href='#'>Test1</a></li>
                <li><a href='#'>Test2</a></li>
                <li><a href='#'>Test3</a></li>
                <li><a href='#'>Test4</a></li>
             </ul>
         </li>
    </ul>   
</div>

My javascript appears to be correct:

function drop(ev) {
    //alert("Got here");
    ev.preventDefault();
    var data = ev.dataTransfer.getData("text");
    //var html = ev.dataTransfer.getData("text/html");

    document.getElementById('favoritesList').appendChild(document.getElementById(data).cloneNode(true));
//$("#favoritesList").append(document.getElementById(data));
}

However, when I drag the top menu to the bottom, it doesn't append the entire "li" element to the favorites, only the element inside of it. I've also tried adding the ondragstart="drag(event)" draggable="true" to each individual "li" element, but it's producing the same results. Any suggestions?