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 _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
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, )
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 __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)
def _get_heb(self): return Hebergement.first(heb_pk=self.table.heb_pk)