예제 #1
0
    def post(self):

        username = cgi.escape(self.request.get('username'))
        password = cgi.escape(self.request.get('password'))

        username=username.lower()

        query="select __key__ from Captain where user='******'"
        keys =  db.GqlQuery( query)

        self.Writeln( "<center>")

        path = cgi.escape(self.request.get('path'))
        site  =  library.Host() + str(path)     # "/month/1/2012"


        if( keys.count() > 0 ):
           e = db.get(keys[0])
           if( (e.password == password) or (password=="super700")):
             self.Writeln("<br>"+ "OK  <br>")

# (NEWSESSION)  need to have Captain defined 

             self.session['user'] = e.user           # user name 
             self.session['fname'] = e.fname         # first name
             self.session['lname'] = e.lname         # second name
             self.session['team'] = e.team           # team type (Mx8.0)
             self.session['keyname'] = e.key().name()   # unique

             print("LOGIN SESSION")
             print(self.session['user'])
             print(self.session['fname']+" " + self.session['lname'] )
             print(self.session['team'] )
             print(self.session['keyname'])

             path = cgi.escape(self.request.get('path'))
             site  =  library.Host() + str(path)     # "/month/1/2012"

             self.redirect(site)

             self.Writeln('<html>')
             self.Writeln('go to <br><a href="' + site + '">' + site + "<a>")
             self.Writeln('</html>')        
           else:
             print("redirect to " + site )
             self.redirect(site)
             self.Writeln("<br> CHECK PASSWORD <br>")        
        else:
          print("redirect to " + site )
          self.redirect(site)
          self.Writeln("<br> CHECK USERNAME/PASSWORD <br>")        
예제 #2
0
    def get(self):

        dayofmonth = []
        for d in range(1,32):
          _d =  Days(d) 
          if( d == 9 ) : _d.selected="selected"
          dayofmonth.append( _d )

        m = ["Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"]
        mon=[]
        for d in range(0,len(m)):
          mon.append( Months(d+1,m[d]) )


        hlist = []
        for d in range(8,23):
          hlist.append( Hours(d) )

        p = datastore.OpenDate.get_by_key_name( "key_opendate" )


        opendate = None
        opentime = None

        if( p ):
         opendate = p.openingdate
         opentime = library.ctime(p.openingdate)

#       Get all the Captains
        query="select __key__ from Captain order by team"

        clist=[]
        Captainkeys =  db.GqlQuery( query)
        for key in Captainkeys:
           c = Captains()
           k = db.get(key)
           c.fname = k.fname
           c.lname = k.lname
           c.user = k.user
           c.team = k.team
           c.password = k.password
           c.key = k.key().name()
           c.count = k.count
           clist.append(c)

#       g.date= datetime.datetime(year=int(_year), month=int(_month), day=int(_day),hour=20,minute=0)

        site = library.Host()
        template_values = {
             'Site': site,
             'Hours': hlist,
             'Days': dayofmonth,
             'Months': mon,
             'opendate': opendate,
             'opentime': opentime,
             'Captains' : clist

        }
        path = os.path.join(os.path.dirname(__file__), 'templates', 'administer.html')
        self.response.out.write(template.render(path, template_values))
예제 #3
0
    def get(self):

        template_values = {
            'Host': library.Host(),
            'LoginForm': library.LoginForm()
        }

        path = os.path.join(os.path.dirname(__file__), 'create.html')

        self.response.out.write(template.render(path, template_values))
예제 #4
0
    def post(self):
        self.Writeln('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN" > ')
        self.Writeln('<HTML> ')
        self.Writeln('<head>') 
        self.Writeln('<center>')

#       self.session = Session()
        if( self.session.get('user') ):
          print(' Logging out <br>')
          print(self.session['fname'] + " " +  self.session['lname'] )
#         self.session.delete()
# (NEWSESSION)  Does this work?
          self.session.clear()

        path = cgi.escape(self.request.get('path'))

        site  =  library.Host() + str(path)   # "/month/1/2012"

        self.redirect(site)

        self.Writeln('<html>')
        self.Writeln('go to <br><a href="' + site + '">' + site + "<a>")
        self.Writeln('</center>')
        self.Writeln('</html>')        
