Skip to content
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

Fixed #25135 -- Deprecated the contrib.admin allow_tags attribute #5215

Closed

Conversation

olasitarska
Copy link
Contributor

This fixes the problems with #5024 PR, hopefully :)

if getattr(attr, "allow_tags", False):
warnings.warn(
"The allow_tags attribute is deprecated. Return a SafeString instance by "
"using format_html, format_html_join or mark_safe instead.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format_html(), format_html_join(), or mark_safe()

@timgraham
Copy link
Member

It would be nice to retain a test to ensure allow_tags still works through the deprecation cycle.

@olasitarska
Copy link
Contributor Author

I fixed all of the things mentioned by you. Let me know if there is anything that can be improved. Thanks a lot!

(Wow, admin tests are not fun! 💀 )

@olasitarska olasitarska force-pushed the 25135-allow-tags-in-admin branch 2 times, most recently from c10f441 to bafd016 Compare August 31, 2015 20:36
@olasitarska
Copy link
Contributor Author

@timgraham any ideas what's broken in this build? I can't find anything useful in details of it.

@timgraham
Copy link
Member

It's nothing to worry about, see https://code.djangoproject.com/wiki/Jenkins#Troubleshooting.

@olasitarska
Copy link
Contributor Author

Cool! Thanks Tim! Should I close and reopen this PR to trigger a new build? ;)

@timgraham
Copy link
Member

One failure in the matrix doesn't matter for review purposes.

@olasitarska
Copy link
Contributor Author

👍

@@ -201,18 +203,19 @@ def link_in_col(is_first, field_name, cl):
except ObjectDoesNotExist:
result_repr = empty_value_display
else:
empty_value_display = getattr(attr, 'empty_value_display', empty_value_display)
empty_value_display = mark_safe(getattr(attr, 'empty_value_display', empty_value_display))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason why we should assume empty_value_display is safe. Patch to fix this and some other edits: http://dpaste.com/2TETT95
Does the new allow_tags test cover django/contrib/admin/helpers.py too? I don't think so as I think it's only part of the change form page (not change list).

@olasitarska
Copy link
Contributor Author

Applied your patch, thanks!

I'm gonna see how I can test it in helpers.py too, can't find a place for it yet. Will try tomorrow morning, it's late here now! 🌔

@timgraham
Copy link
Member

Probably admin_views is the place for the test. Put a method with allow_tags=True in readonly_fields and then fetch the change form view with the test client.

@olasitarska
Copy link
Contributor Author

Not sure how to make isort happy.. I've run isort tests/admin_views/tests.py and isort tests/admin_views/test_adminsite.py and isort tests/admin_views/admin.py, it sorted some things, but still doesn't pass :(

@olasitarska
Copy link
Contributor Author

Not sure I actually know what I'm doing, but isort passes now too ;)

@timgraham any ideas why my local isort wants to sort differently than the check here? Not an issue now, but would be awesome if I could fix my local setup for the future :)

@@ -429,7 +430,8 @@ class PostAdmin(admin.ModelAdmin):
list_display = ['title', 'public']
readonly_fields = (
'posted', 'awesomeness_level', 'coolness', 'value',
'multiline', 'multiline_html', lambda obj: "foo"
'multiline', 'multiline_html', 'multiline_html_allow_tags',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of sorting these, I'd just put 'multiline_html_allow_tags' on the next newline so that we don't need to modify more than one line when removing the deprecated feature

@timgraham
Copy link
Member

Looks good. Could you please squash commits when making those updates?

@olasitarska
Copy link
Contributor Author

Done, and squashed! :) 🎾

@timgraham
Copy link
Member

merged in f2f8972, thanks!

@timgraham timgraham closed this Sep 8, 2015
@olasitarska
Copy link
Contributor Author

Thanks for help @timgraham! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants