def _create_attribute(name, **params): params.setdefault('location', dummy_location) params.setdefault('title', name) params.setdefault('type', u'str') params.setdefault('is_required', False) params.setdefault('is_hidden', False) attr = RoomAttribute(name=name, **params) db.session.flush() return attr
def migrate_locations(self): print cformat('%{white!}migrating locations') default_location_name = self.zodb_root['DefaultRoomBookingLocation'] custom_attributes_dict = self.rb_root['CustomAttributesList'] for old_location in self.zodb_root['RoomBookingLocationList']: # create location l = Location( name=convert_to_unicode(old_location.friendlyName), is_default=( old_location.friendlyName == default_location_name)) print cformat('- %{cyan}{}').format(l.name) # add aspects for old_aspect in old_location._aspects.values(): a = Aspect( name=convert_to_unicode(old_aspect.name), center_latitude=old_aspect.centerLatitude, center_longitude=old_aspect.centerLongitude, zoom_level=old_aspect.zoomLevel, top_left_latitude=old_aspect.topLeftLatitude, top_left_longitude=old_aspect.topLeftLongitude, bottom_right_latitude=old_aspect.bottomRightLatitude, bottom_right_longitude=old_aspect.bottomRightLongitude) print cformat(' %{blue!}Aspect:%{reset} {}').format(a.name) l.aspects.append(a) if old_aspect.defaultOnStartup: l.default_aspect = a # add custom attributes for ca in custom_attributes_dict.get(l.name, []): if ca['type'] != 'str': raise RuntimeError( 'Non-str custom attributes are unsupported: {}'.format( ca)) attr_name = attribute_map.get(ca['name'], ca['name']) attr = RoomAttribute(name=attr_name.replace(' ', '-').lower(), title=attr_name, type=ca['type'], is_required=ca['required'], is_hidden=ca['hidden']) l.attributes.append(attr) print cformat(' %{blue!}Attribute:%{reset} {}').format( attr.title) # add new created location db.session.add(l) print print db.session.commit()
def _process_args(self): name = request.view_args.get('locationId') self._location = Location.find_one(name=name) self._new_attr = None attr_title = request.form.get('newCustomAttributeName', default='').strip() if attr_title: attr_name = attr_title.replace(' ', '-').lower() if RoomAttribute.query.filter_by(name=attr_name).first(): raise BadRequest(_('There is already an attribute named: {0}').format(attr_name)) self._new_attr = RoomAttribute(name=attr_name, title=attr_title, is_hidden=request.form.get('newCustomAttributeIsHidden') == 'on')
def _checkParams(self): name = request.view_args.get('locationId') self._location = Location.find_first(name=name) if not self._location: raise IndicoError(_('Unknown Location: {0}').format(name)) self._new_attr = None attr_title = request.form.get('newCustomAttributeName', default='').strip() if attr_title: attr_name = attr_title.replace(' ', '-').lower() if self._location.get_attribute_by_name(attr_name): raise FormValuesError(_('There is already an attribute named: {0}').format(attr_name)) self._new_attr = RoomAttribute(name=attr_name, title=attr_title, type='str', is_required=request.form.get('newCustomAttributeIsRequired') == 'on', is_hidden=request.form.get('newCustomAttributeIsHidden') == 'on')
def _create_attribute(name): attr = RoomAttribute(name=name, title=name) db.session.add(attr) db.session.flush() return attr
def _process_POST(self, name, title, hidden): self._check_conflict(name) attribute = RoomAttribute(name=name, title=title, is_hidden=hidden) db.session.add(attribute) db.session.flush() return self._jsonify_one(attribute), 201
def _process_args(self): id_ = request.view_args.get('attribute_id') self.attribute = RoomAttribute.get_one( id_) if id_ is not None else None
def _process_args(self): id_ = request.view_args.get('attribute_id') self.attribute = RoomAttribute.get_one(id_) if id_ is not None else None