def get_schema(cls, app_context, log, source_context): clazz = cls.get_entity_class() if source_context.send_uncensored_pii_data: registry = entity_transforms.get_schema_for_entity_unsafe(clazz) else: registry = entity_transforms.get_schema_for_entity(clazz) return registry.get_json_schema_dict()['properties']
def get_schema(cls, app_context, log, source_context): clazz = cls.get_entity_class() registry = entity_transforms.get_schema_for_entity(clazz) # User ID is not directly available in the submission; it's encoded # in a Key, which needs to be unpacked. registry.add_property( schema_fields.SchemaField('user_id', 'User ID', 'string')) ret = registry.get_json_schema_dict()['properties'] del ret['reviewee_key'] return ret
def get_schema(cls, app_context, log, source_context): clazz = cls.get_entity_class() registry = entity_transforms.get_schema_for_entity(clazz) # User ID is not directly available in the submission; it's encoded # in a Key, which needs to be unpacked. registry.add_property(schema_fields.SchemaField( 'user_id', 'User ID', 'string')) ret = registry.get_json_schema_dict()['properties'] del ret['reviewee_key'] return ret
def test_class_schema(self): registry = entity_transforms.get_schema_for_entity(TestEntity) schema = registry.get_json_schema_dict() self.assertEquals(schema['type'], 'object') self.assertEquals(schema['id'], 'TestEntity') props = schema['properties'] self.assertTrue(props['prop_int']['optional']) self.assertEquals(props['prop_int']['type'], 'integer') self.assertNotIn('optional', props['prop_float']) self.assertEquals(props['prop_float']['type'], 'number') self.assertTrue(props['prop_bool']['optional']) self.assertEquals(props['prop_bool']['type'], 'boolean') self.assertTrue(props['prop_string']['optional']) self.assertEquals(props['prop_string']['type'], 'string') self.assertTrue(props['prop_text']['optional']) self.assertEquals(props['prop_text']['type'], 'text') self.assertTrue(props['prop_date']['optional']) self.assertEquals(props['prop_date']['type'], 'date') self.assertTrue(props['prop_datetime']['optional']) self.assertEquals(props['prop_datetime']['type'], 'datetime') self.assertEquals(props['prop_intlist']['type'], 'array') self.assertTrue(props['prop_intlist']['items']['optional']) self.assertEquals(props['prop_intlist']['items']['type'], 'integer') self.assertEquals(props['prop_stringlist']['type'], 'array') self.assertTrue(props['prop_stringlist']['items']['optional']) self.assertEquals(props['prop_stringlist']['items']['type'], 'string') self.assertTrue(props['prop_ref']['optional']) self.assertEquals(props['prop_ref']['type'], 'string')
def test_class_schema(self): registry = entity_transforms.get_schema_for_entity(TestEntity) schema = registry.get_json_schema_dict() self.assertEquals(schema["type"], "object") self.assertEquals(schema["id"], "TestEntity") props = schema["properties"] self.assertTrue(props["prop_int"]["optional"]) self.assertEquals(props["prop_int"]["type"], "integer") self.assertNotIn("optional", props["prop_float"]) self.assertEquals(props["prop_float"]["type"], "number") self.assertTrue(props["prop_bool"]["optional"]) self.assertEquals(props["prop_bool"]["type"], "boolean") self.assertTrue(props["prop_string"]["optional"]) self.assertEquals(props["prop_string"]["type"], "string") self.assertTrue(props["prop_text"]["optional"]) self.assertEquals(props["prop_text"]["type"], "text") self.assertTrue(props["prop_date"]["optional"]) self.assertEquals(props["prop_date"]["type"], "date") self.assertTrue(props["prop_datetime"]["optional"]) self.assertEquals(props["prop_datetime"]["type"], "datetime") self.assertEquals(props["prop_intlist"]["type"], "array") self.assertTrue(props["prop_intlist"]["items"]["optional"]) self.assertEquals(props["prop_intlist"]["items"]["type"], "integer") self.assertEquals(props["prop_stringlist"]["type"], "array") self.assertTrue(props["prop_stringlist"]["items"]["optional"]) self.assertEquals(props["prop_stringlist"]["items"]["type"], "string") self.assertTrue(props["prop_ref"]["optional"]) self.assertEquals(props["prop_ref"]["type"], "string")
def get_schema(cls, app_context, log, source_context): """Override default entity-based schema to reflect our upgrades. In the entity, labels are stored as a single string property, rather than an arraylist of string or integer for backward compatibility. Current (2014-12-05) usage is that the 'labels' property is a stringified representation of a list of IDs to LabelEntity. On export, we convert the string to an array of string to permit easier correlation from student labels to exported LabelEntity items. We provide external references to labels in preference to simply resolving the labels, because of potential data bloat (minor) and to avoid any future complications due to expansion of the role of labels (as was seen when labels-as-language-indicator was added). Args: app_context: Standard CB application context object log: a catch_and_log object for reporting any exceptions. Not used here, but useful for data source types that are dynamically generated, rather than statically coded. Returns: A JSON schema describing contents. A dict as produced by FieldRegistry.get_json_schema_dict(). """ clazz = cls.get_entity_class() if source_context.send_uncensored_pii_data: registry = entity_transforms.get_schema_for_entity_unsafe(clazz) registry.add_property(schema_fields.SchemaField( 'email', 'Email', 'string', optional=True, description='Email address for this Student.')) else: registry = entity_transforms.get_schema_for_entity(clazz) ret = registry.get_json_schema_dict()['properties'] # Scores are deprecated now that regularized scores are available # in StudentAggregation data source. if 'scores' in ret: del ret['scores'] # We are replacing the labels string with a version that shows # labels as separate items so that the amount of insanity # required in BigQuery SQL is minimized. ret['labels'] = schema_fields.FieldArray( 'labels', 'Labels', description='Labels on students', item_type=schema_fields.SchemaField( 'label', 'Label', 'string', description='ID of a LabelEntity applied to a student') ).get_json_schema_dict() # If a course owner has allowed some or all portions of # 'additional_fields', convert from a flat string into an array # of name/value pairs if 'additional_fields' in ret: additional_field = schema_fields.FieldRegistry('additional_field') additional_field.add_property(schema_fields.SchemaField( 'name', 'Name', 'string', description='HTML form field name. Not necessarily unique.')) additional_field.add_property(schema_fields.SchemaField( 'value', 'Value', 'string', description='HTML form field value.')) ret['additional_fields'] = schema_fields.FieldArray( 'additional_fields', 'Additional Fields', item_type=additional_field, description='List of name/value pairs entered on the ' 'course registration form. Note that for names are not ' 'necessarily unique. E.g., a group of checkboxes for ' '"select all reasons you are taking this course" may well ' 'all have the same name.').get_json_schema_dict() return ret