NameError at /trees/add/ - global name 'content_type' is not defined

106 views
Skip to first unread message

Keith Bornhorst

unread,
Mar 26, 2013, 9:03:17 AM3/26/13
to opentree...@googlegroups.com
Running version 1.3 of OTM and I'm running into the following error when trying to add a single tree using the web interface. Does any of the following scream something obvious? Probably doesn't help that uimport still fails without providing additional information. I was hoping the web interface would work.

Environment:
Request Method: POST

Django Version: 1.3.1
Python Version: 2.7.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.staticfiles',
 'django.contrib.databrowse',
 'django.contrib.gis',
 'django.contrib.humanize',
 'django.contrib.webdesign',
 'django.contrib.markup',
 'django.contrib.flatpages',
 'threadedcomments',
 'treemap',
 'api',
 'registration',
 'template_utils',
 'profiles',
 'django_reputation',
 'tagging',
 'south',
 'sorl.thumbnail',
 'classfaves',
 'qs_tiles',
 'treekey',
 'badges',
 'pagination',
 'django_sorting',
 'pipeline']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.middleware.transaction.TransactionMiddleware',
 'django.contrib.csrf.middleware.CsrfViewMiddleware',
 'django.contrib.csrf.middleware.CsrfResponseMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django_reputation.middleware.ReputationMiddleware',
 'pagination.middleware.PaginationMiddleware',
 'django_sorting.middleware.SortingMiddleware')


Traceback:
File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.7/dist-packages/django/contrib/auth/decorators.py" in _wrapped_view
  23.                 return view_func(request, *args, **kwargs)
File "/home/fccdr/www/opentreemap/treemap/views.py" in tree_add
  1442.             change_reputation_for_user(request.user, 'add tree', new_tree)
File "/home/fccdr/www/opentreemap/profiles/utils.py" in change_reputation_for_user
  91.     Reputation.objects.log_reputation_action(user, change_initiated_by_user, action, reputation_change_amount, model_object)
File "/usr/local/lib/python2.7/dist-packages/django_reputation/models.py" in log_reputation_action
  81.                                           % (action_name, content_type.model))
LOCAL VARS:
Variable Value
action_value
25
user
<User: KeithUSF>
target_object
<Plot: Plot object>
action_name
'add tree'
object_id
4
content_type_object
<ContentType: plot>
self
<django_reputation.models.ReputationManager object at 0x7fa2f71b2410>
originating_user
<User: KeithUSF>

Exception Type: NameError at /trees/add/
Exception Value: global name 'content_type' is not defined


Keith Bornhorst

unread,
Mar 26, 2013, 10:58:10 AM3/26/13
to opentree...@googlegroups.com
Providing additional info.... Given that this appears to be related to Django_Reputation, I logged into the Django Admin system to review and here's what it has in the reputation section:

Django_Reputation
- Permissions: 0 permissions
- Reputation actions: 0 reputation actions
- Reputation contents: 0 reputation contents
- Reputations: a few of the accounts have reputation (5000 for signing up)
- User reputation actions: 0 user reputation actions

That doesn't look right, but if I try to "Add user reputation action" I get a Content type select box filled with options that look appropriate. Do I need to seed or prime some of the database tables?

Keith Bornhorst

unread,
Mar 28, 2013, 10:46:58 AM3/28/13
to opentree...@googlegroups.com
Looks like I didn't follow the directions outline within https://github.com/azavea/OpenTreeMap/wiki/Users-And-Groups and create some reputation actions, reputation permissions, etc.

Bob Troester

unread,
Apr 3, 2013, 10:31:58 AM4/3/13
to opentree...@googlegroups.com
Keith, Hi!
Have you had any success since last Thursday with your 'content_type' problem adding a tree? I hope so, because I have a similar problem with editing a tree.

