10.28,python,django中templates的奇偶性,python,swift多语言文件转android多语言文件

django的cycle标签是用于两个数值切换,也可以做奇偶性判断

 {% for info in list %} <tr  {% cycle 'row1' 'row2' %} > {}

更多标签请看:
http://blog.chinaunix.net/uid-23500957-id-3838222.html

多语言转化

swift多语言文件内容如下:

"btn_yes" = "確認";
"btn_no" = "取消";
"btn_ok" = "確認";

转换成android的多语言,结果下:

<string name="btn_yes">確認</string>
<string name="btn_no">取消</string>
<string name="btn_ok">確認</string>

python转换代码(其中注释、xml节点都无法完美的转换,这里只是一个简单版):

#-*-coding:utf-8-*-
__author__ = 'george.yang'
import re


def getXmlString(iosStr):
    cmp = '"(.*?)".*=.*"(.*?)"'
    myItems = re.findall(cmp,iosStr)
    try:
        ret = '<string name="' + myItems[0][0] + '">' + myItems[0][1] + '</string>'
        return ret
    except Exception as e:
        return iosStr


fin =open("eng.txt","r")
fout = open("eng_out.txt", 'w')

try:
    fout.write("<resources>")
    for (num,value) in enumerate(fin):
        print "line number",num,"is:",value

        outline = getXmlString(value)
        fout.write(outline)
        fout.write('\n')

        print '结果:' + outline
    fout.write("</resources>")
finally:
     fin.close()
     fout.close()

web.py间url拆分,并将逻辑代码拆分到其他目录

#!/usr/bin/env python
#coding=utf-8
import web, settings

urls = (
    '([a-z0-9\/]*)', 'dispatcher'
    )

class dispatcher:
    def __init__(self):
        pass
    def GET(self, path):
        return self.__request(path)

    def POST(self, path):
        return self.__request(path)

    def __request(self, path=''):
        try:
            if path.count('/') < 2:
                path = settings.DEFAULT_PATH
            modelName, controllerName = path.strip()[1:].split('/', 1)
            if not controllerName:
                controllerName = 'index'
            if not modelName or not controllerName:
                return 'model/controller missing'
            moduleList = __import__('action.' + modelName, {}, {}, [modelName])
            modelObj = getattr(moduleList, modelName)()
            if hasattr(modelObj, controllerName):
                result = getattr(modelObj, controllerName)()
            else:
                result = 'no controller'
            return result
        except Exception ,e:
            from action.base import base as baseAction
            baseObj=baseAction()
            if e.message == 'db not exists' :
                return baseObj.error('尚未安装',baseObj.makeUrl('install'))
            return baseObj.error(e.message,baseObj.makeUrl('index'))
            #raise Exception,e.message
def session_hook():
    web.ctx.session = session

if __name__ == "__main__":
    app = web.application(urls, globals())
    #web.header("Content-Type","text/html; charset=utf-8")
    web.config.session_parameters['cookie_name'] = 'py_wpcms_sid'
    web.config.session_parameters['cookie_domain'] = None
    web.config.session_parameters['timeout'] = 86400,
    web.config.session_parameters['ignore_expiry'] = True
    web.config.session_parameters['ignore_change_ip'] = True
    web.config.session_parameters['secret_key'] = 'JJIEhi323rioes34hafwaj2'
    web.config.session_parameters['expired_message'] = 'Session expired'
    session = web.session.Session(app, web.session.DiskStore('data/sessions'), initializer={'login': False})
    def session_hook():
        web.ctx.session = session
    app.add_processor(web.loadhook(session_hook))
    app.run()

来源:https://github.com/taogogo/webpyCMS/

你可能感兴趣的:(python,django)