Fait prendre un peu d'air au code
This commit is contained in:
parent
8ae5870468
commit
1353f00e17
1 changed files with 246 additions and 120 deletions
226
objets.py
226
objets.py
|
@ -100,7 +100,8 @@ class CransLdapObject(object):
|
|||
|
||||
""" Qui peut faire quoi ? """
|
||||
__slots__ = ("in_context", "conn", "lockId", "attrs", "_modifs", "dn", "parent_dn", "mode")
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
can_be_by = {
|
||||
variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
}
|
||||
|
@ -454,7 +455,7 @@ class CransLdapObject(object):
|
|||
ldif = self._modifs.to_ldif()
|
||||
for attr in binary:
|
||||
ldif['%s;binary' % attr] = ldif[attr]
|
||||
del(ldif[attr])
|
||||
del ldif[attr]
|
||||
# Création de la requête LDAP
|
||||
modlist = addModlist(ldif)
|
||||
# Requête LDAP de création de l'objet
|
||||
|
@ -595,9 +596,9 @@ class CransLdapObject(object):
|
|||
for attr in binary:
|
||||
ldif['%s;binary' % (attr,)] = ldif[attr]
|
||||
orig_ldif['%s;binary' % (attr,)] = orig_ldif.get(attr, [])
|
||||
del(ldif[attr])
|
||||
del ldif[attr]
|
||||
try:
|
||||
del(orig_ldif[attr])
|
||||
del orig_ldif[attr]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
@ -858,24 +859,41 @@ class InetOrgPerson(CransLdapObject):
|
|||
class proprio(CransLdapObject):
|
||||
u""" Un propriétaire de machine (adhérent, club…) """
|
||||
__slots__ = ("_machines", "_factures", "full")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.soi, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau,],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.soi,
|
||||
attributs.cableur,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
crans_account_attribs = [attributs.uid, attributs.canonicalAlias, attributs.solde,
|
||||
crans_account_attribs = [
|
||||
attributs.uid, attributs.canonicalAlias, attributs.solde,
|
||||
attributs.contourneGreylist, attributs.derniereConnexion,
|
||||
attributs.homepageAlias, attributs.loginShell, attributs.gecos,
|
||||
attributs.uidNumber, attributs.homeDirectory,
|
||||
attributs.gidNumber, attributs.userPassword,
|
||||
attributs.mailAlias, attributs.cn, attributs.rewriteMailHeaders,
|
||||
attributs.mailExt, attributs.compteWiki, attributs.droits,
|
||||
attributs.shadowExpire]
|
||||
default_attribs = [attributs.nom, attributs.chbre, attributs.paiement, attributs.info,
|
||||
attributs.shadowExpire,
|
||||
]
|
||||
default_attribs = [
|
||||
attributs.nom, attributs.chbre, attributs.paiement, attributs.info,
|
||||
attributs.blacklist, attributs.controle, attributs.historique,
|
||||
attributs.debutAdhesion, attributs.finAdhesion, attributs.debutConnexion,
|
||||
attributs.finConnexion]
|
||||
attributs.finConnexion,
|
||||
]
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
|
@ -1016,7 +1034,11 @@ class proprio(CransLdapObject):
|
|||
|
||||
def fin_adhesion(self):
|
||||
"""Retourne la date de fin d'adhésion"""
|
||||
return max([float(facture.get('finAdhesion', [crans_utils.from_generalized_time_format(attributs.finAdhesion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
return max([
|
||||
float(facture.get('finAdhesion', [crans_utils.from_generalized_time_format(attributs.finAdhesion.default)])[0])
|
||||
for facture in self.factures(refresh=True, mode="ro")
|
||||
if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''
|
||||
] + [0.0])
|
||||
|
||||
def fin_connexion_datetime(self):
|
||||
return datetime.datetime.fromtimestamp(self.fin_connexion())
|
||||
|
@ -1026,7 +1048,11 @@ class proprio(CransLdapObject):
|
|||
|
||||
def fin_connexion(self):
|
||||
"""Retourne la date de fin de connexion"""
|
||||
return max([float(facture.get('finConnexion', [crans_utils.from_generalized_time_format(attributs.finConnexion.default)])[0]) for facture in self.factures(refresh=True, mode="ro") if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''] + [0.0])
|
||||
return max([
|
||||
float(facture.get('finConnexion', [crans_utils.from_generalized_time_format(attributs.finConnexion.default)])[0])
|
||||
for facture in self.factures(refresh=True, mode="ro")
|
||||
if facture.get('controle', [''])[0] != u"FALSE" and facture.get('recuPaiement', [''])[0] != ''
|
||||
] + [0.0])
|
||||
|
||||
def paiement_ok(self, no_bl=False):
|
||||
u"""
|
||||
|
@ -1160,17 +1186,38 @@ class proprio(CransLdapObject):
|
|||
class machine(CransLdapObject):
|
||||
u""" Une machine """
|
||||
__slots__ = ("_proprio", "_certificats")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur, attributs.parent, attributs.respo],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
attributs.parent,
|
||||
attributs.respo,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
attributs.parent,
|
||||
attributs.respo,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
attributs.parent,
|
||||
attributs.respo,
|
||||
],
|
||||
}
|
||||
|
||||
attribs = [attributs.mid, attributs.macAddress, attributs.host,
|
||||
attribs = [
|
||||
attributs.mid, attributs.macAddress, attributs.host,
|
||||
attributs.rid, attributs.info, attributs.blacklist, attributs.hostAlias,
|
||||
attributs.exempt, attributs.portTCPout, attributs.portTCPin,
|
||||
attributs.portUDPout, attributs.portUDPin, attributs.sshFingerprint,
|
||||
attributs.ipHostNumber, attributs.ip6HostNumber, attributs.historique,
|
||||
attributs.dnsIpv6, attributs.machineAlias]
|
||||
attributs.dnsIpv6, attributs.machineAlias,
|
||||
]
|
||||
|
||||
def __unicode__(self):
|
||||
return u"%s : host=%s" % (self.__class__.__name__, self['host'][0])
|
||||
|
@ -1379,7 +1426,8 @@ class adherent(proprio):
|
|||
|
||||
@property
|
||||
def attribs(self):
|
||||
return super(adherent, self).attribs + [attributs.aid, attributs.prenom, attributs.tel,
|
||||
return super(adherent, self).attribs + [
|
||||
attributs.aid, attributs.prenom, attributs.tel,
|
||||
attributs.mail, attributs.mailInvalide, attributs.charteMA,
|
||||
attributs.derniereConnexion, attributs.gpgFingerprint,
|
||||
attributs.carteEtudiant, attributs.etudes,
|
||||
|
@ -1421,9 +1469,23 @@ class adherent(proprio):
|
|||
class club(proprio):
|
||||
u"""Club crans"""
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.respo, attributs.cableur, attributs.soi],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.respo,
|
||||
attributs.cableur,
|
||||
attributs.soi,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
],
|
||||
}
|
||||
ldap_name = "club"
|
||||
|
||||
|
@ -1488,46 +1550,88 @@ class machineWifi(machine):
|
|||
@crans_object
|
||||
class machineCrans(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
],
|
||||
}
|
||||
attribs = machine.attribs + [attributs.prise, attributs.nombrePrises]
|
||||
attribs = machine.attribs + [
|
||||
attributs.prise, attributs.nombrePrises,
|
||||
]
|
||||
ldap_name = "machineCrans"
|
||||
|
||||
@crans_object
|
||||
class borneWifi(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
],
|
||||
}
|
||||
attribs = machine.attribs + [attributs.canal, attributs.puissance, attributs.hotspot,
|
||||
attributs.prise, attributs.positionBorne, attributs.nvram]
|
||||
attribs = machine.attribs + [
|
||||
attributs.canal, attributs.puissance, attributs.hotspot,
|
||||
attributs.prise, attributs.positionBorne, attributs.nvram,
|
||||
]
|
||||
ldap_name = "borneWifi"
|
||||
|
||||
@crans_object
|
||||
class switchCrans(machine):
|
||||
__slots__ = ()
|
||||
can_be_by = { variables.created: [attributs.nounou],
|
||||
variables.modified: [attributs.nounou],
|
||||
variables.deleted: [attributs.nounou],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
],
|
||||
}
|
||||
attribs = machine.attribs + [attributs.nombrePrises]
|
||||
attribs = machine.attribs + [
|
||||
attributs.nombrePrises,
|
||||
]
|
||||
|
||||
ldap_name = "switchCrans"
|
||||
|
||||
@crans_object
|
||||
class facture(CransLdapObject):
|
||||
__slots__ = ("_proprio", "_recuPaiement")
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.cableur],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.cableur,
|
||||
],
|
||||
}
|
||||
attribs = [attributs.fid, attributs.modePaiement, attributs.recuPaiement,
|
||||
attribs = [
|
||||
attributs.fid, attributs.modePaiement, attributs.recuPaiement,
|
||||
attributs.historique, attributs.article, attributs.info,
|
||||
attributs.debutAdhesion, attributs.finAdhesion, attributs.debutConnexion,
|
||||
attributs.finConnexion, attributs.controle ]
|
||||
attributs.finConnexion, attributs.controle,
|
||||
]
|
||||
ldap_name = "facture"
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -1604,19 +1708,41 @@ class facture(CransLdapObject):
|
|||
@crans_object
|
||||
class baseCert(CransLdapObject):
|
||||
__slots__ = ("_machine",)
|
||||
can_be_by = { variables.created: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
variables.modified: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
variables.deleted: [attributs.nounou, attributs.bureau, attributs.parent],
|
||||
can_be_by = {
|
||||
variables.created: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.parent,
|
||||
],
|
||||
variables.modified: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.parent,
|
||||
],
|
||||
variables.deleted: [
|
||||
attributs.nounou,
|
||||
attributs.bureau,
|
||||
attributs.parent,
|
||||
],
|
||||
}
|
||||
default_attribs = [ attributs.xid, attributs.certificat, attributs.hostCert, attributs.historique,
|
||||
attributs.info, attributs.csr ]
|
||||
default_attribs = [
|
||||
attributs.xid, attributs.certificat, attributs.hostCert, attributs.historique,
|
||||
attributs.info, attributs.csr,
|
||||
]
|
||||
|
||||
tlsa_attribs = [ attributs.certificatUsage, attributs.selector, attributs.matchingType,
|
||||
attributs.portTCPin, attributs.portUDPin]
|
||||
x509_attribs = [ attributs.issuerCN, attributs.start, attributs.end,
|
||||
attributs.crlUrl, attributs.revocked, attributs.serialNumber ]
|
||||
tlsa_attribs = [
|
||||
attributs.certificatUsage, attributs.selector, attributs.matchingType,
|
||||
attributs.portTCPin, attributs.portUDPin,
|
||||
]
|
||||
|
||||
private_attribs = [ attributs.privatekey, attributs.encrypted ]
|
||||
x509_attribs = [
|
||||
attributs.issuerCN, attributs.start, attributs.end,
|
||||
attributs.crlUrl, attributs.revocked, attributs.serialNumber,
|
||||
]
|
||||
|
||||
private_attribs = [
|
||||
attributs.privatekey, attributs.encrypted,
|
||||
]
|
||||
|
||||
@property
|
||||
def attribs(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue