PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/v2ex/babel/__init__.py

https://github.com/liaowang11/v2ex
Python | 270 lines | 267 code | 3 blank | 0 comment | 0 complexity | 3f9f5791f88cdd997810935dd84d0f01 MD5 | raw file
  1. SYSTEM_VERSION = '2.4.2'
  2. import datetime
  3. import hashlib
  4. from google.appengine.ext import db
  5. from google.appengine.api import memcache
  6. from google.appengine.api import users
  7. class Member(db.Model):
  8. num = db.IntegerProperty(indexed=True)
  9. auth = db.StringProperty(required=False, indexed=True)
  10. deactivated = db.IntegerProperty(required=True, default=0)
  11. username = db.StringProperty(required=False, indexed=True)
  12. username_lower = db.StringProperty(required=False, indexed=True)
  13. password = db.StringProperty(required=False, indexed=True)
  14. email = db.StringProperty(required=False, indexed=True)
  15. email_verified = db.IntegerProperty(required=False, indexed=True, default=0)
  16. website = db.StringProperty(required=False, default='')
  17. psn = db.StringProperty(required=False)
  18. twitter = db.StringProperty(required=False, default='')
  19. twitter_oauth = db.IntegerProperty(required=False, default=0)
  20. twitter_oauth_key = db.StringProperty(required=False)
  21. twitter_oauth_secret = db.StringProperty(required=False)
  22. twitter_oauth_string = db.StringProperty(required=False)
  23. twitter_sync = db.IntegerProperty(required=False, default=0)
  24. twitter_id = db.IntegerProperty(required=False)
  25. twitter_name = db.StringProperty(required=False)
  26. twitter_screen_name = db.StringProperty(required=False)
  27. twitter_location = db.StringProperty(required=False)
  28. twitter_description = db.TextProperty(required=False)
  29. twitter_profile_image_url = db.StringProperty(required=False)
  30. twitter_url = db.StringProperty(required=False)
  31. twitter_statuses_count = db.IntegerProperty(required=False)
  32. twitter_followers_count = db.IntegerProperty(required=False)
  33. twitter_friends_count = db.IntegerProperty(required=False)
  34. twitter_favourites_count = db.IntegerProperty(required=False)
  35. location = db.StringProperty(required=False, default='')
  36. tagline = db.TextProperty(required=False, default='')
  37. bio = db.TextProperty(required=False, default='')
  38. avatar_large_url = db.StringProperty(required=False, indexed=False)
  39. avatar_normal_url = db.StringProperty(required=False, indexed=False)
  40. avatar_mini_url = db.StringProperty(required=False, indexed=False)
  41. created = db.DateTimeProperty(auto_now_add=True)
  42. last_modified = db.DateTimeProperty(auto_now=True)
  43. last_signin = db.DateTimeProperty()
  44. blocked = db.TextProperty(required=False, default='')
  45. l10n = db.StringProperty(default='en')
  46. favorited_nodes = db.IntegerProperty(required=True, default=0)
  47. favorited_topics = db.IntegerProperty(required=True, default=0)
  48. favorited_members = db.IntegerProperty(required=True, default=0)
  49. followers_count = db.IntegerProperty(required=True, default=0)
  50. level = db.IntegerProperty(required=True, default=1000)
  51. def hasFavorited(self, something):
  52. if type(something).__name__ == 'Node':
  53. n = 'r/n' + str(something.num) + '/m' + str(self.num)
  54. r = memcache.get(n)
  55. if r:
  56. return r
  57. else:
  58. q = db.GqlQuery("SELECT * FROM NodeBookmark WHERE node =:1 AND member = :2", something, self)
  59. if q.count() > 0:
  60. memcache.set(n, True, 86400 * 14)
  61. return True
  62. else:
  63. memcache.set(n, False, 86400 * 14)
  64. return False
  65. else:
  66. if type(something).__name__ == 'Topic':
  67. n = 'r/t' + str(something.num) + '/m' + str(self.num)
  68. r = memcache.get(n)
  69. if r:
  70. return r
  71. else:
  72. q = db.GqlQuery("SELECT * FROM TopicBookmark WHERE topic =:1 AND member = :2", something, self)
  73. if q.count() > 0:
  74. memcache.set(n, True, 86400 * 14)
  75. return True
  76. else:
  77. memcache.set(n, False, 86400 * 14)
  78. return False
  79. else:
  80. if type(something).__name__ == 'Member':
  81. n = 'r/m' + str(something.num) + '/m' + str(self.num)
  82. r = memcache.get(n)
  83. if r:
  84. return r
  85. else:
  86. q = db.GqlQuery("SELECT * FROM MemberBookmark WHERE one =:1 AND member_num = :2", something, self.num)
  87. if q.count() > 0:
  88. memcache.set(n, True, 86400 * 14)
  89. return True
  90. else:
  91. memcache.set(n, False, 86400 * 14)
  92. return False
  93. else:
  94. return False
  95. class Counter(db.Model):
  96. name = db.StringProperty(required=False, indexed=True)
  97. value = db.IntegerProperty()
  98. created = db.DateTimeProperty(auto_now_add=True)
  99. last_increased = db.DateTimeProperty(auto_now=True)
  100. class Section(db.Model):
  101. num = db.IntegerProperty(indexed=True)
  102. name = db.StringProperty(required=False, indexed=True)
  103. title = db.StringProperty(required=False, indexed=True)
  104. title_alternative = db.StringProperty(required=False, indexed=True)
  105. header = db.TextProperty(required=False)
  106. footer = db.TextProperty(required=False)
  107. nodes = db.IntegerProperty(default=0)
  108. created = db.DateTimeProperty(auto_now_add=True)
  109. last_modified = db.DateTimeProperty(auto_now=True)
  110. class Node(db.Model):
  111. num = db.IntegerProperty(indexed=True)
  112. section_num = db.IntegerProperty(indexed=True)
  113. name = db.StringProperty(required=False, indexed=True)
  114. title = db.StringProperty(required=False, indexed=True)
  115. title_alternative = db.StringProperty(required=False, indexed=True)
  116. header = db.TextProperty(required=False)
  117. footer = db.TextProperty(required=False)
  118. sidebar = db.TextProperty(required=False)
  119. category = db.StringProperty(required=False, indexed=True)
  120. topics = db.IntegerProperty(default=0)
  121. created = db.DateTimeProperty(auto_now_add=True)
  122. last_modified = db.DateTimeProperty(auto_now=True)
  123. class Topic(db.Model):
  124. num = db.IntegerProperty(indexed=True)
  125. node = db.ReferenceProperty(Node)
  126. node_num = db.IntegerProperty(indexed=True)
  127. node_name = db.StringProperty(required=False, indexed=True)
  128. node_title = db.StringProperty(required=False, indexed=False)
  129. member = db.ReferenceProperty(Member)
  130. member_num = db.IntegerProperty(indexed=True)
  131. title = db.StringProperty(required=False, indexed=True)
  132. content = db.TextProperty(required=False)
  133. content_rendered = db.TextProperty(required=False)
  134. content_length = db.IntegerProperty(default=0)
  135. hits = db.IntegerProperty(default=0)
  136. stars = db.IntegerProperty(required=True, default=0)
  137. replies = db.IntegerProperty(default=0)
  138. created_by = db.StringProperty(required=False, indexed=True)
  139. last_reply_by = db.StringProperty(required=False, indexed=True)
  140. source = db.StringProperty(required=False, indexed=True)
  141. type = db.StringProperty(required=False, indexed=True)
  142. type_color = db.StringProperty(required=False)
  143. created = db.DateTimeProperty(auto_now_add=True)
  144. last_modified = db.DateTimeProperty(auto_now=True)
  145. last_touched = db.DateTimeProperty()
  146. class Reply(db.Model):
  147. num = db.IntegerProperty(indexed=True)
  148. topic = db.ReferenceProperty(Topic)
  149. topic_num = db.IntegerProperty(indexed=True)
  150. member = db.ReferenceProperty(Member)
  151. member_num = db.IntegerProperty(indexed=True)
  152. content = db.TextProperty(required=False)
  153. source = db.StringProperty(required=False, indexed=True)
  154. created_by = db.StringProperty(required=False, indexed=True)
  155. created = db.DateTimeProperty(auto_now_add=True)
  156. last_modified = db.DateTimeProperty(auto_now=True)
  157. class Avatar(db.Model):
  158. num = db.IntegerProperty(indexed=True)
  159. name = db.StringProperty(required=False, indexed=True)
  160. content = db.BlobProperty()
  161. class Note(db.Model):
  162. num = db.IntegerProperty(indexed=True)
  163. member = db.ReferenceProperty(Member)
  164. member_num = db.IntegerProperty(indexed=True)
  165. title = db.StringProperty(required=False, indexed=True)
  166. content = db.TextProperty(required=False)
  167. body = db.TextProperty(required=False)
  168. length = db.IntegerProperty(indexed=False, default=0)
  169. edits = db.IntegerProperty(indexed=False, default=1)
  170. created = db.DateTimeProperty(auto_now_add=True)
  171. last_modified = db.DateTimeProperty(auto_now=True)
  172. class PasswordResetToken(db.Model):
  173. token = db.StringProperty(required=False, indexed=True)
  174. email = db.StringProperty(required=False, indexed=True)
  175. member = db.ReferenceProperty(Member)
  176. valid = db.IntegerProperty(required=False, indexed=True, default=1)
  177. timestamp = db.IntegerProperty(required=False, indexed=True, default=0)
  178. class Place(db.Model):
  179. num = db.IntegerProperty(required=False, indexed=True)
  180. ip = db.StringProperty(required=False, indexed=True)
  181. name = db.StringProperty(required=False, indexed=False)
  182. visitors = db.IntegerProperty(required=False, default=0, indexed=True)
  183. longitude = db.FloatProperty(required=False, default=0.0, indexed=True)
  184. latitude = db.FloatProperty(required=False, default=0.0, indexed=True)
  185. created = db.DateTimeProperty(auto_now_add=True)
  186. last_modified = db.DateTimeProperty(auto_now=True)
  187. class PlaceMessage(db.Model):
  188. num = db.IntegerProperty(indexed=True)
  189. place = db.ReferenceProperty(Place)
  190. place_num = db.IntegerProperty(indexed=True)
  191. member = db.ReferenceProperty(Member)
  192. content = db.TextProperty(required=False)
  193. in_reply_to = db.SelfReferenceProperty()
  194. source = db.StringProperty(required=False, indexed=True)
  195. created = db.DateTimeProperty(auto_now_add=True)
  196. class Checkin(db.Model):
  197. place = db.ReferenceProperty(Place)
  198. member = db.ReferenceProperty(Member)
  199. last_checked_in = db.DateTimeProperty(auto_now=True)
  200. class Site(db.Model):
  201. num = db.IntegerProperty(required=False, indexed=True)
  202. title = db.StringProperty(required=False, indexed=False)
  203. slogan = db.StringProperty(required=False, indexed=False)
  204. description = db.TextProperty(required=False)
  205. domain = db.StringProperty(required=False, indexed=False)
  206. analytics = db.StringProperty(required=False, indexed=False)
  207. home_categories = db.TextProperty(required=False, indexed=False)
  208. meta = db.TextProperty(required=False, default='')
  209. home_top = db.TextProperty(required=False, default='')
  210. theme = db.StringProperty(required=False, default='default')
  211. l10n = db.StringProperty(default='en')
  212. use_topic_types = db.BooleanProperty(default=False)
  213. topic_types = db.TextProperty(default='')
  214. topic_view_level = db.IntegerProperty(required=True, default=-1)
  215. topic_create_level = db.IntegerProperty(required=True, default=1000)
  216. topic_reply_level = db.IntegerProperty(required=True, default=1000)
  217. class Minisite(db.Model):
  218. num = db.IntegerProperty(required=False, indexed=True)
  219. name = db.StringProperty(required=False, indexed=True)
  220. title = db.StringProperty(required=False, indexed=False)
  221. description = db.TextProperty(default='')
  222. pages = db.IntegerProperty(default=0)
  223. created = db.DateTimeProperty(auto_now_add=True)
  224. last_modified = db.DateTimeProperty(auto_now=True)
  225. class Page(db.Model):
  226. num = db.IntegerProperty(required=False, indexed=True)
  227. name = db.StringProperty(required=False, indexed=True)
  228. title = db.StringProperty(required=False, indexed=False)
  229. minisite = db.ReferenceProperty(Minisite)
  230. content = db.TextProperty(default='')
  231. content_rendered = db.TextProperty(default='')
  232. content_type = db.StringProperty(default='text/html')
  233. weight = db.IntegerProperty(required=True, default=0)
  234. mode = db.IntegerProperty(required=True, default=0)
  235. hits = db.IntegerProperty(required=True, default=0)
  236. created = db.DateTimeProperty(auto_now_add=True)
  237. last_modified = db.DateTimeProperty(auto_now=True)
  238. class NodeBookmark(db.Model):
  239. node = db.ReferenceProperty(Node, indexed=True)
  240. member = db.ReferenceProperty(Member, indexed=True)
  241. created = db.DateTimeProperty(auto_now_add=True)
  242. class TopicBookmark(db.Model):
  243. topic = db.ReferenceProperty(Topic, indexed=True)
  244. member = db.ReferenceProperty(Member, indexed=True)
  245. created = db.DateTimeProperty(auto_now_add=True)
  246. class MemberBookmark(db.Model):
  247. one = db.ReferenceProperty(Member, indexed=True)
  248. member_num = db.IntegerProperty(indexed=True)
  249. created = db.DateTimeProperty(auto_now_add=True)