Added new packages
This commit is contained in:
parent
db1ba6bd1d
commit
121cf3a243
4 changed files with 125 additions and 0 deletions
16
paramecio/citoplasma/templates/forms/i18nform.phtml
Normal file
16
paramecio/citoplasma/templates/forms/i18nform.phtml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
${add_js_home_local('tools.js', 'admin')}
|
||||||
|
<div id="languages_form">
|
||||||
|
${form.show()}
|
||||||
|
<%def name="select_lang(i18n, lang_selected)">
|
||||||
|
% if i18n==lang_selected:
|
||||||
|
choose_flag
|
||||||
|
% else:
|
||||||
|
no_choose_flag
|
||||||
|
% endif
|
||||||
|
</%def>
|
||||||
|
% if lang_selected!=None:
|
||||||
|
% for i18n in arr_i18n:
|
||||||
|
<a class="${select_lang(i18n, lang_selected)} lang_form" href="#"><img src="${make_media_url_module('images/languages/'+i18n+'.png', 'admin')}" alt="${i18n}"/></a>
|
||||||
|
% endfor
|
||||||
|
% endif
|
||||||
|
</div>
|
||||||
53
paramecio/cromosoma/extrafields/i18nfield.py
Normal file
53
paramecio/cromosoma/extrafields/i18nfield.py
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
import json
|
||||||
|
from paramecio.cromosoma.webmodel import PhangoField
|
||||||
|
from paramecio.cromosoma.coreforms import TextForm
|
||||||
|
from paramecio.cromosoma.extraforms.i18nform import I18nForm
|
||||||
|
from paramecio.citoplasma.i18n import I18n
|
||||||
|
from paramecio.citoplasma.httputils import GetPostFiles
|
||||||
|
|
||||||
|
class I18nField(PhangoField):
|
||||||
|
|
||||||
|
def __init__(self, name):
|
||||||
|
|
||||||
|
super().__init__(name)
|
||||||
|
|
||||||
|
self.name_form=I18nForm
|
||||||
|
self.parameters=[TextForm(name, '')]
|
||||||
|
|
||||||
|
def check(self, value):
|
||||||
|
|
||||||
|
self.error=False
|
||||||
|
self.txt_error=''
|
||||||
|
|
||||||
|
final_value={}
|
||||||
|
|
||||||
|
func_get=self.obtain_lang_from_post
|
||||||
|
|
||||||
|
if type(value).__name__=='dict':
|
||||||
|
func_get=self.obtain_lang_value
|
||||||
|
|
||||||
|
for lang in I18n.dict_i18n:
|
||||||
|
final_value[lang]=func_get(lang, value)
|
||||||
|
|
||||||
|
final_value[I18n.default_lang]=final_value.get(I18n.default_lang, '')
|
||||||
|
|
||||||
|
if final_value[I18n.default_lang]=='':
|
||||||
|
|
||||||
|
self.error=True
|
||||||
|
self.txt_error='Sorry, You need default language '+I18n.default_lang
|
||||||
|
return json.dumps(final_value)
|
||||||
|
|
||||||
|
return json.dumps(final_value)
|
||||||
|
|
||||||
|
|
||||||
|
def obtain_lang_value(self, lang, value):
|
||||||
|
|
||||||
|
return value.get(self.name+'_'+lang, '')
|
||||||
|
|
||||||
|
def obtain_lang_from_post(self, lang, value):
|
||||||
|
|
||||||
|
return GetPostFiles.post.get(self.name+'_'+lang, '')
|
||||||
|
|
||||||
|
|
||||||
17
paramecio/cromosoma/extraforms/i18nform.py
Normal file
17
paramecio/cromosoma/extraforms/i18nform.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/python3
|
||||||
|
|
||||||
|
from paramecio.cromosoma.coreforms import BaseForm
|
||||||
|
from paramecio.citoplasma.i18n import I18n
|
||||||
|
from paramecio.citoplasma.mtemplates import standard_t
|
||||||
|
|
||||||
|
class I18nForm(BaseForm):
|
||||||
|
|
||||||
|
def __init__(self, name, value, form):
|
||||||
|
|
||||||
|
super().__init__(name, value)
|
||||||
|
|
||||||
|
self.form_child=form
|
||||||
|
|
||||||
|
def form():
|
||||||
|
|
||||||
|
return standard_t.load_template('forms/i18nform.phtml', form=self.form_child)
|
||||||
39
tests/i18nfieldtest.py
Normal file
39
tests/i18nfieldtest.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
from settings import config
|
||||||
|
from paramecio.cromosoma.extrafields.i18nfield import I18nField
|
||||||
|
from paramecio.citoplasma.httputils import GetPostFiles
|
||||||
|
from paramecio.citoplasma.i18n import I18n
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestFieldMethods(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_i18nfield(self):
|
||||||
|
|
||||||
|
field=I18nField('i18n')
|
||||||
|
|
||||||
|
value=field.check({})
|
||||||
|
|
||||||
|
self.assertTrue(field.error)
|
||||||
|
|
||||||
|
value=field.check({'i18n_es-ES': 'Mi text', 'i18n_en-US': 'My Text'})
|
||||||
|
|
||||||
|
self.assertFalse(field.error)
|
||||||
|
|
||||||
|
GetPostFiles.post={'i18n_es-ES': 'Mi text', 'i18n_en-US': 'My Text'}
|
||||||
|
|
||||||
|
value=field.check('')
|
||||||
|
|
||||||
|
self.assertFalse(field.error)
|
||||||
|
|
||||||
|
I18n.default_lang='en-US'
|
||||||
|
|
||||||
|
GetPostFiles.post={'i18n_es-ES': 'My Text'}
|
||||||
|
|
||||||
|
value=field.check('')
|
||||||
|
|
||||||
|
self.assertTrue(field.error)
|
||||||
|
|
||||||
|
#phrase=slugify.slugify('this!()is a crap phrase o}çÇf oh yeah¡\'')
|
||||||
|
|
||||||
|
#self.assertEqual(phrase, 'this---is-a-crap-phrase-o---f-oh-yeah--')
|
||||||
|
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue