def update(self, instance: LtiConfiguration, validated_data: dict) -> LtiConfiguration: """ Create/update a model-backed instance """ instance = instance or LtiConfiguration() instance.config_store = LtiConfiguration.CONFIG_ON_DB if validated_data: for key, value in validated_data.items(): if key in self.Meta.fields: setattr(instance, key, value) instance.save() return instance
def update(self, instance: LtiConfiguration, validated_data: dict) -> LtiConfiguration: """ Create/update a model-backed instance """ instance = instance or LtiConfiguration() instance.config_store = LtiConfiguration.CONFIG_ON_DB pii_sharing_allowed = self.context.get('pii_sharing_allowed', False) if validated_data: for key, value in validated_data.items(): if key.startswith('pii_') and not pii_sharing_allowed: raise serializers.ValidationError( "Cannot enable sending PII data until PII sharing for LTI is enabled for the course." ) if key in self.Meta.fields: setattr(instance, key, value) instance.save() return instance
def create(self, validated_data): lti_config = validated_data.pop('lti_config', None) instance = LtiConfiguration() instance.version = 'lti_1p1' instance.config_store = LtiConfiguration.CONFIG_ON_DB for key, value in validated_data.items(): if key in set(self.Meta.fields).difference(self.Meta.read_only): setattr(instance, key, value) share_email, share_username = self.pii_sharing_allowed() instance.lti_config = { "pii_share_username": share_username, "pii_share_email": share_email, "additional_parameters": lti_config['additional_parameters'] } instance.save() return instance
def update(self, instance: LtiConfiguration, validated_data: dict) -> LtiConfiguration: """ Create/update a model-backed instance """ instance.config_store = LtiConfiguration.CONFIG_ON_DB lti_config = validated_data.pop('lti_config', None) if lti_config.get('additional_parameters', None): instance.lti_config['additional_parameters'] = lti_config.get('additional_parameters') if validated_data: for key, value in validated_data.items(): if key in self.Meta.fields: setattr(instance, key, value) share_email, share_username = self.pii_sharing_allowed() instance.pii_share_username = share_username instance.pii_share_email = share_email instance.save() return instance