Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with Python 3.X #25

Closed
laurentpayot opened this issue Jun 11, 2013 · 3 comments
Closed

Not working with Python 3.X #25

laurentpayot opened this issue Jun 11, 2013 · 3 comments

Comments

@laurentpayot
Copy link
Contributor

I'm using Python 3.3 with latest django-trunk, mongoengine and pymongo versions from github.

I had some "ImportError: cannot import name smart_unicode", same for force_unicode.
I just commented the import line of these two functions and replaced them by functions doing nothing.

I'm trying to make it work using a simple CreateView:

forms.py

class FeedbackForm(DocumentForm):
class Meta:
model = Feedback
fields = ['name', 'email', 'subject', 'message']

views.py

class FeedbackCreate(CreateView):
model = Feedback
form_class = FeedbackForm

model.py

class Feedback(Document):
name = StringField(max_length=120)
email = EmailField()
subject = StringField(max_length=120)
message = StringField(max_length=1000, required=True)
meta = {'allow_inheritance': False, 'indexes': ['id']}

But all I get is:

Internal Server Error: /fr/contact/
Traceback (most recent call last):
File "/usr/local/lib/python3.3/dist-packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, _callback_args, *_callback_kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, _args, *_kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/base.py", line 86, in dispatch
return handler(request, _args, *_kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/edit.py", line 190, in get
return super(BaseCreateView, self).get(request, _args, *_kwargs)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/edit.py", line 149, in get
form = self.get_form(form_class)
File "/usr/local/lib/python3.3/dist-packages/django/views/generic/edit.py", line 37, in get_form
return form_class(**self.get_form_kwargs())
File "/usr/local/lib/python3.3/dist-packages/mongodbforms-0.1.5-py3.3.egg/mongodbforms/documents.py", line 268, in init
raise ValueError('DocumentForm has no document class specified.')
ValueError: DocumentForm has no document class specified.

@jschrewe
Copy link
Owner

This doesn't really look like it's python 3 but more a general thing.

The traceback looks more like the Meta object of the form doesn't handle the alias from document to model correctly. If I remember this correctly I tried to use document instead of model internally because we are dealing with documents and not models :) I also think that the use model in the Meta part of the form should be okay, but apparently it's not.

So could you try to change every occurrence of model to document and try again?

@jschrewe
Copy link
Owner

Looking closer at this model is the wrong keyword in the meta section. It has to be document = <whatever>. This is at the moment by design. Thinking about it, it might be a good idea to accept both the Django and Mongoengine terminology however.

@laurentpayot
Copy link
Contributor Author

Thanks a lot it's working now, I just opened #27 for a simple import bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants