Django-tinymce in Django Admin - "can't find variable: tinyMCE" - django

I'm trying to use django-tinymce to edit fields in django admin.
I've the app installed in my virtualenv (django-tinymce==1.5.1b4). It's listed in my installed apps -
INSTALLED_APPS = (
#...
'tinymce',
#...
)
My settings includes the following
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
'theme_advanced_toolbar_location': "top",
'theme_advanced_buttons1': "bold,italic,underline,separator,"
"bullist,separator,outdent,indent,separator,undo,redo",
'theme_advanced_buttons2': "",
'theme_advanced_buttons3': "",
}
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True
And I've got the files available at /MEDIA_ROOT/js/tiny_mce (the default).
My models look like -
from tinymce import models as tinymce_models
class MyModel(models.Model)
post = tinymce_models.HTMLField()
When I go to the model admin page, the field appears as a normal text field and my browser tells me there's an error on the inline js script for the field. It says it doesn't recognise the variable tinyMCE. It doesn't look like the page is even trying to load the js file (I'm getting no 404's - I can't see any sign of anything being loaded).
I'm not sure what I'm missing..

Have You, Sir, done python manage.py collectstatic ?
What value variable in settings.py is in TINYMCE_JS_ROOT and TINYMCE_JS_URL
If variable TINYMCE_JS_URL is not set check if You, Sir, have file at /MEDIA_ROOT/js/tiny_mce/tiny_mce.js. If not, try to copy manually from django-tinymce's egg.

OK, looks like it might have been a bug in the django_tinymce code. I've reverted to 1.5.1b2 and everything works as expected. Guess I should look into filing a bug report.

Related

Django 2.2.3 How get all urls patterns and all views name

I code app with Django == 2.2.3
By now i want to get all urls_patterns of all my project and associated view name.
How can i get something like this:
urls_patterns_view_names_list = [
("view_name", "view_name: url_pattern"),
...,
...,
...,
]
I have seen several topics to the question of url patterns but none correspond and do what I want. For the most part the answers are very old and obsessive for my case. That's why I reformulate my question: I want to have the urls patterns and for each url associated the name of his view: How can I do that with Django 2.2.3 on python 3.7?
You can achieve this with django-extensions:
pip install django-extensions
Then in settings.py:
INSTALLED_APPS = [
...
'django_extensions',
...
]
And finally in your command line:
./manage.py show_urls
This will result in exactly what you want. From the package docs:
show_urls: Produce a tab-separated list of (url_pattern, view_function, name) tuples for a project.
It's not directly trivial, but I've written a module, https://github.com/valohai/django-urr, that has utilities for working and traversing Django URL resolvers.
If you end up using it, you can just use
for entry in django_urr.extract_urls():
print(vars(entry))
– see here for all of the contents of entrys.

Does django-constance admin supports database backend?

I'm trying to setup the admin to show settings meant to be stored in database backend (Postgres 9.5.0). I manually created values in shell_plus as follows:
In [1]: from constance.backends.database.models import Constance
In [2]: first_record = Constance.objects.get(id=1)
In [3]: first_record
Out[3]:
pg-admin properly shows the entry although django admin doesn't show it at all. I ran migrate command for both databases (I have default and product databases) but the record still is not showing up. Certainly I can make it work with forcing to register with admin as follows:
admin.site.register(Constance)
but my question is if it's necessary?
Yes, they do.
You need to manage dependencies, but you can just use next command to install:
pip install "django-constance[database]"
Also you need to add some additionl settings to your settings.py :
CONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'
INSTALLED_APPS = (
# other apps
'constance.backends.database',
)
#optional - in case you want specify table prefix
CONSTANCE_DATABASE_PREFIX = 'constance:myproject:'
Then you need to apply migrations by running command python manage.py migrate database
For displaying settings inputs in admin you should specify them in your settings.py. There are various types of fields and you even can add your own types of fields using CONSTANCE_ADDITIONAL_FIELDS parameter.
CONSTANCE_CONFIG = {
'THE_ANSWER': (42, 'Answer to the Ultimate Question of Life, '
'The Universe, and Everything'),
}
You can read more at documentation page.

Django-CMS pages all blank after upgrade from 2.3.5 to 2.4.1

