-
Notifications
You must be signed in to change notification settings - Fork 0
/
auction.py
55 lines (50 loc) · 1.95 KB
/
auction.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
import os
import cgi
import logging
import webapp2
from google.appengine.api import images
from django.template.loaders.filesystem import Loader
from django.template.loader import render_to_string
import auctionitem
import capabilities
import tournament
server_software = os.environ.get('SERVER_SOFTWARE')
dev_server = True if server_software and server_software.startswith("Development") else False
class Auction(webapp2.RequestHandler):
def get(self):
t = tournament.get_tournament()
dinner_date = "%s, %s %d, %d" % (t.dinner_date.strftime("%A"), t.dinner_date.strftime("%B"),
t.dinner_date.day, t.dinner_date.year)
live_auction_items = auctionitem.get_auction_items(t, 'l')
live_intro = ""
if live_auction_items and live_auction_items[0].sequence == 0:
live_intro = live_auction_items[0].description
live_auction_items = live_auction_items[1:]
silent_auction_items = auctionitem.get_auction_items(t, 's')
silent_intro = ""
if silent_auction_items and silent_auction_items[0].sequence == 0:
silent_intro = silent_auction_items[0].description
silent_auction_items = silent_auction_items[1:]
caps = capabilities.get_current_user_caps()
template_values = {
'live_intro': live_intro,
'live_auction_items': live_auction_items,
'silent_intro': silent_intro,
'silent_auction_items': silent_auction_items,
'dinner_date': dinner_date,
'capabilities': caps
}
self.response.out.write(render_to_string('auction.html', template_values))
class ServeImage(webapp2.RequestHandler):
def get(self, id):
t = tournament.get_tournament()
item = auctionitem.AuctionItem.get_by_id(long(id), parent = t.key)
if item and item.image:
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.headers['Cache-Control'] = 'public, max-age=86400;'
self.response.out.write(item.image)
else:
self.error(404)
app = webapp2.WSGIApplication([('/auction', Auction),
('/img/(.*)', ServeImage)],
debug=dev_server)