Пример #1
0
 def get(self):
     
     user = users.get_current_user()
     if user:
         user_prefs = UserPrefs.all().filter('google_account =', user).get()
         if user_prefs is None:
             return self.redirect('/user/home')
         
     store_tweet_history = StoreTweetHistory.all().filter('google_account =', user).filter('expired_at >', datetime.datetime.now()).get()
     if store_tweet_history is None:
         can_tweet = True
         expired_at = None
     else:
         can_tweet = False
         user_timezone = timezone(user_prefs.timezone)
         loc_dt = user_timezone.localize(store_tweet_history.expired_at)
         expired_at = loc_dt.strftime('%Y-%m-%d %H:%M:%S %Z%z')
             
     template_values = {
         'can_tweet': can_tweet,
         'expired_at': expired_at
     }
     
     path = os.path.join(os.path.dirname(__file__), 'templates/store/tweet.html')
     self.response.out.write(template.render(path, template_values))
Пример #2
0
    def post(self):

        user = users.get_current_user()
        
        user_prefs = UserPrefs.all().filter('google_account =', user).get()
        if user_prefs is None:
            return self.error(404)
        
        store_tweet_history = StoreTweetHistory.all().filter('google_account =', user).filter('expired_at >', datetime.datetime.now()).get()
        if store_tweet_history is None:
            user_prefs.free_quantity = user_prefs.free_quantity + 100
            user_prefs.activate_flg = True
            user_prefs.put()
            
            store_tweet_history = StoreTweetHistory()
            store_tweet_history.google_account = user
            store_tweet_history.expired_at = datetime.datetime.now() + datetime.timedelta(days=7)
            store_tweet_history.put()
            
            data = {'status': True}
        else:
            data = {'status': False}
        
        json = simplejson.dumps(data, ensure_ascii=False)
        self.response.content_type = 'application/json'
        self.response.out.write(json)