Amazon images local
parent
f1869c6775
commit
b75f454404
|
@ -190,7 +190,7 @@
|
||||||
</div>
|
</div>
|
||||||
<script id="amazon-ad" type="text/html">
|
<script id="amazon-ad" type="text/html">
|
||||||
<li>
|
<li>
|
||||||
<a href="<%=url %>" style="background-image: url('<%=image %>');">
|
<a href="<%=url %>" style="background-image: url('/api/public/a/img/?i=<%=image %>');">
|
||||||
<span class="title"><%=title %></span>
|
<span class="title"><%=title %></span>
|
||||||
<span class="description"><%=review %></span>
|
<span class="description"><%=review %></span>
|
||||||
</a>
|
</a>
|
||||||
|
|
3
urls.py
3
urls.py
|
@ -1,7 +1,7 @@
|
||||||
|
from views import amazon_search, amazon_image, lexers, sitemap, tags
|
||||||
from django.conf.urls.defaults import include, patterns, url
|
from django.conf.urls.defaults import include, patterns, url
|
||||||
from django.views.generic.simple import direct_to_template
|
from django.views.generic.simple import direct_to_template
|
||||||
from registration.forms import RegistrationFormUniqueEmail
|
from registration.forms import RegistrationFormUniqueEmail
|
||||||
from views import amazon_search, lexers, sitemap, tags
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from snipts.views import search
|
from snipts.views import search
|
||||||
|
@ -39,6 +39,7 @@ urlpatterns = patterns('',
|
||||||
|
|
||||||
url(r'^api/public/lexer/$', lexers),
|
url(r'^api/public/lexer/$', lexers),
|
||||||
url(r'^api/public/a/$', amazon_search),
|
url(r'^api/public/a/$', amazon_search),
|
||||||
|
url(r'^api/public/a/img/$', amazon_image),
|
||||||
|
|
||||||
url(r'^api/', include(public_api.urls)),
|
url(r'^api/', include(public_api.urls)),
|
||||||
url(r'^api/', include(private_api.urls)),
|
url(r'^api/', include(private_api.urls)),
|
||||||
|
|
27
views.py
27
views.py
|
@ -1,11 +1,15 @@
|
||||||
|
from django.http import HttpResponseRedirect, HttpResponseBadRequest
|
||||||
from annoying.decorators import ajax_request, render_to
|
from annoying.decorators import ajax_request, render_to
|
||||||
|
from django.template.defaultfilters import striptags
|
||||||
from django.shortcuts import render_to_response
|
from django.shortcuts import render_to_response
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from snipts.utils import get_lexers_list
|
from snipts.utils import get_lexers_list
|
||||||
from django.db.models import Count
|
from django.db.models import Count
|
||||||
from amazon.api import AmazonAPI
|
from amazon.api import AmazonAPI
|
||||||
|
from django.conf import settings
|
||||||
from taggit.models import Tag
|
from taggit.models import Tag
|
||||||
from django.template.defaultfilters import striptags
|
|
||||||
|
import os, urllib
|
||||||
|
|
||||||
|
|
||||||
@ajax_request
|
@ajax_request
|
||||||
|
@ -19,7 +23,7 @@ def amazon_search(request):
|
||||||
result = []
|
result = []
|
||||||
for product in products:
|
for product in products:
|
||||||
result.append({
|
result.append({
|
||||||
'image': product.small_image_url,
|
'image': product.small_image_url.replace('http://ecx.images-amazon.com/images/I/', ''),
|
||||||
'price': product.list_price,
|
'price': product.list_price,
|
||||||
'review': striptags(product.editorial_review),
|
'review': striptags(product.editorial_review),
|
||||||
'reviews': product.reviews,
|
'reviews': product.reviews,
|
||||||
|
@ -31,6 +35,25 @@ def amazon_search(request):
|
||||||
'result': result
|
'result': result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def amazon_image(request):
|
||||||
|
if 'i' in request.GET:
|
||||||
|
|
||||||
|
img_filename = request.GET.get('i')
|
||||||
|
img_src = 'http://ecx.images-amazon.com/images/I/{}'.format(img_filename)
|
||||||
|
img_loc = os.path.join(settings.STATIC_ROOT, 'images', 'amazon', img_filename)
|
||||||
|
|
||||||
|
try:
|
||||||
|
open(img_loc)
|
||||||
|
return HttpResponseRedirect('/static/images/amazon/' + img_filename)
|
||||||
|
except IOError:
|
||||||
|
urllib.urlretrieve(img_src, img_loc)
|
||||||
|
return HttpResponseRedirect('/static/images/amazon/' + img_filename)
|
||||||
|
|
||||||
|
return HttpResponseRedirect('/static/images/amazon/' + img_filename)
|
||||||
|
else:
|
||||||
|
return HttpResponseBadRequest()
|
||||||
|
return {}
|
||||||
|
|
||||||
@ajax_request
|
@ajax_request
|
||||||
def lexers(request):
|
def lexers(request):
|
||||||
lexers = get_lexers_list()
|
lexers = get_lexers_list()
|
||||||
|
|
Loading…
Reference in New Issue