コード例 #1
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()
コード例 #2
0
ファイル: admin.py プロジェクト: tobiashuste/indico
def create_area(bounds, name, default=False):
    top, bottom = bounds['north_east'], bounds['south_west']

    if default:
        MapArea.query.update({MapArea.is_default: False},
                             synchronize_session='fetch')

    new_area = MapArea()
    new_area.name = name
    new_area.is_default = default
    new_area.top_left_latitude = top['lat']
    new_area.top_left_longitude = top['lng']
    new_area.bottom_right_latitude = bottom['lat']
    new_area.bottom_right_longitude = bottom['lng']
    db.session.add(new_area)
    db.session.flush()
    return new_area
コード例 #3
0
ファイル: admin.py プロジェクト: tobiashuste/indico
def update_area(area_id, area_data):
    top = area_data['bounds']['north_east']
    bottom = area_data['bounds']['south_west']
    map_area = MapArea.get_one(area_id)
    if 'name' in area_data:
        map_area.name = area_data['name']
    if 'default' in area_data:
        if area_data['default']:
            MapArea.query.update({MapArea.is_default: False},
                                 synchronize_session='fetch')
        map_area.is_default = area_data['default']
    map_area.top_left_latitude = top['lat']
    map_area.top_left_longitude = top['lng']
    map_area.bottom_right_latitude = bottom['lat']
    map_area.bottom_right_longitude = bottom['lng']
    db.session.flush()