13
13
from django .utils .safestring import mark_safe
14
14
#from django.utils.html import conditional_escape
15
15
from oembed .models import ProviderRule , StoredOEmbed
16
+ from django .template .loader import render_to_string
16
17
17
18
conditional_escape = lambda x : x
18
19
21
22
MAX_HEIGHT = getattr (settings , "OEMBED_MAX_HEIGHT" , 240 )
22
23
FORMAT = getattr (settings , "OEMBED_FORMAT" , "json" )
23
24
24
- HTML_MAPPING = {
25
- 'photo' : 'url' ,
26
- 'video' : 'html' ,
27
- 'rich' : 'html' ,
28
- }
29
-
30
25
def fetch (url , user_agent = "django-oembed" ):
31
26
request = urllib2 .Request (url )
32
27
request .add_header ('User-Agent' , user_agent )
@@ -111,12 +106,10 @@ def replace(text, max_width=MAX_WIDTH, max_height=MAX_HEIGHT):
111
106
urls .add (part )
112
107
indices_rules .append (i )
113
108
parts .append (part )
114
- print part
115
109
index += 1
116
110
if to_append :
117
111
parts .append (to_append )
118
112
index += 1
119
- print urls
120
113
for stored_embed in StoredOEmbed .objects .filter (match__in = urls , max_width = max_width , max_height = max_height ):
121
114
stored [stored_embed .match ] = stored_embed
122
115
for i , id_to_replace in enumerate (indices ):
@@ -130,10 +123,7 @@ def replace(text, max_width=MAX_WIDTH, max_height=MAX_HEIGHT):
130
123
rule .endpoint , part , max_width , max_height , FORMAT
131
124
)
132
125
resp = simplejson .loads (fetch (url ))
133
- replacement = None
134
- for key in HTML_MAPPING .iterkeys ():
135
- if resp ['type' ] == key :
136
- replacement = resp [HTML_MAPPING [key ]]
126
+ replacement = render_to_string ('oembed/%s.html' % resp ['type' ], {'response' : resp })
137
127
if replacement :
138
128
stored_embed = StoredOEmbed .objects .create (
139
129
match = part ,
0 commit comments