Note that there are some explanatory texts on larger screens.

plurals
  1. POGoogle App Engine : Get User Object from Webapp2 Cached Property (current_user)
    text
    copied!<p>What i am trying to achieve is getting the user object from the webapp2.cached property. i have a method defined in my request handler which gives me the current user.</p> <pre><code>@webapp2.cached_property def current_user(self): user_dict = self.auth.get_user_by_session() return self.auth.store.user_model.get_by_id(user_dict['user_id']) </code></pre> <p>I want to get the User Object because it is a UserProperty() of one of my models which is as follows:</p> <pre><code>class CountryImage(db.Model): image = db.BlobProperty() user = db.UserProperty() country = db.ReferenceProperty(Country) approved = db.BooleanProperty(default=False) </code></pre> <p>Now when the upload form is posted, everything works fine except for the "user" which shows as "None" in the datastore.</p> <p>The possible reason i found while i was playing with it in the interactive console was that the method current_user passes a web cached property and not the actual user object.</p> <p>For Example:</p> <pre><code>&lt; webapp2.cached_property object at 0xb46aee8c &gt; </code></pre> <p>Now my question is what would be the best possible way of retrieving the user object ? Thanks in advance for all your help.</p> <p>Amyth</p> <p>PS: EDIT:</p> <p>following is the code where i am trying to store the image in the datastore:</p> <pre><code>NewImg = models.CountryImage() NewImg.image = self.request.get('image') NewImg.user = self.current_user NewImg.country = models.Country.all().filter("url_name =", country).get() continue_url = self.request.url NewImg.put() </code></pre> <p>PS:</p> <p>Just to add i have also tried using "users.get_current_user()" method which also returns "None"</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload