Esempio n. 1
0
    def FindCourts(self, y, m, d):

        d = "DATETIME(" + str(y) + "," + str(m) + "," + str(d) + ")"
        query = "select __key__ from CourtTime where date= " + d
        keys = db.GqlQuery(query)
        r = []

        for k in keys:
            p = db.get(k)
            c = Courts()
            c.time = library.stime(p.start)

            #          print("keyname = " + self.session['keyname'])
            if (type(p.owner) is types.NoneType):
                c.cts = library.listconv(p.courts)
                c.cts = c.cts  # + " " + p.location    # Add the location (Mg = Mango)
                c.key = k  # no owner
            else:
                g = datastore.Captain.get_by_key_name(p.owner)
                #            print("keyname = " + g.key().name )
                c.key = k  # g.key().name()  has an owner !!!!! < CHECK
                c.cts = g.fname
                c.mine = True

# SESSION  Check here if the session user owns the court
# Dont need to iff user owns this court
#             if( self.session.get('user') ):     # (NEWSESSION)
#                  if( self.session['keyname'] == g.key().name() ):
#                    c.mine=True
# use c.mine to not display checkbox

            r.append(c)

        return r
Esempio n. 2
0
    def post(self):
        print("DelCourtConfirmHandler")
        courtlist = []
        try:
            keylist = self.request.get_all('keys')
            print("get keys")
            for key in keylist:
                c = Courts()
                #           c.key = key
                #
                p = db.get(key)  #Get the court by its unique key (key)
                print("db.get(key)")
                c.date = library.cday(p.start)
                c.weekday = p.weekday
                c.start = library.ctime(p.start)
                c.end = library.ctime(p.end)
                c.desc = p.desc
                c.courts = library.listconv(p.courts)
                c.location = library.location(p.location)

                c.key = key
                courtlist.append(c)

                print key
        except:
            print "EXCEPTION"


# weekday, date, courts,location,start,desc

        template_values = {"CourtList": courtlist}

        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'delcourtconfirm.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 3
0
    def get(self ):

        query="select __key__ from CourtTime order by date"
        keys =  db.GqlQuery( query)
        courtlist=[]
        for k in keys:
           r = db.get(k)
           if( type(r.owner) is not types.NoneType):
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)
                g = datastore.Captain.get_by_key_name( r.owner )
                c.captain = g.fname + " " + g.lname
                c.team = g.team

                courtlist.append( c)

        template_values = {
            'Courts': courtlist
        }

        path = os.path.join(os.path.dirname(__file__), 'bydate.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 4
0
    def get(self ):

        Others=[]   # Others is an array captains
        OtherTeams=[]   # Others is an array of Reservation()
        query="select __key__ from Captain order by lname"
        keys =  db.GqlQuery( query)
        captains = db.get(keys)
        for e in captains:

            keyname =  e.key().name() 
#           Skip if its the logged in captain 
            if( keyname == capt_keyname ): continue

            Others.append( e )
            query="select __key__ from CourtTime where owner= '" + keyname  + "'"      
            keys =  db.GqlQuery( query)
            res = db.get(keys)
#           Get the courts
            courtlist=[]
            for  r in res:
              c = Court()
              c.weekday = r.weekday
              c.date = library.cday(r.date)
              c.start = library.ctime(r.start)
              c.end = library.ctime(r.end)
              c.courts = library.listconv(r.courts)
              courtlist.append( c)

            teamreserve= Reservation()           # make an instance
            teamreserve.fname = e.fname          # Captan's name
            teamreserve.lname = e.lname          
            teamreserve.team = e.team            # Captain's team
            teamreserve.courts= courtlist        # list of reserved courts

            OtherTeams.append( teamreserve )
Esempio n. 5
0
    def post(self):
        print("DelConfirmHandler")
        courtlist = []
        try:
            keylist = self.request.get_all('keys')
            print("get keys")
            for key in keylist:
                print(key)

                p = db.get(key)  #Get the court by its unique key (key)
                print("db.get(key)")
                continue
                c = Courts()
                c.date = library.cday(p.start)
                c.weekday = p.weekday
                c.start = library.ctime(p.start)
                c.end = library.ctime(p.end)
                c.desc = p.desc
                c.courts = library.listconv(p.courts)
                c.location = library.location(p.location)

                c.key = key
                courtlist.append(c)

        except Exception as e:
            print "EXCEPTION: " + str(e)

# weekday, date, courts,location,start,desc

        template_values = {"CourtList": courtlist}
Esempio n. 6
0
    def get1(self):

        query = "select __key__ from CourtTime order by date"
        keys = db.GqlQuery(query)
        courtlist = []
        for k in keys:
            r = db.get(k)
            if (type(r.owner) is not types.NoneType):
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)
                g = datastore.Captain.get_by_key_name(r.owner)
                c.captain = g.fname + " " + g.lname
                c.team = g.team

                courtlist.append(c)

        for t in courtlist:
            self.Writeln(t.date + " " + t.weekday + " " + t.start + "->" +
                         t.end)
            self.Writeln(t.captain + " " + t.team)
            self.Writeln("<br>")
Esempio n. 7
0
    def get(self):

        print("get")
        query = "select __key__ from CourtTime order by date"
        keys = db.GqlQuery(query)

        courtlist = []
        for k in keys:
            p = db.get(k)

            c = Courts()
            c.weekday = p.weekday
            c.date = library.cday(p.date)
            c.start = library.ctime(p.start)
            c.end = library.ctime(p.end)
            c.courts = library.listconv(p.courts)
            c.location = library.location(p.location)
            c.desc = p.desc
            c.key = k
            courtlist.append(c)
            print(c.date)

        template_values = {'CourtList': courtlist}

        path = os.path.join(os.path.dirname(__file__), 'templates', 'all.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 8
0
    def FindCourts( self, y,m,d):


        d = "DATETIME(" + str(y) + "," + str(m) + "," + str(d) + ")"
        query="select __key__ from CourtTime where date= " + d
        keys =  db.GqlQuery( query)
        r = []

        for k in keys:
           p = db.get(k)
           c = Courts()
           c.time = library.stime(p.start)  

           c.location = p.location   #RWO location updated 2/1/2019 

#          print("keyname = " + self.session['keyname'])
           if( type(p.owner) is types.NoneType): 
             c.cts  = library.listconv(p.courts)
             c.cts  = c.cts # + " " + p.location    # Add the location (Mg = Mango)
           else:
             g = datastore.Captain.get_by_key_name( p.owner )
#            print("keyname = " + g.key().name )
             c.cts = g.fname

# SESSION  Check here if the session user owns the court
             if( self.session.get('user') ):     # (NEWSESSION)
                  if( self.session['keyname'] == g.key().name() ):
                    c.mine=True

           r.append( c)

        return r
Esempio n. 9
0
def FindCourts(y, m, d):
    d = "DATETIME(" + str(y) + "," + str(m) + "," + str(d) + ")"
    query = "select __key__ from CourtTime where date= " + d
    keys = db.GqlQuery(query)

    r = []
    for k in keys:
        p = db.get(k)
        c = Courts()
        c.time = library.stime(p.start)
        c.key = k

        if (type(p.owner) is types.NoneType):
            c.cts = library.listconv(p.courts)
            c.cts = c.cts  # + " " + p.location    # Add the location (Mg = Mango)
        else:
            g = datastore.Captain.get_by_key_name(p.owner)
            c.cts = g.fname
            sess = Session()
            if (sess.get(keyname='user')):
                if (sess['keyname'] == g.key().name()):
                    c.mine = True  # To put in boldface (in html)
#                        sess.delete()
# TODO  Keep track of this session  - does it affect Login?

        r.append(c)

    return r
Esempio n. 10
0
    def get(self, month, day, year):

        LoggedIn = False
        User = Team = ""
        path = os.environ['PATH_INFO']

        if (self.session.get('user')):  # (NEWSESSION)
            LoggedIn = True
            User = self.session['fname'] + " " + self.session['lname']
            Team = " (" + self.session['team'] + ")"

        d = "DATETIME(" + year + "," + month + "," + day + ")"
        query = "select __key__ from CourtTime where date= " + d
        keys = db.GqlQuery(query)

        available = False
        courtlist = []
        for k in keys:
            p = db.get(k)
            #         c = Court_old( p.weekday,p.courts, p.start, p.end, p.desc , k )

            # DONE REFACTORed to Court
            c = Court()
            c.day = library.cday(p.start)
            c.start = library.ctime(p.start)
            c.end = library.ctime(p.end)
            c.desc = p.desc
            c.key = k
            c.courts = library.listconv(p.courts)
            c.location = library.location(p.location)
            c.open = True
            if (type(p.owner) is not types.NoneType):
                g = datastore.Captain.get_by_key_name(p.owner)
                c.owner = g.fname
                c.open = False

            courtlist.append(c)
            if (c.open == True): available = True

        template_values = {
            'month': month,
            'day': day,
            'year': year,
            'LoggedIn': LoggedIn,
            'User': User,
            'Team': Team,
            'path': path,
            'Courtlist': courtlist,
            'Available': available
        }

        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'courts.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 11
0
    def get(self, month, day, year):
        pass

        d = "DATETIME(" + year + "," + month + "," + day + ")"
        query = "select __key__ from CourtTime where date= " + d
        keys = db.GqlQuery(query)
        courtlist = []
        for k in keys:
            p = db.get(k)
            c = Courts()
            c.day = library.cday(p.start)
            c.start = library.ctime(p.start)
            c.end = library.ctime(p.end)
            c.desc = p.desc
            c.key = k
            c.courts = library.listconv(p.courts)
            c.location = library.location(p.location)
            c.open = True
            if (type(p.owner) is not types.NoneType):
                g = datastore.Captain.get_by_key_name(p.owner)
                c.owner = g.fname
                c.open = False

            courtlist.append(c)

        template_values = {
            'month': month,
            'day': day,
            'year': year,
            'Courtlist': courtlist,
            'LoginForm': library.LoginForm(),
            #           'Site'      : library.Host() + "/reserve",
            #           'Key'       :  k
        }

        path = os.path.join(os.path.dirname(__file__), 'delcourts.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 12
0
    def get(self ):

        capt_keyname=""
        LoggedIn =  False
        User = Team = ""
        path = os.environ['PATH_INFO']

        CaptainReservation = Reservation()        

        if(self.session.get('user') ):     # (NEWSESSION)

           LoggedIn = True
           User = self.session['fname'] + " " + self.session['lname'] 
           Team = " (" + self.session['team'] + ")" 


           capt_keyname = self.session['keyname'] 
           CaptainReservation.fname = self.session['fname']
           CaptainReservation.lname = self.session['lname']
           CaptainReservation.team  = self.session['team']

# TODO  more efficient db grab
           query="select __key__ from CourtTime where owner='" + capt_keyname + "'"
           keys =  db.GqlQuery( query)
           res = db.get(keys)
           courtlist = []
           for r  in res:
              c = Court()
              c.weekday = r.weekday
              c.date = library.cday(r.date)
              c.start = library.ctime(r.start)
              c.end = library.ctime(r.end)
              c.courts = library.listconv(r.courts)
              courtlist.append( c)

           CaptainReservation.courts = courtlist

# ---------------------------------------------------------------------------------
        query="select __key__ from CourtTime order by date"
        keys =  db.GqlQuery( query)
        bydate=[]
        for k in keys:
           r = db.get(k)
           if( type(r.owner) is not types.NoneType):
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)
                g = datastore.Captain.get_by_key_name( r.owner )
                c.captain = g.fname + " " + g.lname
                c.team = g.team

                bydate.append( c)


# ---------------------------------------------------------------------------------
        template_values = {
             'LoggedIn': LoggedIn,
             'User' : User,
             'Team' : Team,
             'path' : path,


             'CaptainReservation': CaptainReservation,
             'ByDate': bydate,
#            'OtherTeams': OtherTeams
        }

        path = os.path.join(os.path.dirname(__file__),'templates', 'instructions.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 13
0
    def post(self):

        LoggedIn = False
        User = Team = ""
        path = os.environ['PATH_INFO']

        if (self.session.get('user')):  # (NEWSESSION)
            LoggedIn = True
            User = self.session['fname'] + " " + self.session['lname']
            Team = " (" + self.session['team'] + ")"

        if (LoggedIn == False):
            self.Writeln("<p><br><p><br>")
            self.Writeln("<body bgcolor=d2d2ff>")
            self.Writeln("<center>")
            self.Writeln("<h1>Please Login </h1>")
            self.Writeln("</center>")
            return

        courts = self.request.get('courts')
        if (courts == ""):
            self.Writeln("<p><br><p><br>")
            self.Writeln("<body bgcolor=d2d2ff>")
            self.Writeln("<center>")
            self.Writeln("<h1>Please Select Courts </h1>")
            self.Writeln("</center>")
            return

        e = db.get(courts)
        #       This shouldn't ever happen since reserved court can't be selected
        if (type(e.owner) is not types.NoneType):
            self.Writeln("<p><br><p><br>")
            self.Writeln("<body bgcolor=d2d2ff>")
            self.Writeln("<center>")
            self.Writeln("<h1>Courts already Selected </h1>")
            self.Writeln("</center>")
            return

# -------------------------------------------------------------------
#       By now, use has logged in and selected courts

# (NEWSESSION)
        captain_keyname = self.session['keyname']
        Captain = datastore.Captain.get_by_key_name(captain_keyname)
        CourtTime = ""

        g = datastore.OpenDate.get_by_key_name("key_opendate")
        if (g == None):
            self.Writeln("<p><br><p><br>")
            self.Writeln("<center>")
            self.Writeln("<body bgcolor=d2d2ff>")
            self.Writeln("WARNING! Set Opening Date For Reservations")
            return

        start = g.openingdate

        StartDate = library.getDate(g.openingdate)
        StartTime = library.ctime(g.openingdate)
        Today = library.getDate(datetime.datetime.utcnow() -
                                datetime.timedelta(hours=8))
        Today = Today + " @" + library.ctime(datetime.datetime.utcnow() -
                                             datetime.timedelta(hours=7))

        delta = datetime.datetime.utcnow() - datetime.timedelta(
            hours=8) - start

        if (datetime.datetime.utcnow() - datetime.timedelta(hours=8) < start):
            self.Writeln("<p><br><p><br>")
            self.Writeln("<center>")
            self.Writeln("<body bgcolor=d2d2ff>")
            self.Writeln("<h1>Can't Reserve yet </h1>")
            self.Writeln("<h1>Today is " + Today + "</h1>")
            self.Writeln("<h1>Reservations start  " + StartDate + "@" +
                         StartTime + "</h1>")
            self.Writeln("</center>")
            return

        Allowed = 2 + 2 * delta.days

        sofar = Captain.count

        if (sofar >= Allowed):
            Exceeded = True
            template_values = {
                'Host': library.Host(),
                'StartDate': StartDate,
                'StartTime': StartTime,
                'Today': Today,
                'Allowed': Allowed,
                'Captain': Captain,
                'Exceeded': True
            }

            path = os.path.join(os.path.dirname(__file__),
                                'display_request.html')
            self.response.out.write(template.render(path, template_values))
            return


# ----------------------------------------------------------------------------------
#       Reserve the courts

#       courts is the Key to the court selected
        courts = cgi.escape(self.request.get('courts'))
        e = db.get(courts)

        CourtDate = library.getDate(e.date)
        CourtDay = e.weekday
        CourtStart = library.ctime(e.start)
        CourtEnd = library.ctime(e.end)
        Courts = library.listconv(e.courts)
        CourtDesc = e.desc

        Month = e.date.month
        Year = e.date.year

        e.owner = captain_keyname  # either use session value or from Captain db
        db.put(e)

        Captain.count = Captain.count + 1
        db.put(Captain)

        template_values = {
            'Host': library.Host(),
            'Month': Month,
            'Year': Year,
            'StartDate': StartDate,
            'StartTime': StartTime,
            'Today': Today,
            'Allowed': Allowed,
            'Captain': Captain,
            'CourtDate': CourtDate,
            'CourtDay': CourtDay,
            'CourtStart': CourtStart,
            'CourtEnd': CourtEnd,
            'Courts': Courts,
            #           'CourtDesc'  : CourtEnd,
            'Exceeded': False
        }

        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'reserve.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 14
0
    def get(self):

        capt_keyname = ""
        LoggedIn = False
        User = Team = ""
        path = os.environ['PATH_INFO']

        CaptainReservation = Reservation()
        if (self.session.get('user')):

            LoggedIn = True
            User = self.session['fname'] + " " + self.session['lname']
            Team = " (" + self.session['team'] + ")"

            capt_keyname = self.session['keyname']
            CaptainReservation.fname = self.session['fname']
            CaptainReservation.lname = self.session['lname']
            CaptainReservation.team = self.session['team']

            # TODO  more efficient db grab
            query = "select __key__ from CourtTime where owner='" + capt_keyname + "'"
            keys = db.GqlQuery(query)
            res = db.get(keys)
            courtlist = []
            for r in res:
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)

                #             loc="LP"
                #             if( re.search("Mg",r.location,re.IGNORECASE)): loc="Mango"
                c.location = library.location(r.location)

                courtlist.append(c)

            CaptainReservation.courts = courtlist

# ---------------------------------------------------------------------------------
        query = "select __key__ from CourtTime order by date"
        keys = db.GqlQuery(query)
        Mango = []
        Courts = []
        for k in keys:
            r = db.get(k)
            if (type(r.owner) is not types.NoneType):
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)
                g = datastore.Captain.get_by_key_name(r.owner)
                c.captain = g.fname + " " + g.lname
                c.team = g.team

                c.location = library.location(r.location)

                print("location: " + c.location)

                if (c.location is not types.NoneType): Courts.append(c)


# ---------------------------------------------------------------------------------
        template_values = {
            'LoggedIn': LoggedIn,
            'User': User,
            'Team': Team,
            'path': path,
            'CaptainReservation': CaptainReservation,
            #            'Mango': Mango,
            'Courts': Courts
            #            'OtherTeams': OtherTeams
        }

        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'summary.html')
        self.response.out.write(template.render(path, template_values))
Esempio n. 15
0
    def get(self):

        capt_keyname = ""

        # SESSION
        LoggedIn = False
        User = Team = ""
        path = os.environ['PATH_INFO']

        if (self.session.get('user')):  # (NEWSESSION)
            LoggedIn = True
            User = self.session['fname'] + " " + self.session['lname']
            Team = " (" + self.session['team'] + ")"

# SESSION

# Get the list of captains
        query = "select __key__ from Captain order by team"
        keys = db.GqlQuery(query)
        res = db.get(keys)
        CaptainList = []
        for r in res:
            c = Captain()
            c.fname = r.fname
            c.lname = r.lname
            c.user = r.user
            c.team = r.team

            CaptainList.append(c)
#

        CaptainReservation = Reservation()
        user = self.session.get('user')  #Captain name (that's all we need)
        if (user != None):
            LoggedIn = True
            capt_keyname = self.session['keyname']
            CaptainReservation.fname = self.session['fname']
            CaptainReservation.lname = self.session['lname']
            CaptainReservation.team = self.session['team']
            g = datastore.Captain.get_by_key_name(capt_keyname)
            CaptainReservation.count = g.count

            # TODO  more efficient db grab
            query = "select __key__ from CourtTime where owner='" + capt_keyname + "'" + " order by date "
            keys = db.GqlQuery(query)
            res = db.get(keys)
            courtlist = []
            for r in res:
                c = Court()
                c.weekday = r.weekday
                c.date = library.cday(r.date)
                c.start = library.ctime(r.start)
                c.end = library.ctime(r.end)
                c.courts = library.listconv(r.courts)
                c.location = library.location(r.location)
                c.desc = r.desc
                c.key = r.key().name()
                courtlist.append(c)

            CaptainReservation.courts = courtlist


# ---------------------------------------------------------------------------------
        template_values = {
            'Host': "/",
            'LoggedIn': LoggedIn,
            'User': User,
            'Team': Team,
            'path': path,
            'CaptainList': CaptainList,
            'CaptainReservation': CaptainReservation,
            'Site': library.Host() + "/unreserve",
        }

        path = os.path.join(os.path.dirname(__file__), 'templates',
                            'captain.html')
        self.response.out.write(template.render(path, template_values))