Magento 2 collection filters for GRID are not working

I’m developing a module for Magento 2, but when trying to create a GRID, my filters are not working.

I have some settings in other class and load it to the collection, using it inside the _initSelect() function.

When I try to use the values from my other class the filters do not work, but if I set them manually in the _initSelect function, they work.

Here is an example:

enter image description here

If I to a echo $ this->getSelect()->assemble; the result is exactly the same both ways.

Anyone ever dealt with the problem before? If anyone is interested, here is the link to the module github: https://github.com/moloni/magento2/blob/devel/Model/ResourceModel/Orders/Collection.php

Applying filters in Flaks API with MongoDB

I am trying to filter my data based on nationality field of the data.

@app.route("/api/v1/players/<name>", methods = ['GET']) def get_player(name):     """     returns an object of a player given a name     """     try:         player = db.players.find_one({'name': name})         return jsonify({'result': player_to_dict(player)})      except:         return jsonify({             'result': 'failure',              "error": 400,              "message": "Bad Request (Double check player's name)"}), 400  @app.route("/api/v1/players/<nation>", methods = ['GET']) def get_player_by_nation(nation):     """     returns an array of player objects given a nation     """     try:         player = db.players.find({'nation': nation})         return jsonify({'result': player_to_dict(player)})      except:         return jsonify({             'result': 'failure',              "error": 400,              "message": "Bad Request (Double check nation's name)"}), 400 

I tried something like this, but since those two endpoints are considered the same thing, only the /<name> endpoint gets called and gives me an error when I put in a nation name.

What is the convention of applying filters or sorting in Flask?

Django view of reward points that heavily filters and sorts (many) database results

My page (even when it has no data) takes 10+ seconds to load. That’s just too long, considering when you finally get to it there’s no data. When it has data, it takes even longer.

Here is my view, which I’m guessing is the problem:

class RewardPointsEarnedReport(TemplateView):      template_name = 'admin/hr/reward_points_earned_report.html'      @user_is_staff     def dispatch(self, request, *args, **kwargs):         return super(RewardPointsEarnedReport, self).dispatch(request, *args, **kwargs)      def get_context_data(self, **kwargs):         context = super(RewardPointsEarnedReport, self).get_context_data(**kwargs)         employees = get_active_users(self)         page = self.request.GET.get('page')          report_list = RewardPointsEarned.objects.all().order_by('-date_earned')         academic_terms = AcademicTermType.objects.all()         point_types = RewardPointsType.objects.all()         if page is None:             page = 1         try:             header = point_types[int(page)-1]         except:             header = point_types[point_type_list.count()-1]         reports_by_category = [report for report in report_list if report.reward_points_type == header]         this_term = AcademicTerm.objects.get(date_start__lte=datetime.now(),date_end__gte=datetime.now())         current_reports = [report for report in reports_by_category if report.date_earned > this_term.date_end and report.date_earned < this_term.date_start or 0]          point_type_list = []         for point_type in point_types:             point_type_count = RewardPointsEarned.objects.filter(reward_points_type=point_type).filter(date_earned__gte=this_term.date_end).count()             if point_type_count:                 point_type_list.append((point_type, point_type_count))             else:                 point_type_list.append((point_type, 0))         context['point_type_list'] = point_type_list         context['current_reports'] = current_reports         context['academic_terms'] = academic_terms         context['this_term'] = this_term         context['header'] = header         return context 

If anything else could be causing the problem, please let me know. If there’s also nothing I can do let me know as well. I’m pretty stuck, and any help is appreciated!!

I was told to add more code so here is the html:

{% extends "admin/hr/index.html" %} {% load i18n %} {% load in_group %}  {% block active %} <li><a href="{% url 'reports' %}">Reports</a><span class="divider">/</span></li> <li class="active">Reward Points Earned</li> {% endblock %}  <!-- Content --> {% block content %} {% if user|in_group:"aux-dept-urec-hr" or "aux-dept-urec-facilities-admins" or user.is_staff %} <!-- HR --> <div class="span4">   <div class="dropdown" style="margin-bottom:10px;">     <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">       Choose Term     </button>     <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">       <ul style="list-style:none;padding:3px;margin:0px;">         {% for term in academic_terms %}         {% if term == this_term.academic_term_type %}         <li><strong><a class="dropdown-item" href="{% url 'rewards_earned' %}">{{ term }}</a></strong></li>         {% else %}         <li><a class="dropdown-item" href="{% url 'rewards_earned' %}">{{ term }}</a></li>         {% endif %}         {% endfor %}       </ul>     </div>   </div>   <table class="table table-bordered table-striped">     <thead>       <tr class="alert-success">         <th colspan="1">Point Type</th>         <th colspan="1" style="align:center;">Total</th>       </tr>     </thead>     <tbody>       {% for point_type, point_type_count in point_type_list %}       <tr>         {% if header|stringformat:"s" == point_type.name %}         <td><strong>             <a href="{% url 'rewards_earned' %}?page={{ forloop.counter }}">{{ point_type }}</a>           </strong></td>         <td style="text-align:center;">{{ point_type_count }}</td>         {% else %}         <td>           <a href="{% url 'rewards_earned' %}?page={{ forloop.counter }}">{{ point_type }}</a>         </td>         <td style="text-align:center;">{{ point_type_count }}</td>         {% endif %}       </tr>       {% endfor %}     </tbody>   </table> </div>  <div class="span8">   <table class="table table-bordered table-striped">     <thead>       <tr class="alert-info">         <th>Employee</th>         <th>Amount</th>         <th>Type</th>         <th>Date Earned</th>       </tr>     </thead>     <tbody>       {% for report in current_reports %}       <tr>         <td><a href="/helm/hr/employee/{{ report.employee.pk }}">{{ report.employee }}</a></td>         <td>{{ report.points_value }}</td>         <td>{{ report.reward_points_type }}</td>         <td>{{ report.date_earned }}</td>       </tr>       {% empty %}       <tr>         <td style="color: gray;" colspan="4">(None)</td>       </tr>       {% endfor %}     </tbody>   </table> </div> {% endif %} {% endblock %} 

This view displays points earned by someone, and it’s filterable by type. Here is a picture of the view: picture of the view in the website

List products based on slug and sidebar filters

This method shows the list of manufacturers’ offered products based on the slug and sidebar filters.

Most of the time I have to write the same query with only some changes: you can say I am repeating myself. I want my code more readable and short. How can i refactor and reduce the lines of code?

