correction
Précédemment une utilisation assez peu judicieuse des objets en python, qui avait pour effet qu'appeler la macro PagesClub, transformait le comportement de PagesPerso en celui de PagesClub
This commit is contained in:
parent
bebb5a6e3c
commit
aa79f43775
2 changed files with 61 additions and 57 deletions
|
@ -3,17 +3,16 @@
|
||||||
import os
|
import os
|
||||||
import PagesPerso
|
import PagesPerso
|
||||||
|
|
||||||
def comptes():
|
class ClubList(PagesPerso.AccountList):
|
||||||
"""Retourne la liste des comptes"""
|
home = "/home/club"
|
||||||
return filter(lambda x: os.path.isdir(u"/home/club/%s" % x) and not os.path.islink(u"/home/club/%s" % x),
|
www = ""
|
||||||
os.listdir(u"/home/club"))
|
url = "http://clubs.ens-cachan.fr/%s/"
|
||||||
|
|
||||||
def url(self):
|
def comptes(self):
|
||||||
"""URL vers la page perso"""
|
"""Retourne la liste des comptes"""
|
||||||
return u"http://clubs.ens-cachan.fr/%s/" % self.login
|
return filter(lambda x: os.path.isdir(u"/home/club/%s" % x) and not os.path.islink(u"/home/club/%s" % x),
|
||||||
|
os.listdir(u"/home/club"))
|
||||||
|
|
||||||
|
def execute(macro, args):
|
||||||
|
return macro.formatter.rawHTML(ClubList().to_html())
|
||||||
|
|
||||||
PagesPerso.comptes = comptes
|
|
||||||
PagesPerso.account.home = "/home/club"
|
|
||||||
PagesPerso.account.www = ""
|
|
||||||
PagesPerso.account.url = url
|
|
||||||
execute = PagesPerso.execute
|
|
||||||
|
|
|
@ -2,16 +2,57 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class account:
|
class AccountList:
|
||||||
"""Classe représentant la page perso d'une personne"""
|
|
||||||
|
|
||||||
home = "/home"
|
home = "/home"
|
||||||
www = "/www"
|
www = "/www"
|
||||||
|
url = "http://perso.crans.org/%s/"
|
||||||
|
|
||||||
def __init__(self, login):
|
def __init__(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
def comptes(self):
|
||||||
|
"""Retourne la liste des comptes"""
|
||||||
|
return filter(lambda x: os.path.isdir(u"/home/%s/www" % x) and not os.path.islink(u"/home/%s/www" % x),
|
||||||
|
os.listdir(u"/home/mail"))
|
||||||
|
|
||||||
|
|
||||||
|
def makeAnchor(self,letter):
|
||||||
|
return u"<div class=\"vignetteperso\"><a class=\"letter_anchor\" name=\"index_%s\"><span>%s:</span></a></div>" % ( letter, letter )
|
||||||
|
|
||||||
|
def makeIndex(self,letter_list):
|
||||||
|
index = u''
|
||||||
|
for aLetter in letter_list:
|
||||||
|
index = u"%s<a href=\"#index_%s\">%s</a>" % ( index, aLetter, aLetter)
|
||||||
|
return u"<div class=\"alphabetic_index\">%s</div>" % index
|
||||||
|
|
||||||
|
def to_html(self):
|
||||||
|
dirs = self.comptes()
|
||||||
|
dirs.sort()
|
||||||
|
html = u""
|
||||||
|
|
||||||
|
premiere_lettre = ''
|
||||||
|
letter_list = []
|
||||||
|
for d in dirs:
|
||||||
|
if premiere_lettre != d[0]:
|
||||||
|
premiere_lettre = d[0]
|
||||||
|
letter_list.append(premiere_lettre)
|
||||||
|
html = u"%s\n%s" % ( html, self.makeAnchor(premiere_lettre) )
|
||||||
|
html = u"%s\n%s" % (html, Account(self.home, d, self.www, self.url).to_html())
|
||||||
|
|
||||||
|
index = self.makeIndex(letter_list)
|
||||||
|
html = index + html
|
||||||
|
html += u'<br style="clear: both">'
|
||||||
|
return html
|
||||||
|
|
||||||
|
class Account:
|
||||||
|
"""Classe représentant la page perso d'une personne"""
|
||||||
|
|
||||||
|
def __init__(self, home, login, www, url):
|
||||||
"""Instanciation avec le `login' de la personne"""
|
"""Instanciation avec le `login' de la personne"""
|
||||||
self.login = login
|
self.login = login
|
||||||
self.home = "%s/%s" % (self.home, login)
|
self.home = "%s/%s" % (home, login)
|
||||||
|
self.www = www
|
||||||
|
self.url = url
|
||||||
|
|
||||||
_info = None
|
_info = None
|
||||||
def info(self, champ):
|
def info(self, champ):
|
||||||
|
@ -39,10 +80,6 @@ class account:
|
||||||
"""Chemin vers le www"""
|
"""Chemin vers le www"""
|
||||||
return u"%s%s" % (self.home, self.www)
|
return u"%s%s" % (self.home, self.www)
|
||||||
|
|
||||||
def url(self):
|
|
||||||
"""URL vers la page perso"""
|
|
||||||
return u"http://perso.crans.org/%s/" % self.login
|
|
||||||
|
|
||||||
def logo(self):
|
def logo(self):
|
||||||
"""URL du logo s'il y en a un"""
|
"""URL du logo s'il y en a un"""
|
||||||
if self.info("logo"):
|
if self.info("logo"):
|
||||||
|
@ -52,13 +89,13 @@ class account:
|
||||||
else:
|
else:
|
||||||
logo = self.info("logo")
|
logo = self.info("logo")
|
||||||
if os.path.isfile("%s/%s" % (self.chemin(), logo)):
|
if os.path.isfile("%s/%s" % (self.chemin(), logo)):
|
||||||
return u"%s%s" % (self.url(), logo)
|
return u"%s%s" % (self.url % self.login, logo)
|
||||||
return u"http://perso.crans.org/pageperso.png"
|
return u"http://perso.crans.org/pageperso.png"
|
||||||
|
|
||||||
def __str__(self):
|
def to_html(self):
|
||||||
"""Renvoie le code HTML correspondant au fichier .info"""
|
"""Renvoie le code HTML correspondant au fichier .info"""
|
||||||
html = [ u'<div class="vignetteperso">',
|
html = [ u'<div class="vignetteperso">',
|
||||||
u'<a href="%s">' % self.url(),
|
u'<a href="%s">' % (self.url % self.login),
|
||||||
u'<img src="%s" alt="%s">' % (self.logo(), self.login),
|
u'<img src="%s" alt="%s">' % (self.logo(), self.login),
|
||||||
u'</a><br>',
|
u'</a><br>',
|
||||||
self.info("nom") and u'<b>%s</b><br>' % self.info("nom") or u'%s<br>' % self.login,
|
self.info("nom") and u'<b>%s</b><br>' % self.info("nom") or u'%s<br>' % self.login,
|
||||||
|
@ -66,38 +103,6 @@ class account:
|
||||||
u'</div>' ]
|
u'</div>' ]
|
||||||
return u'\n'.join(html)
|
return u'\n'.join(html)
|
||||||
|
|
||||||
def comptes():
|
|
||||||
"""Retourne la liste des comptes"""
|
|
||||||
return filter(lambda x: os.path.isdir(u"/home/%s/www" % x) and not os.path.islink(u"/home/%s/www" % x),
|
|
||||||
os.listdir(u"/home/mail"))
|
|
||||||
|
|
||||||
|
|
||||||
def makeAnchor(letter):
|
|
||||||
return u"<div class=\"vignetteperso\"><a class=\"letter_anchor\" name=\"index_%s\"><span>%s:</span></a></div>" % ( letter, letter )
|
|
||||||
|
|
||||||
def makeIndex(letter_list):
|
|
||||||
index = u''
|
|
||||||
for aLetter in letter_list:
|
|
||||||
index = u"%s<a href=\"#index_%s\">%s</a>" % ( index, aLetter, aLetter)
|
|
||||||
return u"<div class=\"alphabetic_index\">%s</div>" % index
|
|
||||||
|
|
||||||
def execute(macro, args):
|
def execute(macro, args):
|
||||||
dirs = comptes()
|
return macro.formatter.rawHTML(AccountList().to_html())
|
||||||
dirs.sort()
|
|
||||||
|
|
||||||
html = u""
|
|
||||||
|
|
||||||
premiere_lettre = ''
|
|
||||||
letter_list = []
|
|
||||||
for d in dirs:
|
|
||||||
if premiere_lettre != d[0]:
|
|
||||||
premiere_lettre = d[0]
|
|
||||||
letter_list.append(premiere_lettre)
|
|
||||||
html = u"%s\n%s" % ( html, makeAnchor(premiere_lettre) )
|
|
||||||
html = u"%s\n%s" % (html, account(d).__str__())
|
|
||||||
|
|
||||||
|
|
||||||
index = makeIndex(letter_list)
|
|
||||||
html = index + html
|
|
||||||
html += u'<br style="clear: both">'
|
|
||||||
return macro.formatter.rawHTML(html)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue