def decorated(self):
     db = getUtility(IDatabase, name='postgres')
     session = db.session
     heb = Hebergement()
     heb.heb_pk = 1
     session.add(heb)
     session.flush()
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 1)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 5)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 1)
     resPro.res_type = 'indisp'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 4)
     resPro.res_type = 'loue'
     session.add(resPro)
     session.flush()
     session.commit()
     try:
         func(self)
     finally:
         db.refresh()
 def decorated(self):
     db = getUtility(IDatabase, name='postgres')
     session = db.session
     heb = Hebergement()
     heb.heb_pk = 1
     session.add(heb)
     heb = Hebergement()
     heb.heb_pk = 2
     session.add(heb)
     session.flush()
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 1)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2010, 10, 5)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 2
     resPro.res_date = datetime(2010, 10, 5)
     resPro.res_type = 'loue'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 1)
     resPro.res_type = 'indisp'
     session.add(resPro)
     resPro = ReservationProprio()
     resPro.heb_fk = 1
     resPro.res_date = datetime(2009, 10, 4)
     resPro.res_type = 'loue'
     session.add(resPro)
     blck = BlockingHistory()
     blck.heb_pk = 1
     blck.block_start = datetime(2010, 1, 1)
     blck.block_end = datetime(2010, 10, 3)
     session.add(blck)
     blck = BlockingHistory()
     blck.heb_pk = 1
     blck.block_start = datetime(2010, 1, 1)
     blck.block_end = datetime(2010, 2, 3)
     session.add(blck)
     blck = BlockingHistory()
     blck.heb_pk = 2
     blck.block_start = datetime(2010, 10, 10)
     blck.block_end = datetime(2010, 10, 10)
     session.add(blck)
     session.flush()
     session.commit()
     try:
         func(self)
     finally:
         db.refresh()
 def test_simple_get(self):
     PK = 99
     heb = Hebergement(heb_pk=PK)
     sess = session()
     sess.add(heb)
     sess.flush()
     self.assertEqual(heb.heb_pk, Hebergement.first(heb_pk=PK).heb_pk)
 def decorated(self):
     db = getUtility(IDatabase, name='postgres')
     session = db.session
     heb = Hebergement()
     heb.heb_pk = 1
     session.add(heb)
     session.flush()
     blck = BlockingHistory()
     blck.heb_pk = 1
     blck.block_start = datetime(2010, 1, 1)
     session.add(blck)
     session.flush()
     session.commit()
     try:
         func(self)
     finally:
         db.refresh()
Example #5
0
    def _get_heb(self):
        roles = api.user.get_current().getRoles()
        heb = None

        # Proprio of heb in the request?
        if 'Proprietaire' in roles:
            proprio_hebs = getUtility(IVocabularyFactory, name='proprio.hebergements')(self.context)
            for proprio_heb in proprio_hebs:
                if proprio_heb.token == self.table.heb_pk:
                    heb = Hebergement.first(heb_pk=self.table.heb_pk)
                    break

        # Admin
        elif 'Manager' in roles:
            heb = Hebergement.first(heb_pk=self.table.heb_pk)

        return heb
Example #6
0
 def _get_url(self, pk):
     context = Hebergement.first(heb_pk=pk)
     portal = api.portal.get()
     container = portal.hebergement
     commune = context.commune.com_id
     language = self.request.get('LANGUAGE', 'en')
     typeHeb = context.type.getId(language)
     hebId = context.heb_id
     return "%s/%s/%s/%s" % (container.absolute_url(),
                             typeHeb,
                             commune,
                             hebId,
                             )
