Commit aa79f437 authored by Antoine Durand-Gasselin's avatar Antoine Durand-Gasselin Committed by Antoine Durand-gasselin
Browse files

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
parent bebb5a6e
......@@ -3,17 +3,16 @@
import os
import PagesPerso
def comptes():
"""Retourne la liste des comptes"""
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"))
class ClubList(PagesPerso.AccountList):
home = "/home/club"
www = ""
url = "http://clubs.ens-cachan.fr/%s/"
def url(self):
"""URL vers la page perso"""
return u"http://clubs.ens-cachan.fr/%s/" % self.login
def comptes(self):
"""Retourne la liste des comptes"""
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
class account:
"""Classe reprsentant la page perso d'une personne"""
class AccountList:
home = "/home"
www = "/www"
url = "http://perso.crans.org/%s/"
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 reprsentant la page perso d'une personne"""
def __init__(self, login):
def __init__(self, home, login, www, url):
"""Instanciation avec le `login' de la personne"""
self.login = login
self.home = "%s/%s" % (self.home, login)
self.home = "%s/%s" % (home, login)
self.www = www
self.url = url
_info = None
def info(self, champ):
......@@ -39,10 +80,6 @@ class account:
"""Chemin vers le 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):
"""URL du logo s'il y en a un"""
if self.info("logo"):
......@@ -52,13 +89,13 @@ class account:
else:
logo = self.info("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"
def __str__(self):
def to_html(self):
"""Renvoie le code HTML correspondant au fichier .info"""
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'</a><br>',
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>' ]
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):
dirs = 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, 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)
return macro.formatter.rawHTML(AccountList().to_html())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment