pragmaticmates / django-flatpages-i18n Goto Github PK
View Code? Open in Web Editor NEWTranslatable version of django.contrib.flatpages
License: BSD 3-Clause "New" or "Revised" License
Translatable version of django.contrib.flatpages
License: BSD 3-Clause "New" or "Revised" License
Hi there,
I'm getting the following error under django 1.6.x:
[[email protected]] out: Traceback (most recent call last):
[[email protected]] out: File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
[[email protected]] out: self.result = application(self.environ, self.start_response)
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 67, in __call__
[[email protected]] out: return self.application(environ, start_response)
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
[[email protected]] out: self.load_middleware()
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[[email protected]] out: mw_class = import_by_path(middleware_path)
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 26, in import_by_path
[[email protected]] out: sys.exc_info()[2])
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/utils/module_loading.py", line 21, in import_by_path
[[email protected]] out: module = import_module(module_path)
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
[[email protected]] out: __import__(name)
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/flatpages_i18n/middleware.py", line 4, in <module>
[[email protected]] out: from flatpages_i18n.views import flatpage
[[email protected]] out: File "/project_share/env/local/lib/python2.7/site-packages/flatpages_i18n/views.py", line 2, in <module>
[[email protected]] out: from django.core.xheaders import populate_xheaders
[[email protected]] out: ImproperlyConfigured: Error importing module flatpages_i18n.middleware: "No module named xheaders"
[[email protected]] out: [28/Feb/2014 09:08:18] "GET / HTTP/1.1" 500 59
[[email protected]] out:
The culprit seems to be on line 3 in the views.py file.
The populate_xheaders function doesn't seem to exists anymore in the 1.6.x versions.
Here's what I did to diagnose that problem.
$ mkdir flatpages_i18n_test
$ cd flatpages_i18n_test
$ virtualenv venv
$ source venv/bin/activate
$ pip install django==1.5.4
$ grep -r --include "*.py" xheaders lib/python2.7/site-packages/django
lib/python2.7/site-packages/django/contrib/flatpages/views.py:from django.core.xheaders import populate_xheaders
lib/python2.7/site-packages/django/contrib/flatpages/views.py: populate_xheaders(request, response, FlatPage, f.id)
lib/python2.7/site-packages/django/core/xheaders.py:def populate_xheaders(request, response, model, object_id):
## 1.6 switch
$ pip install django==1.6
$ grep -r --include "*.py" xheaders lib/python2.7/site-packages/django
$
A quick check shows that implicit relative imports (from models import Page
instead of .models
or flatpages_i18n
) in a few modules prevent working with Python 3.
I could make a PR but I haven’t seen how to run tests.
Looks like the context processors defined in the TEMPLATE
options of django settings are not loaded and used when rendering flat pages.
Seems like e53d7a7 fixed it though. Would you be able to release a new version? The latest one is 0.7.0
and it does not include this fix.
When I try to use Ckeditor field widget, like this:
from django import forms
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from flatpages_i18n.models import FlatPage_i18n
from flatpages_i18n.admin import FlatPageAdmin as BaseFlatPageAdmin
from flatpages_i18n.forms import FlatpageForm as BaseFlatpageForm
from ckeditor.widgets import CKEditorWidget
class FlatpageForm(BaseFlatpageForm):
for lang in settings.LANGUAGES:
field_id = 'content_%s' % lang[0]
locals()[field_id] = forms.CharField(widget=CKEditorWidget(), \
required=False, label=_(u'Content %s' % lang[0]))
class Meta:
model = FlatPage_i18n
class FlatPageAdmin(BaseFlatPageAdmin):
form = FlatpageForm
admin.site.unregister(FlatPage_i18n)
admin.site.register(FlatPage_i18n, FlatPageAdmin)
The editor is correctly display on the admin view, but when you try to save the form, this fail and return the error "Please correct the error below", but not field of the form is highlighted with an error.
Hi.
I'm looking for flatpages with i18n support, and I've found this project. And I'm curious why it is called "flatpages", because I see dependency on MPTT and I see parent-child relationship added. Flatpages are flat by design, not hierarchical. Have you considered a redesign?
README doesn't mention that django-mptt is a dependency (and that you should add 'mptt' to INSTALLED_APPS).
I'm using django-modeltranslation in my project. Translation with my models working perfect with this form:
<form action="/i18n/setlang/" method="post">
{% csrf_token %}
<input name="next" type="hidden" value="{{ redirect_to }}" />
<select name="language">
{% get_language_info_list for LANGUAGES as languages %}
{% for language in languages %}
<option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
{{ language.name_local }} ({{ language.code }})
</option>
{% endfor %}
</select>
<input type="submit" value="Go" />
</form>
But with django-flatpages-i18n language code wouldn't change (translation not working). How may I use switch language in django-flatpages-i18n?
Hello, would like to let you know that I have encountered a problem with views.flatpage. Some language codes has a hyphen in it, for which, the corresponding local codes use an underscore instead. e.g. for traditional chinese, language code sent by the browser in the request object is "zh-tw". The column that has been created in the flatpage_i18n table is "zh_tw". Calling the flatpage view after setting the language to zh-tw will result in the following error
FieldError at /about/
Cannot resolve keyword 'url_zh-tw' into field. Choices are: content, content_en, content_fr, content_zh_tw, enable_comments, id, registration_required, sites, template_name, title, title_en, title_fr, title_zh_tw, url, url_en, url_fr, url_zh_tw, weight
Request Method: GET
Request URL: http://127.0.0.1:8000/about/
Django Version: 1.5.1
...
For now, to work around it, I added the last line below to blindly replace any '-' with '_', assuming we can't have a hyphen in column names in databases, this works for my project for now.
language = request.LANGUAGE_CODE
language_prefix = '/%s' % language
language = language.replace('-', '_')
Going by the same logic, I suppose the same problem could potentially happen to the spanish and portuguese folks. (e.g. pt-BR for brazilian portuguese)
If you have other solutions, please kindly let me know!
Lastly, thanks for this wonderful package. It's exactly what I have been looking for and provides a simple-to-set-up solution for multilingual flatpages.
Regards,
Albert
After following the install instructions I get the the following error when trying to migrate or run any manage.py command:
File "/Users/athom09/Projects/voyages/voyagesEnv/lib/python2.7/site-packages/flatpages_i18n/models.py", line 1, in <module> from builtins import str as text ImportError: No module named builtins
I just installed django-flatpages-i18n for a Django 2.2 project. I followed the documentation through the "Migrate your database step", but after running python manage.py migrate
, I got the following traceback:
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\django\core\management\__init__.py", line 381, in execu
te_from_command_line
utility.execute()
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\django\core\management\__init__.py", line 357, in execu
te
django.setup()
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_u
nlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_mo
dule
File "<frozen importlib._bootstrap>", line 219, in _call_with_frame
s_removed
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\flatpages_i18n\models.py", line 11, in <module>
class FlatPage_i18n(MPTTModel):
File "C:\Users\micha\AppData\Local\Programs\Python\Python37-32\lib\
site-packages\flatpages_i18n\models.py", line 15, in FlatPage_i18n
null=True, blank=True)
TypeError: __init__() missing 1 required positional argument: 'on_del
ete'
Adding a bunch of , on_delete=models.CASCADE
to the ForeignKey
s in flatpages_i18n\models.py
resolved this issue.
TBA
The current "django-flatpages-i18n" doesn't work with the latest Django version (1.7), probably because of its dependence on "South". Have you planned adding compatibility with the latest version of Django?
Regards,
Luis
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.