def _migrate_location(self): custom_location = self.conf.places[0] if getattr(self.conf, 'places', None) else None custom_room = self.conf.rooms[0] if getattr(self.conf, 'rooms', None) else None location_name = None room_name = None has_room = False if custom_location: location_name = convert_to_unicode(fix_broken_string(custom_location.name, True)) if custom_location.address: self.event.own_address = convert_to_unicode(fix_broken_string(custom_location.address, True)) if custom_room: room_name = convert_to_unicode(fix_broken_string(custom_room.name, True)) if location_name and room_name: mapping = self.global_ns.room_mapping.get((location_name, room_name)) if mapping: has_room = True self.event.own_venue_id = mapping[0] self.event.own_room_id = mapping[1] # if we don't have a RB room set, use whatever location/room name we have if not has_room: venue_id = self.global_ns.venue_mapping.get(location_name) if venue_id is not None: self.event.own_venue_id = venue_id self.event.own_venue_name = '' else: self.event.own_venue_name = location_name or '' self.event.own_room_name = room_name or ''
def migrate_event_locations(self): self.print_step("Migrating event locations") for old_event in committing_iterator(self._iter_events()): custom_location = old_event.places[0] if getattr(old_event, 'places', None) else None custom_room = old_event.rooms[0] if getattr(old_event, 'rooms', None) else None location_name = None room_name = None has_room = False updates = {} if custom_location: location_name = convert_to_unicode(fix_broken_string(custom_location.name, True)) if custom_location.address: updates[Event.own_address] = convert_to_unicode(fix_broken_string(custom_location.address, True)) if custom_room: room_name = convert_to_unicode(fix_broken_string(custom_room.name, True)) if location_name and room_name: mapping = self.room_mapping.get((location_name, room_name)) if mapping: has_room = True updates[Event.own_venue_id] = mapping[0] updates[Event.own_room_id] = mapping[1] # if we don't have a RB room set, use whatever location/room name we have if not has_room: venue_id = self.venue_mapping.get(location_name) if venue_id is not None: updates[Event.own_venue_id] = venue_id updates[Event.own_venue_name] = '' else: updates[Event.own_venue_name] = location_name or '' updates[Event.own_room_name] = room_name or '' if updates: Event.query.filter_by(id=int(old_event.id)).update(updates, synchronize_session=False) if not self.quiet: self.print_success(repr(updates), event_id=old_event.id)
def _migrate_location(self, old_entry, new_entry): custom_location = (old_entry.places[0] if getattr(old_entry, 'places', None) else getattr(old_entry, 'place', None)) custom_room = (old_entry.rooms[0] if getattr(old_entry, 'rooms', None) else getattr(old_entry, 'room', None)) new_entry.inherit_location = not custom_location and not custom_room if new_entry.inherit_location: return # we don't inherit, so let's migrate the data we have # address is always allowed if not custom_location: custom_location = self._get_parent_location(old_entry, attr='places') if not custom_room: custom_room = self._get_parent_location(old_entry, attr='rooms') new_entry.address = (convert_to_unicode(fix_broken_string(custom_location.address, True)) if custom_location and custom_location.address else '') location_name = (convert_to_unicode(fix_broken_string(custom_location.name, True)) if custom_location and custom_location.name else '') if custom_room: room_name = convert_to_unicode(fix_broken_string(custom_room.name, True)) rb_room = self.room_mapping.get((location_name, room_name)) # if we have a room from the rb module, we only link this, otherwise we use the (custom) names if rb_room: new_entry.room = rb_room else: new_entry.venue_name = location_name new_entry.room_name = room_name venue = self.venue_mapping.get(new_entry.venue_name) if venue is not None: # store proper reference to the venue if it's a predefined one new_entry.venue = venue new_entry.venue_name = ''
def migrate_event_locations(self): self.print_step("Migrating event locations") for old_event in committing_iterator(self._iter_events()): custom_location = old_event.places[0] if getattr( old_event, 'places', None) else None custom_room = old_event.rooms[0] if getattr( old_event, 'rooms', None) else None location_name = None room_name = None has_room = False updates = {} if custom_location: location_name = convert_to_unicode( fix_broken_string(custom_location.name, True)) if custom_location.address: updates[Event.own_address] = convert_to_unicode( fix_broken_string(custom_location.address, True)) if custom_room: room_name = convert_to_unicode( fix_broken_string(custom_room.name, True)) if location_name and room_name: mapping = self.room_mapping.get((location_name, room_name)) if mapping: has_room = True updates[Event.own_venue_id] = mapping[0] updates[Event.own_room_id] = mapping[1] # if we don't have a RB room set, use whatever location/room name we have if not has_room: venue_id = self.venue_mapping.get(location_name) if venue_id is not None: updates[Event.own_venue_id] = venue_id updates[Event.own_venue_name] = '' else: updates[Event.own_venue_name] = location_name or '' updates[Event.own_room_name] = room_name or '' if updates: Event.query.filter_by(id=int(old_event.id)).update( updates, synchronize_session=False) if not self.quiet: self.print_success(repr(updates), event_id=old_event.id)
def fixIndexesEncoding(dbi, withRBDB, prevVersion): """ Fix indexes encoding. They may be in unicode and they has to be encoded in utf-8 """ INDEXES = ["name", "surName", "organisation"] ih = IndexesHolder() for idx_name in INDEXES: idx = ih.getById(idx_name) words = idx._words for key in words.iterkeys(): newKey = fix_broken_string(key) values = words[key] del words[key] words[newKey] = values idx.setIndex(words) dbi.commit()
def fixIndexesEncoding(dbi, withRBDB, prevVersion): """ Fix indexes encoding. They may be in unicode and they have to be encoded in utf-8 """ INDEXES = ["name", "surName", "organisation"] ih = IndexesHolder() for idx_name in INDEXES: idx = ih.getById(idx_name) words = idx._words for key in list(words): newKey = fix_broken_string(key) values = words[key] del words[key] words[newKey] = values idx.setIndex(words) dbi.commit()
def fix_indexes(): dbi = DBMgr.getInstance() dbi.startRequest() ih = IndexesHolder() for idx_name in INDEXES: idx = ih.getById(idx_name) words = idx._words for key in words.iterkeys(): newKey = fix_broken_string(key) values = words[key] del words[key] words[newKey] = values idx.setIndex(words) dbi.commit() dbi.endRequest()
def generate_content(cls, attachment): with attachment.file.open() as f: return render_template(cls.TEMPLATES_DIR + 'text_preview.html', attachment=attachment, text=fix_broken_string(f.read(), as_unicode=True))
def testFixBrokenStrings(self): string_value = u"mettre à l'essai".encode("latin1") fixed_string = fix_broken_string(string_value) self.assertEqual(string_value.decode("latin1").encode("utf-8"), fixed_string)
def testFixBrokenStrings(self): string_value = u"mettre à l'essai".encode("latin1") fixed_string = fix_broken_string(string_value) self.assertEqual( string_value.decode("latin1").encode("utf-8"), fixed_string)