コード例 #1
0
def get_station_states():
    qs = Station.select(Station.attributes['State'].alias('state')).where(Station.attributes['State'] != 'None')\
        .order_by(Station.attributes['State']).distinct()
    choices = [
        ('none', 'Please select'),
    ]
    for station in qs:
        choices.append((station.state, station.state))

    return choices
コード例 #2
0
    def get(self, state):

        weather = get_previous_selections()
        stations = []
        queryset = Station.select().where(Station.attributes['State'] == state)
        for station in queryset:
            if station.attributes.get('Name'):
                stations.append({
                    "code": station.WBAN,
                    "name": station.attributes['Name']
                })
        return jsonify(select_option=weather['station'], stations=stations)
コード例 #3
0
def validate_station(form, field):
    field.errors = []
    wbans = []
    queryset = Station.select(Station.WBAN)
    for station in queryset:
        wbans.append(station.WBAN)
    if field.data == 'all':
        pass  # valid selection
    else:
        field_as_int = int(field.data)
        if field_as_int in wbans:
            pass  # valid selection
        else:
            raise ValidationError('Please make a valid selection.')
コード例 #4
0
ファイル: api.py プロジェクト: winrenth/unicorn_server
    def on_get(self, req, resp, name=None):
        try:
            if not name:
                result = list(Station.select().dicts())
            else:
                result = model_to_dict(Station.get(name=name))
        except Exception as ex:
            self.logger.error(ex)
            print ex
            description = ('Aliens have attacked our base! We will '
                           'be back as soon as we fight them off. '
                           'We appreciate your patience.')

            raise falcon.HTTPServiceUnavailable('Service Outage', description,
                                                30)

        resp.context['result'] = result
        resp.status = falcon.HTTP_200