buxeasywork / django-rosetta

Automatically exported from code.google.com/p/django-rosetta
MIT License
0 stars 0 forks source link

local variable 'paginator' referenced before assignmen #59

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. first attempt at /trans/ - 500 error

What version of the product are you using? On what operating system?
0.4.6

Please provide any additional information below.

 File
"/usr/local/lib/python2.5/site-packages/django/core/handlers/base.py", line
92, in get_response
   response = callback(request, *callback_args, **callback_kwargs)

 File
"/usr/local/lib/python2.5/site-packages/django/views/decorators/cache.py",
line 44, in _wrapped_view_func
   response = view_func(request, *args, **kwargs)

 File
"/usr/local/lib/python2.5/site-packages/django/contrib/auth/decorators.py",
line 78, in __call__
   return self.view_func(request, *args, **kwargs)

 File "/project/rosetta/views.py", line 156, in home
   messages = paginator.page(page).object_list

UnboundLocalError: local variable 'paginator' referenced before assignment

Original issue reported on code.google.com by pakhomov...@yandex.ru on 21 Sep 2009 at 10:53

GoogleCodeExporter commented 9 years ago
This is rather strange, as "it shouldn't happen". If you're running Rosetta off 
SVN, could you please svn up to r75 
and see if you can still reproduce? 

Original comment by mbonetti on 21 Sep 2009 at 3:13

GoogleCodeExporter commented 9 years ago
I agree that it's strange. But it can happen. You have several choices here but 
no
choice by default (views.py):

if 'query' in request.REQUEST and request.REQUEST.get('query','').strip():
            query=request.REQUEST.get('query').strip()
            rx=re.compile(query, re.IGNORECASE)
            paginator = Paginator([e for e in rosetta_i18n_pofile if
rx.search(smart_unicode(e.msgstr)+smart_unicode(e.msgid)+u''.join([o[0] for o in
e.occurrences]))], rosetta_settings.MESSAGES_PER_PAGE)
        else:
            if rosetta_i18n_filter == 'all':
                paginator = Paginator([e for e in rosetta_i18n_pofile if not
e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)
            elif rosetta_i18n_filter == 'untranslated':
                paginator = Paginator(rosetta_i18n_pofile.untranslated_entries(),
rosetta_settings.MESSAGES_PER_PAGE)
            elif rosetta_i18n_filter == 'translated':
                paginator = Paginator(rosetta_i18n_pofile.translated_entries(),
rosetta_settings.MESSAGES_PER_PAGE)
            elif rosetta_i18n_filter == 'fuzzy':
                paginator = Paginator(rosetta_i18n_pofile.fuzzy_entries(),
rosetta_settings.MESSAGES_PER_PAGE)

Just to try: I added two lines
else:
                paginator = Paginator([e for e in rosetta_i18n_pofile if not
e.obsolete], rosetta_settings.MESSAGES_PER_PAGE)

and now it works.

P.S. I updated to the revision 75

Original comment by pakhomov...@yandex.ru on 22 Sep 2009 at 12:37

GoogleCodeExporter commented 9 years ago
thank you, fixing this as suggested as soon as I get a moment.

Original comment by mbonetti on 22 Sep 2009 at 12:54

GoogleCodeExporter commented 9 years ago
Fixed in r76, thanks for spotting this.

Original comment by mbonetti on 23 Sep 2009 at 3:52