本文整理汇总了Python中util.jsonify_model_db函数的典型用法代码示例。如果您正苦于以下问题:Python jsonify_model_db函数的具体用法?Python jsonify_model_db怎么用?Python jsonify_model_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jsonify_model_db函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin_config_update
def admin_config_update():
config_db = model.Config.get_master_db()
form = ConfigUpdateForm(obj=config_db)
if form.validate_on_submit():
form.populate_obj(config_db)
if not config_db.flask_secret_key:
config_db.flask_secret_key = util.uuid()
config_db.put()
reload(config)
app.config.update(CONFIG_DB=config_db)
return flask.redirect(flask.url_for("welcome"))
if flask.request.path.startswith("/_s/"):
return util.jsonify_model_db(config_db)
instances_url = None
if config.PRODUCTION:
instances_url = "%s?app_id=%s&version_id=%s" % (
"https://appengine.google.com/instances",
app_identity.get_application_id(),
config.CURRENT_VERSION_ID,
)
return flask.render_template(
"admin/config_update.html",
title=_("Admin Config"),
html_class="admin-config",
form=form,
config_db=config_db,
instances_url=instances_url,
has_json=True,
)
示例2: admin_config_update
def admin_config_update():
config_db = model.Config.get_master_db()
form = ConfigUpdateForm(obj=config_db)
if form.validate_on_submit():
form.populate_obj(config_db)
config_db.put()
reload(config)
app.config.update(CONFIG_DB=config_db)
return flask.redirect(flask.url_for('welcome'))
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(config_db)
instances_url = None
if config.PRODUCTION:
instances_url = '%s?app_id=%s&version_id=%s' % (
'https://appengine.google.com/instances',
app_identity.get_application_id(),
config.CURRENT_VERSION_ID,
)
return flask.render_template(
'admin/config_update.html',
title='Admin Config',
html_class='admin-config',
form=form,
config_db=config_db,
instances_url=instances_url,
has_json=True,
)
示例3: profile
def profile():
form = ProfileUpdateForm()
user_db = auth.current_user_db()
if form.validate_on_submit():
user_db.name = form.name.data.strip()
user_db.email = form.email.data.strip().lower()
user_db.locale = form.locale.data.strip()
user_db.put()
return flask.redirect(flask.url_for(
'set_locale', locale=user_db.locale, next=flask.url_for('welcome')
))
if not form.errors:
form.name.data = user_db.name
form.email.data = user_db.email or ''
form.locale.data = user_db.locale or auth.get_locale()
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(user_db)
return flask.render_template(
'profile.html',
title=_('Profile'),
html_class='profile',
form=form,
user_db=user_db,
)
示例4: user_update
def user_update(user_id):
user_db = model.User.get_by_id(user_id)
if not user_db:
flask.abort(404)
form = UserUpdateForm(obj=user_db)
for permission in user_db.permissions:
form.permissions.choices.append((permission, permission))
form.permissions.choices = sorted(set(form.permissions.choices))
if form.validate_on_submit():
if not util.is_valid_username(form.username.data):
form.username.errors.append('This username is invalid.')
elif not model.User.is_username_available(form.username.data, user_db.key):
form.username.errors.append('This username is already taken.')
else:
form.populate_obj(user_db)
if auth.current_user_id() == user_db.key.id():
user_db.admin = True
user_db.active = True
user_db.put()
return flask.redirect(flask.url_for(
'user_list', order='-modified', active=user_db.active,
))
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(user_db)
return flask.render_template(
'user/user_update.html',
title=user_db.name,
html_class='user-update',
form=form,
user_db=user_db,
)
示例5: resource_update
def resource_update(resource_id):
resource_db = model.Resource.get_by_id(resource_id)
if not resource_db or resource_db.user_key != auth.current_user_key():
return flask.abort(404)
form = ResourceUpdateForm()
if form.validate_on_submit():
resource_db.name = form.name.data
resource_db.put()
return flask.redirect(flask.url_for(
'resource_view', resource_id=resource_db.key.id(),
))
if not form.errors:
form.name.data = resource_db.name
if flask.request.path.startswith('/_s/'):
if form.errors:
return flask.abort(400)
return util.jsonify_model_db(resource_db)
return flask.render_template(
'resource/resource_update.html',
html_class='resource-update',
title='%s' % (resource_db.name),
resource_db=resource_db,
form=form,
has_json=True,
)
示例6: profile
def profile():
user_db = auth.current_user_db()
form = ProfileUpdateForm(obj=user_db)
if form.validate_on_submit():
email = form.email.data
if email and not user_db.is_email_available(email, user_db.key):
form.email.errors.append('This email is already taken.')
if not form.errors:
send_verification = not user_db.token or user_db.email != email
form.populate_obj(user_db)
if send_verification:
user_db.verified = False
task.verify_email_notification(user_db)
user_db.put()
return flask.redirect(flask.url_for('welcome'))
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(user_db)
return flask.render_template(
'profile.html',
title=user_db.name,
html_class='profile',
form=form,
user_db=user_db,
has_json=True,
)
示例7: profile
def profile():
user_db = auth.current_user_db()
form = ProfileUpdateForm(obj=user_db)
if form.validate_on_submit():
send_verification = not user_db.token or user_db.email != form.email.data
form.populate_obj(user_db)
if send_verification:
user_db.verified = False
task.verify_email_notification(user_db)
user_db.put()
return flask.redirect(flask.url_for(
'set_locale', locale=user_db.locale, next=flask.url_for('welcome')
))
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(user_db)
return flask.render_template(
'profile.html',
title=user_db.name,
html_class='profile',
form=form,
user_db=user_db,
has_json=True,
)
示例8: get_product
def get_product(key_id):
product = Product.retrieve_by_id(key_id)
if not product:
return jsonify({"success": False, "msg": "Product with id:%s not found." % key_id})
if request.method == "DELETE":
@check_write_permission
def delete_product():
product.key.delete()
return jsonify({"success": True, "msg": "Product id:%s deleted" % key_id})
return delete_product()
if request.method == "PUT":
@check_write_permission
def put_product():
flag, model = load_data()
if not flag:
return model
if model_populate(model, product) or param("force_save"):
product.put()
return jsonify({"success": True, "msg": "Product has been updated."})
else:
return jsonify({"success": False, "msg": "Product has not been updated."})
return put_product()
return jsonify_model_db(product)
示例9: get_post_json
def get_post_json(key_id):
if not key_id:
raise ApiException('Invalid request: "id" parameter not found.')
product = None
if key_id:
product = Post.retrieve_by_id(key_id)
if not product and key_id:
raise ApiException('Post with "%s" == %s not found' % ('id', key_id), status=404)
return jsonify_model_db(product)
示例10: resource_delete
def resource_delete(resource_id):
resource_db = model.Resource.get_by_id(resource_id)
if not resource_db or resource_db.user_key != auth.current_user_key():
return flask.abort(404)
blobstore.BlobInfo.get(resource_db.blob_key).delete()
resource_db.key.delete()
return util.jsonify_model_db(resource_db)
示例11: profile
def profile():
user_db = auth.current_user_db()
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(user_db)
return flask.render_template(
'profile/profile.html',
title=user_db.name,
html_class='profile-view',
user_db=user_db,
has_json=True,
)
示例12: profile
def profile():
next_url = util.get_next_url()
customer_fields_require = False
user_db = current_user_db()
form = ProfileUpdateForm(obj=user_db)
if form.validate_on_submit():
form.populate_obj(user_db)
user_db.put()
if not "customer_require" in flask.request.form:
flask.flash(u"Профиль успешно обновлен")
return flask.redirect(flask.url_for("pages.index"))
else:
if not form.email.data or not form.company.data:
if not form.email.data:
form.email.errors.append(u"Это поле обязательно для заполнения")
if not form.company.data:
form.company.errors.append(u"Это поле обязательно для заполнения")
customer_fields_require = True
else:
msg = u"Профиль успешно обновлен, "
request = PartnerRequest.query(PartnerRequest.customer == user_db.key)
if request.count():
msg += u"Вы уже делали запрос на сотрудничество, запрос "
request = request.get()
if request.status == REQUEST_STATUS["now"]:
msg += u"еще не рассмотрен"
elif request.status == REQUEST_STATUS["accept"]:
msg += u"одобрен"
elif request.status == REQUEST_STATUS["admin"]:
msg += u"одобрен и Вам были даны права администратора"
else:
msg += u"отклонен"
else:
msg += u"в ближайшее время с Вами свяжется наш менеджер"
request = PartnerRequest(customer=user_db.key)
request.put()
flask.flash(msg)
return flask.redirect(flask.url_for("pages.index"))
if flask.request.path.startswith("/_json/"):
return util.jsonify_model_db(user_db)
return flask.render_template(
"auth/profile.html",
title="Profile",
html_class="profile",
form=form,
user_db=user_db,
customer_fields_require=customer_fields_require,
next_url=next_url,
)
示例13: resource_view
def resource_view(resource_id):
resource_db = model.Resource.get_by_id(resource_id)
if not resource_db or resource_db.user_key != auth.current_user_key():
return flask.abort(404)
if flask.request.path.startswith('/_s/'):
return util.jsonify_model_db(resource_db)
return flask.render_template(
'resource/resource_view.html',
html_class='resource-view',
title='%s' % (resource_db.name),
resource_db=resource_db,
)
示例14: profile
def profile():
user_db = auth.current_user_db()
form = ProfileUpdateForm(obj=user_db)
if form.validate_on_submit():
form.populate_obj(user_db)
user_db.put()
return flask.redirect(flask.url_for("welcome"))
if flask.request.path.startswith("/_s/"):
return util.jsonify_model_db(user_db)
return flask.render_template(
"profile.html", title=user_db.name, html_class="profile", form=form, user_db=user_db, has_json=True
)
示例15: profile
def profile():
form = ProfileUpdateForm()
user_db = auth.current_user_db()
if form.validate_on_submit():
user_db.name = form.name.data.strip()
user_db.email = form.email.data.strip().lower()
user_db.put()
return flask.redirect(flask.url_for("welcome"))
if not form.errors:
form.name.data = user_db.name
form.email.data = user_db.email or ""
if flask.request.path.startswith("/_s/"):
return util.jsonify_model_db(user_db)
return flask.render_template("profile.html", title="Profile", html_class="profile", form=form, user_db=user_db)