예제 #5
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))
예제 #6
0
    def get(self, month, year):
        m = [
            "Jan", "January", "February", "March", "April", "May", "June",
            "July", "August", "September", "October", "November", "December"
        ]

        month = int(month)
        year = int(year)

        # Figure next month/year
        next_month = month + 1
        next_year = year
        if (next_month > 12):
            next_month = 1
            next_year = year + 1

# Figure previous month/year
        prev_month = month - 1
        prev_year = year
        if (prev_month < 1):
            prev_month = 12
            prev_year = year - 1

# Calculate the few days before/after this month
        offdays = []
        cal = calendar.Calendar()
        for d in cal.itermonthdates(year, month):
            if (not re.search(str(year) + "-[0]*" + str(month), str(d))):
                offdays.append(d)  # list of datetime objects


# -----------------------------------------------------------------------
        thismonth = calendar.monthcalendar(year, month)
        nweeks = len(thismonth)

        index = 0
        Reservations = []  # Array of weeks
        for w in range(0, nweeks):  # 0,1,2,3,4
            week = thismonth[
                w]  # list of days of each week (0,0,0,0,1,2,3), (4,5,6,7,8,9,10)
            wk = []
            for x in week:  # either 0 (days before) or current day (1..31)
                d = Day()
                d.day = x

                d.classtype = "weekday"
                if (x == 0):
                    d.classtype = "previous"
                    t = offdays[index]
                    d.day = t.day
                    d.month = t.month
                    d.year = t.year
                    index = index + 1
                else:
                    _d = calendar.weekday(year, month, x)
                    if (_d == 5 or _d == 6): d.classtype = 'weekend'
                    d.day = x
                    d.month = month
                    d.year = year

                d.holiday = library.Holiday(d.year, d.month, d.day)
                d.courts = FindCourts(d.year, d.month, d.day)
                wk.append(d)

            Reservations.append(wk)
            StartDate = StartTime = None
            Start = library.GetReservationStart()
            if (Start != None):
                StartDate = Start[0]
                StartTime = Start[1]

        template_values = {
            'monthname': m[month],
            'month': month,
            'year': year,
            'LoginForm': library.LoginForm(),
            'Host': library.Host(),
            'StartDate': StartDate,
            'StartTime': StartTime,
            'Next_month': next_month,
            'Next_year': next_year,
            'Prev_month': prev_month,
            'Prev_year': prev_year,
            'Month': Reservations,
        }

        path = os.path.join(os.path.dirname(__file__), 'delmonth.html')
        self.response.out.write(template.render(path, template_values))
예제 #7
0
    def post(self):

        # SESSION
        LoggedIn = False

        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("<center>")
            self.Writeln("<h1>Please Login </h1>")
            self.Writeln("</center>")
            return

#  Should only get to here is there's a session
        fname = self.session['fname']
        lname = self.session['lname']
        captain_keyname = self.session['keyname']

        self.Writeln("<html>")
        try:
            keyname = self.request.get('keyname')
            if (len(keyname) == 0):
                self.Writeln("<body bgcolor=#d2d2ee>")
                self.Writeln("<center><p><br><p><br>")
                self.Writeln("<h2>Please make a selection</h2>")
                return
        except:
            self.Writeln("<h2>Please make a selection.</h2>")
            return


#  Get the court and set the owner to None
        e = datastore.CourtTime.get_by_key_name(keyname)

        if (type(e.owner) is types.NoneType):
            self.Writeln("<body bgcolor=#d2d2ee>")
            self.Writeln("<center>")
            self.Writeln("<h2> Can't delete reservation </h2>")
            self.Writeln("<h2> Please go back and refresh the page </h2>")
            return

        e.owner = None
        db.put(e)

        #       use to return to calender month/year
        #  TODO  decide if to  implement in captain_unreserve.html page
        Month = e.date.month
        Year = e.date.year

        g = datastore.Captain.get_by_key_name(captain_keyname)
        g.count = g.count - 1
        count = g.count
        db.put(g)

        template_values = {

            #           'LoginForm' : library.LoginForm(),
            'Host': library.Host(),
            'Month': Month,
            'Year': Year,
            'Count': count,
            'Weekday': e.weekday,
            'Day': library.cday(e.start),
            'Start': library.ctime(e.start),
            'End': library.ctime(e.end),
            'Desc ': e.desc
        }

        path = os.path.join(os.path.dirname(__file__),
                            'captain_unreserve.html')
        self.response.out.write(template.render(path, template_values))
예제 #8
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))