Example #1
0
    def __call__(self, instance, sender=None, **kwargs):
        """
        Handler for the post_save signal.
        Will create a django.po file in each language,
        in the directory specified by self.location.
        """

        # no need to create translation files if not in the master site
        if not getattr(settings, 'MASTER_SITE', False):
            return
            
        if hasattr(instance, 'language') and instance.language != settings.LANGUAGE_CODE:
            return
        
        if get_language() != settings.LANGUAGE_CODE:
            return

        po_form = self.poify(instance)
        if po_form is not None:
            # for each language create a po file
            for language in get_language_codes():
                
                locale_dir = os.path.join( self.location , 'locale',
                    to_locale(language), 'LC_MESSAGES')
                locale_file = os.path.join( locale_dir, 'django.po')

                # create locale dir if not available
                if not os.path.isdir(locale_dir):
                    os.makedirs(locale_dir)
                    
                # acquire exclusive lock this should only be run
                # by one process at a time                
                with mutex(max_wait=30):
                    # write proper header if the file is new
                    # this header contains the character set.
                    write_header = not os.path.exists(locale_file)
                    
                    if write_header: # write header and po stuffz0r
                        with codecs.open(locale_file, 'w', 'utf-8') as fp:
                            fp.write(polibext.po_to_unicode(po_form))
                            
                    else: 
                        #merge existing translation with the new one
                        msg = self.msgmerge(locale_file, polibext.po_to_unicode(po_form).encode('utf-8'))
                        if msg:
                            if len(po_form):
                                # add the new entries to the po file
                                with codecs.open(locale_file, 'a', 'utf-8') as fp:
                                    for entry in po_form: # this avoids printing the header
                                        fp.write(u"\n")
                                        fp.write(polibext.po_to_unicode(entry))
                                        
                                # filter away duplicates  
                                msg = self.msguniq(locale_file)
                                # save entire po file once more and overwrite with filtered shizzle
                                with open(locale_file, 'w') as fp:
                                    fp.write(msg)                                
Example #2
0
from django.http import HttpResponse
from django.template.loader import find_template_source
from django.test import TestCase

from easymode.tree import xml as tree
from easymode.tests.models import TestModel
from easymode.tests.testcases import initdb
from easymode.utils.languagecode import get_language_codes
from easymode.xslt import response


if 'en-us' not in get_language_codes():
    raise Exception('the language "en-us" must be in your LANGUAGES to run the test suite')

__all__ = ('XsltTest',)

@initdb
class XsltTest(TestCase):
    """
    Test the functionality related to xslt
    """
    
    def setUp(self):
        t = TestModel(charfield='Hoi Ik ben de root node')
        t.save()
        f = t.submodels.create(subcharfield="Hoi Ik ben de first level sub node", subintegerfield=10)
        s = t.submodels.create(subcharfield="Hoi ik ben de tweede first level sub node", subintegerfield=100)
        w = t.secondsubmodels.create(ultrafield="Sed tempor. Ut felis. Maecenas erat.")
        f.subsubmodels.create(subsubcharfield="Hoi ik ben de thord level sub node")
        f.subsubmodels.create(subsubcharfield="Hoi ik ben de third level sub node")
        s.subsubmodels.create(subsubcharfield="Hoi ik ben de third level sub node")
Example #3
0
import glob
import os
import re
import sys

from django.conf import settings

from easymode.utils import first_match, bases_walker, url_add_params
from easymode.utils.languagecode import get_language_codes,\
    get_language_codes_as_disjunction, get_language_code_from_shorthand,\
    localize_fieldnames, get_real_fieldname, strip_language_code,\
    get_short_language_codes
from easymode.utils.standin import standin_for

# check if some required settings are fulfilled
if 'de' not in get_language_codes():
    raise Exception('the language "de" must be in your LANGUAGES to run the test suite')
if 'en-us' not in get_language_codes():
    raise Exception('the language "en-us" must be in your LANGUAGES to run the test suite')

if settings.LANGUAGE_CODE is not 'en':
    raise Exception('To run the test suite the LANGUAGE_CODE must be set to "en"')

# find all tests in the testcases folder
path = os.path.join(os.path.dirname(__file__), 'testcases')
pattern = os.path.join(path , r'(.+).py')

filenames = glob.glob(path + '/*.py')

if len(filenames): # delete __init__.py. yes it is always first.
    del(filenames[0])
Example #4
0
from django.conf import settings

from easymode.utils import first_match, bases_walker, url_add_params
from easymode.utils.languagecode import (
    get_language_codes,
    get_language_codes_as_disjunction,
    get_language_code_from_shorthand,
    localize_fieldnames,
    get_real_fieldname,
    strip_language_code,
    get_short_language_codes,
)
from easymode.utils.standin import standin_for

# check if some required settings are fulfilled
if "de" not in get_language_codes():
    raise Exception('the language "de" must be in your LANGUAGES to run the test suite')
if "en-us" not in get_language_codes():
    raise Exception('the language "en-us" must be in your LANGUAGES to run the test suite')

if settings.LANGUAGE_CODE is not "en":
    raise Exception('To run the test suite the LANGUAGE_CODE must be set to "en"')

# find all tests in the testcases folder
path = os.path.join(os.path.dirname(__file__), "testcases")
pattern = os.path.join(path, r"(.+).py")

filenames = glob.glob(path + "/*.py")

if len(filenames):  # delete __init__.py. yes it is always first.
    del (filenames[0])