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()
     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']
Esempio n. 3
0
    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