[intranet/quota] on arrête de planter bêtement lorsque l'utilisateur n'a pas de quota

darcs-hash:20090624081109-bd074-2ea69a8121de6b3a830a7b578341bfbbae828901.gz
This commit is contained in:
Antoine Durand-Gasselin 2009-06-24 10:11:09 +02:00
parent 776af42937
commit 8968220f87

View file

@ -12,24 +12,26 @@ class main(ModuleBase):
def title(self): def title(self):
return "Quotas" return "Quotas"
def icon(self): def icon(self):
quotas = self._get_quota() try:
for a_quota in quotas: quotas = self._get_quota()
if a_quota['quota'] < a_quota['usage']: for a_quota in quotas:
return "icon_alert.png" if a_quota['quota'] < a_quota['usage']:
return "icon.png" return "icon_alert.png"
return "icon.png"
except:
return "icon_disabled.png"
def _get_quota(self): def _get_quota(self):
if (cherrypy.config.configMap["global"]["server.environment"] == "development"): if (cherrypy.config.configMap["global"]["server.environment"] == "development"):
return quota.fake_getUserQuota(cherrypy.session['uid']) return quota.fake_getUserQuota(cherrypy.session['uid'])
else: else:
return quota.getUserQuota(cherrypy.session['uid']) return quota.getUserQuota(cherrypy.session['uid'])
########################## ##########################
# affichage # affichage
########################## ##########################
# #
# methode qui affiche la template # methode qui affiche la template
# #
def index(self ): def index(self ):
@ -68,24 +70,24 @@ class main(ModuleBase):
except Exception, e: except Exception, e:
crans.cp.log('error getting quota for user %s : %s' % (cherrypy.session['uid'], str(e)), 'QUOTA', 1) crans.cp.log('error getting quota for user %s : %s' % (cherrypy.session['uid'], str(e)), 'QUOTA', 1)
values = {'erreur':str(e)} values = {'erreur':str(e)}
return {'template':'quota', return {'template':'quota',
'values': values, 'values': values,
'stylesheets':['quota.css'], 'stylesheets':['quota.css'],
'scripts':['quota.js', 'popup.js'], 'scripts':['quota.js', 'popup.js'],
} }
index.exposed = True index.exposed = True
def index_html(self ): def index_html(self ):
result = self.index() result = self.index()
result['template'] = 'quota_html' result['template'] = 'quota_html'
return result return result
index_html.exposed = True index_html.exposed = True
########################## ##########################
# SVG # SVG
########################## ##########################
# #
# methode qui renvoie une barre en svg # methode qui renvoie une barre en svg
# #
def barreSVG(self, filesystem = ""): def barreSVG(self, filesystem = ""):
@ -103,7 +105,7 @@ class main(ModuleBase):
except Exception, e: except Exception, e:
values = {'erreur':str(e) } values = {'erreur':str(e) }
cherrypy.response.headers['Content-Type']="image/svg+xml" cherrypy.response.headers['Content-Type']="image/svg+xml"
return {'template':'barre.svg', return {'template':'barre.svg',
'values': values, 'values': values,
'standalone':True, 'standalone':True,
} }