Example #1
0
    def test_date_time_string_convert(self):
        with self.assertRaises(ValidationError):
            fields.DateTimeString().convert('01.01.2016')

        self.assertEqual(
            datetime(2009, 2, 13, 23, 16, 40, 0, timezone.utc),
            fields.DateTimeString().convert('2009-02-13T23:16:40Z'))
Example #2
0
 class Schema:
     uuid = fields.UUID()
     user = fields.Inline('user')
     host = fields.Inline('host')
     start = fields.DateTimeString()
     end = fields.DateTimeString()
     duration = fields.Custom('{"type": "integer"}',
                              io="r",
                              formatter=lambda x: x.total_seconds())
Example #3
0
 class Schema:
     roles = fields.ToMany('role')
     associate_group = fields.Inline('associate_group')
     associate_group_id = fields.String()
     last_login_at = fields.DateTimeString()
     current_login_at = fields.DateTimeString()
Example #4
0
INTERNATIONALIZED_ALPHANUMERIC_AND_DELIMITER_OR_EMPTY = (
    r'(^([A-zÀ-ÿ0-9]+[A-zÀ-ÿ0-9-_ ]*[A-zÀ-ÿ0-9]*))|(\s*)$')

HISTORY_CHANGE_FIELDS = {
    'user':
    fields.ItemUri('web.server.api.user_api_models.UserResource',
                   attribute='user_id'),
    'revisionId':
    fields.Integer(attribute='id',
                   description='The unique history identifier'),
    'objectUri':
    None,
    'changes':
    fields.Any(attribute='changes', description='History item changes'),
    'revisionDate':
    fields.DateTimeString(attribute='created',
                          description='History item created date'),
}


def generate_history_record_schema(uri_field, resource_name):
    updated_fields = HISTORY_CHANGE_FIELDS.copy()
    updated_fields['objectUri'] = uri_field
    return alchemy_fields.InlineModel(
        updated_fields,
        description='A history record for {resource_name}'.format(
            resource_name=resource_name),
        model=HistoryRecord,
    )


SHARE_ANALYSIS_EMAIL_SCHEMA = {
Example #5
0
 def test_date_time_string_format_default_utc(self):
     timestamp = datetime(2009, 2, 13, 23, 16, 40, 0)
     self.assertEqual('2009-02-13T23:16:40+00:00',
                      fields.DateTimeString().format(timestamp))
Example #6
0
 def test_date_time_string_format(self):
     timestamp = datetime(2009, 2, 13, 23, 16, 40, 0,
                          timezone(timedelta(hours=2)))
     self.assertEqual('2009-02-13T23:16:40+02:00',
                      fields.DateTimeString().format(timestamp))
Example #7
0
    fields.Email(pattern=EMAIL_PATTERN, nullable=True),
    description='The author\'s username. If not visible to the user, this will be null.',
    attribute='author_username',
    io='r',
)

AUTHOR_URI_SCHEMA = fields.ItemUri(
    'web.server.api.user_api_models.UserResource', attribute='author_id'
)

RESOURCE_URI_SCHEMA = fields.ItemUri(
    'web.server.api.permission_api_models.BackendResource', attribute='resource_id'
)

CREATED_SCHEMA = fields.DateTimeString(
    description='When the dashboard was created.', attribute='created', io='r'
)

LAST_MODIFIED_SCHEMA = fields.DateTimeString(
    description='The last time the dashboard was modified.',
    attribute='last_modified_real',
    io='r',
)

IS_OFFICIAL_SCHEMA = fields.Boolean(
    attribute='is_official',
    description='Indicates whether or not an administrator has flagged the '
    'dashboard as "official" or not.',
    io='r',
)
Example #8
0
 class Schema:
     timing = fields.DateTimeString()
     session = fields.ToOne('session')
 class Schema:
     id = fields.Integer(io='r')
     user = ToOneIntegerField(UserResource)
     task = ToOneIntegerField(TaskResource)
     timestamp = fields.DateTimeString(io='r')