<s> from __future__ import absolute_import , unicode_literals <EOL> import re <EOL> from django . db import models <EOL> from django . template . loader import render_to_string <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> class VideoContent ( models . Model ) : <EOL> """<STR_LIT>""" <EOL> PORTALS = ( <EOL> ( '<STR_LIT>' , re . compile ( r'<STR_LIT>' ) , lambda url : { <EOL> '<STR_LIT:v>' : re . search ( r'<STR_LIT>' , url ) . group ( <NUM_LIT:2> ) , <EOL> } ) , <EOL> ( '<STR_LIT>' , re . compile ( r'<STR_LIT>' ) , lambda url : { <EOL> '<STR_LIT:id>' : re . search ( r'<STR_LIT>' , url ) . group ( <NUM_LIT:1> ) , <EOL> } ) , <EOL> ( '<STR_LIT>' , re . compile ( r'<STR_LIT>' ) , lambda url : { <EOL> '<STR_LIT:id>' : re . search ( r'<STR_LIT>' , url ) . group ( <NUM_LIT:1> ) , <EOL> } ) , <EOL> ) <EOL> video = models . URLField ( <EOL> _ ( '<STR_LIT>' ) , <EOL> help_text = _ ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) ) <EOL> class Meta : <EOL> abstract = True <EOL> verbose_name = _ ( '<STR_LIT>' ) <EOL> verbose_name_plural = _ ( '<STR_LIT>' ) <EOL> def get_context_dict ( self ) : <EOL> "<STR_LIT>" <EOL> return { '<STR_LIT:content>' : self , '<STR_LIT>' : '<STR_LIT>' } <EOL> def get_templates ( self , portal = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> return [ <EOL> '<STR_LIT>' % portal , <EOL> '<STR_LIT>' , <EOL> ] <EOL> def ctx_for_video ( self , vurl ) : <EOL> "<STR_LIT>" <EOL> ctx = self . get_context_dict ( ) <EOL> for portal , match , context_fn in self . PORTALS : <EOL> if match . search ( vurl ) : <EOL> try : <EOL> ctx . update ( context_fn ( vurl ) ) <EOL> ctx [ '<STR_LIT>' ] = portal <EOL> break <EOL> except AttributeError : <EOL> continue <EOL> return ctx <EOL> def render ( self , ** kwargs ) : <EOL> context_instance = kwargs . get ( '<STR_LIT>' ) <EOL> ctx = self . ctx_for_video ( self . video ) <EOL> return render_to_string ( <EOL> self . get_templates ( ctx [ '<STR_LIT>' ] ) , <EOL> ctx , <EOL> context_instance = context_instance ) </s>
