-
Notifications
You must be signed in to change notification settings - Fork 1
/
auctionbase.py
executable file
·88 lines (71 loc) · 3.31 KB
/
auctionbase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
import sys; sys.path.insert(0, 'lib') # this line is necessary for the rest
import os # of the imports to work!
import web
import sqlitedb
from search_auctions import search_auctions
from jinja2 import Environment, FileSystemLoader
from datetime import datetime
from auction import auction
from sql_page import sql_page
###########################################################################################
##########################DO NOT CHANGE ANYTHING ABOVE THIS LINE!##########################
###########################################################################################
######################BEGIN HELPER METHODS######################
# helper method to convert times from database (which will return a string)
# into datetime objects. This will allow you to compare times correctly (using
# ==, !=, <, >, etc.) instead of lexicographically as strings.
# Sample use:
# current_time = string_to_time(sqlitedb.getTime())
def string_to_time(date_str):
return datetime.strptime(date_str, '%Y-%m-%d %H:%M:%S')
#####################END HELPER METHODS#####################
urls = ('/currtime', 'curr_time',
'/selecttime', 'select_time',
'/search_auctions', 'search_auctions',
'/auction','auction'
)
class curr_time(sql_page):
# A simple GET request, to '/currtime'
#
# Notice that we pass in `current_time' to our `render_template' call
# in order to have its value displayed on the web page
def GET(self):
current_time = sqlitedb.getTime()
return self.render_template('curr_time.html', time = current_time)
class select_time(sql_page):
# Aanother GET request, this time to the URL '/selecttime'
def GET(self):
current_time = sqlitedb.getTime()
return self.render_template('select_time.html', time = current_time)
# A POST request
#
# You can fetch the parameters passed to the URL
# by calling `web.input()' for **both** POST requests
# and GET requests
def POST(self):
post_params = web.input()
MM = post_params['MM']
dd = post_params['dd']
yyyy = post_params['yyyy']
HH = post_params['HH']
mm = post_params['mm']
ss = post_params['ss'];
enter_name = post_params['entername']
selected_time = '%s-%s-%s %s:%s:%s' % (yyyy, MM, dd, HH, mm, ss)
update_message = '(Hello, %s. Previously selected time was: %s.)' % (enter_name, selected_time)
try:
sqlitedb.updateTime(selected_time)
except:
update_message = 'ERROR: Time was not adjusted. Remember you cannot go back in time...duh!'
# Here, we assign `update_message' to `message', which means
# we'll refer to it in our template as `message'
return self.render_template('select_time.html', message = update_message)
###########################################################################################
##########################DO NOT CHANGE ANYTHING BELOW THIS LINE!##########################
###########################################################################################
if __name__ == '__main__':
web.internalerror = web.debugerror
app = web.application(urls, globals())
app.add_processor(web.loadhook(sqlitedb.enforceForeignKey))
app.run()