#33525: decorator @html_safe removes completely old class.__str__ method.
-------------------------------------+-------------------------------------
               Reporter:  Maxim      |          Owner:  nobody
  Danilov                            |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  Utilities  |        Version:  4.0
               Severity:  Normal     |       Keywords:  html_string,
           Triage Stage:             |  SafeString
  Unreviewed                         |      Has patch:  1
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  1
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 I can not to get normal __str__ method from safe_string.

 Fro example:


 {{{
 @html_safe
 class TranslatableText(str):
     """Class like a string but returns values depends on get_language."""
 }}}

 After that str(TranslatableText) is always SafeString. If i want call old
 __str__ method it is not possible: html_safe destroy it in
 django\utils\html.py, rows 376-378
 {{{
     klass_str = klass.__str__
     klass.__str__ = lambda self: mark_safe(klass_str(self))
     klass.__html__ = lambda self: str(self)
     return klass
 }}}
 But it is easy to repair:
 {{{
     klass._old_str_method = klass.__str__
     klass.__str__ = lambda self: mark_safe(klass._old_str_method(self))
     klass.__html__ = lambda self: str(self)
     return klass
 }}}
 After that, not only can i get SafeString object, it is also possible to
 call klass._old_str_method and get BaseString object

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33525>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.6256c359a0205512065e4baf708e36b5%40djangoproject.com.

Reply via email to