Ajout des modules initiaux
darcs-hash:20070124114812-f46e9-171ef12f1e1b89ae005adf4aab6f6535fb9289e6.gz
This commit is contained in:
parent
8713311bc1
commit
ed3ab40ccd
80 changed files with 4852 additions and 5 deletions
107
intranet/modules/quota/main.py
Executable file
107
intranet/modules/quota/main.py
Executable file
|
@ -0,0 +1,107 @@
|
|||
#! /usr/bin/env python
|
||||
import cherrypy, tempfile, shutil, os
|
||||
import crans.utils.quota
|
||||
import crans.cp
|
||||
from ClassesIntranet.ModuleBase import ModuleBase
|
||||
|
||||
|
||||
class main(ModuleBase):
|
||||
def category(self):
|
||||
return "Personnel"
|
||||
def title(self):
|
||||
return "Quotas"
|
||||
def icon(self):
|
||||
quotas = self._get_quota()
|
||||
for a_quota in quotas:
|
||||
if a_quota['quota'] < a_quota['usage']:
|
||||
return "icon_alert.png"
|
||||
return "icon.png"
|
||||
|
||||
|
||||
def _get_quota(self):
|
||||
#return quotas = crans.utils.quota.getUserQuota(cherrypy.session['uid'])
|
||||
return [{'%': 33.9, 'quota': 390.62, 'label': u'Dossier personnel', 'limite': 585.94, 'filesystem': '/home', 'usage': 420.32}, {'%': 0.1, 'quota': 100.00, 'label': u'Boite de r\xe9ception', 'limite': 150.00, 'filesystem': '/var/mail', 'usage': 0.06}]
|
||||
|
||||
|
||||
##########################
|
||||
# affichage
|
||||
##########################
|
||||
#
|
||||
# methode qui affiche la template
|
||||
#
|
||||
def index(self ):
|
||||
values = {}
|
||||
try:
|
||||
quotas = self._get_quota()
|
||||
returned_quotas = []
|
||||
for a_quota in quotas:
|
||||
# calculate text equivalent
|
||||
quota = a_quota['quota']
|
||||
usage = a_quota['usage']
|
||||
limite = a_quota['limite']
|
||||
text_equiv = "["
|
||||
text_equiv+= "#" * min( 10, int( 10 * usage / quota ) )
|
||||
text_equiv+= "." * max(0, int( 10 * ( quota - usage ) / quota ) )
|
||||
if limite > quota:
|
||||
text_equiv+= "|"
|
||||
limite_diff = limite - quota
|
||||
diff_proportion = 10 * limite_diff / quota
|
||||
depassement = max(0, usage - quota)
|
||||
text_equiv+= "#" * min(0, int(diff_proportion* ( depassement / limite_diff ) ) )
|
||||
text_equiv+= "." * max(0, int(diff_proportion*( limite_diff - depassement ) / limite_diff ) )
|
||||
text_equiv+= "]"
|
||||
a_returned_quota = {
|
||||
"label":a_quota['label'],
|
||||
"usage":a_quota['usage'],
|
||||
"quota":a_quota['quota'],
|
||||
"limite":a_quota['limite'],
|
||||
"percents":a_quota['%'],
|
||||
"%":a_quota['%'],
|
||||
"text_equiv":text_equiv,
|
||||
"svg_url":"barreSVG?filesystem=%s" % a_quota['filesystem'],
|
||||
}
|
||||
returned_quotas.append(a_returned_quota)
|
||||
values = {'quotas': returned_quotas, 'e': "eeede"}
|
||||
except Exception, e:
|
||||
crans.cp.log('error getting quota for user %s : %s' % (cherrypy.session['uid'], str(e)), 'QUOTA', 1)
|
||||
values = {'erreur':str(e), 'e': "eee"}
|
||||
return {'template':'quota',
|
||||
'values': values,
|
||||
'stylesheets':['quota.css'],
|
||||
'scripts':['quota.js', 'popup.js'],
|
||||
}
|
||||
index.exposed = True
|
||||
|
||||
def index_html(self ):
|
||||
result = self.index()
|
||||
result['template'] = 'quota_html'
|
||||
return result
|
||||
index_html.exposed = True
|
||||
|
||||
|
||||
##########################
|
||||
# SVG
|
||||
##########################
|
||||
#
|
||||
# methode qui renvoie une barre en svg
|
||||
#
|
||||
def barreSVG(self, filesystem = ""):
|
||||
try:
|
||||
values = {'erreur':"Not found"}
|
||||
quotas = self._get_quota()
|
||||
for a_quota in quotas:
|
||||
if a_quota['filesystem'] == filesystem:
|
||||
values = {
|
||||
"usage":a_quota['usage'],
|
||||
"quota":a_quota['quota'],
|
||||
"limite":a_quota['limite'],
|
||||
"percents":a_quota['%'],
|
||||
}
|
||||
except Exception, e:
|
||||
values = {'erreur':str(e) }
|
||||
cherrypy.response.headers['Content-Type']="image/svg+xml"
|
||||
return {'template':'barre.svg',
|
||||
'values': values,
|
||||
'standalone':True,
|
||||
}
|
||||
barreSVG.exposed= True
|
Loading…
Add table
Add a link
Reference in a new issue