Example #7
0
 def getLastHebergementsChanges(self):
     """
     Get last hebergements changes in origin DB for hebs that are in the 2 databases
     """
     if self.origin == 'PIVOT':
         gdw_hebs = self.pg_session.query(Hebergement.heb_code_cgt).all()
         gdw_hebs_cgt = [i.heb_code_cgt for i in gdw_hebs]
         last_changes = HebergementView.get_last_changes(self.date)
         last_changes = [i for i in last_changes if i.heb_code_cgt in gdw_hebs_cgt]
     elif self.origin == 'GDW':
         pivot_hebs = self.mysql_session.query(HebergementView.heb_code_cgt).all()
         pivot_hebs_cgt = [i.heb_code_cgt for i in pivot_hebs]
         last_changes = Hebergement.get_last_changes(self.date, session=self.pg_session, cgt_not_empty=True)
         last_changes = [i for i in last_changes if i.heb_code_cgt in pivot_hebs_cgt]
     return last_changes
    def apply_tarifs_changes(self):
        """ Apply tarifs changes """
        form = self.request.form
        heb_pk = form.get('tarif_heb_pk', None)

        if not heb_pk:
            return 1

        # new tarif from proprio are not directly valid
        roles = api.user.get_current().getRoles()
        is_admin = 'Manager' in roles and True or None
        valid = is_admin and True or None

        heb = Hebergement.first(heb_pk=heb_pk)

        if heb.type.type_heb_type == 'gite':
            tarifs_types = TarifsType.get(gite=True)
        elif heb.type.type_heb_type == 'chambre':
            tarifs_types = TarifsType.get(chambre=True)

        for tt in tarifs_types:
            if tt.type == "CHARGES":
                min, max, cmt = self._get_charges_values(form, tt)
                # Do not have to update_tarif CHARGES if not selected
                if cmt == None:
                    continue
            else:
                min = form.get('tarif_min_{0}_{1}'.format(tt.type, tt.subtype)) or None
                max = form.get('tarif_max_{0}_{1}'.format(tt.type, tt.subtype)) or None
                cmt = form.get('tarif_cmt_{0}_{1}'.format(tt.type, tt.subtype)) or None

            self._update_tarif(heb_pk,
                               tt.type,
                               tt.subtype,
                               min,
                               max,
                               cmt,
                               valid)
        if is_admin:
            return 1
        else:
            return 2
 def getLastHebergementsChanges(self):
     """
     Get last hebergements changes in origin DB for hebs that are in the 2 databases
     """
     if self.origin == 'PIVOT':
         gdw_hebs = self.pg_session.query(Hebergement.heb_code_cgt).all()
         gdw_hebs_cgt = [i.heb_code_cgt for i in gdw_hebs]
         last_changes = HebergementView.get_last_changes(self.date)
         last_changes = [
             i for i in last_changes if i.heb_code_cgt in gdw_hebs_cgt
         ]
     elif self.origin == 'GDW':
         pivot_hebs = self.mysql_session.query(
             HebergementView.heb_code_cgt).all()
         pivot_hebs_cgt = [i.heb_code_cgt for i in pivot_hebs]
         last_changes = Hebergement.get_last_changes(
             self.date, session=self.pg_session, cgt_not_empty=True)
         last_changes = [
             i for i in last_changes if i.heb_code_cgt in pivot_hebs_cgt
         ]
     return last_changes
Example #10
0
 def __str__(self):
     if isinstance(self.context, tuple):
         if hasattr(self.context, 'heb_pk'):
             context = Hebergement.first(heb_pk=self.context.heb_pk)
         else:
             return ''
     else:
         context = aq_inner(self.context)
     portal = api.portal.get()
     container = portal.hebergement
     from gites.db import session
     session = session()
     commune = session.query(Commune.com_id).options(FromCache('gdw')).filter_by(com_pk=context.heb_com_fk).first()
     language = self.request.get('LANGUAGE', 'en')
     typeHeb = session.query(TypeHebergement).options(FromCache('gdw')).filter_by(type_heb_pk=context.heb_typeheb_fk).first()
     hebId = context.heb_id
     return "%s/%s/%s/%s" % (container.absolute_url(),
                             #self.getHebType(self.context.heb_typeheb_fk, language),
                             typeHeb.getId(language),
                             commune.com_id,
                             hebId,
                             )
 def heb(self):
     return Hebergement.first(heb_pk=self.heb_pk)
Example #12
0
 def _get_heb(self):
     return Hebergement.first(heb_pk=self.table.heb_pk)