Django CMS error when displaying advanced settings for page - django-cms

This is the error I get when trying to change the advanced settings of a page while in admin mode:
TypeError at /admin/cms/page/5/advanced-settings/
__str__ returned non-string (type __proxy__)
Environment:
Request Method: GET
Request URL: http://localhost:8000/admin/cms/page/5/advanced-settings/?language=en&cms_path=/
Django Version: 2.1.7
Python Version: 3.6.7
Installed Applications:
['djangocms_admin_style',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
'django.contrib.sitemaps',
'django.contrib.staticfiles',
'django.contrib.messages',
'cms',
'menus',
'sekizai',
'treebeard',
'djangocms_text_ckeditor',
'filer',
'easy_thumbnails',
'djangocms_column',
'djangocms_file',
'djangocms_link',
'djangocms_picture',
'djangocms_style',
'djangocms_snippet',
'djangocms_googlemap',
'djangocms_video',
'structuresend']
Installed Middleware:
['cms.middleware.utils.ApphookReloadMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware']
Template error:
In template /usr/local/lib/python3.6/dist-packages/django/forms/templates/django/forms/widgets/select_option.html, error at line 1
__str__ returned non-string (type __proxy__)
1 : <option value="{{ widget.value|stringformat:'s' }}"{% include "django/forms/widgets/attrs.html" %}> {{ widget.label }} </option>
2 :
Traceback:
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
156. response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py" in _get_response
154. response = response.render()
File "/usr/local/lib/python3.6/dist-packages/django/template/response.py" in render
106. self.content = self.rendered_content
File "/usr/local/lib/python3.6/dist-packages/django/template/response.py" in rendered_content
83. content = template.render(context, self._request)
File "/usr/local/lib/python3.6/dist-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
171. return self._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
150. return compiled_parent._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
150. return compiled_parent._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
150. return compiled_parent._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
62. result = block.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
188. return template.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
173. return self._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
150. return compiled_parent._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
309. return nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
309. return nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
993. return render_value_in_context(output, context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_value_in_context
972. value = str(value)
File "/usr/local/lib/python3.6/dist-packages/django/utils/html.py" in <lambda>
397. klass.__str__ = lambda self: mark_safe(klass_str(self))
File "/usr/local/lib/python3.6/dist-packages/django/forms/boundfield.py" in __str__
33. return self.as_widget()
File "/usr/local/lib/python3.6/dist-packages/django/forms/boundfield.py" in as_widget
93. renderer=self.form.renderer,
File "/usr/local/lib/python3.6/dist-packages/django/forms/widgets.py" in render
230. return self._render(self.template_name, context, renderer)
File "/usr/local/lib/python3.6/dist-packages/django/forms/widgets.py" in _render
235. return mark_safe(renderer.render(template_name, context))
File "/usr/local/lib/python3.6/dist-packages/django/forms/renderers.py" in render
31. return template.render(context, request=request).strip()
File "/usr/local/lib/python3.6/dist-packages/django/template/backends/django.py" in render
61. return self.template.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
171. return self._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/defaulttags.py" in render
209. nodelist.append(node.render_annotated(context))
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py" in render
188. return template.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
173. return self._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in _render
163. return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
937. bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_annotated
904. return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render
993. return render_value_in_context(output, context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py" in render_value_in_context
972. value = str(value)
Exception Type: TypeError at /admin/cms/page/5/advanced-settings/
Exception Value: __str__ returned non-string (type __proxy__)
The problem seems to be a value = str(value) not returning a string, although value is said to be 'Inherit the template of the nearest ancestor'. I'm not sure what's happening here.
Apparently it returns a __proxy__ type, which according to other questions is a type used for translation. What can I do to fix this? I need access to the settings of my page to change the html template it uses.

I had the same problem-- setting I18N=True in my settings.py did the trick.
If that doesn't work, try pip installing django-parler and see if it helps.

For other people who have the same problem.
The settings I18N mustn't set to False.
If your goal is to deactivate multi language site you can delete "i18n_patterns" in urls.py.

As per this comment on the github
modify the urls.py as follows
# replace
urlpatterns += i18n_patterns(path("admin/", admin.site.urls), path("", include("cms.urls")))
# with
urlpatterns += i18n_patterns(
path("admin/", admin.site.urls),
path("", include("cms.urls")),
prefix_default_language=False # NOTICE THIS HERE
)
and in settings.py keep USE_I18N = True.

Related

Django cms filer fails to upload file

While trying to upload a file using django cms filer I am getting the following error
`*Internal Server Error: /admin/filer/clipboard/operations/upload/1/
Traceback (most recent call last):
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/admin/clipboardadmin.py", line 112, in ajax_upload
file_obj.save()
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/imagemodels.py", line 66, in save
super().save(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/abstract.py", line 107, in save
super().save(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/models/filemodels.py", line 279, in save
super().save(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/polymorphic/models.py", line 87, in save
return super().save(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 726, in save
self.save_base(using=using, force_insert=force_insert,
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 762, in save_base
parent_inserted = self._save_parents(cls, using, update_fields)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 791, in _save_parents
updated = self._save_table(
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 868, in _save_table
results = self._do_insert(cls._base_manager, using, fields, returning_fields, raw)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/base.py", line 906, in _do_insert
return manager._insert(
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/query.py", line 1270, in _insert
return query.get_compiler(using=using).execute_sql(returning_fields)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1409, in execute_sql
for sql, params in self.as_sql():
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1352, in as_sql
value_rows = [
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1353, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1353, in <listcomp>
[self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/sql/compiler.py", line 1304, in pre_save_val
return field.pre_save(obj, add=True)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 301, in pre_save
file.save(file.name, file.file, save=False)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/filer/fields/multistorage_file.py", line 120, in save
super().save(name, content, save)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/easy_thumbnails/files.py", line 643, in save
super().save(name, content, *args, **kwargs)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 87, in save
name = self.field.generate_filename(self.instance, name)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/db/models/fields/files.py", line 320, in generate_filename
return self.storage.generate_filename(filename)
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django/core/files/storage.py", line 108, in generate_filename
return os.path.normpath(os.path.join(dirname, self.get_valid_name(filename)))
File "/home/kvint/temp/temp/django-cms-quickstart/venv/lib/python3.10/site-packages/django_storage_url/backends/not_implemented.py", line 14, in get_valid_name
raise NotImplementedError
NotImplementedError
[20/Feb/2023 09:27:05] "POST /admin/filer/clipboard/operations/upload/1/?qqfile=img0.jpg HTTP/1.1" 500 187409
[20/Feb/2023 09:27:05] "GET /admin/filer/folder/1/list/?order_by=-modified_at HTTP/1.1" 200 16717
*`
I used the default installation of DjangoCMS from git#github.com:django-cms/django-cms-quickstart.git
I only modified the DATABASE settings so it uses sqlite
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
Here is my full settings file
from pathlib import Path
import os
import dj_database_url
from django_storage_url import dsn_configured_storage_class
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG') == "True"
ALLOWED_HOSTS = [os.environ.get('DOMAIN'),]
DEBUG = True
ALLOWED_HOSTS = ["localhost",]
if DEBUG:
ALLOWED_HOSTS = ["*",]
# Redirect to HTTPS by default, unless explicitly disabled
#SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False"
X_FRAME_OPTIONS = 'SAMEORIGIN'
# Application definition
INSTALLED_APPS = [
'backend',
# optional, but used in most projects
'djangocms_admin_style',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'whitenoise.runserver_nostatic', # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
'django.contrib.staticfiles',
'django.contrib.sites',
# key django CMS modules
'cms',
'menus',
'treebeard',
'sekizai',
# Django Filer - optional, but used in most projects
'filer',
'easy_thumbnails',
# the default CKEditor - optional, but used in most projects
'djangocms_text_ckeditor',
# some content plugins - optional, but used in most projects
'djangocms_file',
'djangocms_icon',
'djangocms_picture',
'djangocms_style',
'djangocms_googlemap',
'djangocms_video',
# optional django CMS Frontend modules
'djangocms_frontend',
'djangocms_frontend.contrib.accordion',
'djangocms_frontend.contrib.alert',
'djangocms_frontend.contrib.badge',
'djangocms_frontend.contrib.card',
'djangocms_frontend.contrib.carousel',
'djangocms_frontend.contrib.collapse',
'djangocms_frontend.contrib.content',
'djangocms_frontend.contrib.grid',
'djangocms_frontend.contrib.jumbotron',
'djangocms_frontend.contrib.link',
'djangocms_frontend.contrib.listgroup',
'djangocms_frontend.contrib.media',
'djangocms_frontend.contrib.image',
'djangocms_frontend.contrib.tabs',
'djangocms_frontend.contrib.utilities',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.locale.LocaleMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware',
]
ROOT_URLCONF = 'backend.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
'django.template.context_processors.csrf',
'django.template.context_processors.tz',
'django.template.context_processors.i18n',
'cms.context_processors.cms_settings',
'sekizai.context_processors.sekizai',
],
},
},
]
THUMBNAIL_PROCESSORS = (
'easy_thumbnails.processors.colorspace',
'easy_thumbnails.processors.autocrop',
#'easy_thumbnails.processors.scale_and_crop',
'filer.thumbnail_processors.scale_and_crop_with_subject_location',
'easy_thumbnails.processors.filters',
)
CMS_TEMPLATES = [
# a minimal template to get started with
('minimal.html', 'Minimal template'),
# optional templates that extend base.html, to be used with Bootstrap 5
('bootstrap5.html', 'Bootstrap 5 Demo'),
# serving static files with whitenoise demo
('whitenoise-static-files-demo.html', 'Static File Demo'),
]
WSGI_APPLICATION = 'backend.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
# Configure database using DATABASE_URL; fall back to sqlite in memory when no
# environment variable is available, e.g. during Docker build
#DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:')
#DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
if not DEBUG:
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en'
LANGUAGES = [
('en', 'English'),
]
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
# Media files
# DEFAULT_FILE_STORAGE is configured using DEFAULT_STORAGE_DSN
# read the setting value from the environment variable
DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN')
# dsn_configured_storage_class() requires the name of the setting
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')
# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass'
# only required for local file storage and serving, in development
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('/data/media/')
SITE_ID = 1

