-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsponsorship.py
42 lines (36 loc) · 1.27 KB
/
sponsorship.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
from google.appengine.ext import ndb
from google.appengine.api import memcache
import tournament
# Sponsorship information.
class Sponsorship(ndb.Model):
name = ndb.StringProperty()
level = ndb.StringProperty()
sequence = ndb.IntegerProperty()
price = ndb.IntegerProperty()
unique = ndb.BooleanProperty()
sold = ndb.BooleanProperty()
golfers_included = ndb.IntegerProperty()
# Get a list of sponsorships.
def get_sponsorships(level):
t = tournament.get_tournament()
sponsorships = memcache.get('%s/%s' % (t.name, level))
if sponsorships is not None:
return sponsorships
q = Sponsorship.query(ancestor = t.key)
if level != "all":
q = q.filter(Sponsorship.level == level)
q = q.order(Sponsorship.sequence)
sponsorships = q.fetch(30)
if not sponsorships:
s = Sponsorship(parent = t.key, name = level, level = level, sequence = 1, price = 1000, unique = False, sold = False, golfers_included = 4)
sponsorships.append(s)
memcache.add('%s/%s' % (t.name, level), sponsorships, 60*60*24)
return sponsorships
def clear_sponsorships_cache():
t = tournament.get_tournament()
memcache.delete_multi(["%s/all" % t.name,
"%s/Double Eagle" % t.name,
"%s/Hole in One" % t.name,
"%s/Eagle" % t.name,
"%s/Birdie" % t.name,
"%s/Angel" % t.name])