Esempio n. 1
0
 def _process_POST(self, name, room_name_format, map_url_template):
     loc = Location(name=name,
                    room_name_format=room_name_format,
                    map_url_template=(map_url_template or ''))
     db.session.add(loc)
     db.session.flush()
     return self._jsonify_one(loc), 201
Esempio n. 2
0
def get_location(building):
    location = Location.query.filter(Location.name == "Area {}".format(building), ~Location.is_deleted).first()
    if not location:
        location = Location(name="Area {}".format(building))
        print(cformat("%{green!}+%{reset} Adding new location for building {}").format(building))
        db.session.add(location)
        db.session.flush()
    return location
Esempio n. 3
0
    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()
Esempio n. 4
0
def populate_db():
    """Populate DB with fun stuff"""

    # set tileserver URL
    rb_settings.set(
        'tileserver_url',
        'https://indico-maps.web.cern.ch/styles/cern/{z}/{x}/{y}.png')

    location = Location(name="CERN")
    owner = User.get(0)

    for area in MAP_AREAS:
        map_area = MapArea(name=area[0],
                           top_left_latitude=area[1],
                           top_left_longitude=area[2],
                           bottom_right_latitude=area[3],
                           bottom_right_longitude=area[4])
        db.session.add(map_area)

    for name in shower_names:
        # split name in parts
        building, floor, number = ROOM_RE.match(name).groups()
        # random number of showers, since we don't have time
        # to figure out what it really is
        num_showers = random.choice([2, 3, 4])
        file_name = './photos/{}.png'.format(name.replace('/', '_'))
        photo_data = None

        # Check if there's a photo in './photos/xxxx' and use it
        if os.path.exists(file_name):
            with open(file_name, 'r') as f:
                photo_data = f.read()
        else:
            print cformat("%{yellow}!%{reset} Photo for {} not found!").format(
                name)

        for num_shower in range(num_showers):
            room = Room(building=building,
                        floor=floor,
                        number=number,
                        verbose_name="Shower {}".format(num_shower + 1),
                        location=location,
                        division='CERN',
                        owner=owner,
                        capacity=1)
            if photo_data:
                room.photo = Photo(data=photo_data)
            if building in GEO_INFO:
                room.latitude, room.longitude = GEO_INFO[building]
            db.session.add(room)

    db.session.commit()
Esempio n. 5
0
 def _create_location(name, **params):
     location = Location(name=name, **params)
     db.session.add(location)
     db.session.flush()
     return location
Esempio n. 6
0
 def _process(self):
     is_default = Location.find().count() == 0
     db.session.add(Location(name=self._locationName,
                             is_default=is_default))
     flash(_(u'Location added'), 'success')
     return redirect(url_for('rooms_admin.roomBooking-admin'))
Esempio n. 7
0
 def _process(self):
     is_default = Location.find().count() == 0
     db.session.add(Location(name=self._locationName, is_default=is_default))
     flash(_(u'Location added'), 'success')
     self._redirect(urlHandlers.UHRoomBookingAdmin.getURL())