django cms multiple language

settings.py

LANGUAGES = (
    ## Customize this
    ('en', gettext('en')),
    ('zh-hans', gettext('zh-hans')),
)

CMS_LANGUAGES = {
    ## Customize this
    1: [
        {
            'code': 'en',
            'name': gettext('en'),
            'redirect_on_fallback': True,
            'public': True,
            'hide_untranslated': False,
        },
        {
            'code': 'zh-hans',
            'name': gettext('zh-hans'),
            'redirect_on_fallback': True,
            'public': True,
            'hide_untranslated': False,
        },
    ],
    'default': {
        'redirect_on_fallback': True,
        'public': True,
        'hide_untranslated': False,
    },
}

Grails classNotFound problem

In case of some error messages like:

Caused by ClassNotFoundException: TestAbc
->>  359 | run       in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    348 | run       in     ''
|    347 | findClass in java.net.URLClassLoader
|    425 | loadClass in java.lang.ClassLoader
|    262 | run . . . in java.util.concurrent.FutureTask
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run       in java.lang.Thread
| Error 2017-10-13 02:22:25,942 [localhost-startStop-1] ERROR core.StandardContext  - Error listenerStart
| Error 2017-10-13 02:22:25,959 [localhost-startStop-1] ERROR core.StandardContext  - Context [] startup failed due to previous errors

The solution is :

./gradlew grails-clean
./gradlew run

Sorting Map inside Groovy , Javascript

Groovy sorting by multiple properties:

http://www.tothenew.com/blog/groovier-way-of-sorting-over-multiple-fields-in-a-list-of-maps-in-groovy/

List list = [
    [id:0, firstName: 'Sachin', lastName: 'Tendulkar', age: 40 ],
    [id:1, firstName: 'Sachin', lastName: 'Tendulkar', age: 103 ],
    [id:2, firstName: 'Ajay', lastName: 'Tendulkar', age: 48 ],
    [id:3, firstName: 'Virendra', lastName: 'Sehwag', age: 5 ],
    [id:4, firstName: 'Virendra', lastName: 'Sehwag', age: 50 ],
    [id:5, firstName: 'Sachin', lastName: 'Nayyar', age: 15 ]
]

def ids = list.sort { a,b ->
   a.firstName <=> b.firstName ?: a.lastName <=> b.lastName ?: a.age <=> b.age
}*.id

assert ids == [2, 5, 0, 1, 3, 4]

Javascript sorting by multiple properties:

http://stackoverflow.com/questions/9175268/javascript-sort-function-sort-by-first-then-by-second

objects = []
object[0] = {strength: 3, name: "Leo"}
object[1] = {strength: 3, name: "Mike"}

function cmp(a, b) {
    if (a > b) return +1;
    if (a < b) return -1;
    return 0;
}
array.sort(function(a, b) {
    return cmp(a.strength,b.strength) || cmp(a.name,b.name)
})

Grails: ERROR plugins.DefaultGrailsPluginManager – Error configuring dynamic methods for plugin [springSecurityCore:2.0-RC4]: null Message: null

error message:
Error |
2016-04-25 11:12:49,121 [localhost-startStop-1] ERROR plugins.DefaultGrailsPluginManager – Error configuring dynamic methods for plugin [springSecurityCore:2.0-RC3]: null
Message: null
Line | Method
->> 312 | compileStaticRules in grails.plugin.springsecurity.web.access.intercept.AnnotationFilterInvocationDefinition
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
| 222 | initialize in ”
| 747 | initializeFromAnnotations in SpringSecurityCoreGrailsPlugin
| 601 | doCall in SpringSecurityCoreGrailsPlugin$_closure3
| 262 | run . . . . . . . . . . . in java.util.concurrent.FutureTask
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
| 615 | run . . . . . . . . . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run in java.lang.Thread

solution:

./gradlew grails-refresh-dependencies

Virtual Box inner OS screen size

https://www.virtualbox.org/manual/ch04.html

My OS: Debian 8.4.0

Follow the guide above,  below is the solution:

Click “Insert Guest Additions CD Image..”, then in console type:

apt-get install dkms
apt-get update
apt-get upgrade

Then restart, and type in console:

mkdir /mnt/cdrom
mount /dev/cdrom /mnt/cdrom
cd /mnt/cdrom
sh ./VBoxLinuxAdditions.run

Then restart again, and select “Auto-resize Guest Display”, click full screen and exit full screen, then you can resize the debian window.

Done!

Grails 2- pass temporary data from front to controller

To pass temporary data from html to controller, we need to define transient property inside domain. But transient property in domain is not bindable by default, so to solve the problem , we can do :

In domain class

String t1
static transient =['t1']
static constraints = {
   t1 bindable:true
}

We also need to remember to add the t1 property into map inside CustomMarshallerRegistrar for translation between json and java object.

Starting mongod failed

By checking  /var/log/mongodb/mongod.log, we can see the error message:


Detected unclean shutdown - /var/lib/mongo/mongod.lock is not empty.

The solution for this problem can be found at http://stackoverflow.com/questions/9884233/mongodb-service-is-not-starting-up

sudo rm /var/lib/mongodb/mongod.lock
mongod --repair
sudo service mongodb start

It solved the problem.

These commands might be also useful:

kill current mongod process:
1. Find pid

ps -ef | grep mongo

2. kill pid

kill -9 PID