#NEWLINE# @ register . simple_tag #NEWLINE# def media( filename , flags = '' ) : #NEWLINE# #INDENT# '\n     Autor: http://softwaremaniacs.org/blog/2009/03/22/media-tag/\n    \n    {% load media %}\n    <link rel="stylesheet" href="{% media "css/style.css" %}">\n    \n    {% media "css/style.css" %}                <!-- ...style.css?123456789 -->\n    {% media "css/style.css" "no-timestamp" %} <!-- ...style.css -->\n    {% media "images/edit.png" "timestamp" %}  <!-- ...edit.png?123456789 -->\n    {% media "images/edit.png" "absolute" %} <!-- http://example.com/media/edit.png -->\n    ' #NEWLINE# flags = set ( ( f . strip ( ) for f in flags . split ( ',' ) ) ) #NEWLINE# url = urlparse . urljoin ( settings . MEDIA_URL , filename ) #NEWLINE# if ( 'absolute' in flags ) : #NEWLINE# #INDENT# url = _absolute_url ( url ) #NEWLINE# #UNINDENT# if ( ( ( filename . endswith ( '.css' ) or filename . endswith ( '.js' ) ) and ( 'no-timestamp' not in flags ) ) or ( 'timestamp' in flags ) ) : #NEWLINE# #INDENT# fullname = os . path . join ( settings . MEDIA_ROOT , filename ) #NEWLINE# if os . path . exists ( fullname ) : #NEWLINE# #INDENT# url += ( '?%d' % os . path . getmtime ( fullname ) ) #NEWLINE# #UNINDENT# #UNINDENT# return url