Exemplo n.º 1
0
            def getRestaurants(self):
             out = {}
             r = RestaurantModel()
 
             for r in RestaurantModel.all() :
                     if r.active :
                         out[r.key().id()] = r.name
                     
             return out
Exemplo n.º 2
0
 def add(self,
                name, 
                city,
                phone, 
                address, 
                state):
                      rm = RestaurantModel()
                      rm.author = users.get_current_user()
                      # date is inserted auto
                      rm.name = name
                      rm.city = city
                      rm.phone = phone
                      rm.address = address
                      rm.state = state
                      rm.active = False
                      rm.put()
Exemplo n.º 3
0
 def getRestaurantFromID(self,id):
      rm = RestaurantModel()
      for r in RestaurantModel.all() :
          if r.key().id() == id :
              rm = r
      
      return rm
Exemplo n.º 4
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
Exemplo n.º 5
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())
Exemplo n.º 6
0
            def getLatestRestaurants(self):
             out = {}
             #r = RestaurantModel()
 
             for r in RestaurantModel.all() :
                     if r.active :
                         details = r.city + ' , ' + r.state
                         out[r.name.title()] = details.title()
                     
             return out
Exemplo n.º 7
0
 def addRestaurantNameId(self,id):
     r = RestaurantModel.get_by_id(int(id))
     r_name = r.name
     
     rem = memcache.get("rem")
     if rem is not None :
         rem.current_model_edit_id = id
         rem.current_model_name = r_name
         if not memcache.add("rem",rem) :
             memcache.replace("mc_error",True)
     
     m = RestaurantEditModel.get_by_key_name(users.get_current_user().user_id())
     m.current_model_edit_id = id
     m.current_model_name = r_name
     m.put()
Exemplo n.º 8
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
Exemplo n.º 9
0
 def getRestaurant(self,id):
     return RestaurantModel.get_by_id(int(id))
Exemplo n.º 10
0
 def delete(self,id):
     #delete restaurant
     menu_delete = []
     category_delete = []
     item_delete = []
     
     rm = RestaurantModel.get_by_id(int(id))
     if rm :
         menus = rm.menus
     
         if menus :
             for x in menus :
                 #logging.info('delete menu : ' + str( x.key().id()))
                 mm = MenuModel.get_by_id(x.key().id())
                 menu_delete.append(x.key().id())
                 menucategory = mm.categories
             
                 if menucategory :
                     for y in menucategory :
                         #logging.info('delete category : ' + str(y.key().id()))
                         mcm = MenuCategoryModel.get_by_id(y.key().id())
                         category_delete.append(y.key().id())
                         items = mcm.items
                     
                         if items :
                             for z in items :
                                 #logging.info('delete item : ' + str(z.key().id()))
                                 item_delete.append(z.key().id())
   
             for menu in menu_delete :
                 #logging.info('delete menu : ' + str(menu))
                 mm = MenuModel.get_by_id(menu)
                 mm.delete()
        
             for category in category_delete :
                 #logging.info('delete category : ' + str(category))
                 mcm = MenuCategoryModel.get_by_id(category)
                 mcm.delete()
        
             for item in item_delete :
                 #logging.info('delete item : ' + str(item))
                 mim = MenuItemModel.get_by_id(item)
                 mim.delete()
             
             
             #invites
             rKey = rm.key()
             for i in InvitationModel.all():
                 if str(i.restaurant_key) == str(rKey) :
                     i.delete()
                     
             #country
             if rm.active :
                 cm = CountryModel.get_by_id(int(rm.country_id))
                 rc = cm.restaurant_count
                 
                 if not str(rc) == '1' :
                     cm.restaurant_count = rc - 1
                 else :
                     cm.restaurant_count = rc - 1
                     cm.active = False
                       
                 cm.put()
             
             
             #city
             if rm.active :
                 ci = CityModel.get_by_id(int(rm.city_id))
                 rc = ci.restaurant_count
                 
                 if not str(rc) == '1' :
                     ci.restaurant_count = rc - 1
                 else :
                     ci.restaurant_count = rc - 1
                     ci.active = False
                       
                 ci.put()
                 
                 
             #state
             if rm.active :
                 st = StateModel.get_by_id(int(rm.state_id))
                 rc = st.restaurant_count
                 
                 if not str(rc) == '1' :
                     st.restaurant_count = rc - 1
                 else :
                     st.restaurant_count = rc - 1
                     st.active = False
                       
                 st.put()
                 
                 
             
             rm.delete()
Exemplo n.º 11
0
 def addCityModel(self,rm_id,cm_id):
     rm = RestaurantModel.get_by_id(rm_id)
     cm = CityModel.get_by_id(cm_id)
     rm.citymodel = cm
     rm.put()