Django FeinCMS and page extensions issue - python

I'm experimenting with Page extensions and FeinCMS 1.2.1.
I'd like to create this simple page extension:
from django.db import models
def register(cls, admin_cls):
cls.add_to_class(models.TextField())
but I keep getting this error:
AttributeError: 'module' object has no attribute 'TextField'
The package containing the extension is called dev.extensions and the module categories, I have added it to the Python path and the extension is registered with Page.register_extensions('dev.extensions.categories').
I'm wondering what I'm doing wrong, please help.
The complete stacktrace follows.
c:\sandbox\projects\feindev>python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_manager(settings)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 436, in execute_m
anager
setup_environ(settings_mod)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\core\management\__init__.py", line 419, in setup_env
iron
project_module = import_module(project_name)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "c:\sandbox\projects\feindev\..\fein
dev\__init__.py", line 52, in <module>
Page.register_extensions('dev.extensions.types')
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\models.py", line 270, in register_extensions
cls.register_extension(fn)
File "c:\sandbox\environments\feincms-1.2
.1\lib\site-packages\feincms\module\page\models.py", line 564, in register_exten
sion
register_fn(cls, PageAdmin)
File "c:\sandbox\projects\feindev\dev\ext
ensions\types\__init__.py", line 4, in register
cls.add_to_class(models.TextField())
AttributeError: 'module' object has no attribute 'TextField'

Maybe models is getting reassigned somewhere to another module before your register function gets run?
Try changing your code to this:
from django.db import models as django_models
def register(cls, admin_cls):
cls.add_to_class('field_name_here', django_models.TextField())

Related

AttributeError: 'module' object has no attribute 'commit_on_success'

I'm trying to use Django-nested-inlines application but it raises error. Here is a simple code:
MODELS.PY
class Language_Quiz(models.Model):
name = models.CharField(max_length=40)
language = models.OneToOneField(sfl_models.Language)
class Question(models.Model):
language_quiz = models.ForeignKey(Language_Quiz)
text = models.TextField()
class Answer(models.Model):
question = models.ForeignKey(Question,related_name='answers')
text = models.TextField()
correct = models.BooleanField()
ADMIN.PY
from django.contrib import admin
import models
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline
class AnswerInline(NestedTabularInline):
model = models.Answer
class QuestionInline(NestedTabularInline):
model = models.Question
class LanguageQuizAdmin(NestedModelAdmin):
inlines = [QuestionInline]
admin.site.register(models.Language_Quiz,LanguageQuizAdmin)
admin.site.register(models.Answer)
admin.site.register(models.Question)
But when I run server or try to make migrations, the error is raised. I have no idea where is the problem. Where is the problem?
TRACEBACK
(venv) C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2>python manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
utility.execute()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\core\management\__init__.py", line 328, in execute
django.setup()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\apps\registry.py", line 115, in populate
app_config.ready()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\contrib\admin\apps.py", line 22, in ready
self.module.autodiscover()
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\contrib\admin\__init__.py", line 24, in autodiscover
autodiscover_modules('admin', register_to=site)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\django\utils\module_loading.py", line 74, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "c:\python27\Lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\language_tests\admin.py", line 3, in <module>
from nested_inlines.admin import NestedModelAdmin, NestedTabularInline
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\nested_inlines\admin.py", line 16, in <module>
class NestedModelAdmin(ModelAdmin):
File "C:\Users\Milano\PycharmProjects\FutileStudio\SolutionsForLanguages_2\venv\lib\site-packages\nested_inlines\admin.py", line 131, in NestedModelAdmin
#transaction.commit_on_success
AttributeError: 'module' object has no attribute 'commit_on_success'
As Kapil Sachdev and karthikr commented, the problem is with compatibility. Django-nested-inlines has probably some issues working with Django 1.8+.
In my case, the solution was very simple. Download using pip Django-nested-inline (without 's' at the end of the 'inline') and just change import. I didn't even have to change the code.

AttributeError: 'module' object has no attribute 'Command'

I'm working with django 1.7 and i have created this management command:
File structure:
app/
__init__.py
management/
__init__.py
commands/
__init__.py
modal_asign.py
Code:
from django.core.management.base import BaseCommand, CommandError
from webinar.models import Webinar
class Commands(BaseCommand):
help = 'Assign modal link to every webinar'
def handle(self):
latest_webinar = Webinar.objects.all().order_by('-webinar_date')[0]
for webinars in latest_webinar:
print "http://webinar.academiaa2.com/webinars/#displayModal" + webinars
and i'm getting this error when trying to test it with python manage.py modal_asign
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 238, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 42, in load_command_class
return module.Command()
AttributeError: 'module' object has no attribute 'Command'
Your class name is called Commands, whereas django expects it to be called Command. Hence the error.
Change
class Commands(BaseCommand):
to
class Command(BaseCommand):

How to Import Function from different directory in python

