本文整理汇总了Python中google.appengine.ext.db.Model类的典型用法代码示例。如果您正苦于以下问题:Python Model类的具体用法?Python Model怎么用?Python Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkParameters
def checkParameters(self):
super(FixedReferenceProvider, self).checkParameters()
try:
Model.get(self.param_values['key'])
except:
raise ParameterValueError('Key %r does not exist!' %
self.param_values['key'])
示例2: __setattr__
def __setattr__(self,attrname,value):
"""
DataStore api stores all prop values say "email" is stored in "_email" so
we intercept the set attribute, see if it has changed, then check for an
onchanged method for that property to call
"""
if attrname.find('_') != 0:
if hasattr(self,'_' + attrname):
curval = getattr(self,'_' + attrname)
if curval != value:
self.__isdirty = True
if hasattr(self,attrname + '_onchange'):
getattr(self,attrname + '_onchange')(curval,value)
DBModel.__setattr__(self,attrname,value)
示例3: post
def post(self, object_key):
try:
obj = Model.get(object_key)
except BadKeyError:
self.error(405)
return
if self.request.get('value') == '' and not self.request.get('result'):
obj.delete()
return
if self.request.get('value'):
obj.value = self.request.get('value')
try:
obj.manager = self.request.environ['current_user']
except AttributeError:
pass
if self.request.get('result'):
obj.result = int(self.request.get('result'))
obj.put()
if obj.value is None:
obj.delete()
示例4: get
def get(self, key):
login_url = users.create_login_url(self.request.uri)
logout_url = users.create_logout_url(login_url)
user = self.request.environ['current_user']
emp = Model.get(key)
pr = PerformanceReview.all().filter('employee', emp).\
order('-date').get()
pr_form = pr.forms.filter('type', self.type).get()
if pr_form is None:
pr_form = PerformanceReviewForm(pr=pr,
type=self.type,
status='draft')
pr_form.put()
self.form = pr_form
if self.flag:
job_assessment = JobAssessment(form=pr_form)
job_assessment.put()
if self.flag:
self.redirect('/%(type)s/pr/get/%(type)s/%(key)s'
% {'type': self.type,
'key': pr.key()})
示例5: post
def post(self):
user = users.get_current_user()
ilmoitusVar = Model.get(self.request.get('key'))
ilmoitusVar.Ilmoittaja = user
OlenTemp =self.request.get('Olen')
ilmoitusVar.Olen = self.request.get('Olen')
etsinTemp = self.request.get('Etsin')
ilmoitusVar.Etsin = etsinTemp
PaikkaTemp = self.request.get('Paikka')
if PaikkaTemp!="":
ilmoitusVar.Paikka = self.request.get('Paikka')
ilmoitusVar.Time = datetime.time(int(self.request.get('Hour')), int(self.request.get('Min')))
DateTemp = self.request.get('Date')
Date_res = DateTemp.split('.')
ilmoitusVar.Date = datetime.date(int(Date_res[2]), int(Date_res[1]), int(Date_res[0]))
ilmoitusVar.Datetime = datetime.datetime(int(Date_res[2]), int(Date_res[1]), int(Date_res[0]), int(self.request.get('Hour')), int(self.request.get('Min')))
KuvausTemp = self.request.get('Kuvaus')
if KuvausTemp!="":
ilmoitusVar.Kuvaus = self.request.get('Kuvaus')
VastattuTemp =self.request.get('Vastattu')
if VastattuTemp!="":
ilmoitusVar.Vastattu = int(VastattuTemp)
AgeTemp = self.request.get('Age')
if AgeTemp != "":
ilmoitusVar.Age = int(self.request.get('Age'))
ilmoitusVar.put()
self.redirect('/modified')
示例6: post
def post(self):
notification = Notification(
item_cl = Model.get(Key(self.request.get('key'))),
message = self.request.get('message'),
user = users.User(self.request.get('email')),
is_cl = ("True" == self.request.get('is_cl')),
time = datetime.now(),
read = False)
notification.put()
示例7: post
def post(self):
user = users.get_current_user()
if not user:
self.redirect(users.create_login_url(self.request.uri))
else:
path=os.path.join(os.path.dirname(__file__),'confirm.html')
postKey = self.request.get('key')
ilmoitusVar = Model.get(postKey)
template_values = {"url":users.create_logout_url("/"), 'key':postKey, 'datetime':ilmoitusVar.Datetime, 'age':ilmoitusVar.Age, 'gender':ilmoitusVar.Olen, 'location':ilmoitusVar.Paikka }
self.response.out.write(template.render(path,template_values))
示例8: __call__
def __call__(self, environ, start_response):
current_user = users.get_current_user()
url = users.create_login_url("/")
req = Request(environ)
non_auth_urls = ['/create_role', '/p', '/users', '/add_emp', '/edit_user', '/upload_contacts', '/parse_xls']
if environ['PATH_INFO'] not in non_auth_urls:
if current_user is None:
try:
auth_header = req.headers['Authorization']
except KeyError:
resp = Response(status="307", location=url)
return resp(environ, start_response)
username, password = '', ''
try:
user_info = base64.decodestring(auth_header[6:])
username, password = user_info.split(':')
except ValueError:
resp = Response(status="401")
return resp(environ, start_response)
user_info = User.gql("WHERE username = :username ",
username=username).get()
if user_info is None:
resp = Response(status="401")
return resp(environ, start_response)
if not check_password(password, user_info.password):
resp = Response(status="401")
return resp(environ, start_response)
else:
email = str(current_user.email()).strip()
user_info = User.all().filter('email', email).get()
if user_info is None:
user_info = User(
email=current_user.email())
user_info.put()
environ["current_user"] = user_info
try:
environ["current_role"] = Model.get(user_info.role[0]).value
except IndexError:
environ["current_role"] = ''
resp = req.get_response(self.app)
return resp(environ, start_response)
示例9: post
def post(self):
super(UploadFile, self).post()
key = self.request.POST.get('key')
form = Model.get(key)
blob_info = blobstore.BlobInfo.get(self.blob_key)
form.file_key = str(blob_info.key())
form.file_name = blob_info.filename
form.put()
示例10: __new__
def __new__(cls,
return_tuple=False,
**kwargs):
if return_tuple:
props = set()
for name in cls.properties():
props.add(name)
props |= set(kwargs.keys())
props = list(props)
Model2 = namedtuple('Model2', props)
return Model2(**{name: (kwargs[name] if name in kwargs else None) for name in props})
else:
return Model.__new__(Model, **kwargs)
示例11: post
def post(self):
key = self.request.get('key')
email = self.request.get('email').strip()
user = User.get(key)
user.email = email
first_name = self.request.get('first_name').strip()
user.first_name = first_name
last_name = self.request.get('last_name').strip()
user.last_name = last_name
position = self.request.get('position')
user.position = position
first_date = self.request.get('first_date')
try:
first_date = datetime.datetime.strptime(first_date, '%Y-%m-%d').date()
except ValueError:
first_date = None
user.first_date = first_date
dept = self.request.get('dept')
dept_ref = Dept.all().filter('name', dept).get()
if dept_ref is None:
dept_ref = Dept(name=dept)
dept_ref.put()
user.dept = dept_ref
try:
manager = Model.get(self.request.get('manager'))
except BadKeyError:
manager = None
user.manager = manager
roles = self.request.get('role')[:-1].split(',')
user.role = []
for role in roles:
role_key = Role.gql("WHERE value = :role",
role=role).get().key()
user.role.append(role_key)
user.put()
self.response.out.write('You have successfully updated user info')
示例12: post
def post(self):
user = self.request.environ['current_user']
role_key = Role.gql("WHERE value = :hr", hr='hr').get().key()
if role_key not in user.role:
self.error(403)
return
start_str = self.request.get('start')
finish_str = self.request.get('finish')
type = self.request.get('type')
event = Event.all().filter('type', type).get()
try:
first_date = event.first_effective_date
except AttributeError:
first_date = None
employees = self.request.get('employees')[:-1].split(',')
try:
start = datetime.datetime.strptime(start_str, '%Y-%m-%d').date()
finish = datetime.datetime.strptime(finish_str, '%Y-%m-%d').date()
except ValueError:
self.response.out.write('incorrect date')
self.error(403)
return
description = "PR %s: %s-%s" % (type, start_str, finish_str)
period = PerformanceReviewPeriod(type=type,
description=description,
start_date=start,
finish_date=finish)
period.put()
for employee in employees:
if employee != '':
user = Model.get(employee)
pr = PerformanceReview(employee=user,
first_effective_date=first_date,
manager=user.manager,
period=period,
date=start)
pr.put()
self.response.out.write(period.key())
示例13: jsonToModel
def jsonToModel(Model, jsonString):
jsonObj = json.loads(jsonString)
if jsonObj.has_key(KEY_IDENTIFIER):
instance = Model.get(jsonObj[KEY_IDENTIFIER])
else:
instance = Model()
for property, value in jsonObj.items():
if hasattr(Model, property):
value = convertToGaeDatatype(instance, property, value)
setattr(instance, property, value)
else:
if property != KEY_IDENTIFIER:
logging.info('Ignored the "%s" property not found on the %s class' % (property, Model.__name__))
return instance
示例14: get
def get(self):
users = User.all().order('first_name').fetch(1000)
for user in users:
user.roles = ''
for role in user.role:
user.roles = user.roles + Model.get(role).value + ' '
upload_url_first_date = blobstore.create_upload_url('/upload_first_date')
upload_url = blobstore.create_upload_url('/upload_contacts')
self.template_values.update({'users': users,
'upload_url_first_date': upload_url_first_date,
'upload_url': upload_url})
self.response.out.write(template.render(self.path,
self.template_values))
示例15: get
def get(self):
user = self.request.environ['current_user']
current_role = self.request.environ['current_role']
email = None
if user is not None:
email = user.email
login_url = users.create_login_url(self.request.uri)
logout_url = users.create_logout_url(login_url)
roles = []
for role_key in user.role:
roles.append(Model.get(role_key).value)
template_values = {
'username': email,
'user': user,
'roles': roles,
'current_role': current_role,
'logout_url': logout_url}
path = 'templates/index.html'
self.response.out.write(template.render(path, template_values))