Ask Your Question
0

Why would visitor be none when getting comments

asked 2011-09-06 06:15:20 -0500

anonymous user

Anonymous

I'm having a problem with a custom askbot setup that I'm finding rather hard to diagnose. When attempting to run two particular unit tests together, I'm getting the following error:

    /my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/askbot/middleware/pagesize.py TIME: 2011-09-06 11:40:17,935 MSG: pagesize.py:process_exception:43   File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/django/core/handlers/base.py", line 100, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/my/home/directory/workspace/my/project/directory/../rimawebsites/forum/views/readers.py", line 15, in question
    **kwargs)
  File "/my/home/directory/workspace/my/project/directory/../rimawebsites/forum/views/render.py", line 5, in render_jinja2_into_django_template
    response = jinja2_view(request, *args, **kwargs)
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/django/utils/decorators.py", line 76, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/askbot/views/readers.py", line 552, in question
    return render_into_skin('question.html', data, request)
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/askbot/skins/loaders.py", line 145, in render_into_skin
    return HttpResponse(template.render(context), mimetype = mimetype)
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/coffin/template/__init__.py", line 54, in render
    return super(Template, self).render(**context)
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/jinja2/environment.py", line 894, in render
    return self.environment.handle_exception(exc_info, True)
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/question.html", line 2, in top-level template code
    {% import "macros.html" as macros %}
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/two_column_body.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/base.html", line 5, in top-level template code
    {% block body %}
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/two_column_body.html", line 6, in block "body"
    {% block content%}
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/question.html", line 141, in block "content"
    macros.post_comments_widget(
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/macros.html", line 498, in template
    {% spaceless %}
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/coffin/template/defaulttags.py", line 369, in _strip_spaces
    return strip_spaces_between_tags(caller().strip())
  File "/my/home/directory/workspace/my/project/directory/forum/skins/rima_skin/templates/macros.html", line 511, in template
    {% set comments = post.get_comments()[:max_comments] %}
  File "/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/askbot/models/content.py", line 56, in get_comments
    if visitor.is_anonymous():

/my/home/directory/workspace/my/project/directory/.ve/lib/python2.6/site-packages/askbot/middleware/pagesize.py TIME: 2011-09-06 11:40:17,935 MSG: pagesize.py:process_exception:44 <type 'exceptions.AttributeError'>
/my/home/directory/workspace/my/project ...
(more)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2011-09-06 08:02:24 -0500

Evgeny gravatar image

Do you have django.contrib.auth properly enabled?

You'll need the following in the MIDDLEWARE_CLASSES setting (among others):

'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',

And in the INSTALLED_APPS:

'django.contrib.auth',
'django.contrib.sessions',

Value of the visitor comes from request.user, which is installed onto the request object by the auth system. If the user is authenticated, then instance of real user object will be added, otherwise - an instance of AnonymousUser. In your case you are getting None.

edit flag offensive delete link more
0

answered 2011-09-06 10:00:35 -0500

Daniel gravatar image

updated 2011-09-06 10:05:08 -0500

The macro calls had been changed so that the "visitor" parameter was no longer assigned when calling. I.E.

 post.get_comments(visitor = user)

had become

 post.get_comments()

Changing it back solved the problem.

edit flag offensive delete link more

Comments

Oh, that would do it, thanks.

Evgeny gravatar imageEvgeny ( 2011-09-06 10:04:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-09-06 06:15:20 -0500

Seen: 147 times

Last updated: Sep 06 '11