예제 #1
0
 def POST(self):
     user = users.get_current_user()
     isadmin = users.is_current_user_admin()
     
     if user :
             validateForm = invite_form()
             if not validateForm.validates():
                 return main_view.user.invite(validateForm)
             
             else :
                 data = web.input()
                 i = Invite()
                 
                 restaurant_keyname = i.checkIfCodeExists(data.invite_code)
                 if restaurant_keyname :
                     rm = RestaurantModel.get(restaurant_keyname)
                     
                     # add profile to restaurant
                     if not users.is_current_user_admin():
                         p = UserProfileModel()
                         current_profile = p.get_by_key_name(users.get_current_user().user_id())
                         if current_profile.key() not in rm.profiles:
                             rm.profiles.append(current_profile.key())
                             rm.put()
                            
                     upm = UserProfileModel.get_by_key_name(user.user_id())
                     upm.invited = True
                     upm.put()
                     
                     return web.seeother('/user/')
                 else:
                     return 'invitation code failed'
     
     else:
            return web.seeother('/')
예제 #2
0
 def getRestaurantsInProfile(self):
     r = {}
     p = UserProfileModel()
     current_profile = p.get_by_key_name(users.get_current_user().user_id())
     restaurant = RestaurantModel.gql("WHERE profiles = :1", current_profile.key())
     for x in restaurant:
         r[x.key().id()] = x.name
         
     return r
예제 #3
0
 def getRestaurantName(self):
     r = {}
     p = UserProfileModel()
     current_profile = p.get_by_key_name(users.get_current_user().user_id())
     restaurant = RestaurantModel.gql('WHERE profiles = :1', current_profile.key())
     for x in restaurant:
         r[x.key().id()] = x.name
         
     return sorted(r.iteritems())
예제 #4
0
 def add(self):
     
                      user = users.get_current_user().user_id()
                      up = UserProfileModel(key_name=user)
                      up.author = users.get_current_user()
                      up.nickname = user
                      up.invited = False
                      up.active = True
                      # date is inserted auto
                      up.put()
예제 #5
0
 def GET(self):
     user = users.get_current_user()
     #check if invited form has been submitted or clicked thru
     if user :
             
             if not users.is_current_user_admin():
                 upm = UserProfileModel.get_by_key_name(user.user_id())
                 if not upm.invited :
                     return main_view.user.invite(invite_form)
                 else :
                     return web.seeother('/user/')
             else :
                 return web.seeother('/user/')
     
     else:
            return web.seeother('/')
예제 #6
0
 def add(self,
                name,
                country,
                city,
                phone, 
                address, 
                state):
                      
                    #success = True
                    default_restaurant = False
                    restaurant_id=0
                    try :
                          rm = RestaurantModel()
                          
                          #  if this is first restaurant added - make default
                          if not Restaurant.getRestaurantName(self) :
                              default_restaurant = True
                        
                          rm.author = users.get_current_user()
                          # date is inserted auto
                          rm.name = name
                          rm.country = country
                          rm.city = city.strip().lower()
                          rm.phone = phone
                          rm.address = address
                          rm.state = state.strip().lower()
                          rm.active = False
                          rm.default_restaurant = default_restaurant
                          # add profile relationship
                          p = UserProfileModel()
                          
                          
                          current_profile = p.get_by_key_name(users.get_current_user().user_id())
                          admin_profile1 = p.get_by_key_name('114115181577730413318')
                          if current_profile.key() not in rm.profiles:
                              rm.profiles.append(current_profile.key())
                              if users.get_current_user().user_id() != '114115181577730413318' :
                                  #add wiley.snyder
                                  if(admin_profile1):
                                      rm.profiles.append(admin_profile1.key())
                              
                              rm.put()
                              restaurant_id = rm.key().id()
                              
                              #create invite key
                              if users.is_current_user_admin():
                                 
                                      try :
                                          im = InvitationModel()
                                          im.invitation_code = Restaurant.createInvitationKey(self,rm.key().id())
                                          im.restaurant_key = str(rm.key())
                                          im.put()
                                      except :
                                          #success = False
                                          x = RestaurantModel.get_by_id(rm.key().id())
                                          x.delete()
                                          raise
                                          
                                          
                    except :
                        #success = False
                        raise
                        
                    return restaurant_id
예제 #7
0
 def getProfile(self):
      up = UserProfileModel()
      profile = up.get_by_key_name(users.get_current_user().user_id())
                                         
      return  profile