-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #2956: Images in explorations have descriptive alt attributes #2972
Conversation
@kirankonduru, please remove code in this PR that's related to the other one. The file diff should only reflect changes that are being made to the specific issue that's being fixed. Remember to base your branch off of develop at the outset, and not your other feature branch. When you've done that, please assign this issue to @anthkris for review. Thanks! |
…nto desc-altimg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can see, this looks great! The UX is on par with other areas of the editor where you cannot save your changes until you fill in the required information.
Hey @kirankonduru Please take a look at the failing checks. Take a look at this resource: https://github.com/oppia/oppia/wiki/If-your-build-fails... |
@anthkris the test fails because a default value is needed in the description field (alt field) if we want to make it a required field. What do you suggest as the default value for this field? |
@kirankonduru I'd suggest making the UI similar to the publish window. The default text should offer an exemplar. Perhaps something like "George Frideric Handel, 18th century baroque composer" or something relatively universal. It may also be helpful to add a bit to the label for the field, the "Alternative text (for screen readers)" part to say "Alternative text (for screen readers): Describe the contents of this image" @seanlip Any thoughts? |
Hi @anthkris, no thoughts on my end -- I defer to you and @jaredsilver on this. |
While we may understand what alt text and screen readers are, I have a feeling that most teachers and other exploration creators may not. Therefore, it may make sense to tell the user why instead of what. For example, the label might say "Briefly explain this image to a visually impaired learner." And then, the placeholder could offer an exemplar as @anthkris mentioned. As an exploration creator, this may lead me to write a better and more descriptive alternative text because now I know the importance of why I'm doing it, and I also have a good example of what it should look like. What do you think about that approach, @anthkris? |
Thanks @jaredsilver That's exactly what I was thinking! I think people have a vague notion of what the alt attribute is but not how to write a good one or why it's really important. I like this approach! @kirankonduru Please let me know if you have any other questions or concerns. |
Here is the modified image upload section Now the alt field must have a string with length greater than zero if we want to make that field required. In the current schemas all the fields that are required (for example in the insert tabs section) the input fields have some descriptive text by default. |
I think that it may be better to remove the first part of the label, "Alternative text (for screen readers)" and just stick with the why explanation (the second part). As for the example, it's considered bad practice to write "image of" or "picture of" in the alt text. It's redundant. |
So any other suggestions for default text in the alt field? |
I can understand the problem; it's difficult to come up with something universal, but we do want it to fit the guidelines for a good alt description. So we don't want them to think that they can simply complete the phrase "Image of..." |
In the current schemas whenever we make a field required we need to provide a default value. The forms are generic and are used in insert tabs and others too. We need to modify the current schemas if we want to allow the default value to be an empty string and in that case we can force the user to fill in the data. |
Note that, if there's confirmation that the right thing to do here (from a user perspective) is to have a default value that is the empty string, then it should be possible to remove the general requirement that the default value must be nonempty for required fields. @kirankonduru -- what other fields make use of this requirement? Just want to make sure that this infrastructural change doesn't break anything. |
All these files have the same condition that is needed to make a field required and whenever we have an empty string as a defualt value the tests fail. |
OK. If that's a comprehensive list of the affected fields, I am fine with removing that restriction. |
|
schema_utils.py
Outdated
@@ -236,8 +236,10 @@ def has_length_at_most(obj, max_value): | |||
|
|||
@staticmethod | |||
def is_nonempty(obj): | |||
"""Returns True iff the given object (a string) is nonempty.""" | |||
return bool(obj) | |||
"""Always returns True so that an input field can be made required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't the correct place to do this. It results in the method not saying what it does on the tin, and that's a programming antipattern.
Where exactly is the default value being tested? We need to modify that test somehow, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function checks for the default value and for the new implementation we need the function to return true even for strings of zero length right?
The test fails here in line 170 of schema_utils_test.py if we don't provide a default.
assert set(ui_config.keys()) <= set(reference_dict.keys())
The is_nonempty method returns a null value and give an assertion error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the function should return True if it's nonempty and False otherwise. We need to preserve the behaviour in order to ensure that user-submitted values are valid.
I don't think the line you're pointing to is the right one -- that just checks the keys, and doesn't apply any validators. Is it schema_utils.normalize_against_schema() that's the issue here? As part of the function, validation is applied.
If so, my question is: what is the code that's responsible for passing the image UI config to be validated here? Can you post the full traceback of the error?
schema_utils.py
Outdated
@@ -236,8 +236,10 @@ def has_length_at_most(obj, max_value): | |||
|
|||
@staticmethod | |||
def is_nonempty(obj): | |||
"""Returns True iff the given object (a string) is nonempty.""" | |||
return bool(obj) | |||
"""Always returns True so that an input field can be made required |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the function should return True if it's nonempty and False otherwise. We need to preserve the behaviour in order to ensure that user-submitted values are valid.
I don't think the line you're pointing to is the right one -- that just checks the keys, and doesn't apply any validators. Is it schema_utils.normalize_against_schema() that's the issue here? As part of the function, validation is applied.
If so, my question is: what is the code that's responsible for passing the image UI config to be validated here? Can you post the full traceback of the error?
This is the traceback Traceback (most recent call last): Sorry the mistake was on my part. In a hurry I modified the wrong part and hence was getting the wrong traceback. |
OK, here's what to do:
Note that this preserves the conceptual clarity, which is important when writing code. Things need to do what they say on the tin, otherwise developers will have trouble figuring out what's going on and modifying existing code safely. @anthkris -- to confirm, we do want the default value for that text box to be empty, right? (I personally don't know the best thing to do here from a UI/UX perspective, so I'd defer to you here.) |
@seanlip It would be ideal to have an exemplar there, as we do in the publish modal. However, there may be some difficulty in creating something universal enough that everyone looking at it could understand. So, in this case, empty string may be the best case scenario |
…eld" This reverts commit 91dbba6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @kirankonduru! Couple of things, and I also had a question for @anthkris.
schema_utils.py
Outdated
@@ -237,7 +239,7 @@ def has_length_at_most(obj, max_value): | |||
@staticmethod | |||
def is_nonempty(obj): | |||
"""Returns True iff the given object (a string) is nonempty.""" | |||
return bool(obj) | |||
return obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please return this to how it was before you touched it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
}], | ||
'ui_config': { | ||
'placeholder': ( | ||
'Description of Image (Example : "George Frideric, ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anthkris could you please check if you're happy with this (punctuation, spacing, capitalization, etc.)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kirankonduru I really like what you did with the descriptive text! I think that makes the example very clear. The only nit I would mention is that the composer's name is George Frideric Handel, so just add Handel to the end of his name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kirankonduru Been mulling it over all day, and I'd also recommend removing the quotation marks from around the example. They may give the wrong impression that the description should be in quotes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anthkris I removed the Handel from George Frideric Handel because that was overflowing the input field
Can we remove Description of image and just keep this part
Example : George Frideric Handel, 18th century baroque composer
schema_utils_test.validate_schema(ca_spec['schema']) | ||
self.assertEqual( | ||
ca_spec['default_value'], | ||
schema_utils.normalize_against_schema( | ||
ca_spec['default_value'], ca_spec['schema'])) | ||
ca_spec['default_value'], ca_spec['schema'], False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When passing in args that have default values, include the name of the arg. I.e. apply_custom_validators=False
rather than just False
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -17,6 +17,7 @@ | |||
from extensions.rich_text_components import base | |||
|
|||
|
|||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop extra newline. Classes should have exactly 2 blank lines above them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -59,11 +59,14 @@ def _validate_customization_arg_specs(self, customization_arg_specs): | |||
self.assertTrue(isinstance(ca_spec['description'], basestring)) | |||
self.assertGreater(len(ca_spec['description']), 0) | |||
|
|||
#Image component has a required field whose default value is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add space after each '#'.
Also, I think the docstring is slightly incorrect (the default value is empty, not non-empty). Here's a rewrite to try and convey its meaning better:
The default value might not pass validation checks (e.g. the Image component has a required field whose default value is empty). Thus, when checking the default value schema, we don't apply the custom validators.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Code LGTM, apart from the question I had for @anthkris. Thanks @kirankonduru! |
I'd say, in this case, those extra words may be helpful to a user who has
no idea of what the alt attribute should do.
I'd suggest removing the middle name, Frideric.
On Wed, Feb 1, 2017 at 6:27 AM Kiran Konduru ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In extensions/rich_text_components/Image/Image.py
<#2972>:
> 'schema': {
'type': 'unicode',
+ 'validators': [{
+ 'id': 'is_nonempty',
+ }],
+ 'ui_config': {
+ 'placeholder': (
+ 'Description of Image (Example : "George Frideric, '
@anthkris <https://github.com/anthkris> I removed the Handel from George
Frideric Handel because that was overflowing the input field
[image: screenshot from 2017-02-01 17 53 35]
<https://cloud.githubusercontent.com/assets/13452436/22506642/9883f12e-e8a7-11e6-8fa6-c52bbbc50232.png>
Can we remove Description of image and just keep this part
Example : George Frideric Handel, 18th century baroque composer
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2972>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AKWwLrY44Il0w9sD0saQpIbbmG0Z9BVpks5rYHokgaJpZM4Lt41->
.
--
K. Anthony
Instructional Designer
knanthony.com
|
@kirankonduru @seanlip LGTM! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Fixes #2956 : Whenever images are uploaded in explorations the creator needs to specify the alt field which is a required field now.