i've a problem when making a loop using a GridFS pictures:
class VentesHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
user = self.get_secure_cookie("mechtari")
info = tornado.escape.json_decode(user)
email = info["personnel"]["email"]
produits = self.db.users.find({"personnel.email":email},{"produit_up":1, "_id":0}).distinct("produit_up")
produit_pic_id = self.db.users.find({"personnel.email":email}).distinct("produit_up.avatar.photo")
orientation = self.db.users.find({"personnel.email":email}).distinct("produit_up.avatar.orientation")
renderer = self.fs
self.render("ventes.html", produits=produits, produit_pic_id=produit_pic_id, orientation=orientation, renderer=renderer)
and the template:
{% for produit in produits %}
{% for id in produit_pic_id %}
<div class="produit">
{% import pymongo %}
{% if orientation=="portrait" %} <!-- dumb technic to avoid image stretching ^_^ -->
<span><img src="/{{renderer.get(pymongo.son_manipulator.ObjectId([id for id in produit_pic_id])).filename}}" height="200px" class="imag">
{% else %}
<span><img src="/{{renderer.get(pymongo.son_manipulator.ObjectId(id)).filename}}" width="200px"class="imag">
{% end %}
</div>
</div>
{% end %}
{% end %}
{% end %}
i got the pictures repeated the time of uploaded products! so if i uploaded 2 products (product_up), then i'll get 4 products with all possibles switching of the product pictures! by the way, note the hack to avoid (self not defined...) and what about the import? do i make another variable
x = pymongo.son_manipulator
to avoid the template to load the whole module and uses a lot of memory?