# coding:utf-8

import simplejson as json

from ru.curs.celesta.showcase.utils import XMLJSONConverter

def check_numbers_theme(context, main=None, add=None, filterinfo=None, session=None, data=None):
    
    dataDict = json.loads(data)
    
    dataTheme = dataDict['schema']['data']['theme']

    if not isinstance(dataTheme, list):
        dataTheme = [dataTheme]
    
    return_data = {
        'schema': { 
            '@not_unique': ''
        }
    }               
    if len(dataTheme) != len(set(x['order'] for x in dataTheme)):
        return_data['schema']['@not_unique'] = u'Значения некоторых номеров не уникальны!'
        
    return XMLJSONConverter.jsonToXml(json.dumps(return_data))
    
