ngageoint / geoq

Django web application to collect geospatial features and manage feature collection among groups of users
MIT License
704 stars 133 forks source link

Python IndexError when displaying WorkCell #279

Closed go0ty closed 9 years ago

go0ty commented 10 years ago

I create a job, then create some test Work Cells underneath that job. Whenever I click on any WorkCells, I receive the following error:

IndexError at /geoq/workcells/work/31


list index out of range Request Method: GET Request URL: http://10.0.3.88:8000/geoq/workcells/work/31 Django Version: 1.5.4 Exception Type: IndexError Exception Value:
list index out of range Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in getitem, line 231 Python Executable: /usr/bin/python Python Version: 2.7.3

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, _callback_args, *_callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
  2. return view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
  3. return self.dispatch(request, _args, *_kwargs) File "/home/user/geoq/geoq/core/views.py" in dispatch
  4. return super(UserAllowedMixin, self).dispatch(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
  5. return handler(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py" in get
  6. context = self.get_context_data(object=self.object) File "/home/user/geoq/geoq/core/views.py" in get_context_data
  7. cv['map'] = Map.objects.all()[0] File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in getitem
  8. return list(qs)[0]

Exception Type: IndexError at /geoq/workcells/work/31 Exception Value: list index out of range

jaycrossler commented 10 years ago

Ah. Looks like you might not have a 'map' created.

We should change core.views.py to be something like:

    if self.object.job.map:
        cv['map'] = self.object.job.map
    else:
        maps = Map.objects.all()
        if maps and len(maps):
            cv['map'] = maps[0]
        else:
            new_default_map = Map(name="Default Map",

description="Default Map that should have the layers you want on most maps") new_default_map.save() cv['map'] = new_default_map

I don't have time to test this now, want to spin on it and see if that works?

--Jay

On Fri, Nov 21, 2014 at 10:27 AM, Patrick D notifications@github.com wrote:

I create a job, then create some test Work Cells underneath that job. Whenever I click on any WorkCells, I receive the following error:

IndexError at /geoq/workcells/work/31

list index out of range Request Method: GET Request URL: http://10.0.3.88:8000/geoq/workcells/work/31 Django Version: 1.5.4 Exception Type: IndexError Exception Value:

list index out of range Exception Location: /usr/local/lib/python2.7/dist-packages/django/db/models/query.py in getitem, line 231 Python Executable: /usr/bin/python Python Version: 2.7.3

Traceback: File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response

  1. response = callback(request, _callback_args, *_callback_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
  2. return view_func(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in view
  3. return self.dispatch(request, _args, *_kwargs) File "/home/user/geoq/geoq/core/views.py" in dispatch
  4. return super(UserAllowedMixin, self).dispatch(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/base.py" in dispatch
  5. return handler(request, _args, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/django/views/generic/detail.py" in get
  6. context = self.get_context_data(object=self.object) File "/home/user/geoq/geoq/core/views.py" in get_context_data
  7. cv['map'] = Map.objects.all()[0] File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py" in getitem
  8. return list(qs)[0]

Exception Type: IndexError at /geoq/workcells/work/31 Exception Value: list index out of range

— Reply to this email directly or view it on GitHub https://github.com/ngageoint/geoq/issues/279.

go0ty commented 10 years ago

This works! Thank you.