public function colabrativetwo(Request $  request, $  slug = 0, $  division_id = 0, $  section_id = 0, $  manufacturer_id = 0, $  list="") {         $  cookieId = $  this->setInitialCookie($  request);         if (!empty($  cookieId))             $  cookieExists = true;          $  manufacturerArr = array();         $  prodFeatured = array();             $  geting=DB::table('product_category')->select('name')->get();              $  filterArray=array();             foreach( $  geting as $  get){                 $  localarray=array();                 $  localarray['name']=$  get->name;                  $  filterArray[]=$  localarray;             }           if ($  slug !== 0 || $  division_id != 0 || $  section_id != 0 || $  manufacturer_id != 0) {              $  where = array();             $  slug_colum = array();             if ($  slug !== 0 && $  slug != '') {                 if ($  slug == 'low-emitting-material-prerequisite') {                      $  slug_colum[] = 'products.low_emitting_material_prerequisite_expiry_date';                     $  slug_colum[] = 'products.low_emitting_material_prerequisite_file';                 }                 elseif ($  slug == 'low-emitting-material-credit')                 {                     $  slug_colum[] = 'products.low_emitting_material_credit_expiry_date';                     $  slug_colum[] = 'products.low_emitting_material_credit_file';                 }                  /*else{                     $  slug_colum[]='products.low_emitting_material_prerequisite_expiry_date'; //                    $  slug_colum[] = 'products.low_emitting_material_prerequisite_file';                  }*/              }              if ($  division_id != 0) {                 $  where['products.division_id'] = $  division_id;             }              if ($  section_id != 0) {                 $  where['products.section_id'] = $  section_id;             }              if ($  manufacturer_id != 0) {                 $  where['manufacturers.id'] = $  manufacturer_id;             }              if (isset($  slug_colum[1])) {                  $  productsFeatured = Product::select('products.id','products.low_emitting_material_prerequisite_file',                 'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.name', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where(function ($  query) use ($  slug_colum) {                             if($  slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {                                 $  query->where($  slug_colum[1], '!=', '');                             } else {                                 $  query->where($  slug_colum[0], '>=', date('Y-m-d'))                                 ->where($  slug_colum[1], '!=', '');                             }                         })                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('divisions.code', 'asc')                         ->orderBy('sections.code', 'asc')                         ->groupBy('products.id')                         ->get();                   $  divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where(function ($  query) use ($  slug_colum) {                             if($  slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {                                 $  query->where($  slug_colum[1], '!=', '');                             } else {                                 $  query->where($  slug_colum[0], '>=', date('Y-m-d'))                                 ->where($  slug_colum[1], '!=', '');                             }                         })                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->groupBy('divisions.id')                         ->get();                  $  sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where(function ($  query) use ($  slug_colum) {                             if($  slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {                                 $  query->where($  slug_colum[1], '!=', '');                             } else {                                 $  query->where($  slug_colum[0], '>=', date('Y-m-d'))                                 ->where($  slug_colum[1], '!=', '');                             }                         })                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('sections.code', 'asc')                         ->groupBy('sections.id')                         ->get();                  $  manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.name AS name', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where(function ($  query) use ($  slug_colum) {                             if($  slug_colum[0] = 'products.low_emitting_material_prerequisite_expiry_date') {                                 $  query->where($  slug_colum[1], '!=', '');                             } else {                                 $  query->where($  slug_colum[0], '>=', date('Y-m-d'))                                 ->where($  slug_colum[1], '!=', '');                             }                         })                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('name', 'asc')                         ->groupBy('manufacturers.id')                         // ->limit(3)                         ->get();             } else {                  // dd($  productsFeatured);                 $  productsFeatured = Product::select('products.id','products.low_emitting_material_prerequisite_file',                 'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.name', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('divisions.code', 'asc')                         ->orderBy('sections.code', 'asc')                         ->groupBy('products.id')                         ->get();                  $  divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->groupBy('divisions.id')                         // ->limit(3)                         ->get();                  $  sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('sections.code', 'asc')                         ->groupBy('sections.id')                         // ->limit(3)                         ->get();                  $  manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.name AS name', DB::raw('COUNT(DISTINCT products.id) as products_count'))                         ->where($  where)                         ->whereIn('products.status', ['active'])                         ->where('users.user_type', 'manufacturer_paid')                         ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                         ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                         ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                         ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                         ->join('users', 'manufacturers.user_id', '=', 'users.id')                         ->orderBy('name', 'asc')                         ->groupBy('manufacturers.id')                         // ->limit(2)                         ->get();             }         } else {             // dd('oan di siri');              $  productsFeatured = Product::select('products.id', 'products.name','products.low_emitting_material_prerequisite_file',             'manufacturers.phone','manufacturers.address','manufacturers.linkedin_url','manufacturers.city', 'products.specs_file','products.specs_file_url','products.low_emitting_material_credit_file', 'products.logo', 'products.division_id', 'products.section_id', 'products.manufacturer_id', 'divisions.name as division_name', 'divisions.code as division_code', 'sections.name as section_name', 'sections.code')                     ->whereIn('products.status', ['active'])                     ->where(function ($  query) {                         $  query->where('products.low_emitting_material_prerequisite_file', '!=', '');                     })                     ->where('users.user_type', 'manufacturer_paid')                     ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                     ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                     ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                     ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                     ->join('users', 'manufacturers.user_id', '=', 'users.id')                     ->orderBy('divisions.code', 'asc')                     ->orderBy('sections.code', 'asc')                     ->groupBy('products.id');                     // ->limit(3)                     // ->get()                      if($  request->ajax() && $  request->manufacturer){                          $  productsFeatured->whereIn('products.manufacturer_id', $  request->manufacturer);                         $  productsFeatured = $  productsFeatured->get();                                           } else{                         $  productsFeatured = $  productsFeatured->get();                     }    // dd($  productsFeatured);             $  divisionsFeatured = Product::select('divisions.id', 'divisions.name as name', 'divisions.code as division_code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                     ->whereIn('products.status', ['active'])                     ->where(function ($  query) {                         $  query->where('products.low_emitting_material_prerequisite_file', '!=', '');                     })                     ->where('users.user_type', 'manufacturer_paid')                     ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                     ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                     ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                     ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                     ->join('users', 'manufacturers.user_id', '=', 'users.id')                     ->groupBy('divisions.id');                     // ->get();                     if($  request->ajax() && $  request->manufacturer){                          $  divisionsFeatured->whereIn('products.manufacturer_id', $  request->manufacturer);                         $  divisionsFeatured = $  divisionsFeatured->get();                      } else{                         $  divisionsFeatured = $  divisionsFeatured->get();                     }                $  sectionsFeatured = Product::select('sections.id', 'sections.name as name', 'sections.code', DB::raw('COUNT(DISTINCT products.id) as products_count'))                     ->whereIn('products.status', ['active'])                     ->where(function ($  query) {                         $  query->where('products.low_emitting_material_prerequisite_file', '!=', '');                     })                     ->where('users.user_type', 'manufacturer_paid')                     ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                     ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                     ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                     ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                     ->join('users', 'manufacturers.user_id', '=', 'users.id')                     ->orderBy('sections.code', 'asc')                     ->groupBy('sections.id');                     // ->get();                     if($  request->ajax() && $  request->manufacturer){                          $  sectionsFeatured->whereIn('products.manufacturer_id', $  request->manufacturer);                         $  sectionsFeatured = $  sectionsFeatured->get();                      } else{                         $  sectionsFeatured = $  sectionsFeatured->get();                     }              $  manufacturersFeatured = Product::select('manufacturers.id AS id', 'manufacturers.id AS id',             'manufacturers.name', 'manufacturers.address',              'manufacturers.city', 'manufacturers.state', 'manufacturers.state',              'manufacturers.phone', DB::raw('COUNT(DISTINCT products.id) as products_count'))                     ->whereIn('products.status', ['active'])                     ->where(function ($  query) {                         $  query->where('products.low_emitting_material_prerequisite_file', '!=', '');                     })                     ->where('users.user_type', 'manufacturer_paid')                     ->leftJoin('products_selected_leeds', 'products.id', '=', 'products_selected_leeds.product_id')                     ->leftJoin('sections', 'products.section_id', '=', 'sections.id')                     ->leftJoin('divisions', 'products.division_id', '=', 'divisions.id')                     ->join('manufacturers', 'products.manufacturer_id', '=', 'manufacturers.id')                     ->join('users', 'manufacturers.user_id', '=', 'users.id')                     ->orderBy('name', 'asc')                     ->groupBy('manufacturers.id');                     // ->limit(3)                     // ->get();                     if($  request->ajax() && $  request->manufacturer){                          $  manufacturersFeatured->whereIn('products.manufacturer_id', $  request->manufacturer);                         $  manufacturersFeatured = $  manufacturersFeatured->get();                      } else{                         $  manufacturersFeatured = $  manufacturersFeatured->get();                     }         }             // dd($  productsFeatured );         foreach ($  productsFeatured as $  productFeatured) {              $  recSecFeatured['fav_yes'] = '';             $  recSecFeatured['id'] = $  productFeatured->id;             $  recSecFeatured['name'] = $  productFeatured->name;             $  recSecFeatured['logo'] = $  productFeatured->logo;             $  recSecFeatured['div_id'] = $  productFeatured->division_id;             $  recSecFeatured['division_name'] = $  productFeatured->division_name;             $  recSecFeatured['division_code'] = $  productFeatured->division_code;             $  recSecFeatured['low_emitting_material_prerequisite_file'] = $  productFeatured->low_emitting_material_prerequisite_file;             $  recSecFeatured['specs_file'] = $  productFeatured->specs_file;             $  recSecFeatured['specs_file_url'] = $  productFeatured->specs_file_url;               $  mfg = Manufacturer::where('id', $  productFeatured->manufacturer_id)->first();               // Manufacturere information             $  mfgArr = array();             $  mfgArr['id'] = $  mfg['id'];             $  mfgArr['name'] = $  mfg['name'];             $  mfgArr['logo'] = $  mfg['logo'];             $  mfgArr['address'] = $  mfg['address'];             $  mfgArr['city'] = $  mfg['city'];             $  mfgArr['phone'] = $  mfg['phone'];             $  mfgArr['websiteurl'] = $  mfg['websiteurl'];             $  mfgArr['linkedin_url'] =$  mfg['linkedin_url'];             if (!$  this->find_key_value($  manufacturerArr, 'id', $  mfgArr['id'])) {                  $  chkFav = DB::table('user_list_details_temp')                         ->where('type', 'manufacturer')                         ->where('unique_id', $  cookieId)                         ->where('reference_id', $  mfg['id'])                         ->select('id as fav_yes')                         ->first();                 $  mfgArr['fav_yes'] = "";                 if (!empty($  chkFav))                      $  mfgArr['fav_yes'] = $  chkFav->fav_yes;                 // Check if this product exists in non-logged in fav list                  $  manufacturerArr[] = $  mfgArr;             }              $  recSecFeatured['address'] =    $  mfg['address'];             $  recSecFeatured['city']    =    $  mfg['city'];             $  recSecFeatured['phone']   =    $  mfg['phone'];             $  recSecFeatured['websiteurl']   =     $  mfg['websiteurl'];             $  recSecFeatured['linkedin_url'] =     $  mfg['linkedin_url'];             $  recSecFeatured['mfg_id']       =     $  mfg['id'];             $  recSecFeatured['mfg_name']     =     $  mfg['name'];             $  recSecFeatured['mfg_logo']     =     $  mfg['logo'];             $  productSection = Section::where('id', $  productFeatured->section_id)->first();             $  recSecFeatured['sec_id'] = $  productSection['id'];             $  recSecFeatured['sec_code'] = $  productSection['code'];             $  recSecFeatured['sec_name'] = $  productSection['name'];             $  recSecFeatured['slug'] = str_slug($  productFeatured->name);             // Check if this product exists in non-logged in fav list             $  chkFav = DB::table('user_list_details_temp')                     ->where('type', 'product')                     ->where('unique_id', $  cookieId)                     ->where('reference_id', $  productFeatured->id)                     ->select('id as fav_yes')                     ->first();             $  recSecFeatured['fav_yes'] = "";             if (!empty($  chkFav))                 $  recSecFeatured['fav_yes'] = $  chkFav->fav_yes;             // Check if this product exists in non-logged in fav list               $  featuredProductsIdsArr[] = $  productFeatured->id;             $  prodFeatured[] = $  recSecFeatured;         }          //echo "<pre>";print_r( $  prodFeatured );exit;      /***         *         * @author Muneeb Faruqi         * @todo grouped prodFeatured on division name to each product under its certain division...         **/         $  new_test = collect($  prodFeatured)->groupBy('division_name')->toArray();         $  data['leedProducts'] = $  new_test;         $  data['filterArray']=$  filterArray;         /*$  data['leedProducts'] = $  prodFeatured;*/     /*@Muneeb Faruqi Changes Ends*/         $  data['leedManufacturer'] = $  manufacturerArr;         //$  data['leedDivision'] = $  divisionsArr;         $  data['leedDivision'] = $  divisionsFeatured->toArray();         $  data['leedSection'] = $  sectionsFeatured->toArray();         $  data['leedManufacturers'] = $  manufacturersFeatured->toArray();          // dd($  manufacturersFeatured->toArray());          // SEO Code for this page //         $  data['seoPageTitle'] = "Collaborative for High Performance Schools (CHPS.net) product database - Zero Docs";         $  data['seoPageDescription'] = "Pre-Approved low-emitting collaborative for high performance schools CHPS products for construction projects, schools, office and healthcare.";         $  data['seoPageKeywords'] = "Collaborative for high performance schools, LEEDv4 low emitting products, California Department of Public Health CDPH low-emission testing method for CA Specification 01350";         // SEO Code for this page //         // Start Cookie End Code         $  data['cookieId'] = $  cookieId;          $  data['slug'] = $  slug;         $  data['division_id'] = $  division_id;         $  data['section_id'] = $  section_id;         $  data['manufacturer_id'] = $  manufacturer_id;          $  data['class'] = '';         if (!empty($  list) && $  list === 'list') {             $  data['layout'] = 'list';             $  data['class'] = 'library-list-view';         } else {             $  data['layout'] = 'card';         }         $  data['showTooltipHelpText'] = "No";         $  showTooltipChpsPage = $  request->session()->get('tooltip_chps_page', 'No');         if($  showTooltipChpsPage == 'Yes') {             $  request->session()->put('tooltip_chps_page', 'No');             $  data['showTooltipHelpText'] = "Yes";         } //Code by abdullah for sidebar filters data of manufacturers, products, leeds         // $  data['manufacturers'] = Manufacturer::where('status','active')->select('id','name')->orderBy('name', 'asc')->get();          // dd($  data['manufacturers']);         $  agent = new Agent();         if($  agent->isDesktop()) {             $  data['isDesktop'] = true;         } else {             $  data['isDesktop'] = false;         }          $  data['leed_records'] = DB::table('leed_tags')->where('leed_tags.status', 'active')         ->whereIn('products.status', ['active'])         ->where('products.division_id', '>', 0)         ->where('products.section_id', '>', 0)         ->where('products.manufacturer_id', '>', 0)         ->join('products_selected_leeds', 'leed_tags.id', '=', 'products_selected_leeds.leed_id')         ->join('products', 'products_selected_leeds.product_id', '=', 'products.id')         ->orderBy('leed_tags.description', 'asc')         ->select('leed_tags.description', 'leed_tags.id', 'leed_tags.parent_id', DB::raw('COUNT(DISTINCT products_selected_leeds.product_id) as products_count'))         ->groupBy('leed_tags.id')         ->get();  /*** * * @author  Muneeb Faruqi * @todo Manipulated the below array according to $  new_test */  foreach($  data['leedProducts'] as $  all_manufacturers){      foreach($  all_manufacturers as $  manufacturer_new){         $  list_all_manufacturers[] = array('mfgg_name' => $  manufacturer_new['mfg_name'], 'mfgg_id' =>$  manufacturer_new['mfg_id'],             'product_name' => $  manufacturer_new['name'], 'product_id' => $  manufacturer_new['id']);     }     // $  list_all_manufacturers[] = $  all_manufacturers['mfg_name']; }  /*@Muneeb Faruqi Changes Ends*/  $  data['list_all_active_manufacturers'] = array_unique($  list_all_manufacturers, SORT_REGULAR);  // dd($  data['list_all_active_manufacturers']); // unique by mfgg_name $  data['manufacturers'] = $  this->unique_multidim_array($  data['list_all_active_manufacturers'],'mfgg_name');  if($  request->ajax()){     $  data['checkedManufactureArray'] = $  request->manufacturer; }else{     $  data['checkedManufactureArray'] = array();  }          if ($  cookieExists) {             if($  request->ajax()){                  // dd($  checkedManufactureArray);                     // return view('guest::new_design_frontend.ajax',$  data);                     return  view('guest::new_design_frontend.product-library')->with($  data);               }else{                 return  view('guest::new_design_frontend.product-library')->with($  data);              }             // return view('guest::newcollaborative', $  data);                     //  dd($  data);              } else {             // $  this->sendResponseWithCookie('guest::newcollaborative', $  data, $  cookieId);             $  this->sendResponseWithCookie('guest::new_design_frontend.product-library', $  data, $  cookieId);         }   }  ``` 

designfilt runs through errorcode but still filters

I have data that I filtered with a filt made through designfilt. During optimization, there was a slight bottleneck in the designfilt call (~1.7 seconds). When I opened up the code through profiler, I realized one line of the code was taking 1.7 seconds:

I have no idea what this means in the context of my filter, or how to fix it.

The code still runs and filters correctly, so the only reason to fix it would be to speed up the code.

My filter design:

    'HalfPowerFrequency',0.22,'DesignMethod','butter'); 

Line in filtdesign that is highlighted by profiler:

  [err,requestedResponse,parseParams,h] = parseAndDesignFilter(inputParamValueNames, varargin{:});   % If there was an error:  % 1) If fdesign code was generated, evaluate it to % make sure that we error out in cases where we have valid specification % sets, but with an invalid specified value (this can happen when the % error is due to incorrect design methods, design options, or due to % unknown parameters, here the generated fdesign code will contain user % defined parameter values).  % 2)Parse input parameters. 

How do I programmatically set contextual filters?

I need to set a contextual filter programmatically and almost every view I have will have this filter. However, some wont and will have other contextual filters instead.

I have tried following the examples in here but this will just set the first argument to be my filter value regardless of what field is it for.

In views_pre_build I get the keyed arguments list under $ view->argument and can do ->setArgument() but this doesn’t change the set of results.

Is there an easier way of setting a specific contextual filter?