def handleApply(self, action): data, errors = self.extractData() if errors: self.status = EditForm.formErrorsMessage return wrapper = getSAWrapper('gites_wallons') session = wrapper.session config = data.get('calendarConfig') all_hebs = getHebergementsForProprio( self.context, session, only_active=False, ) for heb in all_hebs: oldConfig = heb.heb_calendrier_proprio heb.heb_calendrier_proprio = config # mise à jour dernière date de modification du calendrier heb.heb_calendrier_proprio_date_maj = date.today() session.add(heb) if oldConfig != config: if config == u'non actif': hebBlockHist = HebergementBlockingHistory() hebBlockHist.heb_blockhistory_blocked_dte = date.today() hebBlockHist.heb_blockhistory_heb_pk = heb.heb_pk session.add(hebBlockHist) else: blockHist = self.getBlockedInfo(session, heb.heb_pk) if blockHist is not None: blockHist.heb_blockhistory_activated_dte = date.today() blockedDate = blockHist.heb_blockhistory_activated_dte - blockHist.heb_blockhistory_blocked_dte blockHist.heb_blockhistory_days = blockedDate.days session.add(blockHist) session.flush() session.expunge_all() self.status = ""
def blockCalendars(self, proprioPk): proprio = self.getProprio(proprioPk) for hebergement in proprio.hebergements: hebergement.heb_calendrier_proprio = u'bloque' self.session.add(hebergement) hebBlockHist = HebergementBlockingHistory() hebBlockHist.heb_blockhistory_blocked_dte = self.now() hebBlockHist.heb_blockhistory_heb_pk = hebergement.heb_pk self.session.add(hebBlockHist) self.session.flush() self.session.commit()