class UserMetaResource(WigoResource): model = User @user_token_required @api.response(200, 'Success', model=api.model( 'UserMeta', { 'last_message_received': fields.DateTime(), 'last_friend_request': fields.DateTime(), 'last_notification': fields.DateTime(), 'is_tapped': fields.Boolean(), 'is_friend': fields.Boolean(), 'is_blocked': fields.Boolean(), 'attending_event_id': fields.Integer(), 'friend_request': fields.String(), 'num_friends_in_common': fields.Integer() })) def get(self, user_id): user_id = self.get_id(user_id) meta = {} if user_id == g.user.id: user_meta = wigo_db.get_redis().hgetall( skey('user', user_id, 'meta')) if user_meta: def format_date(field): return datetime.utcfromtimestamp(float( user_meta[field])).isoformat() if 'last_message_received' in user_meta: meta['last_message_received'] = format_date( 'last_message_received') if 'last_friend_request' in user_meta: meta['last_friend_request'] = format_date( 'last_friend_request') if 'last_notification' in user_meta: meta['last_notification'] = format_date( 'last_notification') meta['attending_event_id'] = g.user.get_attending_id() else: meta['is_tapped'] = g.user.is_tapped(user_id) meta['is_friend'] = g.user.is_friend(user_id) meta['is_blocked'] = g.user.is_blocked(user_id) if g.user.is_friend_request_sent(user_id): meta['friend_request'] = 'sent' elif g.user.is_friend_request_received(user_id): meta['friend_request'] = 'received' if request.args.get('num_friends_in_common') == 'true': meta['num_friends_in_common'] = len( g.user.get_friend_ids_in_common(user_id)) meta['num_friends'] = wigo_db.get_sorted_set_size( skey('user', user_id, 'friends')) return meta
def test_with_default(self): field = fields.DateTime(default='2014-08-25') self.assertEqual(field.__schema__, { 'type': 'string', 'format': 'date-time', 'default': '2014-08-25' })
def test_defaults(self): field = fields.DateTime() self.assertFalse(field.required) self.assertEqual(field.__schema__, { 'type': 'string', 'format': 'date-time' })
def test_datetime_field_with_title(self): field = fields.DateTime(title='A title') self.assertEqual(field.__schema__, { 'type': 'string', 'format': 'date-time', 'title': 'A title' })
def test_datetime_field_with_required(self): field = fields.DateTime(required=True) self.assertTrue(field.required) self.assertEqual(field.__schema__, { 'type': 'string', 'format': 'date-time' })
def test_datetime_field_with_description(self): field = fields.DateTime(description='A description') self.assertEqual( field.__schema__, { 'type': 'string', 'format': 'date-time', 'description': 'A description' })
def test_model_with_required(self): model = self.api.model( 'Person', { 'name': fields.String(required=True), 'age': fields.Integer, 'birthdate': fields.DateTime(required=True), }) self.assertEqual( model.__schema__, { 'properties': { 'name': { 'type': 'string' }, 'age': { 'type': 'integer' }, 'birthdate': { 'type': 'string', 'format': 'date-time' } }, 'required': ['birthdate', 'name'] })
fields.String(description='name of carshare operator', required=True), 'partner_id': fields.String(description='DB identifier with the carshare operator', required=True), 'name': fields.String(description='name of car (usually licence plate)', required=True), 'vin': fields.String(description='VIN number of the car (if available)', required=True), 'electric': fields.Boolean(description='True if car is recognized as an EV', required=True), 'until': fields.DateTime( description='time the vehicle is available until (if applicable)', required=True), 'fuel': fields.Integer( description= 'Percentage of fuel remaining in vehicle (null = unknown)') }) carshare_lots_field = api.model( 'CarshareLotsField', { 'company': fields.String(description='name of carshare operator', required=True), 'name': fields.String(description='name of car (usually licence plate)', required=True), 'capacity':
def test_max_exclusive(self): field = fields.DateTime(max='1984-06-07', exclusiveMax=True) self.assertIn('maximum', field.__schema__) self.assertEqual(field.__schema__['maximum'], '1984-06-07') self.assertIn('exclusiveMaximum', field.__schema__) self.assertEqual(field.__schema__['exclusiveMaximum'], True)
def test_max_as_datetime(self): field = fields.DateTime(max=datetime(1984, 6, 7, 1, 2, 0)) self.assertIn('maximum', field.__schema__) self.assertEqual(field.__schema__['maximum'], '1984-06-07T01:02:00') self.assertNotIn('exclusiveMaximum', field.__schema__)
def test_min_as_date(self): field = fields.DateTime(min=date(1984, 6, 7)) self.assertIn('minimum', field.__schema__) self.assertEqual(field.__schema__['minimum'], '1984-06-07') self.assertNotIn('exclusiveMinimum', field.__schema__)
app.register_blueprint(blueprint) ns = api.namespace('jobs', description='Job operations') # Fields that are expected and need to be exposed from a Job fields = api.model( 'Job', { 'id': fields.String(), 'name': fields.String(), 'task_class': fields.String(attribute=lambda x: x.func_ref.replace(':', '.').replace( '.execute', '')), 'next_run_time': fields.DateTime(dt_format='iso8601'), 'misfire_grace_time': fields.String(), 'coalesce': fields.Boolean(), 'trigger': fields.String(), 'args': fields.List(fields.String), 'start_date': fields.DateTime(attribute=lambda x: x.trigger.start_date, dt_format='iso8601'), 'end_date': fields.DateTime(attribute=lambda x: x.trigger.end_date, dt_format='iso8601'), 'timezone':
list_parser = api.parser() for arg in _filter_parser.args + _order_by_parser.args + _pagination_parser.args: list_parser.add_argument(arg) search_parser = api.parser() for arg in _filter_parser.args + _order_by_parser.args + _pagination_parser.args + _query_parser.args: search_parser.add_argument(arg) # Fields for ContratoAPI data marshal contratos_fields = { 'id': fields.Integer(description='O número identificador único de um contrato'), 'orgao': fields.String(description='Órgão'), 'data_assinatura': fields.DateTime(dt_format='iso8601'), 'vigencia': fields.Integer(), 'objeto': fields.String(description='Texto que aparece na descricao do contrato'), 'modalidade': fields.String(description='e.g. Pregão'), 'evento': fields.String(), 'processo_administrativo': fields.String(), 'cnpj': fields.String(), 'nome_fornecedor': fields.String(), 'valor':