-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdistributors.py
78 lines (70 loc) · 2.28 KB
/
distributors.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
#!/usr/bin/python
#Licensed under the GPLv2 (not later versions)
#see LICENSE.txt for details
from google.appengine.api import memcache
import logging
from model import Distributor, Contributor
def Distributor_authorized(av):
#True if av is on the authorized distributor list, else False
token = "dist_auth_%s" % av
memrecord = memcache.get(token)
if memrecord is None:
#dist is not in memcache, check db
dbrecord = Distributor.gql('WHERE avkey = :1', av).get()
if dbrecord is None:
memcache.set(token, False)
return False
else:
memcache.set(token, True)
return True
else:
#dist is in memcache. check value
if memrecord:
return True
else:
return False
def Distributor_add(av, name):
record = Distributor.gql('WHERE avkey = :1', av).get()
if record is None:
NewDist = Distributor(avkey = av, avname = name)
NewDist.put()
token = "dist_auth_%s" % av
memcache.set(token, True)
def Distributor_delete(av, name):
record = Distributor.gql('WHERE avkey = :1', av).get()
if record is not None:
record.delete()
token = "dist_auth_%s" % av
memcache.delete(token)
def Contributor_authorized(av):
#True if av is on the authorized distributor list, else False
token = "contr_auth_%s" % av
memrecord = memcache.get(token)
if memrecord is None:
#dist is not in memcache, check db
dbrecord = Contributor.gql('WHERE avkey = :1', av).get()
if dbrecord is None:
memcache.set(token, False)
return False
else:
memcache.set(token, True)
return True
else:
#dist is in memcache. check value
if memrecord:
return True
else:
return False
def Contributor_add(av, name):
record = Contributor.gql('WHERE avkey = :1', av).get()
if record is None:
NewDist = Contributor(avkey = av, avname = name)
NewDist.put()
token = "contr_auth_%s" % av
memcache.set(token, True)
def Contributor_delete(av, name):
record = Contributor.gql('WHERE avkey = :1', av).get()
if record is not None:
record.delete()
token = "contr_auth_%s" % av
memcache.delete(token)