Ajout des modules initiaux

darcs-hash:20070124114812-f46e9-171ef12f1e1b89ae005adf4aab6f6535fb9289e6.gz
This commit is contained in:
gdetrez 2007-01-24 12:48:12 +01:00
parent 8713311bc1
commit ed3ab40ccd
80 changed files with 4852 additions and 5 deletions

107
intranet/modules/quota/main.py Executable file
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 986 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,40 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
#if $getVar('usage', False)
#set total = $limite
#set quota = $quota
#set usage = $usage
#set usage_percent = int( 100 * $usage/$limite )
#set quota_percent = int( 100 * $quota/$limite )
<defs>
<linearGradient id="barre_gradient" x1="0%" y1="0%" x2="100%" y2="0%">
<stop offset="0%" style="stop-color:rgb(0,255,0);stop-opacity:1"/>
<stop offset="$quota_percent%" style="stop-color:rgb(255,255,0);stop-opacity:1"/>
<stop offset="100%" style="stop-color:rgb(255,0,0);stop-opacity:1"/>
</linearGradient>
</defs>
<g font-family="Verdana" font-size="10">
<rect x="1" y="1" width="$total" height="22" style="fill:url(#barre_gradient);stroke:black;stroke-width:2;"/>
<line x1="$int(quota+2)" y1="15" x2="$int(quota+2)" y2="22" style="stroke:rgb(0,0,0);stroke-width:2"/>
<text x="2" y="40">0Mo</text>
<text x="$int(quota+2)" y="40">$int(quota) Mo</text>
<text x="$int(total+2)" y="40">$int(total) Mo</text>
</g>
<g font-family="Verdana" font-size="10">
<rect x="2" y="2" width="$usage" height="20" style="fill:white;opacity:0.7"/>
<line x1="$int(usage+2)" y1="2" x2="$int(usage+2)" y2="22" style="stroke:rgb(99,99,99);stroke-width:1"/>
<text x="4" y="15">$percents%</text>
</g>
#else
<g font-family="Verdana" font-size="10">
<text x="21" y="35" style="color:red">$getVar('erreur', 'BROKEN')</text>
</g>
#end if
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -0,0 +1,13 @@
<div class="framed_gray">
#for un_truc in $quotas
<h3>$un_truc.label</h3>
<embed src="$un_truc.svg_url" width="100%" height="50"
type="image/svg+xml"
pluginspage="http://www.adobe.com/svg/viewer/install/" />
#end for
<div style="text-align:right;">Si les graphiques ne s'affichent pas, essayez la <a href="index_html">version html</a></div>
</div>

View file

@ -0,0 +1,22 @@
<div class="framed_gray">
#for un_truc in $quotas
<h3>$un_truc.label</h3>
#set total = $un_truc.limite
#set usage = int( 100 * $un_truc.usage/$un_truc.limite )
#set quota = int( 100 * $un_truc.quota/$un_truc.limite )
<div style="float:left;height:1.2em;width:40%;border:thin black solid;position:relative;background:#f99">
<div style="float:left;height:.8em;width:$usage%;background:blue;position:absolute;top:0;left:0;">
<span style="display:none">
$un_truc.text_equiv
</span>
</div>
<div style="float:left;height:1.2em;width:$quota%;background:#aaa"></div>
</div> $un_truc['%'] %
#end for
<div style="text-align:right;"><a href="index">version svg</a></div>
</div>