<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . utils . html import format_html , format_html_join <EOL> from django . utils . encoding import force_text , python_2_unicode_compatible <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils import timezone <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> from django . core . exceptions import ValidationError <EOL> def flatatt ( attrs ) : <EOL> """<STR_LIT>""" <EOL> return format_html_join ( '<STR_LIT>' , '<STR_LIT>' , sorted ( attrs . items ( ) ) ) <EOL> @ python_2_unicode_compatible <EOL> class ErrorDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return self . as_ul ( ) <EOL> def as_ul ( self ) : <EOL> if not self : return '<STR_LIT>' <EOL> return format_html ( '<STR_LIT>' , <EOL> format_html_join ( '<STR_LIT>' , '<STR_LIT>' , <EOL> ( ( k , force_text ( v ) ) <EOL> for k , v in self . items ( ) ) <EOL> ) ) <EOL> def as_text ( self ) : <EOL> return '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % ( k , '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % force_text ( i ) for i in v ] ) ) for k , v in self . items ( ) ] ) <EOL> @ python_2_unicode_compatible <EOL> class ErrorList ( list ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return self . as_ul ( ) <EOL> def as_ul ( self ) : <EOL> if not self : return '<STR_LIT>' <EOL> return format_html ( '<STR_LIT>' , <EOL> format_html_join ( '<STR_LIT>' , '<STR_LIT>' , <EOL> ( ( force_text ( e ) , ) for e in self ) <EOL> ) <EOL> ) <EOL> def as_text ( self ) : <EOL> if not self : return '<STR_LIT>' <EOL> return '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % force_text ( e ) for e in self ] ) <EOL> def __repr__ ( self ) : <EOL> return repr ( [ force_text ( e ) for e in self ] ) <EOL> def from_current_timezone ( value ) : <EOL> """<STR_LIT>""" <EOL> if settings . USE_TZ and value is not None and timezone . is_naive ( value ) : <EOL> current_timezone = timezone . get_current_timezone ( ) <EOL> try : <EOL> return timezone . make_aware ( value , current_timezone ) <EOL> except Exception : <EOL> raise ValidationError ( _ ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> % { '<STR_LIT>' : value , <EOL> '<STR_LIT>' : current_timezone } ) <EOL> return value <EOL> def to_current_timezone ( value ) : <EOL> """<STR_LIT>""" <EOL> if settings . USE_TZ and value is not None and timezone . is_aware ( value ) : <EOL> current_timezone = timezone . get_current_timezone ( ) <EOL> return timezone . make_naive ( value , current_timezone ) <EOL> return value </s>
