本文整理匯總了Python中django.db.reset_queries方法的典型用法代碼示例。如果您正苦於以下問題:Python db.reset_queries方法的具體用法?Python db.reset_queries怎麽用?Python db.reset_queries使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.db
的用法示例。
在下文中一共展示了db.reset_queries方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: check_password
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def check_password(environ, username, password):
"""
Authenticates against Django's auth database
mod_wsgi docs specify None, True, False as return value depending
on whether the user exists and authenticates.
"""
UserModel = auth.get_user_model()
# db connection state is managed similarly to the wsgi handler
# as mod_wsgi may call these functions outside of a request/response cycle
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return None
if not user.is_active:
return None
return user.check_password(password)
finally:
db.close_old_connections()
示例2: groups_for_user
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def groups_for_user(environ, username):
"""
Authorizes a user based on groups
"""
UserModel = auth.get_user_model()
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return []
if not user.is_active:
return []
return [force_bytes(group.name) for group in user.groups.all()]
finally:
db.close_old_connections()
示例3: check_password
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def check_password(environ, username, password):
"""
Authenticate against Django's auth database.
mod_wsgi docs specify None, True, False as return value depending
on whether the user exists and authenticates.
"""
# db connection state is managed similarly to the wsgi handler
# as mod_wsgi may call these functions outside of a request/response cycle
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return None
if not user.is_active:
return None
return user.check_password(password)
finally:
db.close_old_connections()
示例4: check_password
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def check_password(environ, username, password):
"""
Authenticates against Django's auth database
mod_wsgi docs specify None, True, False as return value depending
on whether the user exists and authenticates.
"""
# db connection state is managed similarly to the wsgi handler
# as mod_wsgi may call these functions outside of a request/response cycle
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return None
if not user.is_active:
return None
return user.check_password(password)
finally:
db.close_old_connections()
示例5: groups_for_user
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def groups_for_user(environ, username):
"""
Authorizes a user based on groups
"""
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return []
if not user.is_active:
return []
return [force_bytes(group.name) for group in user.groups.all()]
finally:
db.close_old_connections()
示例6: __enter__
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def __enter__(self):
self.force_debug_cursor = self.connection.force_debug_cursor
self.connection.force_debug_cursor = True
self.initial_queries = len(self.connection.queries_log)
self.final_queries = None
request_started.disconnect(reset_queries)
return self
示例7: __exit__
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def __exit__(self, exc_type, exc_value, traceback):
self.connection.force_debug_cursor = self.force_debug_cursor
request_started.connect(reset_queries)
if exc_type is not None:
return
self.final_queries = len(self.connection.queries_log)
示例8: __enter__
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def __enter__(self):
self.force_debug_cursor = self.connection.force_debug_cursor
self.connection.force_debug_cursor = True
# Run any initialization queries if needed so that they won't be
# included as part of the count.
self.connection.ensure_connection()
self.initial_queries = len(self.connection.queries_log)
self.final_queries = None
request_started.disconnect(reset_queries)
return self
示例9: groups_for_user
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def groups_for_user(environ, username):
"""
Authorize a user based on groups
"""
db.reset_queries()
try:
try:
user = UserModel._default_manager.get_by_natural_key(username)
except UserModel.DoesNotExist:
return []
if not user.is_active:
return []
return [force_bytes(group.name) for group in user.groups.all()]
finally:
db.close_old_connections()
示例10: run
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def run(self):
os.umask(022)
while True:
ddb.reset_queries()
jobs = queue.Job.objects.filter(state=1, account__host__state=1,
created__lt=datetime.now() - timedelta(seconds=-200000000))
for job in jobs:
check_die()
if job.is_done():
jlogger.info('Collected %s' % job)
job.collect()
check_die(20)
示例11: django_context
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def django_context(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
with log_django_context_metric(f.__name__):
db.reset_queries()
db.close_old_connections()
try:
return f(*args, **kwargs)
finally:
db.close_old_connections()
return wrapper
示例12: queryset_iterator
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def queryset_iterator(qs, complex_popolo_fields):
# To save building up a huge list of queries when DEBUG = True,
# call reset_queries:
reset_queries()
start_index = 0
while True:
chunk_qs = qs.order_by('pk')[start_index:start_index + FETCH_AT_A_TIME]
empty = True
for person_extra in chunk_qs.joins_for_csv_output():
empty = False
person_extra.complex_popolo_fields = complex_popolo_fields
yield person_extra
if empty:
return
start_index += FETCH_AT_A_TIME
示例13: __enter__
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def __enter__(self):
self.force_debug_cursor = self.connection.force_debug_cursor
self.connection.force_debug_cursor = True
self.starting_count = len(self.connection.queries)
request_started.disconnect(reset_queries)
return self
示例14: __exit__
# 需要導入模塊: from django import db [as 別名]
# 或者: from django.db import reset_queries [as 別名]
def __exit__(self, exc_type, exc_value, traceback):
self.connection.force_debug_cursor = self.force_debug_cursor
request_started.connect(reset_queries)
if exc_type is not None:
return
final_count = len(self.connection.queries)
self.num_queries = final_count - self.starting_count