Пример #1
0
 def from_json(json_post):
     content = json_post.get('body')
     if content is None or content == '':
         raise ValidationError('post does not have a body')
     return Post(content=content)
Пример #2
0
 def from_json(json_intersComment):
     body = json_intersComment.get('comment')
     if body is None or body == '':
         raise ValidationError('comment can not be empty')
     return IntersComment(body=body)
Пример #3
0
 def validate_timestamp(self):
     '''Valudate: time, make sure timestamp > now'''
     now = arrow.utcnow()
     if self.timestamp <= now:
         raise ValidationError(
             VALIDERROR_TEMPLATE["wrong_expect"] % ('timestamp', 'after now'))
Пример #4
0
 def from_json(json_post):
     body = json_post.get('body')
     if body is None or body == '':
         raise ValidationError('文章没有内容')
     return Post(body=body)
Пример #5
0
 def from_json(json_origins):
     body = json_origins.get('body')
     if body is None or body == '':
         raise ValidationError('文章没有内容哦!')
     return OriginsPost(body=body)
Пример #6
0
 def from_json(json_post):
     body = json_post.get("body")
     if body is None or body == "":
         raise ValidationError("post does not have a body")
     return Post(body=body)
Пример #7
0
 def from_json(json_post):
     body = json_post.get('body')
     if body is None or body == '':
         raise ValidationError('post does not have a body')
     return Post(body=body)
Пример #8
0
 def from_json(json_location):
     lon = json_location.get('longitude')
     lat = json_location.get('latitude')
     if (lon is None or lon == '') or (lat is None or lat == ''):
         raise ValidationError('location does not have lateral data')
     return Location(lon=lon, lat=lat)
Пример #9
0
 def from_json(json_post):
     body = json_post.get("body")
     if body is None or body == "":
         raise ValidationError("提交的文章为空")
     return Post(body=body)
Пример #10
0
 def from_json(blog_json):
     body = blog_json.get('body')
     if body is None or body == '':
         raise ValidationError('博客文章木有正文!')
     return Blog(body=body)
Пример #11
0
 def from_json(comment_json):
     body = comment_json.get('body')
     if body is None or body == '':
         raise ValidationError('木有评论!')
     return Comment(body=body)
Пример #12
0
 def from_json(json_comment):
     body = json_comment.get('body')
     if not body or body == '':
         raise ValidationError('没有内容')
     return Comment(body=body)
Пример #13
0
 def from_json(json_post):
     body = json_post.get('body')
     if not body or body == '':
         raise ValidationError('没有内容')
     return Post(body=body)
Пример #14
0
def get_alternative_destinations():
    """Validates query parameters and assembles output."""

    # print(request.args)
    # ImmutableMultiDict([('iata_code', 'LHR'), 
    #                     ('date', '2019-01-15'), 
    #                     ('min_temperature_celsius', '5'), 
    #                     ('max_temperature_celsius', '20'), 
    #                     ('max_precipitation_mm', '0')]) # max *average* daily rainfall

    try:
        iata_code = request.args.get('iata_code')
        assert iata_code is not None
        assert len(iata_code) == 3
        assert iata_code == iata_code.upper()
        date = datetime.strptime(request.args.get('date'), '%Y-%m-%d')
        min_temperature_celsius = float(request.args.get('min_temperature_celsius'))
        assert min_temperature_celsius >= -50
        assert min_temperature_celsius <= 50
        max_temperature_celsius = float(request.args.get('max_temperature_celsius'))
        assert max_temperature_celsius >= -50
        assert max_temperature_celsius <= 50
        assert min_temperature_celsius <= max_temperature_celsius
        max_precipitation_mm = float(request.args.get('max_precipitation_mm'))
        assert max_precipitation_mm >= 0
        # avg. daily rainfall normally between 1 and 4
        assert max_precipitation_mm <= 10 
    except Exception as e:
        #print(e)
        raise ValidationError('Invalid input')

    defaults = default_destinations(iata_code)

    dests = []
    dests.append(Destination.query.filter_by(iata_code=defaults[0]).first())
    dests.append(Destination.query.filter_by(iata_code=defaults[1]).first())
    dests.append(Destination.query.filter_by(iata_code=defaults[2]).first())

    # query in "strict mode"
    query_weather_strict =  Weather.query.filter(
        Weather.month == MONTH_NAMES[date.month],
        Weather.iata_code != iata_code,
        Weather.min_temperature_celsius >= min_temperature_celsius,
        Weather.max_temperature_celsius <= max_temperature_celsius,
        Weather.daily_precipitation_mm  <= max_precipitation_mm).order_by(
            desc(Weather.min_temperature_celsius))
    # print(query_weather_strict)

    result_strict = query_weather_strict.all()
    # print('Strict search found ' + str(len(result_strict)) + ' destinations.')
    # print(result_strict)

    # query in "fuzzy mode" with tolerances
    query_weather_fuzzy =  Weather.query.filter(
        Weather.month == MONTH_NAMES[date.month],
        Weather.iata_code != iata_code,
        Weather.min_temperature_celsius >= min_temperature_celsius - 5,
        Weather.max_temperature_celsius <= max_temperature_celsius + 5,
        Weather.daily_precipitation_mm  <= max_precipitation_mm + 3).order_by(
            desc(Weather.min_temperature_celsius))

    result_fuzzy = query_weather_fuzzy.all()
    # print('Fuzzy search found ' + str(len(result_fuzzy)) + ' destinations.')
    # print(result_fuzzy)

    # print(type(result_fuzzy))
    # <class 'list'>

    # append unordered result of fuzzy search to ordered result of strict search
    # only append elements that are not part of the strict search result

    result = result_strict + list(set(result_fuzzy) - set(result_strict))
    # print('Found ' + str(len(result)) + ' destinations. (Results strict search first.)')
    # print(result)

    # overwrite default destinations with search result
    for index, weather in enumerate(result):
        if index > 2:
            break
        dests[index] = Destination.query.filter_by(iata_code=weather.iata_code).first()

    line_1 = '{"alternative_destinations":\n'
    line_2 = '  [\n'
    line_3 = '    {"iata_code": "%s", "city": "%s"},\n' % (dests[0].iata_code, dests[0].city)
    line_4 = '    {"iata_code": "%s", "city": "%s"},\n' % (dests[1].iata_code, dests[1].city)
    line_5 = '    {"iata_code": "%s", "city": "%s"}\n'  % (dests[2].iata_code, dests[2].city)
    line_6 = '  ]\n'
    line_7 = '}\n'

    response_string = line_1 + line_2 + line_3 + line_4 + line_5 + line_6 + line_7
    response = make_response(response_string)
    response.mimetype = 'application/json'
    return response
