mirror of
https://github.com/Hopiu/wagtail-modeltranslation.git
synced 2026-05-28 08:28:19 +00:00
Version 0.0.2
This commit is contained in:
parent
46a67a34e6
commit
e36442fdd4
10 changed files with 89 additions and 33 deletions
34
README.rst
34
README.rst
|
|
@ -1,28 +1,32 @@
|
|||
=====
|
||||
WAGTAIL MODELTRANSLATION ADAPTATION
|
||||
=====
|
||||
# WAGTAIL MODELTRANSLATION ADAPTATION
|
||||
|
||||
Simple app containing a mixin model that integrates modeltranslation
|
||||
(https://github.com/deschler/django-modeltranslation) into wagtail panels system.
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
## Quick start
|
||||
|
||||
1. Add "wagtail_modeltranslation" to your INSTALLED_APPS setting like this::
|
||||
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'wagtail_modeltranslation',
|
||||
**YOUR APPS**
|
||||
)
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'wagtail_modeltranslation',
|
||||
**YOUR APPS**
|
||||
)
|
||||
|
||||
2. Use TranslationMixin to integrate django-modeltranslation with Wagtail admin:
|
||||
|
||||
from wagtail_modeltranslation.models import TranslationMixin
|
||||
from wagtail_modeltranslation.models import TranslationMixin
|
||||
class FooModel(Page, TranslationMixin):
|
||||
foo = models.CharField()
|
||||
FooModel.panels = [...]
|
||||
|
||||
class FooModel(Page, TranslationMixin):
|
||||
foo = models.CharField()
|
||||
3. Visit django-modeltranslation for documentation - http://django-modeltranslation.readthedocs.org/en/latest/
|
||||
|
||||
FooModel.panels = [...]
|
||||
|
||||
2. Visit django-modeltranslation for documentation - http://django-modeltranslation.readthedocs.org/en/latest/
|
||||
## Release Notes:
|
||||
|
||||
### v0.0.2
|
||||
|
||||
**Features**:
|
||||
|
||||
- Prepopulated fields now works for translated fields (title and slug)
|
||||
|
|
|
|||
BIN
dist/wagtail-modeltranslation-0.0.2.tar.gz
vendored
Normal file
BIN
dist/wagtail-modeltranslation-0.0.2.tar.gz
vendored
Normal file
Binary file not shown.
2
setup.py
2
setup.py
|
|
@ -9,7 +9,7 @@ os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))
|
|||
|
||||
setup(
|
||||
name='wagtail-modeltranslation',
|
||||
version='0.0.1',
|
||||
version='0.0.2',
|
||||
packages=['wagtail_modeltranslation'],
|
||||
include_package_data=True,
|
||||
license='BSD License',
|
||||
|
|
|
|||
|
|
@ -1,39 +1,44 @@
|
|||
Metadata-Version: 1.1
|
||||
Name: wagtail-modeltranslation
|
||||
Version: 0.0.1
|
||||
Version: 0.0.2
|
||||
Summary: Integration of django-modeltranslation with Wagtail CMS
|
||||
Home-page: UNKNOWN
|
||||
Author: Rui Martins
|
||||
Author-email: rmartins16@gmail.com
|
||||
License: BSD License
|
||||
Description: =====
|
||||
WAGTAIL MODELTRANSLATION ADAPTATION
|
||||
=====
|
||||
Description: # WAGTAIL MODELTRANSLATION ADAPTATION
|
||||
|
||||
Simple app containing a mixin model that integrates modeltranslation
|
||||
(https://github.com/deschler/django-modeltranslation) into wagtail panels system.
|
||||
|
||||
Quick start
|
||||
-----------
|
||||
## Quick start
|
||||
|
||||
1. Add "wagtail_modeltranslation" to your INSTALLED_APPS setting like this::
|
||||
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'wagtail_modeltranslation',
|
||||
**YOUR APPS**
|
||||
)
|
||||
INSTALLED_APPS = (
|
||||
...
|
||||
'wagtail_modeltranslation',
|
||||
**YOUR APPS**
|
||||
)
|
||||
|
||||
2. Use TranslationMixin to integrate django-modeltranslation with Wagtail admin:
|
||||
|
||||
from wagtail_modeltranslation.models import TranslationMixin
|
||||
from wagtail_modeltranslation.models import TranslationMixin
|
||||
class FooModel(Page, TranslationMixin):
|
||||
foo = models.CharField()
|
||||
FooModel.panels = [...]
|
||||
|
||||
class FooModel(Page, TranslationMixin):
|
||||
foo = models.CharField()
|
||||
3. Visit django-modeltranslation for documentation - http://django-modeltranslation.readthedocs.org/en/latest/
|
||||
|
||||
FooModel.panels = [...]
|
||||
|
||||
2. Visit django-modeltranslation for documentation - http://django-modeltranslation.readthedocs.org/en/latest/
|
||||
## Release Notes:
|
||||
|
||||
### v0.0.2
|
||||
|
||||
**Features**:
|
||||
|
||||
- Prepopulated fields now works for translated fields (title and slug)
|
||||
|
||||
Platform: UNKNOWN
|
||||
Classifier: Environment :: Web Environment
|
||||
Classifier: Framework :: Django
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ wagtail_modeltranslation/models.py
|
|||
wagtail_modeltranslation/tests.py
|
||||
wagtail_modeltranslation/translation.py
|
||||
wagtail_modeltranslation/views.py
|
||||
wagtail_modeltranslation/wagtail_hooks.py
|
||||
wagtail_modeltranslation.egg-info/PKG-INFO
|
||||
wagtail_modeltranslation.egg-info/SOURCES.txt
|
||||
wagtail_modeltranslation.egg-info/dependency_links.txt
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
$(document).ready(function() {
|
||||
$.each(langs, function(idx, lang_code){
|
||||
$('#id_title_'+lang_code).on('focus', function() {
|
||||
console.log('focus');
|
||||
$('#id_slug_'+lang_code).data('previous-val', $('#id_slug_'+lang_code).val());
|
||||
$(this).data('previous-val', $(this).val());
|
||||
});
|
||||
|
||||
$('#id_title_'+lang_code).on('keyup keydown keypress blur', function() {
|
||||
if ($('body').hasClass('create') || (!$('#id_slug_'+lang_code).data('previous-val').length || cleanForSlug($('#id_title_'+lang_code).data('previous-val')) === $('#id_slug_'+lang_code).data('previous-val'))) {
|
||||
// only update slug if the page is being created from scratch, if slug is completely blank, or if title and slug prior to typing were identical
|
||||
$('#id_slug_'+lang_code).val(cleanForSlug($('#id_title_'+lang_code).val()));
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -7,6 +7,10 @@ from modeltranslation.translator import translator, TranslationOptions
|
|||
|
||||
# regist wagtail Page model for translation
|
||||
class PageTR(TranslationOptions):
|
||||
fields = ('title', 'slug')
|
||||
fields = (
|
||||
'title',
|
||||
'slug',
|
||||
'seo_title',
|
||||
'search_description',)
|
||||
|
||||
translator.register(Page, PageTR)
|
||||
|
|
|
|||
Binary file not shown.
26
wagtail_modeltranslation/wagtail_hooks.py
Normal file
26
wagtail_modeltranslation/wagtail_hooks.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# coding: utf-8
|
||||
|
||||
from django.utils.html import format_html, format_html_join
|
||||
from django.conf import settings
|
||||
|
||||
from wagtail.wagtailcore import hooks
|
||||
|
||||
|
||||
@hooks.register('insert_editor_js')
|
||||
def translated_slugs():
|
||||
js_files = [
|
||||
'wagtail_modeltranslation/js/translated_slugs.js',
|
||||
]
|
||||
|
||||
js_includes = format_html_join('\n', '<script src="{0}{1}"></script>',
|
||||
((settings.STATIC_URL, filename) for filename in js_files)
|
||||
)
|
||||
|
||||
lang_codes = []
|
||||
for lang in settings.LANGUAGES:
|
||||
if lang[0] != settings.LANGUAGE_CODE:
|
||||
lang_codes.append("'%s'" % lang[0])
|
||||
|
||||
js_languages = "<script>var langs=[%s];</script>" % (", ".join(lang_codes))
|
||||
|
||||
return format_html(js_languages) + js_includes
|
||||
BIN
wagtail_modeltranslation/wagtail_hooks.pyc
Normal file
BIN
wagtail_modeltranslation/wagtail_hooks.pyc
Normal file
Binary file not shown.
Loading…
Reference in a new issue