I have following file structure:
/usr/share/pyshared/orca/scripts/toolkits/Gecko/script.py
In this file def getExtents is function that I have to access in following file i.e:
/usr/share/pyshared/orca/scripts/default.py
so I am trying to import function from script.py to the following file:
/usr/share/pyshared/orca/scripts/default.py
following line is added in /usr/share/pyshared/orca/scripts/default.py:
from orca.scripts.toolkits.Gecko.script import getExtents
But I get following errors:
File "<string>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1498, in main
init(pyatspi.Registry)
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 1215, in init
loadUserSettings()
File "/usr/lib/pymodules/python2.7/orca/orca.py", line 837, in loadUserSettings
_scriptManager.activate()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 80, in activate
self.setActiveScript(self.getScript(None), "activate")
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 247, in getScript
appScript = self.getDefaultScript()
File "/usr/lib/pymodules/python2.7/orca/script_manager.py", line 214, in getDefaultScript
import scripts.default as default
File "/usr/lib/pymodules/python2.7/orca/scripts/default.py", line 57, in <module>
from orca.scripts.toolkits.Gecko.script import getExtents
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/__init__.py", line 1, in <module>
from script import Script
File "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py", line 52, in <module>
import orca.scripts.default as default
AttributeError: 'module' object has no attribute 'default'
I think you probably need
from orca.scripts import default
Also, as mentioned in the comments, check you've got the relevant __init__.py
edit: re-reading the stacktrace, looks like you've got a circular import too, you're trying to import orca.scripts.default in line 52 of "/usr/lib/pymodules/python2.7/orca/scripts/toolkits/Gecko/script.py"

Flask-Superadmin - 'module' object has no attribute 'FileField'

I'm tring to launch simple code from the docs:
https://flask-superadmin.readthedocs.org/en/latest/quickstart.html
Here is the code:
from flask import Flask
from flask.ext.superadmin import Admin
app = Flask(__name__)
admin = Admin(app)
app.run()
but the following error occures:
Traceback (most recent call last):
File "test.py", line 2, in <module>
from flask.ext.superadmin import Admin
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask/exthook.py", line 62, in load_module
__import__(realname)
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/__init__.py", line 2, in <module>
from model import ModelAdmin
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/model/__init__.py", line 1, in <module>
from .base import ModelAdmin, AdminModelConverter
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/model/base.py", line 10, in <module>
from flask_superadmin.form import BaseForm, ChosenSelectWidget, DatePickerWidget, \
File "/home/un1t/workspace/dj/python/local/lib/python2.7/site-packages/flask_superadmin/form.py", line 115, in <module>
class FileField(wtf.FileField):
AttributeError: 'module' object has no attribute 'FileField'
I use the following versions of libraries:
Flask==0.10.1
Flask-Script==0.6.2
Flask-SuperAdmin==1.7
Flask-WTF==0.9.1
flask-mongoengine==0.7.0
WTForms==1.0.4
What is wrong, or where could I find working examples?
This is a bug in the import. I fixed it in my fork; clone from there and then try it again.

freeswitch python scripts errno 10 no child processes

I' ve got an issue when running freeswitch with some python scripts inside dialplan using django.db models. Whenever it starts it causes errors:
freeswitch#ubuntu> 2013-08-15 06:56:08.094348 [ERR] mod_python.c:231 Error importing module
2013-08-15 06:56:08.094348 [ERR] mod_python.c:164 Python Error by calling script "fs_scripts.ringback": <type 'exceptions.IOError'>
Message: [Errno 10] No child processes
Exception: None
Traceback (most recent call last)
File: "/home/piotrek/lettel/fs_scripts/ringback.py", line 19, in <module>
File: "/home/piotrek/lettel/api/call.py", line 3, in <module>
File: "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 11, in <module>
File: "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py", line 184, in inner
File: "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
File: "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 93, in __init__
File: "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
File: "/home/piotrek/lettel/lettel/settings.py", line 13, in <module>
File: "/usr/local/lib/python2.7/dist-packages/djcelery/__init__.py", line 25, in <module>
File: "/usr/local/lib/python2.7/dist-packages/celery/__compat__.py", line 135, in __getattr__
File: "/usr/local/lib/python2.7/dist-packages/celery/_state.py", line 19, in <module>
File: "/usr/local/lib/python2.7/dist-packages/celery/utils/__init__.py", line 22, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/entity.py", line 10, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/abstract.py", line 12, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/connection.py", line 24, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/log.py", line 8, in <module>
File: "/usr/local/lib/python2.7/dist-packages/kombu/utils/compat.py", line 68, in <module>
File: "/usr/lib/python2.7/platform.py", line 1337, in system
File: "/usr/lib/python2.7/platform.py", line 1304, in uname
File: "/usr/lib/python2.7/platform.py", line 1039, in _syscmd_uname
edit: the line that causes errors is a simple import from django.db:
from django.db import models
This whole setup is already running on some server that I dont have access to, so it seems to be nothing wrong with django app or scripts...
Any help would be appreciated cause I am running out of ideas how to solve this problem...
I dont know your performance and scalability requirements, despite that a softswitch have realtime requirements to run rtp stream and signalling. So is not a good solution run django applications under mod_python. Furthermore that is not the same as python interpreter directly, somethings does not work. You can check the mod_python issues here:
mod_python issues
I would advice you to split your python solution in a client/server architecture. The script running under mod_python will make queries to your Django application. That way you will get rid of the complexity in Freeswitch side, get scalable, improve performance and most probably get everything working OK.

Categories