示例#1
0
 def create(self):
     """
     Create the ID
     """
     try:
         # retrieve the parameters
         u = self.params['user']
         
         if len(u['name']) < 2 or len(u['name']) > 16:
             raise 'ID 長度有誤'
             
         from google.appengine.api import users
         from model.user import User
         from model.counter import Counter
         from random import randint
         
         user = User.gql('WHERE name = :1', u['name']).get()
         if user is not None:
             raise 'ID 重覆'
         
         guser = users.get_current_user()
         # create user entity
         user = User(key_name=guser.email(),
                     name=u['name'],
                     email=guser.email())
         user.put()
         
         # add user counter
         shard_name = randint(0, 3)
         counter = Counter.get_by_key_name('user_counter_%d' % shard_name)
         if counter is None:
             counter = Counter(key_name='user_counter_%d' % shard_name, name="user_counter")
         counter.count += 1
         counter.put()
         
         if self.session.has_key('error'):
             del self.session['error']
             self.session.put()
         
         self.redirect('/auth')
     except Exception, ex:
         self.session['error'] = ex
         self.session.put()
         self.redirect('/signup')
示例#2
0
 def get_searched_count(word, user=None):
     count = 0
     for counter in Counter.gql("WHERE name=:1",
                             get_counter_name(word,user)):
         count += counter.count
     return count
示例#3
0
 def put(self):
     Counter.increase_counter(get_counter_name(self.word))
     Counter.increase_counter(get_counter_name(self.word,self.user))
     super(Vocabulary, self).put()