I am using Django 1.4.3 and have several sites built using Django-CMS 2.3.5. I want to upgrade them to Django-CMS 2.4.1, so that I can then start to move to Django 1.5.
When I type ./manage runserver from a virtualenv with Django-CMS 2.3.5, all works fine. When I move to a virtualenv with Django-CMS 2.4.1, but otherwise the same, none of my pages can be accessed.
In the admin panel, they all have the name None. If I edit one, the screen shows them with the correct name and all the plugins there. If I try to save the page, the info all disappears, including the name and slug and plugins, and I get a message at the top asking me to fix the below errors (of which there are none). I can press "publish draft", but the browser cannot find any page but /, and this has no plugins on it (and it still has name None in the admin panel).
If I try to add a new plugin, I get an alert saying <django.utils.functional.__proxy__ object at 0x1067a9e90>.
I am not using the MultilingualURLMiddleware middleware, and have USE_I18N = False.
I added 'django.middleware.locale.LocaleMiddleware' to MIDDLEWARE_CLASSES anyway (but it doesn't help if I do not).
I typed ./manage.py migrate, ./manage cms fix-mptt and for good measure ./manage.py cms delete_orphaned_plugins as well.
How do I keep my pages when I migrate to the new version of Django-CMS?
thanks
Here are upgrade instruction.
I think your problem is in new style CMS_LANGUAGES.
Try to set:
USE_I18N = True
CMS_LANGUAGES = {
1: [
{
'code': 'en',
'name': gettext('English'),
'public': True,
},
],
'default': {
'fallbacks': ['en',],
'public': False,
}
}
Also run ./manage.py cms check to checking django CMS installation
The most crucial thing I've ever learnt in django was taking manuel backup of the project.db before any migration process done by manage.py.

Getting django-facebook to work

I an trying to get django-facebook to work as per instructions given in the readme on
https://github.com/tschellenbach/Django-facebook. I am new to django.
It looks simple but I am facing the following problems. I am not able to get it to work.
In the readme it says AUTH_USER_MODEL = 'member.FacebookUser'. I am guessing the right option is
AUTH_USER_MODEL = 'django_facebook.FacebookUser'
after importing the models - this took me some t even after making that change, syncdb throws an error stating that:
FacebookUser does not have a USERNAME_FIELD.
Not able to solve that I decided to use the default user model - auth.user. That works and I was able to load facebook/example. However after authentication from facebook, I get an error
You need to set AUTH_PROFILE_MODULE in your project settings
So I added AUTH_PROFILE_MODULE = 'django_facebook.FacebookProfile'
Now it returns a new error -
FacebookProfile matching query does not exist. Lookup parameters were {'user_id_exact': 2L}
What should I do now?
Do python manage.py syncdb or whatever it needs to be done to update your database schema with the new table (facebook_profile).
Also, you don't mention it but I have and app that uses django_facebook and I have my settings.py file like this:
TEMPLATE_CONTEXT_PROCESSORS = (
...
'django_facebook.context_processors.facebook',
...
)
AUTHENTICATION_BACKENDS = (
...
'django_facebook.auth_backends.FacebookBackend',
)
I hope it helps

Undetected Django app when installing from git

I'm having trouble installing django-admin_action_mail from git.
I tried to install it via:
pip install
git+https://github.com/mjbrownie/django-admin_action_mail.git
But Django did not pick it up when I added it to settings.INSTALLED_APPS.
Did I miss something?
The admin code for that app is commented out (see here: https://github.com/mjbrownie/django-admin_action_mail/blob/master/admin_action_mail/admin.py ) so nothing is going to show up on the admin page - even if it's working and enabled.
It looks as though you need to create your own models to handle the mailing functions. Take a look at the README where it tells you to add something like the following in your app's admin.py:
from admin_action_mail.actions import mail_action
class MyModelAdmin(admin.ModelAdmin):
#Note all args are optional
actions = [
mail_action(
'description' : "Send Email to Related Users",
'email_dot_path' : 'email', # dot path string to email field (eg 'user.email')
'email_template_html' : 'admin_action_email/email.html'
'reply_to' : 'noreply#example.com' # defaults to request.user.email
)
]
admin.site.register(MyModel, MyModelAdmin)
Have you added a model like that to your own app's admin.py?
EDIT: As the problem appears to be with installation, the following should help:
You can add arbitrary paths to your wsgi path spec, that means it will pick up Python app modules in other locations. Assuming your app is installed in /home/user2161049/myapp you can put your external modules under /home/user2161049/myapp/external. In this case copy the contents of that app into /home/user2161049/myapp/external/admin_action_mail/.
To add this to your settings.py:
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(SITE_ROOT, 'external'))
The first line defines SITE_ROOT based on the current running script (setup.py) at startup. The second adds the external folder into the search path. You can put anything you want in there, and even define a specific folder somewhere else if you want to keep your externals out of your app folder. Restart the server and it should find the app just fine.