Wednesday, December 14, 2016

Un quart d'heure d'anonymat en ligne

Le texte ci-dessous est issu d’un article rédigé originellement pour l’INA, actualisé et republié sur le blog de Jean-Marc Manach sous le titre Comment (ne pas) être (cyber)espionné ?. L’article original a été rédigé pendant l’été 2012 [lire plus ...]


Chat sécurisé

Échanger des fichiers

Notes confidentielles

De la difficulté de téléphoner

IRL

Pour aller plus loin

Friday, July 8, 2016

Virtual and Augmented Reality



The ENTiTi software lets you easily transform your art into virtual and augmented reality in just minutes! FREE download now!


a powerful cloud-based platform that enables any company or individual to create interactive virtual and augmented reality content without any developer skills.

Monday, June 27, 2016

SharePoint Calculated Columns


SharePoint Calculated Columns are powerful tools when creating out-of-the-box solutions. With these columns, we can manipulate other columns in the list item. Below are a few basic functions complete with details on how to utilize them...

Here is my lookup values, for an corporate environment sample, with some conditional formatting, HTML and CSS:

=IF([Owner]="Press Review",CONCATENATE("<DIV style='color: #ffffff; background-color: #ff0000; padding: 2px 4px !important;'>"," ",Owner," ","</DIV>"),IF([Owner]="Decisions",CONCATENATE("<DIV style='color: #ffffff; background-color: #2C5700; padding: 2px 4px !important;'>"," ",Owner," ","</DIV>"),IF([Owner]="Staff Notices",CONCATENATE("<DIV style='color: #ffffff; background-color: #FF9E00; padding: 2px 4px !important;'>"," ",Owner," ","</DIV>"),IF([Owner]="Job Vacancies",CONCATENATE("<DIV style='color: #ffffff; background-color: #009ECE; padding: 2px 4px !important;'>"," ",Owner," ","</DIV>"),IF([Owner]="Training",CONCATENATE("<DIV style='color: #ffffff; background-color: #CE0000; padding: 2px 4px !important;'>"," ",Owner," ","</DIV>")

Tuesday, June 7, 2016

Dominate creating and manipulating HTML documents


Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.

Simple Image Gallery

import glob
from dominate import document
from dominate.tags import *

photos = glob.glob('photos/*.jpg')

with document(title='Photos') as doc:
    h1('Photos')
    for path in photos:
        div(img(src=path), _class='photo')

with open('gallery.html', 'w') as f:
    f.write(doc.render())


Result:

<!DOCTYPE html>
<html>
  <head>
    <title>Photos</title>
  </head>
  <body>
    <h1>Photos</h1>
    <div class="photo">
      <img src="photos/IMG_5115.jpg">
    </div>
    <div class="photo">
      <img src="photos/IMG_5117.jpg">
    </div>
  </body>
</html>

in stackoverflow creating html in python

Tuesday, May 24, 2016

Python and HTML files

Python Phrasebook Covers

url parse

from urllib.parse import urlparse, urlunparse, urljoin
print("=== 0801_url_parse.py ===")

URLscheme = "http"
URLlocation = "www.python.org"
URLpath = "lib/module-urlparse.html"

modList = ("urllib", "urllib2", "httplib", "cgilib")

#Distribution de l'adresse dans un tuple
print("Recherche Google parsée pour urlparse")
parsedTuple = urlparse("http://www.google.com/search?hl=en&q=urlparse&btnG=Google+Search")
print(parsedTuple)

#Fusion de liste en URL
print("\nPage de document Python non parsée")
unparsedURL = urlunparse((URLscheme, URLlocation, URLpath, '', '', ''))
print("\t" + unparsedURL)

#Fusion du chemin avec le nouveau fichier pour créer
#la nouvelle URL
print("\nPages Python supplémentaires utilisant join")
for mod in modList:
    newURL = urljoin(unparsedURL, "module-%s.html" % (mod))
    print("\t" + newURL)

#Jointure du chemin au sous-chemin pour créer une nouvelle URL
print("\nPages Python avec jointures de sous-chemins")
newURL = urljoin(unparsedURL, "/module-urllib2/request-objects.html")
print("\t" + newURL)



html open

import urllib.request
print("=== 0802_html_open.py ===")

webURL = "http://www.python.org"
localURL = "file:\\tmp\default2.html"

#Ouverture de l'URL sur le Web
u = urllib.request.urlopen(webURL)
buffer = u.read()
print("Lecture web ***")
print(u.info())
print("%d octets de %s.\n" % (len(buffer), u.geturl()))

#Ouverture de l'URL en local
print("Lecture d'un fichier local ***")
print(localURL)
u = urllib.request.urlopen(localURL)
buffer = u.read()
print(u.info())
print("%d octets de %s.\n" % (len(buffer), u.geturl()))
print(buffer)


html links

from html.parser import HTMLParser
import urllib.request, urllib.parse, urllib.error
import sys
print("=== 0803_html_links.py ===")

#Definition du parseur HTML
class parseurLiens(HTMLParser):
    def handle_starttag(self, tag, attrs):
        if tag == 'a':
            for name,value in attrs:
                if name == 'href':
                    print(value)
                    print((self.get_starttag_text()))

#Creation d'une instance du parseur HTML
monParseur = parseurLiens()

#Ouverture du fichier HTML
data = urllib.request.urlopen("http://www.python.org/index.html").read()
monParseur.feed(data.decode('utf-8'))
monParseur.close()


html images

from html.parser import HTMLParser
import urllib.request, urllib.parse, urllib.error
import sys
print("=== 0804_html_images.py ===")

urlString = "http://www.python.org"

#Enregistrement du fichier d'image sur le disque
def lireFicIMA(addr):
    u = urllib.request.urlopen(addr)
    data = u.read()

    splitPath = addr.split('/')
    fName = splitPath.pop()
    print("Stockage local de %s" % fName)

    f = open(fName, 'wb')
    f.write(data)
    f.close()

#Définition du parseur HTML
class parseImage(HTMLParser):
    def handle_starttag(self, tag, attrs):
        if tag == 'img':
            for name,value in attrs:
                if name == 'src':
                    lireFicIMA(urlString + "/" + value)

#Création de l'instance du parseur HTML
monParseur = parseImage()

#Ouverture du fichier HTML
u = urllib.request.urlopen(urlString)
print("Ouverture de l'URL =============================")
print(u.info())

#Alimentation du fichier HTML dans le parseur
data = u.read()
monParseur.feed(data.decode('utf-8'))
monParseur.close()
print("Les fichiers sont dans le dossier courant")


html text

from html.parser import HTMLParser
import urllib.request
print("=== 0805_html_text.py ===")

urlText = []

#Définition du parseur HTML
class parseurTexte(HTMLParser):
    def handle_data(self, data):
        if data != '\n':
            urlText.append(data)

#Création de l'instance du parseur HTML
monParseur = parseurTexte()

#Alimentation du fichier HTML dans le parseur
data = urllib.request.urlopen("http://docs.python.org/lib/module-HTMLParser.html").read()
monParseur.feed(data.decode('utf-8'))
monParseur.close()
for unBloc in urlText:
    print(unBloc


html cookie

import os
import urllib.request, urllib.error
import http.cookiejar
print("=== 0806_html_cookie.py ===")

cookieFile = "cookie.dat"
testURL = 'http://maps.google.com'

#Creation de l'instance de cookie jar
boiteACooky = http.cookiejar.LWPCookieJar()

#Creation de l'objet opener HTTPCookieProcessor
opener=urllib.request.build_opener(urllib.request.HTTPCookieProcessor(boiteACooky))

#Installation de l'opener HTTPCookieProcessor
urllib.request.install_opener(opener)

#Creation de l'objet Request
r = urllib.request.Request(testURL)

#Ouverture du fichier HTML
h = urllib.request.urlopen(r)
print("En-tete de la page \n======================")
print(h.info())

print("Cookies de la page \n======================")
for ind, cookie in enumerate(boiteACooky):
  print("%d - %s" % (ind, cookie))

#Enregistrement des cookies
boiteACooky.save(cookieFile)


html quotes

from html.parser import HTMLParser
import urllib.request, urllib.parse, urllib.error
import sys
print("=== 0807_html_quotes.py ===")

localURL = "file:\\tmp\default.html"

#Definition du parseur HTML
class parseAttrs(HTMLParser):
    def init_parser (self):
        self.pieces = []

    def handle_starttag(self, tag, attrs):
        fixedAttrs = ""
        for name, value in attrs:
            fixedAttrs += "%s=\"%s\" " % (name, value)
            self.pieces.append("<%s %s>" % (tag, fixedAttrs))

    def handle_charref(self, name):
        self.pieces.append("&#%s;" % (name))

    def handle_endtag(self, tag):
        self.pieces.append("</%s>" % (tag))

    def handle_entityref(self, ref):
        self.pieces.append("&%s" % (ref))

    def handle_data(self, text):
        self.pieces.append(text)

    def handle_comment(self, text):
        self.pieces.append("<!-%s->" % (text))

    def handle_pi(text):
        self.pieces.append("<?%s>" % (text))

    def handle_decl(self, text):
        self.pieces.append("<!%s>" % (text))

    def parsed (self):
        return "".join(self.pieces)

#Creation d'une instance du parseur HTML
parseAttrib = parseAttrs()

#Initialisation des donnees de parseur
parseAttrib.init_parser()

#Alimentation du fichier HTML dans le parseur
data = urllib.request.urlopen(localURL).read()
parseAttrib.feed(data.decode('utf-8'))

#Affichage du contenu du fichier original
print("Fichier original\n========================")
print(data)

#Affichage du fichier parse
print("\nFichier final\n========================")
print(parseAttrib.parsed())

parseAttrib.close()



in Brad Dayley, Python 3 (Python Phrasebook), L'essentiel du code et des commandes, peason.fr

Wednesday, May 18, 2016

Basic Network Commands



ipconfig (to configure network interfaces and view related information)

net use (e. g. drive mapping)

netstat (displays incoming and outgoing connections and other information)

ping  (sends ICMP echo request packets to a destination)

traceroute  (similar to ping, but provides information about the path a packet takes)

nslookup  (looks up the IP addresses associated with a domain name or the reverse)

whois  (looks up the registration record associated with a domain name)

nmap (port scanner)

Nmap.org

more in:
TechWorm

Basic Network Utilities



ipconfig (to configure network interfaces and view related information)

net use (e. g. drive mapping)

netstat (displays incoming and outgoing connections and other information)

ping  (sends ICMP echo request packets to a destination)

traceroute  (similar to ping, but provides information about the path a packet takes)

nslookup  (looks up the IP addresses associated with a domain name or the reverse)

whois  (looks up the registration record associated with a domain name)

nmap (port scanner)

Nmap.org

more in:
TechWorm

JavaScript URL Buider with Date Picker

The sample builds an URL for BusinessObjects [Business Objects]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882">

<head>

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <title>JavaScript URL Builder</title>

    <meta name="Author" content="Rui Granadeiro"/>
    <meta name="description" content="new page" />
    <meta name="keywords" content="Rui Granadeiro Content Management System" />
    <link rel="stylesheet" href="reports/autocomplete.css" media="screen" type="text/css">
    <link rel="stylesheet" href="reports/calendar.css" media="screen" type="text/css">
    <script type="text/javascript" src="reports/autocomplete.js"></script>
    <script type="text/javascript" src="reports/calendar_en.js"></script>

<script type="text/javascript">
function goTo()
{
             var initdate = document.forms[0].initdate.value;
             var enddate = document.forms[0].enddate.value;
             var institution = document.forms[0].institution.value;
             window.open( "http://boprodsvr:8080/BOE/OpenDocument/opendoc/openDocument.jsp?iDocID=159964&lsSInstitution+Requesting+Service%20?="+institution+"&sType=wid&sRefresh=Y&lsSStart+Date:="+initdate+"%2000:00:00&lsSEnd+Date:="+enddate+"%2000:00:00&lsSInstitution+Logo?=JS");
             return false;
}
</script>
</head>

<body>       


            <style type="text/css">
                body {
                    font-family:Arial, Helvetica, sans-serif;
                    font-size:smaller;
                }
                span {
                    font-weight:bold;
                }
               
                a {
                    color:#039;
                    text-decoration:none;
                    font-weight:bold;
                }
               
                a:hover {
                    color:#03f;
                }
            </style>
           
            <span style="margin-top:0; padding-top:0">Interactive reports: </span>
           
            <form name="boreports" action="" method="get" onsubmit="return goTo()">

                        Start date (included): <input name="initdate" type="text" value="" size="10" />
                        <script language="JavaScript">
                        new tcal ({
                            // form name
                            'formname': 'boreports',
                            // input name
                            'controlname': 'initdate'
                        });
                   
                    </script>
                           
                        End date (excluded): <input name="enddate" type="text" value="" size="10" />
                        <script language="JavaScript">
                        new tcal ({
                            // form name
                            'formname': 'boreports',
                            // input name
                            'controlname': 'enddate'
                        });
                     </script>

                           &nbsp;Institution requesting service:&nbsp;
                        <select name="institution" value="*">
                            <option value="*">All</option>
                            <option value="AAA">AAA</option>
                            <option value="BBBB">BBBB</option>
                            <option value="CCCCC">CCCCC</option>
                        </select>
         
                   <input style="cursor: hand;" type="submit" value="Get your report">&nbsp;<input style="cursor: hand;" type="reset" value="Reset" />

             </form>
             <br />
   
</body>
</html>

People Search Core Results XSL Display

1 - In Results Query Options define the Fixed Keyword Query like in a Search Box.

2 - In Display Properties under XSL Editor define your XML Stylesheet (or a link to an external file, as below):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    <xsl:include href="/EN/dt/dtsystemfiles/xslsheets/tu-who-is-who-en.xsl"/>
</xsl:stylesheet>

3 - The external file, to adapt conveniently:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:param name="ResultsBy" />
  <xsl:param name="ViewByUrl" />
  <xsl:param name="ViewByValue" />
  <xsl:param name="IsNoKeyword" />
  <xsl:param name="IsFixedQuery" />
  <xsl:param name="MoreResultsText" />
  <xsl:param name="MoreResultsLink" />
  <xsl:param name="CollapsingStatusLink" />
  <xsl:param name="CollapseDuplicatesText" />
  <xsl:param name="MeHeaderValue" />
  <xsl:param name="CollHeaderValue" />
  <xsl:param name="CollOfCollHeaderValue" />
  <xsl:param name="EveryoneHeaderValue" />
  <xsl:param name="AddToMyColleaguesText" />
  <xsl:param name="SrchRSSText" />
  <xsl:param name="SrchRSSLink" />
  <xsl:param name="ShowMessage" />
  <xsl:param name="ShowActionLinks" />

  <!-- When there is keywory to issue the search -->
  <xsl:template name="dvt_1.noKeyword">
    <span class="ms-sbplain">
      <xsl:choose>
        <xsl:when test="$IsFixedQuery">
          Please set the 'Fixed Query' property for the webpart.
        </xsl:when>
        <xsl:otherwise>
          Enter one or more words to search for in the search box.
        </xsl:otherwise>
      </xsl:choose>
    </span>
  </xsl:template>

  <!-- When empty result set is returned from search -->
  <xsl:template name="dvt_1.empty">
    <xsl:if test="$ShowActionLinks">
      <div class="srch-sort">
        <xsl:if test="string-length($SrchRSSLink) &gt; 0">
          <a type="application/rss+xml" href ="{$SrchRSSLink}" title="{$SrchRSSText}" id="SRCHRSSL">
            <img border="0" src="/_layouts/images/rss.gif" alt=""/>
            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
            <xsl:value-of select="$SrchRSSText"/>
          </a>
        </xsl:if>
      </div>
    </xsl:if>
    <br/>
    <br/>

    <span class="ms-sbplain" id="CSR_NO_RESULTS">
      No results matching your search were found.

      <ol>
        <li>Check your spelling. Are the words in your query spelled correctly?</li>
        <li>Try using synonyms. Maybe what you're looking for uses slightly different words.</li>
        <li>Make your search more general. Try more general terms in place of specific ones.</li>
        <li>Try your search in a different scope. Different scopes can have different results.</li>
      </ol>
    </span>
  </xsl:template>


  <!-- Main body template. Sets the Results view (Relevance or date) options -->
  <xsl:template name="dvt_1.body">
    <xsl:if test="$ShowActionLinks">
      <div class="srch-sort">
        <xsl:value-of select="$ResultsBy" />
        <xsl:if test="$ViewByUrl">
          |
          <a href ="{$ViewByUrl}" id="CSR_RV" title="{$ViewByValue}">
            <xsl:value-of select="$ViewByValue" />
          </a>
        </xsl:if>
        <xsl:if test="string-length($SrchRSSLink) &gt; 0">
          |
          <a type="application/rss+xml" href ="{$SrchRSSLink}" title="{$SrchRSSText}" id="SRCHRSSL">
            <img border="0" src="/_layouts/images/rss.gif" alt=""/>
            <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
            <xsl:value-of select="$SrchRSSText"/>
          </a>
        </xsl:if>
      </div>
      <div style="margin-top: 15px;"></div>
      <br />
      <br />
    </xsl:if>
   
    <p>If this page is outdated please send the correct information to <a href="mailto:dt.webmaster">dt.webmaster</a></p>

    <table cellpadding="1" cellspacing="5" width="100%">
     
      <!--<xsl:for-each select="All_Results/Result">-->
     
<xsl:for-each select="All_Results/Result[jobtitle=starts-with(jobtitle,'Chef')]">
    <xsl:sort select="preferredname"/>
   
    <tr>
        <td>
            <xsl:choose>
              <xsl:when test="string-length(pictureurl)&gt;0">
                <xsl:variable name="picture" select="pictureurl"/>
                <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" />
              </xsl:when>
              <xsl:otherwise>
                 <img height="100" src="http://spjsnet/EN/dt/PublishingImages/blank-profile.jpg" alt="Photo non autoris&#233;e" border="0" />
              </xsl:otherwise>
          </xsl:choose>
        </td>
      
        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:text>Chief</xsl:text></strong><br />
        </td>

        <td>  
            <xsl:text>User:&#160;</xsl:text><strong><xsl:value-of select="substring-after(accountname,'\')"/></strong><br />
            <xsl:text>Phone:&#160;</xsl:text><strong><xsl:value-of select="workphone" /></strong><br />
            <xsl:text>Office:&#160;</xsl:text><strong><xsl:value-of select="officenumber" /></strong>
          </td>
          <td width="25%"></td>
    </tr>
      </xsl:for-each>
 

  <xsl:for-each select="All_Results/Result[jobtitle='Agent 1']">
    <xsl:sort select="preferredname"/>
   
    <tr>
   
        <td>
            <xsl:choose>
              <xsl:when test="string-length(pictureurl)&gt;0">
                <xsl:variable name="picture" select="pictureurl"/>
                <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" />
              </xsl:when>
              <xsl:otherwise>
                 <img height="100" src="http://spjsnet/EN/dt/PublishingImages/blank-profile.jpg" alt="Photo non autoris&#233;e" border="0" />
              </xsl:otherwise>
          </xsl:choose>
        </td>

        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:text>Agent1</xsl:text></strong><br />
        </td>
        <td>  
            <xsl:text>User:&#160;</xsl:text><strong><xsl:value-of select="substring-after(accountname,'\')"/></strong><br />
            <xsl:text>Phone:&#160;</xsl:text><strong><xsl:value-of select="workphone" /></strong><br />
            <xsl:text>Office:&#160;</xsl:text><strong><xsl:value-of select="officenumber" /></strong>
          </td>
          <td width="25%">
              <xsl:text>Language&#160;coverage:&#160;</xsl:text><br />
            <!--<xsl:value-of select="languages"/>-->
            <strong><xsl:value-of select="translate(Agent1languages, ';',' ')"/></strong>
          </td>
    </tr>
      </xsl:for-each>


  <xsl:for-each select="All_Results/Result[jobtitle='Administrateur']">
    <xsl:sort select="preferredname"/>
   
    <tr>
   
        <td>
            <xsl:choose>
              <xsl:when test="string-length(pictureurl)&gt;0">
                <xsl:variable name="picture" select="pictureurl"/>
                <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" />
              </xsl:when>
              <xsl:otherwise>
                 <img height="100" src="http://spjsnet/EN/dt/PublishingImages/blank-profile.jpg" alt="Photo non autoris&#233;e" border="0" />
              </xsl:otherwise>
          </xsl:choose>
        </td>

        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:text>Agent1</xsl:text></strong><br />
        </td>
        <td>  
            <xsl:text>User:&#160;</xsl:text><strong><xsl:value-of select="substring-after(accountname,'\')"/></strong><br />
            <xsl:text>Phone:&#160;</xsl:text><strong><xsl:value-of select="workphone" /></strong><br />
            <xsl:text>Office:&#160;</xsl:text><strong><xsl:value-of select="officenumber" /></strong>
          </td>
          <td width="25%">
              <xsl:text>Language&#160;coverage:&#160;</xsl:text><br />
            <!--<xsl:value-of select="languages"/>-->
            <strong><xsl:value-of select="translate(Agent1anguages, ';',' ')"/></strong>
          </td>
    </tr>
      </xsl:for-each>

     
   <xsl:for-each select="All_Results/Result[jobtitle='Agent 2']">
    <xsl:sort select="preferredname"/>
   
    <tr>

        <td>
            <xsl:choose>
              <xsl:when test="string-length(pictureurl)&gt;0">
                <xsl:variable name="picture" select="pictureurl"/>
                <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" />
              </xsl:when>
              <xsl:otherwise>
                 <img height="100" src="http://spjsnet/EN/dt/PublishingImages/blank-profile.jpg" alt="Photo non autoris&#233;e" border="0" />
              </xsl:otherwise>
          </xsl:choose>
        </td>

        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:value-of select="jobtitle" /></strong><br />
        </td>
        <td>  
            <xsl:text>Utilisateur:&#160;</xsl:text><strong><xsl:value-of select="substring-after(accountname,'\')"/></strong><br />
            <xsl:text>T&#233;l.:&#160;</xsl:text><strong><xsl:value-of select="workphone" /></strong><br />
            <xsl:text>Bureau:&#160;</xsl:text><strong><xsl:value-of select="officenumber" /></strong>
          </td>
          <td width="25%"></td>
    </tr>
      </xsl:for-each>
     
   <xsl:for-each select="All_Results/Result[jobtitle='Secr&#233;taire']">
    <xsl:sort select="preferredname"/>
   
    <tr>

        <td>
            <xsl:choose>
              <xsl:when test="string-length(pictureurl)&gt;0">
                <xsl:variable name="picture" select="pictureurl"/>
                <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" />
              </xsl:when>
              <xsl:otherwise>
                 <img height="100" src="http://spjsnet/EN/dt/PublishingImages/blank-profile.jpg" alt="Photo non autoris&#233;e" border="0" />
              </xsl:otherwise>
          </xsl:choose>
        </td>

        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:text>Secretary</xsl:text></strong><br />
        </td>
        <td>  
            <xsl:text>Utilisateur:&#160;</xsl:text><strong><xsl:value-of select="substring-after(accountname,'\')"/></strong><br />
            <xsl:text>T&#233;l.:&#160;</xsl:text><strong><xsl:value-of select="workphone" /></strong><br />
            <xsl:text>Bureau:&#160;</xsl:text><strong><xsl:value-of select="officenumber" /></strong>
          </td>
          <td width="25%"></td>
    </tr>
      </xsl:for-each>


     
  <!--<xsl:for-each select="All_Results/Result">
    <xsl:sort select="preferredname"/>
    <tr>
        <td>
            <strong><xsl:variable name="email" select="workemail"/>
                <a href="mailto:{$email}"><xsl:value-of select="preferredname"/></a></strong><br />
            <strong><xsl:value-of select="jobtitle" /></strong><br />
            <xsl:variable name="picture" select="pictureurl"/>
            <img height="100" src="{pictureurl}" alt="{preferredname}" border="0" /><br />
            <xsl:value-of select="substring-after(accountname,'\')"/><br />
            <strong><xsl:value-of select="workphone" /></strong><br />
            <strong><xsl:value-of select="officenumber" /></strong><br />
          </td>
    </tr>
  </xsl:for-each>-->
   
    </table>
      
    <xsl:call-template name="DisplayMoreResultsAnchor" />
  </xsl:template>


  <!-- This template is called for each result -->
<!--  <xsl:template match="All_Results/Result"> -->
    <xsl:template name="customsort">
    <xsl:variable name="id" select="id"/>
    <xsl:variable name="url" select="url"/>
    <xsl:variable name="email" select="workemail"/>
    <xsl:variable name="sip" select="sipaddress"/>
    <xsl:variable name="prefix">IMNRC('</xsl:variable>
    <xsl:variable name="suffix">')</xsl:variable>
    <!--<table class="psrch-result" CELLPADDING="0" CELLSPACING="0" BORDER="5" width="100%"> -->
    <tr>
      <!--
        <td valign="top" class="psrch-propcell" width="100%">
          <span class="psrch-Title">
            <xsl:value-of select="preferredname"/>
          </span>
        </td>
-->
    </tr>
    <!--    </table> -->
  </xsl:template>

  <xsl:template name="HitHighlighting">
    <xsl:param name="hh" />
    <xsl:apply-templates select="$hh"/>
  </xsl:template>

  <xsl:template match="ddd">
    &#8230;
  </xsl:template>
  <xsl:template match="c0">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c1">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c2">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c3">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c4">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c5">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c6">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c7">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c8">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>
  <xsl:template match="c9">
    <b>
      <xsl:value-of select="."/>
    </b>
  </xsl:template>

  <xsl:template match="All_Results/DummyResult/Me">
    <span class="srch-SocDistTitle">
      <xsl:value-of select="$MeHeaderValue" />
    </span>

  </xsl:template>

  <xsl:template match="All_Results/DummyResult/Colleague">
    <span class="srch-SocDistTitle">
      <xsl:value-of select="$CollHeaderValue" />
    </span>

  </xsl:template>
  <xsl:template match="All_Results/DummyResult/ColleagueOfColleague">
    <span class="srch-SocDistTitle">
      <xsl:value-of select="$CollOfCollHeaderValue" />
    </span>
  </xsl:template>

  <xsl:template match="All_Results/DummyResult/Everyone">
    <span class="srch-SocDistTitle">
      <!-- (everyoneheadervalue) <xsl:value-of select="$EveryoneHeaderValue" /> -->
      Transportation Department Team Members and Contacts
    </span>
  </xsl:template>

  <!-- The "view more results" for fixed query -->
  <xsl:template name="DisplayMoreResultsAnchor">
    <xsl:if test="$MoreResultsLink">
      <a href="{$MoreResultsLink}">
        <xsl:value-of select="$MoreResultsText"/>
      </a>
    </xsl:if>
  </xsl:template>

  <xsl:template name="DisplayAddToMyColleaguesLink">
    <xsl:param name="url"/>
    <a href="{$url}">
      <xsl:value-of select="$AddToMyColleaguesText"/>
    </a>
    <br/>
  </xsl:template>

  <!-- document collapsing link setup -->
  <xsl:template name="DisplayCollapsingStatusLink">
    <xsl:param name="status"/>
    <xsl:param name="url"/>
    <xsl:if test="$CollapsingStatusLink">
      <xsl:choose>
        <xsl:when test="$status=1">
          <br/>
          <xsl:variable name="CollapsingStatusHref" select="concat(substring-before($CollapsingStatusLink, '$$COLLAPSE_PARAM$$'), 'duplicates:&quot;', $url, '&quot;', substring-after($CollapsingStatusLink, '$$COLLAPSE_PARAM$$'))"/>
          [<a href="{$CollapsingStatusHref}" title="{$CollapseDuplicatesText}">
            <xsl:value-of select="$CollapseDuplicatesText"/>
          </a>]
        </xsl:when>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <!-- XSL transformation starts here -->
  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="$IsNoKeyword = 'True'" >
        <xsl:call-template name="dvt_1.noKeyword" />
      </xsl:when>
      <xsl:when test="$ShowMessage = 'True'">
        <xsl:call-template name="dvt_1.empty" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name="dvt_1.body"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="DisplayOfficeProfile">
    <xsl:param name="title" />
    <xsl:param name="dep" />
    <xsl:param name="phone" />
    <xsl:param name="office" />
   
    <span class="psrch-Metadata">
      <xsl:if test='string-length($title) &gt; 0'>
        (title?) <xsl:value-of select="$title" />
        -
      </xsl:if>
      <xsl:if test='string-length($dep) &gt; 0'>
        (department?) <xsl:value-of select="$dep" />
        -
      </xsl:if>
      <xsl:if test='string-length($phone) &gt; 0'>
        (phone?) <xsl:value-of select="$phone" />
        -
      </xsl:if>
      <xsl:if test='string-length($office) &gt; 0'>
        (office?)
        <xsl:value-of select="$office" />
      </xsl:if>
    </span>
    <br/>
  </xsl:template>

  <!-- End of Stylesheet -->
</xsl:stylesheet>

Sunday, May 15, 2016

Python CGI Database (4 of 4)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3
import cgi

print "Content-Type: application/xhtml+xml; charset=utf-8\n"

print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print '    <title>eCarnet - Employées d un service</title>'
print '</head>'
print '<body>'

form = cgi.FieldStorage()
id_service = str(form["matricule"].value)
nom = str(form["nom"].value)
prenom = str(form["prenom"].value)
matricule = str(form["matricule"].value)
tel_fixe = str(form["tel_fixe"].value)

db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
cursor.execute("INSERT INTO employe(matricule, prenom, nom, tel_fixe, id_service) VALUES (?, ?, ?, ?, ?)", (matricule, prenom, nom, tel_fixe, id_service))
db_connection.commit()
db_connection.close()

print '    <h1>Ajout de l employé - ' + prenom + ' ' + nom + ' -</h1>'
print '    <p>' + prenom + ' ' + nom + ' a bien été ajouté dans la base de données</p>'
print '    <p><a href="eCarnet_home.py">Retour au eCarnet.</a></p>'
print ' </body>'
print ' </html>'

Python CGI Database (3 of 4)

# -*- coding: utf-8 -*-

import sqlite3
import cgi

print "Content-Type: application/xhtml+xml; charset=utf-8\n"

print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print '    <title>eCarnet - Employées d un service</title>'
print '</head>'
print '<body>'

form = cgi.FieldStorage()
service_id = str(form["service"].value)
db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()
cursor.execute("SELECT emplacement FROM service WHERE id=" + service_id)
row = cursor.fetchone()
service_nom = str(row['emplacement'])

print '    <h1>Employés du service - ' + service_nom + ' -</h1>'

cursor.execute("SELECT prenom, nom, tel_fixe FROM employe WHERE id_service=" + service_id)
rows = cursor.fetchall()

print '    <ol>'
for row in rows:
    print '        <li>' + row['prenom'] + ', ' +row['nom'] + ', ' + row['tel_fixe'] + '</li>'
print '    </ol>'
print '</body>'
print '</html>'

db_connection.close()

Python CGI Database (2 of 4)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3

print "Content-Type: application/xhtml+xml; charset=utf-8\n"

print '<!DOCTYPE html>'
print '<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">'
print '<head>'
print '    <title>eCarnet - Home</title>'
print '</head>'
print '<body>'
print '    <h1>Bienvenue sur eCarnet de ULB</h1>'
print '    <h2>Employés</h2>'

# Connection à la base de données
#db_connection = sqlite3.connect('database.sqlite3')
db_connection = sqlite3.connect('database.test-01.db')
db_connection.row_factory = sqlite3.Row
cursor = db_connection.cursor()

# Sélection des enregistrements
cursor.execute("SELECT prenom, nom, tel_fixe FROM employe")

# Création de la liste des employées
rows = cursor.fetchall()
print '    <ol>'
for row in rows:
    print'        <li>' +row['prenom'] + ' ' +row['nom'] + ', ' +row['tel_fixe'] + '  </li>'
print '    </ol>'
   
# Formulaire de recherche des employés d'un service   
print '    <h2>Employés par service</h2>'
print '    <form action="eCarnet_service.py" method="get">'
print '    <p><select name="service">'
cursor.execute ("SELECT id, nom, emplacement From service")
rows = cursor.fetchall()
for row in rows:
    print '            <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print '    </select>'
print '        <input type="submit" value="Lister" /></p>'
print '    </form>'

# Formulaire d'ajout d'un nouvel employé   
print '    <h2>Ajouter un nouvel employé</h2>'
print '    <form action="eCarnet_add_employee.py" method="get">'
print '    <p>Prénom : <input type="text" name="prenom" /></p>'
print '    <p>Nom : <input type="text" name="nom" /></p>'
print '    <p>Matricule : <input type="text" name="matricule" /></p>'
print '    <p>Tèl. fixe : <input type="text" name="tel_fixe" /></p>'
print '    <p>Service : <select name="service">'
for row in rows:
    print '            <option value="' + str(row['id']) + '">' + row['emplacement'] + '</option>'
print '        </select>'
print '        <input type="submit" value="Ajouter" /></p>'
print '    </form>'  
print '</body>'
print '</html>'

db_connection.close()

Python CGI Database (1 of 4)

<?xml version=“1.0” encoding=“utf-8”?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr">
    <head>
        <meta charset="UTF-8">
        <!--<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
        <title>Université libre de Bruxelles</title>
    </head>
    <body>
    <img src="logo_ulb.png" alt="Logo de l'ULB" width="656" height="80" />
    <h1>Bienvenue sur le site de l'ULB</h1>
    <section>
        <h2>Que voulez-vous consulter ?</h2>
        <ul>
            <li><a href="status.html">Les statuts de l'université</a></li>
            <li><a href="/cgi-bin/eCarnet_home.py">Le carnet d'adresses des employés</a></li>
            <li><a href="ca.html">La composition du Conseil d'Aministration</a></li>
        </ul>
    </section>
    </body>
</html>

Python CGI Web Server

#! Path to Python.exe "C:\Web development\Python27\python.exe"

from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler

httpd = HTTPServer(('', 8080), CGIHTTPRequestHandler)
print("Demarrage du serveur web...")
httpd.serve_forever()

Thursday, May 12, 2016

Python and AJAX tutorial for beginners with web.py and jQuery

Kooneiform

Request methods

... a zipped copy of the files in this tutorial, you can get it here. Run app.py and then point your browser to http://localhost:8080 (on Windows; use the appropriate address for your setup).