def post(self): disable = 1 #list to hold IDs of matched tables without teams no_team_tables = [] #get tables that match tot_ts = Table.gql("") #add the beginning count total_tables = tot_ts.count(2000) ts = Table.gql("WHERE name IN('SVB', :1)", u'SV Böblingen D1') #add the number affected with SVB and SV B total_bad = ts.count(2000) deletecounter = 0 for t in ts: teams = Team.gql("WHERE table = :1", t) if teams.count() == 0: #do the delete thing helperfunctions.deletetable(t.key()) deletecounter += 1 #add the number of deleted tables delete_tables = deletecounter post_ts = Table.gql("WHERE name IN('SVB', :1)", u'SV Böblingen D1') #add the number remainig after the delete operation remaining_tables = post_ts.count(2000) template_values = { 'total_tables': total_tables, 'total_bad': total_bad, 'delete_tables': delete_tables, 'remaining_tables': remaining_tables, 'disable': disable } path = os.path.join(os.path.dirname(__file__), 'admin/admin.html') self.response.out.write(template.render(path, template_values))
def get(self): #test param exists and is right type try: table_delete = int(self.request.get('table_to_delete')) except: table_delete = 0 if(table_delete == 0): logging.warning("param or type wrong") self.redirect('/existingtable') else: u = None if users.get_current_user() == None: if 'sportablesuser' in self.request.cookies: u = User.gql("WHERE tempusername = :1", self.request.cookies['sportablesuser']) else: u = User.gql("WHERE username = :1", users.get_current_user()) if u != None: if u.count() == 1: #test if table exists k = db.Key.from_path('Table', table_delete) tb = db.get(k) if not type(tb) is NoneType: for o in u: #test if user is owner if o.key().id() == tb.user.key().id(): helperfunctions.deletetable(k) table_id = 0 table_object = 'table' return_page = 'Your tables' object_action = 'deleted' object_url = 'existingtable' self.redirect('/displaymessage?table_id=' +str(table_id)+'&table_object='+table_object+'&return_page=' +return_page+'&object_action='+object_action+'&object_url='+object_url) else: logging.warning("attempt to delete another user's table") self.redirect('/existingtable') else: logging.warning("attempt to delete a table that doesn't exist") self.redirect('/existingtable') else: logging.warning("user has a google or temp account but has no User entity") self.redirect('/existingtable') else: logging.warning("user has neither logged in with a google account or a set a cookie") self.redirect('/existingtable')