def save_alerte(self): date_a = self.date_a.text() day, month, year = date_a.split("/") dt = datetime.now() datetime_ = datetime( int(year), int(month), int(day), int(dt.hour), int(dt.minute), int(dt.second), int(dt.microsecond) ) alt = Alerte() alt.objets = unicode(self.objets.toPlainText()) alt.date_a = datetime_ alt.save() self.cancel() raise_success(_(u"Confirmation"), _(u"The store has been changing"))
def saveTableItems(self): n = self.rowCount() for i in range(n): item = self.cellWidget(i, 0) if item.checkState() == QtCore.Qt.Checked: alert = Alerte.filter(id=self.data[i][3]).get() alert.status = False alert.save()
def alerte(): list_al , msg = [], "" min_nbr_day = 0 max_nbr_day = 4 try: alerte = Alerte.get() except: alerte = None if alerte: for al in Alerte.filter(status=True): dat = (al.date_a - datetime.now()).days if dat <= max_nbr_day and dat >= min_nbr_day: list_al.append(al) msg += "%d jr(s) pour: %s " % (dat, al.objets) return list_al, msg
def save_al(list_): """Enregistrer les alertes qui sont dans la liste""" for el in list_: try: al = Alerte.filter(objets=el[0]).get() except: al = Alerte() al.objets = unicode(el[0]) al.date_a = el[1] al.status = True al.save()
def set_data_for(self): self.data = [(al.objets, al.date_a, al.status) for al in Alerte.all()]
#!/usr/bin/env python # -*- coding: utf-8 -*- #maintainer : Fad from model import Alerte from data_helper import make_date, save_al list_alert = [(u"periode de transfere des poussins dans les poulaillers", make_date(4)), (u"periode de reforme", make_date(80)), ("phage ponde est arrive", make_date(18)), (u"le nettoyage des poulaillers apres la periode de reforme", make_date(81)), (u"Il est temps de faire une commande de nouveau poussins", make_date(79)),] save_al(list_alert) print "Les alertes", Alerte.all()