0

I have a django app that works just fine when running the python manage.py runsever command locally. When I tried to migrate it and modified my apache config file to use wsgi.py, everything works except for one page where the django filter fields are shuffled above a django table. Every time I restart the apache server, the filter fields are shuffled again in a new order. The local server always displays the filter fields in the correct order. Does anyone know why this is happening?

local server using python runserver command enter image description here

apache server using wsgi enter image description here

apache2.conf

    WSGIDaemonProcess /SeedInv python-home=/path/to/Software/anaconda3/envs/Django python-path=/path/to/WebServer/SeedInv
    WSGIProcessGroup /SeedInv
    WSGIScriptAlias /SeedInv /path/to/WebServer/SeedInv/SeedInv/wsgi.py process-group=/SeedInv

    <Directory /path/to/WebServer/SeedInv/SeedInv>
    <Files /path/to/WebServer/SeedInv/Seedinv/wsgi.py>
        Require all granted
    </Files>
    </Directory>

    Alias /static "/path/to/WebServer/SeedInv/static"
    <Directory "/path/to/WebServer/SeedInv/static">
        Require all granted
    </Directory>

    Alias /media "/path/to/WebServer/SeedInv/media"
    <Directory "/path/to/WebServer/SeedInv/media">
        Require all granted
    </Directory>

wsgi.py

import os
import sys
sys.path.append('/path/to/anaconda3/envs/Django/lib/python3.6/site-packages')
from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "SeedInv.settings")
application = get_wsgi_application()

filters.py

class GenoFilter(django_filters.FilterSet):

    class Meta:
        model = Genotypes
        fields = {'parent_f_row': ['icontains'],
                  'parent_m_row': ['icontains'],
                  'parent_f_geno': ['icontains'],
                  'parent_m_geno': ['icontains'],
                  'genotype': ['icontains'],
                  'seed_count': ['lt', 'gt'],
                  }

tables.py

class GenotypesTable(tables.Table):
    export_formats = ['tsv']

    class Meta:
        model = Genotypes
        template_name = 'django_tables2/bootstrap.html'

views.py

def InventoryTable(request):
    queryset = Genotypes.objects.all()
    f = GenoFilter(request.GET, queryset=queryset)
    table = GenotypesTable(f.qs)
    RequestConfig(request, paginate={'per_page': 25}).configure(table)

    export_format = request.GET.get('_export', None)
    if TableExport.is_valid_format(export_format):
        exporter = TableExport(export_format, table)
        return exporter.response('table.{}'.format(export_format))

    return render(request, 'Inventory/index.html',
                           {
                            'table': table,
                            'filter': f,
                            })

models.py

# Genotype database model
class Genotypes(models.Model):
    """list of current genotypes"""
    parent_f_row = models.CharField(max_length=200,
                                    validators=[],)
    parent_m_row = models.CharField(max_length=200,
                                    validators=[],)
    parent_f_geno = models.CharField(max_length=200,
                                     validators=[],)
    parent_m_geno = models.CharField(max_length=200,
                                     validators=[],)
    genotype = models.CharField(max_length=200,
                                validators=[],)
    seed_count = models.IntegerField(validators=[], default=0)
    actual_count = models.BooleanField(default=False)
    experiment = models.CharField(max_length=200,
                                  validators=[],
                                  blank=True,)
    comments = models.CharField(max_length=300,
                                validators=[],
                                blank=True,
                                )

    def __str__(self):
        return self.genotype

    class Meta:
        verbose_name_plural = "Genotypes"

Thanks for your help!

MeeshCompBio
  • 109
  • 1
  • 9

1 Answers1

1

Until Python 3.7, you shouldn't rely on dictionaries being ordered. You can use an OrderedDict if the order of the keys is important.

from collections import OrderedDict

class GenoFilter(django_filters.FilterSet):

    class Meta:
        model = Genotypes
        fields = OrderedDict([
            ('parent_f_row', ['icontains']),
            ('parent_m_row', ['icontains']),
            ('parent_f_geno', ['icontains']),
            ('parent_m_geno', ['icontains']),
            ('genotype', ['icontains']),
            ('seed_count', ['lt', 'gt']),
        ])                  
Alasdair
  • 298,606
  • 55
  • 578
  • 516
  • Thank you for the help. Do you know why I only see that issue on wsgi.py with apache and not the local server? – MeeshCompBio Dec 13 '18 at 15:38
  • No, I'm not sure why, unless you were running a different version of Python in development that does order dictionaries. – Alasdair Dec 13 '18 at 15:41
  • Interesting, wsgi.py is using the same conda env as the local Django server. Regardless, thanks for the help! – MeeshCompBio Dec 13 '18 at 15:53