Пример #15
0
 def from_json(json_post):
     content = json_post.get('content')
     if content is None or content == '':
         raise ValidationError('post does not have any content')
     return Post(content=content, user_id=id)
Пример #16
0
 def from_json(json_comment):
     body = json_comment.get("body")
     if body is None or body == "":
         raise ValidationError("评论不能为空")
     return Comment(body=body)
Пример #17
0
 def from_json(json_question):
     body = json_question.get('body')
     if body is None or body == '':
         raise ValidationError('question does not have a body')
     return Question(body=body)
Пример #18
0
 def from_json(json_tipo_usuario):
     descricao = json_tipo_usuario.get('descricao')
     if descricao is None or descricao == '':
         raise ValidationError('tipo de usuario nao tem uma descricao')
     return Tipo_Usuario(descricao=descricao)
Пример #19
0
 def from_json(json_post):  #JSON格式转化成模型实例
     mounts = json_post.get('mounts')
     if mounts is None or mounts == '':
         raise ValidationError(u'请确定数量')
     return Order(mounts=mounts)
Пример #20
0
 def from_json(json_post):
     title = json_post.get('title')
     body = json_post.get('body')
     if body is None or body == '':
         raise ValidationError('post does not have a body')
     return Todo(title, body)
Пример #21
0
 def from_json(json_post: dict):
     body = json_post.get('body')
     if body is None or body == '':
         return ValidationError("post does not have a body")
     return Post(body=body)
Пример #22
0
 def from_json(json_post):
     name = json_post.get('name')
     if name is None or name == '':
         raise ValidationError('Operation does not have a name')
     return Operation(name=name)
Пример #23
0
 def from_json(json_comment):
     body = json_comment.get('body')
     if body is None or body == '':
         raise ValidationError('评论没有内容')
     return Comment(body=body)
Пример #24
0
 def from_json(json_post):
     name = json_post.get('name')
     if name is None or body == '':
         raise ValidationError('workflow does not have a name')
     return Workflow(name=name)
Пример #25
0
 def from_json(json_inters):
     body = json_inters.get('body')
     if body is None or body == '':
         raise ValidationError('文章没有内容哦!')
     return IntersPost(body=body)
Пример #26
0
 def from_json(json_post):
     name = json_post.get('name')
     if name is None or name == '':
         raise ValidationError('WorkItem does not have a name')
     return WorkItem(name=name)
Пример #27
0
 def from_json(json_comment):
     body = json_comment.get('body')
     if body is None or body == '':
         raise ValidationError('comment does not have a body')
     return Comment(body=body)
Пример #28
0
 def import_data(self, data):
     try:
         self.name = data['name']
     except KeyError as e:
         raise ValidationError("Invalid Information: missing " + e.args[0])
Пример #29
0
 def from_json(json_data):
     body = json_data.get('body')
     if not body:
         raise ValidationError('post does not have a body', 400)
     return Post(body=body)
Пример #30
0
 def from_json(json_like):
     user_id = json_like.get('userID')
     if user_id is None or user_id == '':
         raise ValidationError('Like does not have information')
     like = Like(user_id=user_id)
     return like