示例#1
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