No module named middleware for django-bouncer - django

I'm using django-bouncer to make a waiting list in a Django 1.6 app. Unfortunately, when I add 'bouncer.middleware.MembersOnlyMiddleware' to my MIDDLEWARE_CLASSES as required, I get: "ImportError: No module named middleware." I tried going into the Django shell and typing "from bouncer.middleware import MembersOnlyMiddleware," but that received the same error.
What can I do to resolve this problem?

django-bouncer and bouncer are not the same package.
Try to install django-bouncer:
pip install django-bouncer

Related

Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'

It's the first time I work with django rest and Django Oauth toolkit
I'm following this tutorial
oauth2-with-django-rest-framework
But when I run python manage.py migrate I get the following error:
ImportError: Could not import 'oauth2_provider.ext.rest_framework.OAuth2Authentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named ext.rest_framework.
What is going wrong ? is there another module I should install ?
my virtual environment contains :
certifi==2017.4.17
chardet==3.0.4
Django==1.11.2
django-extensions==1.8.1
django-oauth-toolkit==1.0.0
djangorestframework==3.6.3
idna==2.5
oauthlib==2.0.2
pytz==2017.2
requests==2.18.1
six==1.10.0
Unidecode==0.4.21
urllib3==1.21.1
It looks like oath2_provider.ext has been moved to oauth_provider.contrib. You could try installing an older version of django-oauth-toolkit, or try changing the value in DEFAULT_AUTHENTICATION_CLASSES from:
'oauth2_provider.ext.rest_framework.OAuth2Authentication',
to:
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
Note that the tutorial is a couple of years old, you might find other problems like this.
I was facing same issue. In my setting file DEFAULT_AUTHENTICATION_CLASSES was already
'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
I just installed older version as #Alasdair ask. My issue resolved. thanks

Odoo custom module with external Python library

I created an Odoo Module in Python using the Python library ujson.
I installed this library on my development server manually with pip install ujson.
Now I want to install the Module on my live server. Can I somehow tell the Odoo Module to install the ujson library when it is installed? So I just have to add the Module to my addons path and install it via the Odoo Web Interface?
Another reason to have this automated would be if I like to share my custom module, so others don't have to install the library manually on their server.
Any suggestions how to configure my Module that way? Or should I just include the library's directory in my module?
You should try-except the import to handle problems on odoo server start:
try:
from external_dependency import ClassA
except ImportError:
pass
And for other users of your module, extend the external_dependencies in your module manifest (v9 and less: __openerp__.py; v10+: __manifest__.py), which will prompt a warning on installation:
"external_dependencies": {
'python': ['external_dependency']
},
Big thanks goes to Ivan and his Blog
Thank you for your help, #Walid Mashal and #CZoellner, you both pointed me to the right direction.
I solved this task now with the following code added to the __init__.py of my module:
import pip
try:
import ujson
except ImportError:
print('\n There was no such module named -ujson- installed')
print('xxxxxxxxxxxxxxxx installing ujson xxxxxxxxxxxxxx')
pip.main(['install', 'ujson'])
In python file using the following command, you can install it (it works for odoo only). Eg: Here I am going to install xlsxwriter
try:
import xlsxwriter
except:
os.system("pip install xlsxwriter")
import xlsxwriter
The following is the code that is used in odoo base module report in base addons inside report.py (odoo_root_folder/addons/report/models/report.py) to install wkhtmltopdf.
from openerp.tools.misc import find_in_path
import subprocess
def _get_wkhtmltopdf_bin():
return find_in_path('wkhtmltopdf')
try:
process = subprocess.Popen([_get_wkhtmltopdf_bin(), '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except (OSError, IOError):
_logger.info('You need Wkhtmltopdf to print a pdf version of the reports.')
basically you need to find some python code that will run the library and install it and include that code in one of you .py files, and that should do it.

ImportError when using Haystack 2.0.0 with Django 1.5 and Gunicorn WSGI

I use django-haystack 2.0.0 to index my site, and it has been working great until I upgraded to Django 1.5 and started using the WSGI interface. If I just use the django_gunicorn command it works great, but the Django documentation "highly recommends" I use the gunicorn command.
When I start my site with the gunicorn command, Haystack throws the following error on any page load:
ImportError: cannot import name signals
I have no problems importing signals from the Django or Python shells. I use virtualenv and install all packages locally inside that environment. My wsgi.py file looks just like the default one in the django admin, except that I add the local path to the python path as such:
path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-2])
if path not in sys.path:
sys.path.append(path)`
Any help you could provide would be very appreciated, thank you!
I don't use gunicorn, but I had the same problem when I used the HAYSTACK_SIGNAL_PROCESSOR setting to point to a custom class that I wrote. That class imported one of my models, which eventually propagated up the import chain, to import my settings module, thus causing a circular import.
When using a setting such as HAYSTACK_SIGNAL_PROCESSOR that points to a class, make sure that class standsalone, and doesn't import either directly or indirectly the Django settings file.

Django User Registration Issue

Django newbie, running on Ubuntu 12.04, Django 1.3.1 and apt-get install python-django-registration.
Trying build a demo site to use the user registration module. I followed the steps from http://lightbird.net/dbe/forum3.html. But when I try to access accounts/ or admin/, getting the following error: "name 'registration' is not defined"
I am able to access the admin interface, after commenting out the registration part in urls.py. Any tips to overcome this issue?
is "registration" in INSTALLED_APPS in settings.py?
Is django-registration on your PYTHONPATH? Also I assume that you did syncdb after adding registration to installed app. If both are true, then try opening a shell prompt with python manage.py shell and import something from the registration module and see what error that gives

Django simple Captcha "No module named fields" error

Hi I am trying to implement Django simple capcha into my app but when i try to import from view.py "from captcha.fields import CaptchaField" i get an error "No module named fields". but i am able to import this in the django shell terminal. What else am i missing
Did you add captcha to the INSTALLED_APPS in your settings.py?
If so, did you install it, where did you install it, and is it on your Python path?
I encountered same problem before and I installed django-simple-captcha. It worked finally