Python django.db.reset_queries() Examples

The following are 28 code examples of django.db.reset_queries(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.db , or try the search function .
Example #1
Source File: modwsgi.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
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() 
Example #2
Source File: modwsgi.py    From GTDWeb with GNU General Public License v2.0 6 votes vote down vote up
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() 
Example #3
Source File: modwsgi.py    From python2017 with MIT License 6 votes vote down vote up
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() 
Example #4
Source File: modwsgi.py    From bioforum with MIT License 6 votes vote down vote up
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() 
Example #5
Source File: modwsgi.py    From python2017 with MIT License 6 votes vote down vote up
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() 
Example #6
Source File: modwsgi.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
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() 
Example #7
Source File: modwsgi.py    From openhgsenti with Apache License 2.0 6 votes vote down vote up
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() 
Example #8
Source File: modwsgi.py    From Hands-On-Application-Development-with-PyCharm with MIT License 6 votes vote down vote up
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() 
Example #9
Source File: modwsgi.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
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() 
Example #10
Source File: djangotestcase.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #11
Source File: djangotestcase.py    From maas with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #12
Source File: utils.py    From python2017 with MIT License 5 votes vote down vote up
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) 
Example #13
Source File: utils.py    From python2017 with MIT License 5 votes vote down vote up
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 
Example #14
Source File: utils.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: utils.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
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 
Example #16
Source File: candidates_create_csv.py    From yournextrepresentative with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #17
Source File: utils.py    From python with Apache License 2.0 5 votes vote down vote up
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) 
Example #18
Source File: utils.py    From python with Apache License 2.0 5 votes vote down vote up
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 
Example #19
Source File: utils.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
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 
Example #20
Source File: utils.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
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) 
Example #21
Source File: utils.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
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 
Example #22
Source File: actor_helper.py    From rssant with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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 
Example #23
Source File: manager.py    From qmpy with MIT License 5 votes vote down vote up
def run(self, project=None):
        os.umask(022)
        while True:
            check_die()
            ddb.reset_queries()
            for host in rsc.Host.objects.filter(state=1):
                self.fill_host(host, project=project)
            check_die(60) 
Example #24
Source File: manager.py    From qmpy with MIT License 5 votes vote down vote up
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) 
Example #25
Source File: modwsgi.py    From bioforum with MIT License 5 votes vote down vote up
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() 
Example #26
Source File: utils.py    From bioforum with MIT License 5 votes vote down vote up
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) 
Example #27
Source File: utils.py    From bioforum with MIT License 5 votes vote down vote up
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 
Example #28
Source File: utils.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
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)