Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
pymongo works as stack in tornado?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
aliane abdelouahab  
View profile  
 More options Sep 26 2012, 4:43 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Wed, 26 Sep 2012 01:43:35 -0700 (PDT)
Local: Wed, Sep 26 2012 4:43 am
Subject: pymongo works as stack in tornado?
hi, it seems that the bug i got when implementing a deletion from
GridFS is because of a king of stack: an item cant be removed from
anywhere, but only the latest one added! because when iterating in the
template, it cant get the one that is in the middle on in the last
after refreshing.

here is the code:

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"]
        try:
            produits = self.db.users.find({"personnel.email":email},
{"produit_up":1,"_id":0}).distinct("produit_up")
            renderer = self.fs
        except (errors.AutoReconnect, errors.ConnectionFailure):
                self.redirect("/error")
        try:
            self.render("ventes.html", produits=produits,
renderer=renderer)
        except gridfs.errors.NoFile, e:
            self.write(str(e))

class Supprimer(BaseHandler):
    @tornado.web.authenticated
    def post(self):
        debut = time.clock()
        prod = self.get_arguments("supprime")
        produ = prod[0][:]
        idd = self.db.users.find_one({"produit_up.spec.id":produ})
["produit_up"][0["avatar"]["photo"]
        try:
            self.db.users.update({"produit_up.spec.id":produ},
{"$pull":{"produit_up"{"spec.id":produ}}})
            self.fs.delete(ObjectId('{0}'.format(idd)))
        except (errors.AutoReconnect, errors.ConnectionFailure):
                self.redirect("/error")
    self.redirect("/ventes") # this will redirect to the first code.

and the template:

{% for produit in produits %}
<div class="produit">
<span class="nom">Le nom du produit: {{produit["spec"]["namep"]}}</
span>
{% from bson import ObjectId %}
{% if produit["avatar"]["orientation"]=="portrait" %}
<span><img src="/{{renderer.get(ObjectId(produit["avatar"]
["photo"])).filename}}"height="250px" class="imag">
{% else %}
<span><img src="/{{renderer.get(ObjectId(produit["avatar"]
["photo"])).filename}}"width="250px"class="imag">
{% end %}

<div class="supprimer" >
<form name="supprimer" class="supprimer" method="post" action="/
supprimer">
{% raw xsrf_form_html() %}
<input type="hidden" value="{{produit["spec"]["id"]}}"
name="supprime"/

<input type="submit" value="SUPPRIMER!"/>
</form>
</div>

so here is how it works:
i delete an element,
self.db.users.update({"produit_up.spec.id":produ}, {"$pull":
{"produit_up:{"spec.id":produ}}})
and then go to to gridFS to delete the picture of that element:
self.fs.delete(ObjectId('{0}'.format(idd)))
and then i'll redirect the user to the page where he can find the
product that are still there.
and if i've two products it's okey, since the result will be only one
product staying, but if i've more than 3, then, if i dont delete the
first one (the last one added) then i got an error from pymongo
complaining of missing the _id of the porject deleted, it's like the -
id is still rendered!
here is the link to mongodb groups;
https://groups.google.com/group/mongodb-user/browse_thread/thread/50b...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 30 2012, 8:45 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sun, 30 Sep 2012 05:45:14 -0700 (PDT)
Local: Sun, Sep 30 2012 8:45 am
Subject: Re: pymongo works as stack in tornado?
i still dont get the solution, i know that i dide something bad,
because the returned ObjectID dont match to the deleted element, but
why!
here the code formatted on stackoverflow
http://stackoverflow.com/questions/12653548/gridfs-elements-dont-foll...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
aliane abdelouahab  
View profile  
 More options Sep 30 2012, 10:57 am
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Sun, 30 Sep 2012 07:57:00 -0700 (PDT)
Subject: Re: pymongo works as stack in tornado?
am sorry, i've solved it.
it seems that the problem came from using the list index, i've fixed
it to the first one, this is why i dident get the error when deleting
the first element.
http://stackoverflow.com/questions/12653548/gridfs-elements-dont-foll...

On 30 sep, 13:45, aliane abdelouahab <alabdeloua...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »