Esempio n. 1
0
def deletetable(tablek):
    tb = db.get(tablek)
    tms = Team().all()
    tms.filter('table = ', tablek)
    for tm in tms:
        deleteteam(tm.key(), tablek)
    tb.delete()
Esempio n. 2
0
def deletetable(tablek):
    tb = db.get(tablek)
    tms = Team().all()
    tms.filter('table = ', tablek)
    for tm in tms:
        deleteteam(tm.key(), tablek)
    tb.delete()
Esempio n. 3
0
 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))        
Esempio n. 4
0
 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))
Esempio n. 5
0
 def get(self):
     #test param exists and is right type
     notapp=1
     if 'sportablesapp' in self.request.cookies:
         notapp=0
     try:
         result_set = int(self.request.get('result_set'))
     except:
         result_set = 0      
     try:
         table_get = int(self.request.get('table_name'))
     except:
         table_get = 0           
     if(table_get == 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_get)
                 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():
                             tms = Team().all()
                             tms.filter('table = ', k)
                             tms.order('-points')
                             tms.order('-goal_difference')
                             tms.order('-goals_for')
                             tms.order('name')
                             if(tms.count()<2):
                                 disable = 1
                             else:
                                 disable = 0           
                             #new test part
                             rs = Result().all()
                             rs.filter('table = ', k)
                             rs_away = Result().all()
                             rs_away.filter('table = ', k)
                             hrl = []
                             if int(result_set) != 0:
                                 rs.filter('home_team_id = ', result_set)
                                 rs_away.filter('away_team_id = ', result_set)
                                 for r in rs:
                                     hrl.append(int(r.key().id()))
                                 for r in rs_away:
                                     hrl.append(int(r.key().id()))
                                 rs = Result.get_by_id(hrl)
                                 rs.sort(key=lambda result: result.time_added)        
                             #new test end
                             score_options = range(300)
                             template_values = {
                                 'notapp': notapp,
                                 'tabledata': tb,
                                 'teamsdata': tms,
                                 'result_set_data': result_set,
                                 'resultsdata': rs,
                                 'disable': disable,
                                 'score_options': score_options
                             }
                             path = os.path.join(os.path.dirname(__file__), 'results.html')
                             self.response.out.write(template.render(path, template_values))
                         else:
                             logging.warning("attempt to get teams from another user's table")
                             self.redirect('/existingtable')
                 else:
                     logging.warning("attempt to get teams from 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')
Esempio n. 6
0
 def get(self):
     #test param exists and is right type
     notapp=1
     if 'sportablesapp' in self.request.cookies:
         notapp=0
     try:
         table_get = int(self.request.get('table_name'))
     except:
         table_get = 0           
     if(table_get == 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_get)
                 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():
                             tms = Team().all()
                             tms.filter('table = ', k)
                             tms.order('-points')
                             tms.order('-goal_difference')
                             tms.order('-goals_for')
                             tms.order('name')
                             if(tms.count()<2):
                                 disable = 1
                             else:
                                 disable = 0
                             if(tms.count()<1):
                                 disable2 = 1
                             else:
                                 disable2 = 0
                             template_values = {
                                 'notapp': notapp,
                                 'tabledata': tb,
                                 'teamsdata': tms,
                                 'disable': disable,
                                 'disable2': disable2
                             }
                             path = os.path.join(os.path.dirname(__file__), 'teams.html')
                             self.response.out.write(template.render(path, template_values))
                         else:
                             logging.warning("attempt to get teams from another user's table")
                             self.redirect('/existingtable')
                 else:
                     logging.warning("attempt to get teams from 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')
Esempio n. 7
0
   def get(self):
       try:
           table_id = int(self.request.get('table'))
       except:
           table_id = 0
           
       accounttype_id = 1 #once used to set temp account off a button
       
       # Set var default to indicate that user is not using the app
       notapp=1
       
       # get the query string      
       startingurl = self.request.uri      
       param = urllib.urlencode({startingurl:1})
       urlqs = startingurl.endswith('&') and (startingurl + param) or (startingurl + '&' + param)
 
       # when appversion is present set a cookie that can be picked up by all the other pages and set template var to 1
       if 'appversion' in urlqs:
           # is the app so set the cookie to remember that
           print 'Set-Cookie: sportablesapp=1';
           notapp=0 
               
       # check cookie again user may have returned to homepage after navigating around and lost the param from the querystring  
       if 'sportablesapp' in self.request.cookies:
           notapp=0    
       
       if(table_id == 0):
           u = None
           tempu = None
           login_cookie = Cookie.BaseCookie()
           tablecount = 0
           if users.get_current_user():
               u = User.all()
               u.filter('username = '******'sportablesuser' in self.request.cookies:
                   usercookie = self.request.cookies['sportablesuser']
                   tempu = User.all()
                   tempu.filter('tempusername = '******'Sign out'
           else:
               if(int(accounttype_id) == 1):
                   is_temp_account = 1
                   is_logged_in = 1
                   usercookie = None
                   if 'sportablesuser' in self.request.cookies:
                       usercookie = self.request.cookies['sportablesuser']
                       u = User.all()
                       u.filter('tempusername = '******'sportablesuser'] = usercookie
                       u.fetch(1)
                       for g in u:
                           for t in g.tables:
                               tablecount += 1
                   else:
                       randomid = uuid.uuid4()
                       login_cookie['sportablesuser'] = randomid
                       new_user = User(tempusername=str(randomid))
                       new_user.put()
                       u = User.all()
                       u.filter('tempusername = '******'sportablesuser']["expires"] = COOKIE_TIME
               url = users.create_login_url(self.request.uri)
               url_linktext = 'Sign in'
               
           #find out the languages the requesting browser accepts
           al=self.request.headers.get('Accept-Language')
           accepted_languages = helperfunctions.parse_accept_language(al)
           language_strings = helperfunctions.get_messages(accepted_languages)
               
           template_values = {
               'tablecount': tablecount,
               'url': url,
               'url_linktext': url_linktext ,
               'notapp' : notapp,
               'language_strings': language_strings
               }
           path = os.path.join(os.path.dirname(__file__), 'index.html')
           self.response.out.write(template.render(path, template_values))
           for morsel in login_cookie.values():
               self.response.headers.add_header('Set-Cookie',morsel.OutputString(None))
       else:
           k = db.Key.from_path('Table', int(table_id))
           t = db.get(k)
           tms = Team().all()
           tms.filter('table = ', k)
           tms.order('-points')
           tms.order('-goal_difference')
           tms.order('-goals_for')
           tms.order('name')
           rs = Result().all()
           rs.filter('table = ', k)
           is_table_owner = False
           usercookie = None
           login_cookie = Cookie.BaseCookie()
           #test to see a table has returned
           if users.get_current_user():
               u = User.all()
               u.filter('username = '******'sportablesuser' in self.request.cookies:
                   usercookie = self.request.cookies['sportablesuser']
                   login_cookie['sportablesuser'] = usercookie
                   login_cookie['sportablesuser']["expires"] = COOKIE_TIME
                   u = User.all()
                   u.filter('tempusername = '******'tabledata': t,
               'teamsdata': tms,
               'resultsdata': rs,
               'owner': is_table_owner
               }
           path = os.path.join(os.path.dirname(__file__), 'viewer.html')
           self.response.out.write(template.render(path, template_values))
           for morsel in login_cookie.values():
               self.response.headers.add_header('Set-Cookie',morsel.OutputString(None))