How to use _extract_special_params method in autotest

Best Python code snippet using autotest_python

model_logic.py

Source:model_logic.py Github

copy

Full Screen

...649 # see query_objects()650 _SPECIAL_FILTER_KEYS = ('query_start', 'query_limit', 'sort_by',651 'extra_args', 'extra_where', 'no_distinct')652 @classmethod653 def _extract_special_params(cls, filter_data):654 """655 :return: a tuple of dicts (special_params, regular_filters), where656 special_params contains the parameters we handle specially and657 regular_filters is the remaining data to be handled by Django.658 """659 regular_filters = dict(filter_data)660 special_params = {}661 for key in cls._SPECIAL_FILTER_KEYS:662 if key in regular_filters:663 special_params[key] = regular_filters.pop(key)664 return special_params, regular_filters665 @classmethod666 def apply_presentation(cls, query, filter_data):667 """668 Apply presentation parameters -- sorting and paging -- to the given669 query.670 :return: new query with presentation applied671 """672 special_params, _ = cls._extract_special_params(filter_data)673 sort_by = special_params.get('sort_by', None)674 if sort_by:675 assert isinstance(sort_by, list) or isinstance(sort_by, tuple)676 query = query.extra(order_by=sort_by)677 query_start = special_params.get('query_start', None)678 query_limit = special_params.get('query_limit', None)679 if query_start is not None:680 if query_limit is None:681 raise ValueError('Cannot pass query_start without query_limit')682 # query_limit is passed as a page size683 query_limit += query_start684 return query[query_start:query_limit]685 @classmethod686 def query_objects(cls, filter_data, valid_only=True, initial_query=None,687 apply_presentation=True):688 """689 Returns a QuerySet object for querying the given model_class690 with the given filter_data. Optional special arguments in691 filter_data include:692 -query_start: index of first return to return693 -query_limit: maximum number of results to return694 -sort_by: list of fields to sort on. prefixing a '-' onto a695 field name changes the sort to descending order.696 -extra_args: keyword args to pass to query.extra() (see Django697 DB layer documentation)698 -extra_where: extra WHERE clause to append699 -no_distinct: if True, a DISTINCT will not be added to the SELECT700 """701 special_params, regular_filters = cls._extract_special_params(702 filter_data)703 if initial_query is None:704 if valid_only:705 initial_query = cls.get_valid_manager()706 else:707 initial_query = cls.objects708 query = initial_query.filter(**regular_filters)709 use_distinct = not special_params.get('no_distinct', False)710 if use_distinct:711 query = query.distinct()712 extra_args = special_params.get('extra_args', {})713 extra_where = special_params.get('extra_where', None)714 if extra_where:715 # escape %'s...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful