-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
49 lines (38 loc) · 1.11 KB
/
models.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
import datetime
import os
import requests
import json
import random
from google.cloud import ndb, storage
from lib.util import random_string, random_number, generate_token, random_name, find_urls
import config
# client connection
client = ndb.Client()
timestring = "%Y-%m-%dT%H:%M:%SZ"
# user inherits from flask_login and ndb
class Version(ndb.Model):
name = ndb.StringProperty() # name
allow = ndb.BooleanProperty() # allow to signup
created = ndb.DateTimeProperty()
@classmethod
with client.context():
cls(
name = name,
allow = False,
created = datetime.datetime.utcnow()
).put()
return cls.query(cls.email == email).get()
@classmethod
def get_all(cls):
with client.context():
# return cls.query(cls.updated < timestamp).fetch(10000)
return cls.query().fetch(200)
@classmethod
def get_allowed_by_email(cls, email):
with client.context():
return cls.query(cls.email == email, cls.allow == True).get()
@classmethod
def get_by_email(cls, email):
with client.context():
return cls.query(cls.email == email).get()