Using 1.3 (now with the jlivni SanFrancisco templates because they seemed more compatible with 1.3), I can add a tree with the bulk load program, uimport.py (remembering to change the State code in that program from 'CA' to my 'VT'). To keep things simple, I just defined long,lat,scientific, and address fields in the input csv file.

In the web interface, I can find the tree on the edit map and drag the tree to a better location. It seems to accept the edit, but it also displays a message by the map 'Related -: global name "content_type" is not defined.' Also, I can edit the so-called General and Status fields, like Tree condition, and have the new value stick but when I try to update Environment fields like Tree condition the spinner just spins forever. Then if I exit and come back to the page, the tree is back in its old position on the map!

Now, "content_type" is normally associated with html pages but when I looked where it was being used (with grep -R content_type .) I found little direct reference. in treemap/views.py plot_edit_choices and tree_edit_choices return HttpResponse without specifying a content_type, unlike all the other uses I saw. However, adding a definition didn't seem to make any difference, so it seemed I was barking up the wrong tree.

I have followed your lead and made sure that all the settings in the 'Users and Groups' wiki page were set (I missed some the first time around) and that helped some of my earlier problems, so thanks for pointing out those details. (I'm running my testing as OTM admin, so some of the permission problems shouldn't apply, but what do I know?) But now I'm stuck - any ideas?

A related problem that maybe someone has insight on: I can add a tree with uimport.py, as I said, but I can't add from the browser. When I try I get an exception
"IntegrityError at /trees/add/
null value in column "annual_stormwater_management" violates not-null constraint"

but in the database that column only exists in the treemap_resourcesummarymodel table, and I haven't seen any place in the code where that field might be used without initialization. Can anyone suggest where to look?

jr...@courtdatatech.com

unread,
Apr 12, 2013, 6:16:45 PM4/12/13
to opentree...@googlegroups.com
Hey Guys
 re: content_type  problem moving a tree

the error is really misleading but this solved my problem 

check your django_reputationreputationaction table
adding row 5 and 6 did it for me...

make sure it has the following lines

1;"add tree";"Reputation to add a tree"
2;"edit tree";"Reputation to edit a tree"
3;"edit verified";"Can edit a verified tree"
4;"Administrative Action";"Can administer site"
5;"add plot";"Reputation to add a plot"
6;"edit plot";"Reputation to edit a plot"

jr...@courtdatatech.com

unread,
Apr 12, 2013, 6:20:50 PM4/12/13
to opentree...@googlegroups.com
regarding "annual_stormwater_management" violates not-null constraint

try:

python manage.py update_aggregates


On Wednesday, April 3, 2013 9:31:58 AM UTC-5, Bob Troester wrote:

Bob Troester

unread,
Apr 14, 2013, 10:30:52 PM4/14/13
to opentree...@googlegroups.com
Hey, jreis!
A thousand thanks for your tip on adding add plot and edit plot to the reputation actions! (I used the admin interface rather than editing the database table directly, and used other text in the Description field, but the key to making it work were those two entries.) All of a sudden I could edit any tree!

So I took it upon myself to edit the "Users and Groups" wiki page to add those two actions.

When I went back and looked at those reputatation actions I noticed on the 1.3 local_settings.example.py file reputation scores for two other actions,' add stewardship' and 'remove stewardship'. I also noticed that those actions are referenced in treemap/views.py, so the code for using those actions is probably in place, buld be usedt I didn't add them to the wiki list, pending confirmation of exactly how (and if) they should be used. Any ideas?
Bob

Bob Troester

unread,
Apr 14, 2013, 10:59:55 PM4/14/13
to opentree...@googlegroups.com
jreis,
Thanks for this *correct!* suggestion to solve my problem on adding trees through the web interface. This add problem, unlike the edit problem discussed in this thread just above, had already been solved a couple of days before, as I noted in my thanks to Adam Hinz in the post "Adding first tree from web interface fails..." But don't go away, I've got plenty more problems for you to solve!
Bob
Reply all
Reply to author
Forward
0 new messages