execution_date jinja resolving as a string

I have an airflow dag that uses the following jinja template: "{{ execution_date.astimezone('Etc/GMT+6').subtract(days=1).strftime('%Y-%m-%dT00:00:00') }}"
This template works in other dags, and it works when the schedule_interval for the dag is set to timedelta(hours=1). However, when we set the schedule interval to 0 8 * * *, it throws the following traceback at runtime:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 1426, in _run_raw_task
self.render_templates()
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 1790, in render_templates
rendered_content = rt(attr, content, jinja_context)
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 2538, in render_template
return self.render_template_from_field(attr, content, context, jinja_env)
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 2520, in render_template_from_field
for k, v in list(content.items())}
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 2520, in <dictcomp>
for k, v in list(content.items())}
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 2538, in render_template
return self.render_template_from_field(attr, content, context, jinja_env)
File "/usr/lib/python2.7/site-packages/airflow/models/__init__.py", line 2514, in render_template_from_field
result = jinja_env.from_string(content).render(**context)
File "/usr/lib64/python2.7/site-packages/jinja2/environment.py", line 1008, in render
return self.environment.handle_exception(exc_info, True)
File "/usr/lib64/python2.7/site-packages/jinja2/environment.py", line 780, in handle_exception
reraise(exc_type, exc_value, tb)
File "<template>", line 1, in top-level template code
TypeError: astimezone() argument 1 must be datetime.tzinfo, not str
It appears the execution date being passed in is a string, not a datetime object; but I am only able to hit this error on this specific dag, and no others. I've tried deleting the dag entirely and recreating it with no luck.
Looks like astimezone(..) function is misbehaving, it expects a datetime.tzinfo while you are passing it an str argument ('Etc/GMT+6')
TypeError: astimezone() argument 1 must be datetime.tzinfo, not str
While I couldn't make the exact thing work, I believe following achieves pretty much the same effect as what you are trying
{{ execution_date.in_timezone("US/Eastern") - timedelta(days=1) }}
Recall that
execution_date macro is a Pendulum object
in_timezone(..) converts it into a datetime.datetime(..)
then we just add a datetime.timedelta(days=1) to it

