-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagnet.py
73 lines (49 loc) · 1.33 KB
/
magnet.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
from google.appengine.ext import ndb
from google.appengine.ext.ndb import polymodel
class Magnet(polymodel.PolyModel):
IMAGE = 1
WORD = 2
CHARACTER = 3
owner = ndb.KeyProperty(kind='UserProfile', repeated=False)
text = ndb.StringProperty()
def get_width():
return 0
def get_height():
return 0
class ImageMagnet(Magnet):
def get_width():
return 2
def get_height():
return 2
def get_type():
return Magnet.IMAGE
class WordMagnet(Magnet):
def get_width():
return len(text)
def get_height():
return 1
def get_type():
return Magnet.WORD
class CharacterMagnet(Magnet):
def get_width():
return 1
def get_height():
return 1
def get_type():
return Magnet.CHARACTER
class MagnetFactory():
@staticmethod
def get_magnet(type_id):
if type_id == Magnet.CHARACTER:
return CharacterMagnet()
elif type_id == Magnet.WORD:
return WordMagnet()
elif type_id == Magnet.IMAGE:
return ImageMagnet()
class MagnetLocation(ndb.Model):
pass
class MagnetLayout(ndb.Model):
user_id = ndb.StringProperty(required=True)
locations = ndb.LocalStructuredProperty(MagnetLocation)
#Queries we care about:
#1 List of users containers