本文整理汇总了Python中peewee.DoesNotExist方法的典型用法代码示例。如果您正苦于以下问题:Python peewee.DoesNotExist方法的具体用法?Python peewee.DoesNotExist怎么用?Python peewee.DoesNotExist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类peewee
的用法示例。
在下文中一共展示了peewee.DoesNotExist方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: details
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def details(number):
number_entry = models.Number.select().where(models.Number.number == number).get()
try:
event = (
models.Event.select()
.where(models.Event.primary_number_id == number_entry)
.get()
)
except peewee.DoesNotExist:
event = None
info = hotline.telephony.lowlevel.get_number_info(number)
return flask.render_template(
"numberadmin/details.html",
number=number_entry,
event=event,
info=info,
NumberPool=models.NumberPool,
)
示例2: get_profile
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get_profile(identifier):
"""Get or create remote profile.
Fetch it from federation layer if necessary or if the public key is empty for some reason.
"""
try:
sender_profile = Profile.get(Profile.identifier == identifier)
if not sender_profile.public_key:
raise DoesNotExist
except DoesNotExist:
remote_profile = retrieve_remote_profile(identifier)
if not remote_profile:
logging.warning("Remote profile %s not found locally or remotely.", identifier)
return
sender_profile = Profile.from_remote_profile(remote_profile)
return sender_profile
示例3: accept_organizer_invitation
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def accept_organizer_invitation(
invitation_id: str, user: dict
) -> Optional[models.Event]:
try:
organizer_entry = get_event_organizer(invitation_id)
except peewee.DoesNotExist:
return None
if organizer_entry.user_email != user["email"]:
return None
organizer_entry.user_id = user["user_id"]
organizer_entry.user_name = user["name"]
organizer_entry.save()
return organizer_entry.event
示例4: check_db_schema_version
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def check_db_schema_version():
""" Ensure DB schema is correct version. Drop tables if not. """
db_schema_version = None
try:
db_schema_version = Setting.get(Setting.name == 'DB_SCHEMA_VERSION').value
except (peewee.OperationalError, peewee.DoesNotExist, peewee.ProgrammingError) as e:
printdbg("[info]: Can't get DB_SCHEMA_VERSION...")
printdbg("[info]: SCHEMA_VERSION (code) = [%s]" % SCHEMA_VERSION)
printdbg("[info]: DB_SCHEMA_VERSION = [%s]" % db_schema_version)
if (SCHEMA_VERSION != db_schema_version):
printdbg("[info]: Schema version mis-match. Syncing tables.")
try:
existing_table_names = db.get_tables()
existing_models = [m for m in db_models() if m._meta.db_table in existing_table_names]
if (existing_models):
printdbg("[info]: Dropping tables...")
db.drop_tables(existing_models, safe=False, cascade=False)
except (peewee.InternalError, peewee.OperationalError, peewee.ProgrammingError) as e:
print("[error] Could not drop tables: %s" % e)
示例5: get
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get(self, uid):
try:
user = Users.get(id=uid)
except DoesNotExist:
raise HTTPError(404)
self.response(dict(
id=user.id,
login=user.login,
email=user.email,
is_admin=user.is_admin,
disabled=user.disabled,
packages=list(
map(
lambda x: x.name,
user.package_set
)
)
))
示例6: post
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def post(self):
try:
login, password = self.json['login'], self.json['password']
except KeyError:
raise HTTPError(400)
try:
user = Users.check(login, password)
except DoesNotExist:
raise HTTPError(403)
self.set_secure_cookie(
'session',
(
user.id,
self.request.remote_ip,
IOLoop.current().time()
),
SESSION_DAYS
)
return self.response({
'login': user.login,
'is_admin': user.is_admin,
})
示例7: validate
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def validate(self, name, data):
"""
If there is a problem with the data, raise ValidationError.
:param name: The name of this field.
:param data: Dictionary of data for all fields.
:raises: ValidationError
"""
super().validate(name, data)
if self.value is not None:
try:
# self.query could be a query like "User.select()" or a model like "User"
# so ".select().where()" handles both cases.
self.value = [self.query.select().where(self.lookup_field == v).get() for v in self.value if v]
except (AttributeError, ValueError, peewee.DoesNotExist):
raise ValidationError('related', field=self.lookup_field.name, values=self.value)
示例8: get_or_create
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get_or_create(cls, **kwargs):
defaults = kwargs.pop('defaults', {})
query = cls.select()
for field, value in kwargs.items():
query = query.where(getattr(cls, field) == value)
try:
result = await query.get(), False
except cls.DoesNotExist:
try:
if defaults:
kwargs.update(defaults)
with cls._meta.database.atomic():
result = await cls.create(**kwargs), True
except IntegrityError as exc:
try:
result = await query.get(), False
except cls.DoesNotExist:
raise exc
return result
示例9: get_object
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get_object(source, *args):
"""Get object asynchronously.
:param source: mode class or query to get object from
:param args: lookup parameters
:return: model instance or raises ``peewee.DoesNotExist`` if object not
found
"""
warnings.warn("get_object() is deprecated, Manager.get() "
"should be used instead",
DeprecationWarning)
if isinstance(source, peewee.Query):
query = source
model = query.model
else:
query = source.select()
model = source
# Return first object from query
for obj in (await select(query.where(*args))):
return obj
# No objects found
raise model.DoesNotExist
示例10: get_player
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get_player(self, login=None, pk=None, lock=True):
"""
Get player by login or primary key.
:param login: Login.
:param pk: Primary Key identifier.
:param lock: Lock for a sec when receiving.
:return: Player or exception if not found
:rtype: pyplanet.apps.core.maniaplanet.models.Player
"""
try:
if login:
return await Player.get_by_login(login)
elif pk:
return await Player.get(pk=pk)
else:
raise PlayerNotFound('Player not found.')
except DoesNotExist:
if lock:
await asyncio.sleep(4)
return await self.get_player(login=login, pk=pk, lock=False)
else:
raise PlayerNotFound('Player not found.')
示例11: ask_upload
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def ask_upload():
"""
Ask for upload: to keep a max number of concurrent uploads
"""
if MODE == "standalone":
return jsonify({
"success": True,
"allowed": True
})
try:
s_id = request.form['s_id']
with Session.connect():
session = Session.get(s_id=s_id)
allowed = session.ask_for_upload(True)
return jsonify({
"success": True,
"allowed": allowed
})
except DoesNotExist:
return jsonify({"success": False, "message": "Session not initialized. Please refresh the page."})
示例12: is_in_gallery
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def is_in_gallery(id_job, mode="webserver"):
"""
Check whether a job is in the gallery
:param id_job: job id
:type id_job: str
:param mode: webserver or standalone
:type mode: str
:return: True if job is in the gallery, else False
:rtype: bool
"""
if mode == "webserver":
from dgenies.database import Gallery, Job
from peewee import DoesNotExist
try:
return len(Gallery.select().where(Gallery.job == Job.get(id_job=id_job))) > 0
except DoesNotExist:
return False
return False
示例13: status
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def status(self):
"""
Get job status and error. In webserver mode, get also mem peak and time elapsed
:return: status and other informations
:rtype: dict
"""
if MODE == "webserver":
try:
with Job.connect():
job = Job.get(Job.id_job == self.id_job)
return {"status": job.status, "mem_peak": job.mem_peak, "time_elapsed": job.time_elapsed,
"error": job.error}
except DoesNotExist:
return {"status": "unknown", "error": ""}
else:
try:
status, error = self.get_status_standalone(True)
return {"status": status, "mem_peak": None, "time_elapsed": None, "error": error}
except FileNotFoundError:
return {"status": "unknown", "error": ""}
示例14: delete
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def delete(self):
"""
Remove a job
:return:
* [0] Success of the deletion
* [1] Error message, if any (else empty string)
:rtype: (bool, str)
"""
if not os.path.exists(self.output_dir) or not os.path.isdir(self.output_dir):
return False, "Job does not exists"
if MODE == "webserver":
try:
job = Job.get(id_job=self.id_job)
except DoesNotExist:
pass
else:
is_gallery = Gallery.select().where(Gallery.job == job)
if is_gallery:
return False, "Delete a job that is in gallery is forbidden"
job.delete_instance()
shutil.rmtree(self.output_dir)
return True, ""
示例15: get_object_or_404
# 需要导入模块: import peewee [as 别名]
# 或者: from peewee import DoesNotExist [as 别名]
def get_object_or_404(query_or_model, *query):
if not isinstance(query_or_model, SelectQuery):
query_or_model = query_or_model.select()
try:
return query_or_model.where(*query).get()
except DoesNotExist:
abort(404)