Need help to set up a wizard in OpenERP 7.0

I'm trying to implement a wizard that will update a form a then (if possible, send a signal to workflow to change status of an object, but that will be for later). I'm trying and trying, but I'm doing something wrong since I get stuck with this annoying error!
ValueError: No such external ID currently defined in the system: processos_uc.reformulate_generic_request_wizard
I've got these two files inside the "wizard" folder:
reformulate_wizard.py:
from openerp.osv import osv
from openerp.osv import fields
from openerp.tools.translate import _
class ref_generic_request(osv.osv_memory):
_name='ref.generic.request'
_columns = {
'reformulation_info': fields.text('Reformulation instructions', help='Instructions for the requestor justification the reformulation needs'),
}
def save_info(self, cr, uid, ids, context=None):
if 'active_id' in context:
info=self.browse(cr,uid,ids)[0].reformulation_info
self.pool.get('generic.request').write(cr,uid,context['active_id'],
{'reformulation_info' : reformulation_info})
return {
'type': 'ir.actions.act_window_close',
}
ref_generic_request()
reformulate_wizard.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_reformulate_generic_request_wizard" model="ir.ui.view">
<field name="name">reformulate_generic_request_wizard.form</field>
<field name="model">ref.generic.request</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Insert reformulation info" version="7.0">
<group colspan="4" >
<separator string="bla bla bla here" colspan="4"/>
<field name="reformulation_info" string="Reformulation info"/>
<newline/>
</group>
<separator string="" colspan="4" />
<group colspan="4" col="6">
<button icon="gtk-cancel" special="cancel" string="Cancel"/>
<button icon="gtk-ok" name="save_info" string="Send to reformulation" type="object" />
</group>
</form>
</field>
</record>
<record id="action_reformulate_generic_request" model="ir.actions.act_window">
<field name="name">Reformulate Request</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">ref.generic.request</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="view_reformulate_generic_request_wizard"/>
<field name="target">new</field>
</record>
<act_window id="action_reformulate_generic_request"
name="Reformulate Request"
res_model="generic.request"
view_mode="form"
target="new"
/>
</data>
</openerp>
And I didn't forget the __init__.py with the "import reformulate_wizard" in it.
I am calling the wizard from my xml view like this (and I guess that's where I'm getting the error):
<button name="%(reformulate_generic_request_wizard)d" string="Button that calls wizard" type="object" />
In my base folder I'm importing the wizard folder inside the __init__.py:
import parecer
import pedido_generico
import tracing
import wizard
And here is the content of my __openerp__.py (The error might be from the order I'm loading things):
{
'name': 'Processos UC',
'version': '0.1',
'category': 'Tools',
'description': """
OpenERP Module that implements UC's business processes.""",
'author': 'Filipe Castanheira',
'website': 'http://www.uc.pt',
'depends': ['base','web'],
'demo': [],
'test':[],
#'js': [
# 'static/js/custom.js',
#],
'css': [ 'static/css/uc_css.css' ],
'update_xml' : [
'data/action_server.xml',
'security/security.xml',
'security/processos_uc_domain_rules.xml',
'wizard/reformulate_wizard.xml',
'processos_view.xml',
'parecer_wkf.xml',
'pedido_wkf.xml',
],
'data': [
'security/ir.model.access.csv',
'data/owner_groups.xml',
'data/subject_type.xml',
],
'installable': True,
'images': [],
}
Here is the error message from the server logs.
2014-05-14 16:55:45,182 19742 ERROR may_9 openerp.tools.convert: Parse error in /home/lfc/openerp/v7/addons/processos_uc/processos_view.xml:23:
(...)XML displayed here(...)
Traceback (most recent call last):
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 847, in parse
self._tags[rec.tag](self.cr, rec, n)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 807, in _tag_record
f_val = _eval_xml(self,field, self.pool, cr, self.uid, self.idref)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 154, in _eval_xml
for n in node]), idref)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 148, in _process
idref[id]=self.id_get(cr, id)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 824, in id_get
res = self.model_id_get(cr, id_str)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 833, in model_id_get
return model_data_obj.get_object_reference(cr, self.uid, mod, id_str)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 18, in lookup
r = self.lookup(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 46, in lookup
value = d[key] = self.method(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 869, in get_object_reference
data_id = self._get_id(cr, uid, module, xml_id)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 18, in lookup
r = self.lookup(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 46, in lookup
value = d[key] = self.method(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 862, in _get_id
raise ValueError('No such external ID currently defined in the system: %s.%s' % (module, xml_id))
ValueError: No such external ID currently defined in the system: processos_uc.reformulate_generic_request_wizard
2014-05-14 16:55:45,186 19742 ERROR may_9 openerp.netsvc: No such external ID currently defined in the system: processos_uc.reformulate_generic_request_wizard
Traceback (most recent call last):
File "/opt/openerp/v7/server/openerp/netsvc.py", line 292, in dispatch_rpc
result = ExportService.getService(service_name).dispatch(method, params)
File "/opt/openerp/v7/server/openerp/service/web_services.py", line 433, in dispatch
return fn(*params)
File "/opt/openerp/v7/server/openerp/service/web_services.py", line 444, in exp_authenticate
res_users = pooler.get_pool(db).get('res.users')
File "/opt/openerp/v7/server/openerp/pooler.py", line 49, in get_pool
return get_db_and_pool(db_name, force_demo, status, update_module)[1]
File "/opt/openerp/v7/server/openerp/pooler.py", line 33, in get_db_and_pool
registry = RegistryManager.get(db_name, force_demo, status, update_module)
File "/opt/openerp/v7/server/openerp/modules/registry.py", line 192, in get
update_module)
File "/opt/openerp/v7/server/openerp/modules/registry.py", line 218, in new
openerp.modules.load_modules(registry.db, force_demo, status, update_module)
File "/opt/openerp/v7/server/openerp/modules/loading.py", line 350, in load_modules
force, status, report, loaded_modules, update_module)
File "/opt/openerp/v7/server/openerp/modules/loading.py", line 256, in load_marked_modules
loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
File "/opt/openerp/v7/server/openerp/modules/loading.py", line 187, in load_module_graph
load_update_xml(module_name, idref, mode)
File "/opt/openerp/v7/server/openerp/modules/loading.py", line 74, in <lambda>
load_update_xml = lambda *args: _load_data(cr, *args, kind='update_xml')
File "/opt/openerp/v7/server/openerp/modules/loading.py", line 124, in _load_data
tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 954, in convert_xml_import
obj.parse(doc.getroot())
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 847, in parse
self._tags[rec.tag](self.cr, rec, n)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 807, in _tag_record
f_val = _eval_xml(self,field, self.pool, cr, self.uid, self.idref)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 154, in _eval_xml
for n in node]), idref)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 148, in _process
idref[id]=self.id_get(cr, id)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 824, in id_get
res = self.model_id_get(cr, id_str)
File "/opt/openerp/v7/server/openerp/tools/convert.py", line 833, in model_id_get
return model_data_obj.get_object_reference(cr, self.uid, mod, id_str)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 18, in lookup
r = self.lookup(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 46, in lookup
value = d[key] = self.method(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 869, in get_object_reference
data_id = self._get_id(cr, uid, module, xml_id)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 18, in lookup
r = self.lookup(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/tools/cache.py", line 46, in lookup
value = d[key] = self.method(self2, cr, *args)
File "/opt/openerp/v7/server/openerp/addons/base/ir/ir_model.py", line 862, in _get_id
raise ValueError('No such external ID currently defined in the system: %s.%s' % (module, xml_id))
ValueError: No such external ID currently defined in the system: processos_uc.reformulate_generic_request_wizard
Any help is more than welcome!
The error message is telling you where the trouble is: you're using an id reformulate_generic_request_wizard that isn't declared anywhere.
Your button should point at the action's id, action_reformulate_generic_request_wizard.
So, try this:
<button name="%(action_reformulate_generic_request_wizard)d" string="Button that calls wizard" type="object" />

DoesNotExist at /en-us/ A template tag couldn't find the page with lookup arguments `{'reverse_id': u'home', 'site': 1} `

I am currently going through the django-cms-demo. I have been using the code found here:
https://github.com/andrewschoen/django-cms-demo/tree/master/demo.
I had this working prior to adding the Poll app plugin. I had been getting reverse matching errors when I add the Poll app plugin in the django-admin. After a couple of fixes, I started getting the error below:
"A template tag couldn't find the page with lookup arguments {'reverse_id': u'home', 'site': 1}. The URL of the request was: 'http'://example.com/en-us/"
Traceback:
Environment:
Request Method: GET
Request URL: 'http'://127.0.0.1:8888/en-us/
Django Version: 1.5.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'cms',
'mptt',
'menus',
'south',
'sekizai',
'reversion',
'cms.plugins.text',
'polls',
'filer',
'easy_thumbnails',
'cms.plugins.link',
'cms.plugins.picture',
'tinymce',
'djangocms_column',
'cmsplugin_filer_file',
'cmsplugin_filer_image',
'cmsplugin_filer_teaser',
'cmsplugin_filer_folder',
'cmsplugin_filer_video')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
'cms.middleware.language.LanguageCookieMiddleware')
Template error:
In template /home/vagrant/django_cms/demo_cms/templates/subpage_base.html, error at line 26
A template tag couldn't find the page with lookup arguments {'reverse_id': u'home', 'site': 1}
. The URL of the request was: 'http'://example.com/en-us/
16 :
17 : {% placeholder sidebar %}
18 :
19 :
20 : {% block sub_content %}{% endblock %}
21 :
22 :
23 : {% endblock %}
24 :
25 : {% block footer %}
26 : {% show_placeholder 'footer' 'home' %}
27 : {% endblock %}
28 :
29 :
Traceback:
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
140. response = response.render()
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/response.py" in render
105. self.content = self.rendered_content
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/response.py" in rendered_content
82. content = template.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
140. return self._render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
124. return compiled_parent._render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
124. return compiled_parent._render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in _render
134. return self.nodelist.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/classytags/core.py" in render
106. return self.render_tag(context, **kwargs)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/sekizai/templatetags/sekizai_tags.py" in render_tag
76. rendered_contents = nodelist.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/loader_tags.py" in render
63. result = block.nodelist.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/base.py" in render
830. bit = self.render_node(node, context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/django/template/debug.py" in render_node
74. return node.render(context)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/classytags/core.py" in render
106. return self.render_tag(context, **kwargs)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/classytags/helpers.py" in render_tag
75. data = self.get_context(context, **kwargs)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/cms/templatetags/cms_tags.py" in get_context
468. return _show_placeholder_for_page(**self.get_kwargs(*args, **kwargs))
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/cms/templatetags/cms_tags.py" in _show_placeholder_for_page
436. page = _get_page_by_untyped_arg(page_lookup, request, site_id)
File "/home/vagrant/django_cms/local/lib/python2.7/site-packages/cms/templatetags/cms_tags.py" in _get_page_by_untyped_arg
107. raise Page.DoesNotExist(body)
Exception Type: DoesNotExist at /en-us/
Exception Value: A template tag couldn't find the page with lookup arguments {'reverse_id': u'home', 'site': 1}
. The URL of the request was: 'http'://example.com/en-us/
change:
{% show_placeholder 'footer' 'home' %}
to:
{% show_placeholder 'footer' %}
Or add an id in your home page advanced settings called home

sqlalchemy Sqlite not loading table rows

I'm using sqlite with sqlalchemy:
when I execute this command:
engine.execute("select * from teams");
<sqlalchemy.engine.base.ResultProxy object at 0x245b190>
Thus, it works as it returns a reference
I've a .py file which contain the class Team:
class Team(Base):
__tablename__ = 'teams'
id = Column(Integer,autoincrement=False, primary_key=True)
name = Column(String(255))
flag = Column(String(255))
url = Column(String(255))
I import Team from classes import
But when I try to use the ORM, i get the following error:
for instance in session.query(Team):
... print instance.id
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/orm/query.py", line 2224, in __iter__
return self._execute_and_instances(context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/orm/query.py", line 2239, in _execute_and_instances
result = conn.execute(querycontext.statement, self._params)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1450, in execute
params)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1583, in _execute_clauseelement
compiled_sql, distilled_params
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1697, in _execute_context
context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/base.py", line 1690, in _execute_context
context)
File "/usr/lib/python2.7/site-packages/SQLAlchemy-0.7.7-py2.7.egg/sqlalchemy/engine/default.py", line 331, in do_execute
cursor.execute(statement, parameters)
sqlalchemy.exc.OperationalError: (OperationalError) no such table: teams u'SELECT teams.id AS teams_id, teams.name AS teams_name, teams.flag AS teams_flag, teams.url AS teams_url \nFROM teams' ()
It says it can't find the table teams- confirm with SqlLite ( I use firefox plugin) that it exists and that is the name. Also, copy the SQL in the error message in a Sqlite window and see if it runs.

Resources