三月 25, 2012

limodou的學習記錄
limodou
is about »
» parsimonious Ò»¸öPEG·ÖÎöÄ£¿é

ÕâÁ½ÌìÒ»Ö±ÔÚ¿¼ÂÇÈçºÎʵÏÖÒ»¸ö±È½ÏcoolµÄ»¥¶¯Ê½±àд½Ì³ÌµÄ¹¦ÄÜ£¬µ±È»Ò²¿ÉÒÔÓÃÀ´Ð´²©¿Í£¬×÷Ϊ·ÅÔÚ uliweb.clkg.org ÉϵÄÒ»¸ö½Ì³ÌµÄÑùÀý¡£Õâ¸öÑùÀý»á±ß×ö±ßд¡£ÄÇôºÜÖØÒªµÄÒ»¸öÎÊÌâ¾ÍÊÇÈçºÎ¸ù¾Ý¼ÈëµÄÄÚÈÝÉú³ÉÒ×ÓÚʹÓõÄhtmlµÄÒ³Ã档Ŀǰ²»ÏëʹÓÃËù¼û¼´ËùµÃµÄ±à¼­Æ÷£¬ÕâÑùÉú³ÉÒ³Ãæ±È½ÏÂé·³¡£´òËãʹÓýṹ»¯Îı¾£¬²»¹ýÉÏ´«Í¼Æ¬¿ÉÄܲ»ÊǺܷ½±ã£¬²»¹ýû̫´ó¹Øϵ¡£µ«ÊÇÈçºÎ½øÐнâÎö£¬²ÉÓÃÄĸö°ü¾Í³ÉΪһ¸öÎÊÌâ¡£ÎÒÏ£Íû¸ñʽ¾¡¿ÉÄܵļòµ¥¡£ÕýºÃÕâÁ½Ìì¿´ÁËpyconÉϵÄÒ»¸öÊÓƵ

 

Parsing Horrible Things with Python. ÉÏÃæ½éÉÜÁËÑݽ²ÕßÓõļ¸¸ö½âÎöÆ÷£¬ºÜ¶àÊÇ»ùÓÚPEG(¹ØÓÚPEG http://www.brynosaurus.com/pub/lang/peg.pdf ÎÒÒ²²»¶®£¬µÚÒ»´ÎÌý˵)·½Ê½µÄ½âÎö¡£ÓÚÊÇÎÒÏëÊÔÊÔʹÓÃparsimonious×÷Ò»¸ö½âÎöÆ÷¡£ÓÚÊÇ¿ªÊ¼ÏÂÔØ£¬³¢ÊÔ¡£²»¹ý£¬·¢ÏÖÄ¿Ç°»¹ÎÞ·¨Ö»Ð´Îı¾µÄÐÎʽ¾ÍÉú³ÉÒ»¸ö½âÎöÆ÷£¬Îª´ËÎÒдÁËÒ»¸öÎÊÌâÔÚgithubÉÏ¡£×÷Õ߻ظ´ÊÇÈÃÎÒ¹Ø×¢Ëü£¬Ä¿Ç°Õâ¸ö¹¦ÄÜ»¹Ã»ÓÐʵÏÖ£¬Ö»ÊÇʵÏÖÁË¿ÉÒÔ½âÎöPEGÓï·¨¡£¿´µ½ËüµÄµ×²ãʵÏÖÆäʵ»¹ÊÇ»ùÓÚÕýÔò±í´ïʽ£¬Ö»²»¹ýдÆðÀ´¿ÉÒÔÈÝÒ׵㡣ÓÚÊÇÎÒ»¹ÊÇÔÚÕâ¸ö»ù±¾ÉϽøÐÐÁ˳¢ÊÔ¡£·¢ÏÖ³ýÁË»¹ÎÞ·¨¶¨ÒåÎı¾µÄGrammarÖ®Í⣬ËüÌṩµÄVisitorÒ²²»ÊÇÎÒÏëÏóµÄÄÇÑù¹¤×÷¡£²»¹ý£¬ËüÒѾ­¿ÉÒÔÉú³ÉASTµÄÊ÷£¬ÕâÒ»µã»¹ÊDz»´í¡£

½ñÌìÔÚ³¢ÊÔʱ·¢ÏÖÔÚ´òÓ¡ÓÐunicodeµÄ½áµãʱ»á±¨´í£¬ÓÚÊÇÎÒ·¢ÁËÒ»¸öÎÊÌâÔÚgithubÉÏ£¬ÎÒÄ¿Ç°ÊÇÊÖ¹¤ÐÞ¸ÄÁËËüµÄ´úÂëÕâÑùÎÒ¿ÉÒÔ¼ÌÐøʵÏÖÏÂÈ¥¡£ÎÒÏÖÔÚÏë×öµÄ¾ÍÊÇ×öÒ»¸öÏóWikiÒ»ÑùµÄ½âÎöÆ÷£¬¼õÉÙʹÓÃËõ½üµÄ·½Ê½¡£ÕâÑù¾Í¿ÉÒÔδÀ´ÓÃÓڽ̳ÌÍøÕ¾ÄÚÈݵÄת“Q¹¦ÄÜÁË¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十一月 15, 2011

limodou的學習記錄
limodou
is about »
» uliweb·¢²¼0.0.1a7°æ±¾ÁË

ÒѾ­ÔÚpypiÉÏ¿ÉÒÔ¿´µ½£¬²¢ÇÒ¿ÉÒÔͨ¹ýcode.googleºÍgithubÀ´ÏÂÔØ¡£Ê¹ÓÃeasy_install Ó¦¸ÃÒ²¿ÉÒÔ°²×°¡£

ÏÖÔÚsaeµÄÄÚ²â°æ±¾ÒѾ­ÄÚÖÃÁËuliwebµÄ°æ±¾£¬²¢ÇÒsqlalchemyÒ²°²×°ÁË£¬°æ±¾ÊÇ0.7.3¡£

Ϊʲô°æ±¾ºÅÕâôµÍ£¬ÒòΪÎҸоõ»¹²»ÊÇÌرðµÄÂúÒ⣬µÈÔÙÌí¼ÓһЩÐµĹ¦ÄÜÕùÈ¡Éý¼¶µ½0.0.1°É¡£×îÐÂÒªÌí¼ÓµÄ¹¦Äܼƻ®:

Êý¾Ýµ¼Èëµ¼³ö‰ˆ¼Ó¶Ôcsv, excelµÄÖ§³Ö
‰ˆ¼ÓÒ»¸öÊý¾Ý¿âά»¤µÄ½çÃ棬½«·ÅÔÚplugsÖУ¬ÒÔ±ã¿ÉÒÔÔÚsaeÉÏʹÓÃ

½«form, generic, dbuploadÎĵµÐ´Íê

bug fix

ºóÃ滹ҪÍê³ÉµÄ£º

plugsÏà¹ØµÄÎĵµ

ormµÄ½øÒ»²½ÓÅ»¯

CRUDµÄ´úÂë¿ò¼ÜµÄÉú³É

forum¹¦ÄܵĽøÒ»²½ÓÅ»¯

¿ª·¢Ò»¸öBlog app

rss feedÉú³ÉÖ§³Ö

develop¹¦ÄÜʹÓÃjqueryÖØд

Óëin.jsµÄ¼¯³É

 


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十一月 12, 2011

limodou的學習記錄
limodou
is about »
» uliweb×¼±¸·¢²¼Ð°汾ÁË

°æ±¾½«ÊÇ0.0.1a7,²»¹ý»¹ÓÐһЩûŪÍêµÄ¡£ÓÐһЩ±ä»¯»áÔì³ÉÓëÏÖÓеijÌÐò²»¼æÈݵĵط½£º

1. MiddlewareµÄÅäÖÃд·¨±ä»¯

Ô­À´ÊÇÔÚGLOBALÏ£¬ÏÖÔÚ¶ÀÁ¢ÁË£¬ÏÖÔÚµÄд·¨ÊÇ£º

[MIDDLEWARES]
name = 'middleware_class_path'[, order]

ÎĵµËµÃ÷£º http://readthedocs.org/docs/uliweb/en/latest/middleware.html#id4

Ó°Ïì×î´óµÄ¿ÉÄܾÍÊÇapps/settings.iniÁË£¬Èç¹ûÄãÓõ½ÊÂÎñ£¬¿ÉÄÜ»áдtransaction_middleware£¬ÄÇô¿ÉÄÜÒªÐ޸ġ£ÆäËüµÄmiddleÒ»°ã¶¼ÔÚij¸öappϵÄsettings.iniÖж¨ÒåºÃÁË£¬Ò»°ã²»ÓÃÔÙÖظ´¶¨Ò壬ËùÒÔÓ°Ïì²»´ó¡£


2. appÒÀÀµ¶¨Òå±ä»¯¡£Ô­À´ÊÇÔÚappϵÄconfig.iniÖеÄ[DEFAULT]ÖУ¬ÏÖÔÚÐÞ¸ÄΪ[DEPENDS]ÁË¡£

ÒÔÉÏÄÚÈÝ£¬Ö»ÒªÊÇÉæ¼°µ½uliwebºÍplugsµÄapp¶¼ÒѾ­½øÐÐÁËÐ޸ġ£Ö»ÓÐ×ÔÒѶ¨ÒåµÄappºÍsettingsÒªÊÖ¹¤ÐÞ¸Äһϡ£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十月 26, 2011

limodou的學習記錄
limodou
is about »
» ¹ØÓÚÈçºÎʹÓÃUpload App½øÐÐÎļþÉÏ´«µÄÎĵµ

²Î¼û http://readthedocs.org/docs/uliweb/en/latest/app_upload.html


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十月 22, 2011

limodou的學習記錄
limodou
is about »
» Ìí¼ÓrbacʹÓõÄÎĵµ

µØÖ·£º http://uliweb.readthedocs.org/en/latest/app_rbac.html


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十月 19, 2011

limodou的學習記錄
limodou
is about »
» ÔÚwindowsÏ°²×°LessµÄ¼Ç¼

ÔÚÎÒµÄÏîÄ¿ÖпªÊ¼Ê¹ÓÃbootstrap£¬²»¹ýÈÃÎҸоõµ½²»ÂúÒâµÄÊÇËü°ÑһЩ»ù±¾µÄ±êÇ©µÄÑùʽҲÐÞ¸ÄÁË£¬Èç:tableµÈ£¬ÕâÑù¾ÍÔì³ÉºÍÎÒÒÔǰʹÓõÄһЩcss»áÓÐһЩ³åÍ»£¬Òò´ËÎÒ´òËãÊÔןÄÔìһϣ¬½«Ä³Ð©Ñùʽµ¥¶ÀÓÃclassÀ´¶¨Ò壬²»Ö±½ÓÔÚÔ­±êÇ©É϶¨Òå¡£¶øbootstrapʹÓÃÁËLess(http://www.lesscss.org)À´Éú³Écss£¬Òò´ËÖ±½ÓÐÞ¸Äcss²¢²»Ì«ºÃ¡£ÓÚÊÇ´òËã×°Ò»¸öLessµÄ¹¤¾ßÀ´´¦Àí¡£

ÔÚbootstrapµÄÎĵµÖÐ˵ÊÇʹÓÃnpm install lessÀ´°²×°¡£²»¹ýnpmÊÇnode.jsµÄ°ü¹ÜÀíÆ÷£¬ËùÒÔÒªÏëʹÓÃnpm֮ǰ£¬ÒªÏÈ°²×°node.js»·¾³¡£ÏÖÔÚ×îеĿª·¢°æ±¾ÊÇ0.5.9°æ±¾£¬ÒѾ­ÓÐwindowsϵĶþ½øÖÆ°üÁË¡£ÎÒ°²×°ºÃºó£¬°²ÕÕnpmµÄ²Ù×÷²½ÖèÖ´ÐÐʧ°Ü£¬ºÃÏó×ÜÊÇ˵ÍøÂçÓÐÎÊÌ⣬ÒòΪÔÚ°²×°npmʱͬʱ»¹Òª°²×°Ò»Ð©×Ó°ü£¬¶¼ÊÇÒÀÀµÓÚgitµÄ£¨ÎҵĻ·¾³ÉÏÒѾ­ÓÐgitÁË£©£¬µ«ÊDz»ÖªµÀΪʲô²»ÐС£

ÓÚÊÇÕÒµ½ÁíÒ»¸ö²ÉÓÃcygwin°²×°node.jsµÄÎÄÕ¡£ÕâƪÎÄÕÂдµÃºÜÏêϸ£¬ËüÊDzÉÓÃÖ±½Ó±àÒëµÄ·½Ê½À´°²×°µÄ¡£¶ÔÓÚwin7µÄ»·¾³£¬ÆäÖÐ̸µ½rebaseallÕâ¸öÃüÁîµÄÖ´Ðзdz£ÖØÒª¡£²»¹ý¶ÔÓÚ±àÒë0.5.9ʧ°Ü£¬ºóÀ´ÎÒ¸ÄΪÎȶ¨°æ0.4.12¾ÍûÎÊÌâÁË¡£²»¹ý°²×°npmÒÀȻʧ°Ü¡£

ÓÚÊÇÓÖÕÒµ½Ò»¸öÍøÕ¾£¬ËüÊÇ°Ñnode.jsÔÚwindowsÏÂÍêÕûµÄ´ò°üÁË£¬ÆäÖÐ×îеİ汾ÒѾ­ÓÐnpmÁË¡£²»¹ý˵Ã÷¿´²»Ì«Çå³þ£¬ËµÊÇdocÏÂÓÐÎĵµ£¬µ«ÊÇûÕÒµ½¡£Ëü˵ÊÇÒѾ­×Ô´øÁËcygwinµÄ»·¾³£¬Ó¦¸Ã¿ÉÒÔÍÑÀëcygwinÀ´ÔËÐС£ÎÒÏÈÔËÐÐbin/shell.cmd£¬È»ºóÖ´ÐУº

node npm install less

ÕâÀïҪעÒâ¼ÓÉÏnode¡£²»´í£¬ÖÕÓڳɹ¦ÁË¡£less°²×°µ½ÁËlib/node_modules/lessĿ¼Ï¡£µ½ÕâÀïÎÒÓָ㲻¶®ÁË£¬ÔõôÔËÐÐlessc°¡¡£

ÓÚÊÇÎҾͽ«node/binϵļ¸¸öÖ÷ÒªµÄÎļþ£º

node.exe

node_modules

npm

npm-g

npm_g

ºÍlibĿ¼Õû¸ö¿½±´µ½ÁËcygwinµÄ°²×°Ä¿Â¼Ï¡£Ê¹ÓÃcygwinÀ´ÔËÐС£

ÓÖÔÚÍøÉÏËÑË÷Ò»µ½ÁËÕâƪÎÄÕ£¬¼ÓÁËÒ»¸ö·ûºÅÁ´½Ó:

ln -s /lib/node_modules/less/bin/lessc /bin/lessc

ÕâÑùlessc¾Í¿ÉÒÔÓÃÁË¡£

ÕâÑùÔÚcygwinÏÂÇГQµ½bootstrapµÄĿ¼Ï£¬Ö´ÐУº

make

¾Í¿ÉÒÔ¶ÔlibϵÄbootstrap.less½øÐбàÒëÁË£¬Í¬Ê±¿ÉÒÔÉú³Émin.cssÎļþ¡£

³¢ÊÔ¹ý³ÌºÜÂÒ£¬²»¹ýºÃ´õless¿ÉÒÔÓÃÁË¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

十月 7, 2011

limodou的學習記錄
limodou
is about »
» uliweb auth½øÐÐÁËÓÅ»¯

Îĵµ¿ÉÒԲμû:http://uliweb.readthedocs.org/en/latest/auth.html

ÓÅ»¯ºóµÄ¹¦ÄÜÓëÔ­À´µÄʹÓÃÓе㲻ͬ£º

1. User±í‰ˆ¼ÓÁËnickname×Ö¶Î

2. Ô­À´auth/__init__.pyÖеÄif_login¸ÄΪÁËhas_login£¬²¢ÇÒÔ­require_loginÖ»ÊÇdecorator£¬ÏÖÔÚΪ¼È¿É×÷Ϊdecorator£¬ÓÖ¿É×÷Ϊһ°ãº¯ÊýʹÓá£

3. ½«require_loginдµ½settings.iniÖÐFUNCTIONSºÍDECORATORS£¬Óû§¿ÉÒÔͨ¹ý£º

from uliweb import functions, decorators

functions.require_login()
@decorators.require_login

À´·Ö±ðʹÓÃÁ½ÖÖÐÎʽ¡£

4. functionsÊÇЉˆµÄÈ«¾Ö¶ÔÏó£¬ÓÃÓÚ´Ósettings.iniÖУ¬Í¨¹ý¡°.function"µÄÐÎʽÀ´»ñÈ¡FUNCTIONSÖеĺ¯Êý£¬ºÍdecoratorsµÄʹÓ÷½Ê½ÀàËÆ¡£

5. ÔÚsettings.iniÖÐ×¢²áÁË/login, /logout URL£¬Ìí¼ÓauthÖ®ºó¾ÍÊÇȱʡʹÓÃÁË¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 25, 2011

limodou的學習記錄
limodou
is about »
» ³õ²½ÊµÏÖÁËSoapµÄÖ§³Ö

Îĵµ£º http://uliweb.readthedocs.org/en/latest/soap.html

²»¹ý»¹Ã»Óо­¹ýÕýʽÏîÄ¿µÄÑéÖ¤£¬¹À¼Æ»¹ÓкܶàÒªÐ޸ĵġ£

ͬʱ»¹¶Ôuliweb×öÁËÒ»µãÓÅ»¯£¬È磺

ʹÓÃÊÂÎñÖмä¼þʱ£¬ÏÖÔÚÖ§³Öµ±response.error=Trueʱ×Ô¶¯»Ø¹ö¡£ÒÔÇ°Ö»ÄÜÔÚÅ×Ò쳣ʱ²Å»á×Ô¶¯´¦Àí£¬Òò´ËÈç¹ûÄã×ÔÐд¦ÀíÒì³£¾ÍÐèÒª×ÔÐд¦ÀíÊÂÎñ¡£ÏÖÔÚͨ¹ýÕâ¸ö·½·¨¾Í¼òµ¥¶àÁË¡£

½«libĿ¼´¦ÀíÕâpackageÁË¡£

EXPOSESµÄ¶¨Ò巽ʽ½øÐÐÁËÐ޸ġ£ÎĵµÒѾ­¸üС£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 19, 2011

limodou的學習記錄
limodou
is about »
» uliwebÈÕÖ¾´¦Àí˵Ã÷Îĵµ

ÒѾ­Íê³É£¬·Åµ½uliweb-docÖÐÁË¡£¿ÉÒÔ·ÃÎÊ: http://uliweb.readthedocs.org/en/latest/log.html


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 17, 2011

limodou的學習記錄
limodou
is about »
» loggingµÄʹÓ÷ÖÎö

×òÌ죬Lord LeatherfaceÎÊÎÒΪʲôʹÓÃÁËsudsºó£¬Êä³öÈÕÖ¾±ä³ÉÁËÁ½Ìõ¡£ÓÚÊÇÎÒ×ÐϸµØÑо¿ÁËloggingµÄÈÕÖ¾´¦Àí»úÖÆ£¬²¢ÇÒÔٴο¼ÂÇÁËuliwebµÄÈÕÖ¾´¦Àí£¬×îÖÕ¶ÔuliwebµÄÈÕÖ¾½øÐÐÁËÖع¹£¬²¢ÇÒŪÇå³þÁËΪʲô»áÓÐÁ½ÌõÈÕÖ¾µÄÏÖÏó£¬Òò´ËÒÔ±¾ÎÄ×÷Ò»¸ö¼Ç¼¡£

¶ÔÓÚloggingÎÒÏë´ó¼ÒÓõÃÓ¦¸Ã²»ÉÙ£¬ÄÇôÎÒÏÈÌἸ¸öÎÊÌ⣺

1. loggingÖ±½ÓÊä³öÈÕÖ¾£¬Èçlogging.info()Óëlog = logging.getLogger('name') log.info()ÓÐʲô²»Í¬£¿

2. ¡°No handlers could be found for logger¡±ÊÇÔõô»ØÊ£¿

3. root loggerÓÐʲôÓã¬ÈçºÎ»ñµÃ£¿

4. ÐÎÈç"a.b.c"µÄloggerÃûÓÐʲôÓã¿

5. Èç¹ûÒ»¸öloggerÖ´Ðжà´ÎaddHandler£¬ÄÇôÿ¸öhandler¶¼»á±»Ö´ÐÐÂð£¿

6. loggerµÄ´«²¥(propagate)ÊÇÔõô»ØÊ£¿ÈçºÎ×èÖ¹Ëü£¿

ÓÐʱºò´ø×ÅÎÊÌâѧϰ¿ÉÄÜ»á¸ü¿ì¡£ÄÇôÏÂÃæ¸ù¾ÝÎÒµÄÀí½âÒ»µãµã½øÐнâÊÍ¡£

loggingÖÐlogÊÇ¿ÉÒÔ·Ö¼¶µÄ£¬ËüµÄ¼¶±ðÓëÄãʹÓÃgetLogger()ÖеÄÃû×ÖÓйØϵ¡£±ÈÈ磬Äã¿ÉÒÔʹÓÃ"uliweb"»ò"uliweb.app"£¬ËüÃǵÄÇø±ð¾ÍÊÇ"uliweb.app"ÖÐÓÐÒ»¸ö'.'¡£ÄÇôlogging»á×Ô¶¯Éú³É"uliweb"ºÍ"uliweb.app"µÄlogger£¬²¢ÇÒ"uliweb"½«ÊÇ"uliweb.app"µÄloggerµÄ¸¸¶ÔÏó¡£ÕâÒ»µã¿ÉÒÔÕâÑùÑéÖ¤£º

>>> import logging

>>> log = logging.getLogger('uliweb.app')

>>> log.manager.loggerDict.items()

[('uliweb.app', <logging.Logger instance at 0x017CE238>), ('uliweb', <logging.PlaceHolder instance at 0x017CE2D8>)]

ÕâÀïÓÐÒ»¸öͦÓÐÒâ˼µÄ£¬¾ÍÊÇ'uliweb'Õâ¸öloggerËüµÄ¶ÔÏóÊÇPlaceHolder£¬Ï൱ÓÚÊÇÒ»¸ö¡°Ðé"ÈÕÖ¾¶ÔÏó¡£logging¿ÉÒÔÔÊÐíͨ¹ýgetLogger()À´×Ô¶¯Éú³É¶ÔÓ¦µÄlogger¶ÔÏ󡣶ÔÓÚ·Ö¼¶µÄÈÕÖ¾Ãû×Ö£¬Ëü»áÒ»¼¶¼¶µØ´´½¨£¬Èç¹û¸¸¶ÔÏó»¹²»´æÔÚ£¬Ôò»á×Ô¶¯´´½¨Ò»¸öռλ¶ÔÏó¡£Èç¹û£¬ºóÃæÓû§ÓÖͨ¹ýgetLogger()À´´´½¨Ò»¸ö¸¸¶ÔÏó£¬Ôòlogging»á×Ô¶¯¶Ô¸¸×Ó¹Øϵ½øÐÐÖØÐÂÐÞ¶©£¬±£Ö¤¶ÔÏó¹ØϵµÄÕýÈ·ÐÔ¡£

ÔÙ¿´Ò»¿´¸¸×Ó¹Øϵ£º

>>> log.parent

<logging.RootLogger instance at 0x017E3AD0>

>>> log1 = logging.getLogger('uliweb')

>>> log.parent

<logging.Logger instance at 0x01820DA0>

>>> log.parent.name

'uliweb'

ͦÓÐÒâ˼¡£µ±ÎÒÃÇÖ±½Óͨ¹ýgetLogger('uliweb.app')»ñµÃÈÕÖ¾¶ÔÏóʱ£¬ËüµÄparent²¢²»ÊÇռλ¶ÔÏó'uliweb'£¬¶øÊÇRootLogger¡£Õâ¸öRootLoggerÊÇÔÚµ¼Èëloggingʱ×Ô¶¯ÓÉÄ£¿é´´½¨µÄ£¬ËüµÄ´´½¨´úÂëÊÇ£º

root = RootLogger(WARNING)

Logger.root = root

Logger.manager = Manager(Logger.root)

LoggerÊÇÕæÕýµÄloggerµÄÀà¡£¿ÉÒÔ¿´ËüÔÚÔËÐÐʱ»á¸øËü¸³ÓèrootºÍmanager¶ÔÏ󡣶ømanager¾ÍÊÇÓÃÀ´´´½¨logger²¢½øÐйÜÀíµÄÀࡣǰÃæµÄ´úÂë¾ÍÊÇͨ¹ý²é¿´manager.loggerDictÀ´²é¿´ËùÓÐÒѾ­¶¨ÒåµÄlogger¡£
Òò´Ë´ÓÉÏÃæµÄ´úÂëÎÒÃÇ¿ÉÒÔÀí½â£¬ÔÚÖ±½Ó´´½¨Ò»¸ö¶à¼¶µÄloggerʱ£¬Èç¹û¸¸¶ÔÏó²»´æÔÚ£¬Ôò¸¸¶ÔÏó×ÔÈ»ÊÇroot¶ÔÏó¡£Èç¹û¸¸¶ÔÏó±»´´½¨£¬Ôò¸¸×Ó¹Øϵ±»ÐÞÕý¡£

root¶ÔÏóÓÐʲôÓÃÄØ£¿Ëü¾ÍÊÇȱʡµÄÈÕÖ¾¶ÔÏó¡£Ê¹ÓÃloggingµÄ×î¼òµ¥µÄ·½·¨ÊÇ£º

import logging

logging.info()

¿ÉÒÔÖ±½ÓÊä³ö¡£ÕâÀïÓÐʲôÃØÃÜ£¿¿´Ò»¿´´úÂëÒ»ÇоͶ¼Çå³þÁË¡£

def info(msg, *args, **kwargs):

    """

    Log a message with severity 'INFO' on the root logger.

    """

    if len(root.handlers) == 0:

        basicConfig()

    root.info(*((msg,)+args), **kwargs)

ÕâÀïÏȶÔrootµÄhandlers½øÐÐÅжϡ£ÄÇôhandlersÊÇʲô¶«Î÷£¿Ëü¾ÍÊÇÓÃÀ´´¦ÀíÿÌõÈÕÖ¾µÄ´¦ÀíÀàµÄʵÀý¡£Ã¿¸ölogger¿ÉÒÔÓв»Ö¹Ò»¸öhandlerʵÀý¡£²¢ÇÒÿ¸öhandler¶ÔÏó¿ÉÒÔÓÐ×ÔÒѵÄÈÕÖ¾Êä³ö¼¶±ð£¬¿ÉÒÔºÍloggerµÄ²»Í¬¡£handlerµÄ´¦ÀíÎÒÃǺóÃæÔÙ˵¡£ÉÏÃæµÄ´úÂëÒâ˼¾ÍÊÇ£¬Èç¹ûroot»¹Ã»Óж¨Òå´¦Àí¶ÔÏó£¬ÔòÖ´ÐÐbasicConfig()½øÐÐȱʡÅäÖá£È»ºóʹÓÃroot.info()½øÐÐÊä³ö¡£ËùÒÔÎÒÃÇ¿ÉÒÔÀí½â£ºlogging.info()Æäʵ¾ÍÊÇʹÓÃrootÀ´½øÐÐÊä³öµÄ£¬Äã¿ÉÒÔÀí½âËüÊÇÒ»¸öÈ«¾ÖÐԵģ¬È±Ê¡µÄÈÕÖ¾¶ÔÏó¡£²¢ÇÒ¿ÉÒÔ×Ô¶¯½øÐÐÅäÖá£
ÄÇô£¬ÎªÊ²Ã´ÒªÅäÖã¿ÒòΪRootLogger(WARNING)Ö»ÊÇ´´½¨ÁËloggerÀ࣬µ«ÊÇ»¹Ã»ÓÐÌí¼ÓÈκεÄhandler£¬Òò´ËhandlersÊǿյġ£Ò²¾ÍÊÇ˵£¬´´½¨ÁËÒ»¸ölogger£¬²¢²»±íʾËü¾Í¿ÉÒÔÊä³öÈÕÖ¾¡£ÊDz»ÊÇÓÐЩÆæ¹Ö£¿»¹ÊÇÒÔ´úÂëΪÉÏ£º

    def callHandlers(self, record):

        c = self

        found = 0

        while c:

            for hdlr in c.handlers:

                found = found + 1

                if record.levelno >= hdlr.level:

                    hdlr.handle(record)

            if not c.propagate:

                c = None    #break out

            else:

                c = c.parent

        if (found == 0) and raiseExceptions and not self.manager.emittedNoHandlerWarning:

            sys.stderr.write("No handlers could be found for logger"

                             " \"%s\"\n" % self.name)

            self.manager.emittedNoHandlerWarning = 1

ÉÏÃæµÄ´úÂëÊÇLoggerÀàÖÐÓÃÀ´Êä³öÈÕÖ¾µÄÒ»¸ö·½·¨£¬ËùÓеÄÃØÃܶ¼ÔÚÕâÀïÃæÁË¡£ÕâÀï²»Ò»ÌõÌõ½â¾öÁË£¬ËµÒ»ÏÂÎÒµÄÀí½â°É¡£ËüÊ×ÏÈÉèÖÃÁËÒ»¸öfoundµÄ±êÖ¾£¬ËüµÄ×÷ÓþÍÊÇÈç¹ûÕÒµ½ÁËÒ»¸ö¿ÉÓõÄhandler£¬Ôò¼Ó1£¬È»ºóµÈ×îºóÅжÏһϣ¬Èç¹ûfoundΪ0£¬Ôò±íʾÄ㻹ûÓжÔlogger½øÐÐÅäÖã¬ÔÚ×îºó»áÊä³ö¡°No handlers could be found for logger¡±µÄÐÅÏ¢¡£»¹¼ÇµÃrootµÄÊÂÇéÂ𣿴´½¨ÁËÒ»¸ölogger²¢²»±íʾËü¾Í´øÓÐhandlerÁË£¬Ò²¾ÍÊÇÎÞ·¨½øÐд¦Àí¡£Òò´Ëlogging.info()´úÂëÖУ¬»áµ±rootûÓÐÅäÖÃhandlerʱ£¬Ê¹ÓÃbasicConfig()À´½øÐÐÅäÖá£ÄÇôÔÚbasicConfig()µÄ´úÂëÖУ¬Äã»á¿´µ½Ëü»á¸ù¾Ý´«ÈëµÄ²ÎÊý×Ô¶¯Éú³ÉÏàÓ¦µÄHandlerʵÀý£¬Ìí¼Óµ½rootÖÐÈ¥¡£ËùÒÔlogging.info()²»»á±¨´í£¬ÊÇÒòΪËü×Ô¶¯ÅäÖÃÁË¡£¶øÄã×ÔÒÑͨ¹ýgetLogger()µÃµ½µÄij¸öÈÕÖ¾¶ÔÏ󣬿ÉûÓÐ×Ô¶¯»¯µÄÅäÖ÷½Ê½£¬ËùÒÔÓпÉÄܻᱨ´í¡£Òò´ËÏÖÔÚÎÒÃÇ¿ÉÒÔ¾ÍÓÐÒ»¸öÓ¡Ïó£¬ÈÕ־ʹÓÃÇ°ÒªÅäÖã¬Ö÷ÒªÊÇÌí¼ÓÏàÓ¦µÄhandler¡£ÄÇôÕâ¶Î´úÂ뻹ÓÐʲôÌØÊâµÄ£¿Ò»¸ö¾ÍÊÇc.propagate(propagateµÄÖÐÎÄÒâ˼ÊÇ´«²¥)£¬ËüÊÇLoggerµÄÒ»¸öÊôÐÔ£¬È±Ê¡Îª1¡£´ÓÉÏÃæµÄ´úÂë¿ÉÒÔ¿´³ö£¬Èç¹ûpropagateΪ0»ò¼ÙÖµ£¬ÔòÑ­»·¾ÍÍ˳öÁË¡£Èç¹ûΪ1£¬ÔòÑ­»·»á¼ÌÐø´Ó¸¸¶ÔÏó¿ªÊ¼£¬Ö±µ½ÕÒ²»µ½»òpropagateΪ¼Ù¡£Òò´Ëlogging»áÀûÓÃpropagateºÍ¸¸¶ÔÏó½øÐеݹ鴦Àí»ò´«²¥´¦Àí¡£Òò´Ë¾ÍÑù¾ÍʵÏÖÕâÑùÒ»ÖÖЧ¹û£ºÔÚ´«²¥Çé¿öÏ£¬´Ó×Ó½áµãµ½¸¸½áµãµÄhandler¶¼»á±»´¦ÀíÒ»·¬¡£µ±È»£¬»¹ÓÐÒ»¸ö¼ì²éµã¾ÍÊÇÐÅÏ¢Êä³öµÄÈÕÖ¾¼¶±ðÒª´óÓÚµÈÓÚhandlerµÄÈÕÖ¾¼¶±ð¡£Òò´Ë£¬Èç¹û¸¸½áµãºÍ×Ó½áµã¶¼¶¨ÒåÁËhandler£¬²¢ÇÒÈÕÖ¾¼¶±ð¶¼·ûºÏÒªÇó£¬ÕâÑùµÄÈ·»áÊä³öÁ½ÌõÈÕÖ¾£¬µ«ÊÇÓɲ»Í¬µÄhandlerÊä³öµÄ¡£ËùÒÔ£¬Èç¹û×Ó¶ÔÏó¶¨ÒåÁË×ÔÒѵÄhandler£¬ÎªÁ˱ÜÃâ´«²¥£¬Òò´ËÓ¦¸ÃÉèÖÃËüµÄpropagate=0¡£µ«ÊÇ£¬ÀûÓô«²¥£¬ÎÒÃÇÒ²¿ÉÒÔʵÏÖ£¬×ÓÈÕÖ¾¶ÔÏ󲻶¨Òå×ÔÒѵÄhandler£¬Òò´Ë×îÖÕÊÇʹÓø¸¶ÔÏóµÄhandler¡£ÌرðÊǶÔÓÚ¸¸¶ÔÏóÊÇroot¶ÔÏóµÄÇé¿ö£¬Ö»ÒªÖ´ÐÐÁËbasicConfig()£¬ÔòÒ»¶¨»á´æÔÚhandler£¬¾Í¿ÉÒÔ¸´ÓÃrootµÄhandlerÁË¡£
ÉÏÃæµÄ´úÂ뻹ÓÐÒ»µãҪעÒâµÄ¾ÍÊÇ£¬Ëü»á¶ÔloggerµÄËùÓÐhandler½øÐÐÑ­»·£¬µ±È»Í¬Ê±Òª¼ì²éÈÕÖ¾Êä³ö¼¶±ð¡£Òò´Ë£¬Èç¹ûÄãΪһ¸ölogger¶¨ÒåÁ˶à¸öhandler£¬ÄÇô¾ÍÓпÉÄܶ¼»áÊä³ö¡£Èç¹ûÏëÇø·Ö²»Í¬µÄhandler£¬¿ÉÒÔÀûÓü¶±ðÀ´¿ØÖÆ¡£
¶ÔÓÚroot¶ÔÏó£¬ÔÙ˵һµã¾ÍÊÇʲôʱºòÒªÖ´ÐÐbasicConfig()½øÐÐÅäÖã¿Èç¹ûÄãûÓÐ×Ô¶¨Òålogger£¬Ö»ÊÇʹÓÃloggingÖÐÒѾ­ÌṩµÄÈ磺info(), debug()Ö®ÀàµÄ·½·¨£¬µÄÈ·²»±ØÌرðµ÷ÓÃbasicConfig()£¬ÒòΪÕâЩº¯ÊýÔÚÖ´ÐÐʱ¶¼×öÁ˼ì²é£¬Èç¹ûûͨ¹ý£¬Ôò×Ô¶¯»áµ÷ÓÃbasicConfig()¡£µ«ÊÇ£¬Èç¹ûÄã²»ÊÇÕâÑùʹÓ㬶øÊÇʹÓÃ×Ô¶¨ÒåµÄlogger£¬Òò´Ë»¹Êǽ¨ÒéÄãÏÈÖ´ÐÐbasicConfig()½øÐÐȱʡµÄÅäÖá£ÔÚʹÓÃ×Ô¶¨ÒåµÄlogger£¬Òª×¢ÒâµÄÎÊÌâ¾ÍÊÇ£ºhandlerµÄÌí¼ÓÓëpropagateµÄ´¦Àí¡£

ÄÇôÈç¹ûÎÒÏë»ñµÃroot¶ÔÏó¸ÃÈçºÎ×öÄØ£¿Ê¹ÓÃlogging.rootÂ𣿳£Óõķ½·¨»¹ÊÇͨ¹ýgetLogger('')À´»ñµÃ¡£²ÎÊý¿ÉÒÔÊÇ''»òÆäËüΪ¼ÙµÄÖµ¡£

ͨ¹ýÉÏÃæµÄ½²½â£¬ÎÒÏëÄãÓ¦¸ÃÖªµÀÎÒÌáµÄ¼¸¸öÎÊÌâµÄ´ð°¸ÁË°É¡£ÏÂÃæÔÙ¼òµ¥×ܽáһϣº
loggerÊÇ·Ö¼¶µÄ£¬Óи¸×Ó¹Øϵ¡£
loggerµÄ´¦ÀíÒª¿¿handlerÀ´Êä³ö£¬»ñµÃÁËlogger²¢²»Ò»¶¨»á×Ô¶¯´´½¨handler£¬Òò´ËloggerÒ»°ã¶¼ÐèÒªÅäÖá£
ÔÚ´æÔÚ¸¸×Ó¹ØϵµÄÇé¿öÏ£¬ÈÕÖ¾ÊÇ¿ÉÒÔ±»´«²¥Êä³öµÄ£¬²¢ÇÒ¿ÉÒÔͨ¹ýpropagateÊôÐÔÀ´¿ØÖÆ¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 15, 2011

limodou的學習記錄
limodou
is about »
» uliwebÖÐtimezoneµÄ´¦Àí

ÔÚºÜÔçÒÔÇ°µÄ°æ±¾ÖУ¬uliwebÖоÍÒѾ­ÓÐÁËtimezoneµÄ´¦Àí£¬ÔÚuliweb/utils/data.pyÖУ¬ÒѾ­¶¨ÒåÁËÈô¸ÉÓëÈÕÆÚ¡¢Ê±¼äÏà¹ØµÄapi¡£ÄÇʱÎÒ²ÉÓõÄÊÇpytzÀ´½øÐÐʱÇøµÄ´¦Àí¡£ÔÚdefault_settings.iniÖÐGLOBAL/TIME_ZONEÖÐÉèÖÃÁËȱʡµÄʱÇø£¬È±Ê¡ÊÇNone¡£Í¬Ê±uliormÖеÄÈÕÆÚ¡¢Ê±¼äÔÚ×Ô¶¯Éú³Éʱ£¬Ò²ÊÇʹÓÃdate.pyÖеĺ¯ÊýÀ´Éú³ÉµÄ¡£Æô¶¯uliwebʱ£¬»á×Ô¶¯µ¼Èëpytz£¬È»ºó¸ù¾ÝTIME_ZONEÀ´ÉèÖÃʱÇø¡£µ«ÊǺóÀ´·¢ÏÖ£¬pytzµÄtzinfoÐÅϢ̫´óÁË£¬µ¼Èë·Ç³£Âý¡£ÓÚÊǾͰÑÕâ¸ö×Ô¶¯³õʼ»¯È¥µôÁË¡£ÒòΪpytzµÄʱÇøÊý¾ÝÌ«¶à£¬¶øÇÒÌ«¸´ÔÓ£¬±ÈÈçÏÄÁîʱµÄ´¦Àí£¬µÄȷʹÓÃÆðÀ´±È½ÏÂé·³¡£ÓÚÊÇÎÒ¾ÍÏëÖ»Òª¼òµ¥µÄʱÇø¾Í¹»ÁË£¬±ÈÈ磺UTCºÍGMT-12µ½GMT+12µÄʱÇø£¬ÎÒÏëʹÓÃʱÇøµÄÈËÓ¦¸Ã×ã¹»Á˽⣬ËûÏëҪʲôʱÇø¡£

²»¹ý´ËÊÂÒ»Ö±ÍÏ×Å£¬Ö±µ½Ç°Á½Ì컨ÁËЩʱ¼ä°ÑÕâ¸öÊ»ù±¾¸ã¶¨ÁË¡£Ê×ÏȲο¼ÁËpythonÊÖ²áÖйØÓÚdatetimeģʽÖеÄtzinfoµÄʾÀý£¨ºÃÏóÓв¿·ÖÊÇ´ÓpytzÖÐÀ´µÄ£©£¬±àдÁËUTCºÍGMT-12µ½GMT+12ʱÇøµÄÀ࣬²¢½øÐÐÁ˳õʼ»¯¡£È»ºóÓÖÐÞ¸ÄÁËdate.pyÖеÄһЩº¯Êý£¬Ê¹Æä¸üºÃÓÃһЩ¡£È»ºóÓÖÐÞ¸ÄÁËuliormÖеÄDatetimeProperty, DateProperty, TimePropertyµÈÊôÐÔÀ࣬ͬʱµ÷ÕûÁËuliormµÄvalidateµÄ´¦Àí¡£

ÕâÑù£¬ÔÚuliwebÖÐʹÓÃʱÇø¿ÉÒÔÓÐÁ½ÖÖ״̬£º1. ÎÞʱÇø״̬¡£2.ÓÐʱÇø״̬¡£

ÔÚuliwebÖеÄcontribÖУ¬ÐÂÌṩÁËÒ»¸ötimezoneµÄapp¡£Ò»µ©°üº¬Ëü£¬Ôò×Ô¶¯¸ù¾Ýsettings.iniÖеÄGLOBAL/TIME_ZONEÖеÄÉèÖóõʼ»¯date.pyÖÐʹÓõÄȱʡʱÇø¡£ÕâÑù£¬Ö»ÒªÄãµÄÈÕÆÚºÍʱ¼äº¯Êý¶¼Ê¹ÓÃdate.pyÖÐÌṩµÄ·½·¨£¬¾Í¿ÉÒÔ×Ô¶¯´¦ÀíʱÇø¡£ËùνÎÞʱÇø״̬£¬¾ÍÊÇTIME_ZONEΪNone¡£ÕâÑù£¬Æäʵ¶¼ÊÇ·þÎñÆ÷µÄʱ¼ä£¬Ã»ÓÐʲôʱÇøµÄ¸ÅÄ¿ÉÄܾÍÊÇÎÒÃÇƽ³£ËùʹÓõķ½Ê½¡£¶øÓÐʱÇø״̬£¬ÔòTIME_ZONE²»Îª¿Õ£¬±ÈÈçÉèÖóÉ'UTC'£¬ÔòËùÓÐdate.pyÖеĺ¯Êýȱʡ¶¼Ê¹ÓÃ'UTC'ʱÇøÀ´Éú³Éʱ¼ä¡£ÔÚuliormÖУ¬ÈÕÆÚºÍʱ¼äÊôÐÔÊÇ¿ÉÒÔͨ¹ýÌí¼Óauto_nowºÍauto_now_addÀ´×Ô¶¯ÔÚÐ޸ĺÍÌí¼Óʱ×Ô¶¯Éú³ÉÈÕÆÚÖµ£¬Ëü¾ÍÊÇʹÓÃÁËdate.pyÖеÄnow()º¯Êý¡£ËùÒÔ£¬Ò»µ©ÄãÉèÖÃÁËTIME_ZONE£¬Ôòuliweb»á×Ô¶¯°´Ê±ÇøµÄ·½Ê½½øÐд¦Àí¡£

¶ÔÓÚʱÇøµÄ´¦ÀíÎÒÃÇÒª¿¼ÂÇ·þÎñÆ÷ºÍ¿Í»§¶ËÓпÉÄܲ»Ò»ÖµÄÎÊÌ⣺

Èç¹ûÎÒÃǵķþÎñÆ÷ºÍÓû§µÄ»úÆ÷ÊÇÔÚÒ»¸öµØÇø£¬Õâ¸öÎÊÌâ×îºÃ°ì£¬¿ÉÒÔ²»Ê¹ÓÃʱÇø£¬Ö±½ÓʹÓñ¾µØʱ¼ä¡£ÕâÑùÖ»Òª²»ÉèÖÃTIME_ZONE»ò±£³ÖΪNone¾ÍºÃÁË¡£

µ«Èç¹û·þÎñÆ÷ºÍ¿Í»§¶Ë¿ÉÄܲ»ÔÚÒ»¸öµØÇø£¬±ÈÈçdotcloudµÄÓ¦Óã¬ÄÇô¾ÍÒª¿¼ÂÇÈçºÎ´¦Àí¿Í»§¶ËµÄʱÇø¡£ÕâÀïÎÒÃÇ¿ÉÒÔͳһ·þÎñÆ÷·½µÄʱÇø£¬Í¨¹ýÉèÖÃTIME_ZONE¡£µ«ÊÇ¿Í»§¶ËµÄʱÇø²»ºÃ´¦Àí¡£±ÈÈ磺ÓÐÓû§µÄÇé¿öºÍÎÞÓû§µÄÇé¿ö¡£ÓÐÓû§µÄÇé¿öÏ£¬¿ÉÒÔ¿¼ÂÇÈÃÓû§×ÔÐÐÉèÖÃËùÔÚµÄʱÇø¡£¶øÎÞÓû§µÄÇé¿öÏ£¬ÈçºÎ»ñµÃʱÇøÓв»Í¬µÄ×ö·¨¡£×î¼òµ¥µÄ£¬¾ÍÊÇĬÈÏ¿Í»§Ê±Çø¡£±ÈÈ磬uliwebÖпÉÒÔÉèÖÃGLOBAL/LOCAL_TIME_ZONE£¬È»ºóʹÓÃdate.to_local()À´½«Ò»¸öʱ¼äתΪLOCAL_TIME_ZONEËùÖ¸¶¨µÄʱÇø¡£ÁíÍâÔÚstackoverflowÕÒµ½ÓÐÀàËƵÄÎÊÌ⣬±ÈÈçÕâ¸ö£¬ËüµÄ°ì·¨¾ÍÊÇͨ¹ýä¯ÀÀÆ÷¶ËÖ´ÐÐÒ»¶ÎjavascriptÀ´±ÈÈçÓëUTCµÄ²îÒìÀ´»ñµÃʱÇø²îÒ죬ÕýºÃÒ²ÊÇʹÓÃGMT +|-nµÄÐÎʽ¡£Æä¹Ø¼üµÄjs´úÂëÊÇ£º

<scripttype="text/javascript">

    $(document).ready(function(){

        if("<?php echo $timezone; ?>".length==0){

            var visitortime =new Date();

            var visitortimezone ="GMT "+-visitortime.getTimezoneOffset()/60;

            $.ajax({

                type:"GET",

                url:"http://domain.com/timezone.php",

                data:'time='+ visitortimezone,

                success:function(){

                    location.reload();

                }

            });

        }

    });

</script>


ÕâÊÇphpµÄÀý×Ó£¬ºÜÈݸÄΪÆäËüµÄ³ÌÐòÐÎʽ¡£¹Ø¼üµÄµØ·½¾ÍÊÇ£ºvisitortime.getTimezoneOffset()/60 £¬²¢ÇÒÔڵõ½Ê±ÇøºóÔÙ×Ô¶¯Ë¢Ð£¬È»ºó½«Öµ±£´æµ½sessionÖС£

¼òµ¥×ܽáһϣ¬Í¨¹ýÉèÖÃGLOBAL/TIME_ZONE¿ÉÒÔÉèÖ÷þÎñÆ÷¶ËÈÕÆÚ¡¢Ê±¼äµÄÉú³É£¬±ÈÈçuliormµÄ×Ô¶¯ÈÕÆÚ¡¢Ê±¼äµÄÉú³É¡£ÆäËüµØ·½µÄÈÕÆÚ£¬Í¨¹ýʹÓÃdate.pyÖеÄAPI¡£½¨Òéºǫ́ͳһʹÓÃUTCÈÕÆÚ£¬¼òµ¥ÔÚuliwebÖÐÅäÖÃÈçÏ£º

[GLOBAL]

TIME_ZONE = 'UTC'

ͬʱҪ°²×° 'uliweb.contrib.timezone', ·ñÔò²»Æð×÷Óá£

¶ÔÓÚ¿Í»§¶ËµÄʱÇø´¦Àí£¬Óм¸ÖÖ·½·¨£º

1. ÏÈÉèÖÃGLOBAL/LOCAL_TIME_ZONEµÄʱÇø£¬È»ºóʹÓÃdate.to_local(datetime)À´×Ô¶¯×ªÎªLOCAL_TIME_ZONEµÄʱÇø£¬µ«ÕâÖÖÒ²ÊÇÏ൱Óڹ̶¨µÄʱÇø£¬²»ÄܺÜÁé»îµÄ×ÔÊÊÓ¦¡£

2. ÔÚÉè¼ÆÉÏ£¬ÎªÃ¿¸öÓû§Ìí¼ÓÒ»¸öʱÇøÑ¡ÔñµÄ×ֶΣ¬ÈÃÓû§×ÔÐÐÉèÖá£ÕâÑùÔÚչʾҳÃæÖУ¬¸ù¾ÝÓû§µÄʱÇøÖµÀ´×ª“QʱÇøÏÔʾ¡£

3. ²ÉÓÃjsÔÚÇ°¶Ë̽²âµÄ°ì·¨£¬½«Ç°¶ËµÄʱÇø̽²â³öÀ´£¬²¢±£´æÔÚsessionÖУ¬ºóÐø´¦ÀíÒÔ´ËΪ¿Í»§¶ËʱÇøµÄ´¦Àí¡£

ͬʱ»¹ÓÐÒ»¸öҪעÒâµÄ£¬ÄǾÍÊÇÓû§ÉÏË͵ÄÈÕÆÚÐÅÏ¢µÄ´¦Àí¡£ÒòΪËüÒ²ÊDz»´øʱÇøµÄ£¬ËùÒÔÒª¸ù¾ÝÇ°ÃæµÄ·½Ê½Ä¬ÈÏΪij¸ö¿Í»§¶ËʱÇøÔÙ½øÐд¦Àí¡£

 


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 12, 2011

limodou的學習記錄
limodou
is about »
» uliwebzone¸üÐÂÁËÒ»ÏÂ

ÐÞ¸´ÁËһЩbug£¬²¢ÇÒ·ÖÒ³js¿Ø¼þ»»³ÉsmartpaginatorÁË¡£Í¬Ê±uliwebºÍplugs¶¼Éýµ½×îеİ汾ÁË¡£·¢ÏÖÖ±½ÓÔÚdotcloudÉÏÓÃssh²¿Êð»¹ÊÇ×î·½±ãµÄ¡£ÏîÄ¿´úÂë·Åµ½codeĿ¼Ï£¬uliwebºÍplugs·Åµ½~Ŀ¼Ï£¬ÓÃsetup.py developÀ´°²×°¡£ÒÔºó¾ÍûÓÐͬ²½Ôì³ÉÎļþ¶ªÊ§µÄÇé¿öÁË¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 11, 2011

limodou的學習記錄
limodou
is about »
» ¾²Ì¬Îļþºó׺´¦Àí£¬±ÜÃâä¯ÀÀÆ÷»º´æ

Ôö¼ÓÁËÒ»¸öSTATIC_VERµÄÈ«¾ÖÅäÖÃÏ¿ÉÒÔÔÚʹÓÃurl_for_staticʱ×Ô¶¯¸ù¾ÝÕâ¸öÅäÖÃÏÔÚ¾²Ì¬Á´½ÓºóÃæÌí¼Ó?ver=xxxµÄÐÅÏ¢¡£×Ô¶¯ÊÊÓÃÓÚ{{use}}ºÍ{{link}}Ä£°åtag¡£Ö»Êǵ±Ç°´¦Àí»¹ÊDZȽϼòµ¥£¬ÎÞ·¨×öµ½Õë¶Ôij¸öÐ޸ĵÄÎļþµÄ°æ±¾¡£È±Ê¡ÎªNone£¬±íʾ²»Ìí¼Ó¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

» ¹ú¼Ê»¯¸´ÊýÐÎʽµÄÖ§³ÖÓëpygettextµÄ²¹¶¡

½ñÌì°ÑplugsÖеÄÂÛ̳½øÐÐÁËһЩÓÅ»¯£¬ÆäÖÐÏëʹÓÃuliwebÖÐÔç¾ÍÄÚÖõÄtimesince.pyÄ£¿é¡£Õâ¿éÐèÒªi18nµÄÖ§³Ö¡£ÓÚÊÇʹÓãº

uliweb i18n -l zh_CN --uliweb

À´ÔËÐС£½á¹û±¨´í¡£ÆäÖ÷ÒªÔ­ÒòÊÇtimesinceÖÐʹÓÃÁ˸´ÊýÐÎʽµÄi18nº¯Êýungettext¡£¶øuliwebʹÓõÄpygettext.py²»Ö§³Ö¡£

pygettext.pyÊÇpythonÔÚtoolsĿ¼ÏÂ×Ô´øµÄÒ»¸öÄ£¿é£¬¿ÉÒÔÓÃËüÀ´´ÓpythonÔ´ÂëÖгéÈ¡·­Òë×Ö·û´®£¬ËüÖ§³ÖÃüÁîÐУ¬´úÂëÒ²²»ËãºÜ¸´ÔÓ¡£ËùÒÔÔÚuliwebÖÐÌṩÁË´¿pythonµÄÃüÁîÐй¤¾ß¡£²»¹ýuliwebΪÁËÈÃÆä¿ÉÒÔÖ§³ÖÄ£°åºÍiniÎļþ£¬ÐÞ¸ÄÁËpygettextÔ´Â룬ËùÒÔºÍpython×Ô´øµÄ»¹²»ÍêÈ«Ò»Ñù¡£Ðí¶àÆäËüµÄpythonÏîÄ¿ÊÇʹÓÃxgettext¹¤¾ßÀ´´¦Àí¡£ÒòΪpygettext.py²»Ö§³Ö¸´ÊýµÄ·­Òë´®£¬ÎÒ²éÁËһϣ¬Ö÷ÒªÇø±ð¾ÍÊǶÔÓÚ¸´Êý£¬ÔÚpoÎļþÖÐÊÇÕâÑùµÄ£º

msgid "month"

msgid_plural "months"

msgstr[0] "ÔÂ"

msgstr[1] ""
¶ø²»´ø¸´ÊýµÄÐÎʽÊÇÕâÑùµÄ£º

msgid "month"

msgstr "ÔÂ"

±¾À´Ïë×ÔÒÑÐ޸ĵģ¬²»¹ý»¹ÊÇÏÈgoogleһϰɣ¬ÍòÒ»ÓÐÈ˽â¾öÁËÄØ¡£½á¹û»¹ÕæÕÒµ½ÁË¡£ÓÐÈËÔÚpythonµÄbugsÍøÕ¾ÉÏÌá½»¹ýÕâÑùµÄÎÊÌ⣬ȻºóÓÐÈ˸ø³öÁËÒ»¸ö²¹¶¡¡£´Ópygettext.pyµÄÔ´Âë¿ÉÒÔ¿´µ½£¬ËüÒѾ­ºÜ¶à¿´Ã»Óб»Ð޸ĹýÁË¡£ÓÚÊÇÎÒÏÂÔØÁ˲¹¶¡£¬ÏÈÔÚpython´øµÄ°æ±¾ÉÏ´ò²¹¶¡£¬È»ºóʹÓôúÂë±È½Ï¹¤¾ß½«ÎÒÐèÒªµÄÐÞ¸ÄÔÙ¼Ó½øÈ¥¡£ºóÀ´»¹ÐÞ¸ÄÁËpo_merge.py³ÌÐò¡£×îÖÕ°ÑÕâ¸öÎÊÌâ»ù±¾ÉÏËãÊǽâ¾öÁË¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 8, 2011

limodou的學習記錄
limodou
is about »
» Ìí¼ÓdecoratorsÅäÖÃÏîºÍµ÷ÕûÁËrbacÏà¹ØµÄº¯Êý

½ñÌìÏòuliwebÖЉˆ¼ÓÁËÒ»¸öеÄÅäÖÃÏîDECORATORS£¬ÕâÑùÄã¿ÉÒÔÔÚsettings.iniÖÐÌí¼ÓÀàËÆ£º

[DECORATORS]

check_role = 'uliweb.contrib.rbac.check_role'

check_permission = 'uliweb.contrib.rbac.check_permission'

ÕâÑùµÄÄÚÈÝ¡£Í¬Ê±ÔÚuliwebÖÐÒѾ­Ìí¼ÓÁËÒ»¸ö½ÐdecoratorsµÄ¶ÔÏó£¬ÕâÑù£¬Äã¿ÉÒÔÈçºÎʹÓÃdecoratorº¯Êý£º

 

from uliweb import decorators

@expose('/test')

@decorators.check_role('superuser')

def test():

    return {}

 

Ä¿Ç°rbacÒѾ­Ìṩhas_role, has_permissionÓÃÓÚ¼ì²éÓû§ÊÇ·ñÓÐijЩ½ÇÉ«»òȨÏÞ£¬Í¬Ê±ÓÖÌṩÁËcheck_roleºÍcheck_permission£¬ËüÃÇÊÇdecorator¡£ÕâЩ·½·¨ÒÔÇ°Ö»½ÓÊܵ¥¸ö½ÇÉ«»òȨÏÞ£¬ÏÖÔÚ¿ÉÒÔ´«Èë¶à¸ö½ÇÉ«»òȨÏÞÖµ¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

九月 6, 2011

limodou的學習記錄
limodou
is about »
» ÔÚclass based viewÖÐʹÓÃdecoratorÓëexposeµÄ³åÍ»

ÔÚplugs.forumsÖÐͻȻ·¢ÏÖÉú³ÉµÄijЩ´øidµÄÁ´½Ó³öÏÖÁËÎÊÌ⣬±ÈÈ磺ԭ±¾ÊÇÏ£ÍûµÃµ½'forum_edit/<id>'µÄ½á¹ûµÃµ½ÁË'forum_edit?id=xx'¡£¶øÇÒ»¹±¨³öurlÔÚ´¦ÀíʱÉÙÁ˲ÎÊý£¬¶øforum_editµÄ¶¨ÒåΪ£º

@expose('/forum')

class ForumView(object):
    @_check_role('superuser')
    def forum_edit(self, id):

ºóÀ´Ñо¿·¢ÏÖ£¬µ±Ê¹ÓÃÕâÑùµÄÐÎʽ£º

@expose('/forum')
class ForumView(object):
    def forum_edit(self, id):

ÊÇÕýÈ·µÄ¡£Ô­Òò¾ÍÔÚʹÓÃÁËdecoratorµÄÔµ¹Ê¡£ÒòΪuliweb»áÀûÓÃfunctionµÄ²ÎÊýÀ´×Ô¶¯Éú³ÉurlÖеIJÎÊý£¨´ø<>µÄ¾ÍÊÇ£©¡£Òò´ËÏó forum_edit(id)Ö®ÀàµÄ»áÉú³ÉΪ'forum_edit/<id>'¡£µ«ÊÇÓÉÓÚʹÓÃdecorator£¬ÓпÉÄÜÔì³Éº¯ÊýµÄ¶¨Òå·¢ÉúÁ˱仯£¬ËùÒÔÎÞ·¨°´Ô­Ê¼µÄ·½Ê½»ñµÃÕýÈ·µÄº¯Êý²ÎÊý¡£Òò´Ë£¬¶ÔÓÚÀàÖдø²ÎÊýµÄ·½·¨£¬ÄãÒª¶îÍâÌí¼ÓÒ»¸öexpose()À´Ö÷¶¯¶¨Òåurl£¬È磺

@expose('/forum')
class ForumView(object):
    @expose('forum_edit/<id>')
    @_check_role('superuser')
    def forum_edit(self, id):

ÕâÀïforum_editǰûÓÐ'/'£¬ÕâÑù¾ÍÊÇÒ»¸öÏà¶ÔµÄurl£¬Ëü»áÓëclassÉ϶¨ÒåµÄ½øÐкϲ¢´¦Àí£¬×îÖÕµÄurl½«Îª£º'/forum/forum_edit/<id>'¡£Í¬Ê±Òª×¢Ò⣬exposeÒª·Åµ½ÆäËüµÄdecoratorÖ®ÉÏ£¬±£Ö¤Ëü×îºóÖ´ÐС£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

八月 30, 2011

limodou的學習記錄
limodou
is about »
» ÈçºÎʵÏÖMySqlÖÐÇø·Ö´óСд×ֶζ¨ÒåºÍ²éѯ

MySqlÔÚ¶¨Òå×ֶκͲéѯ×Ö¶Îʱ£¬È±Ê¡ÊÇʹÓ÷ǴóСдÃô¸Ð·½Ê½½øÐд¦ÀíµÄ¡£ÓÐʱÎÒÃÇÐèÒª

½øÐдóСдÃô¸Ð·½Ê½µÄ²éѯ£¬Òò´ËÕâÀïÉæ¼°Á½ÖÖ´¦Àí£¬Ò»ÖÖÊDzéѯʱµÄ´óСдÇø·Ö£¬Èç::

 

    from sqlalchemy.sql import func

    

    User.filter(User.c.username == func.binary('limodou'))

    

ÉÏÊö´úÂ뽫°´´óСд¶Ô'limodou'½øÐвéѯ¡£

 

µ«ÊÇÈç¹ûÄã°ÑCHAR»òVARCHARÉèÖÃΪ²»Öظ´µÄË÷Òý£¬ÔÚ²åÈëÀàËÆ£º ``Limodou`` »ò ``limodou``

ÓпÉÄܻᱨÖظ´¡£Õâ¾Í²»ÊÇ¿¿²éѯÀ´½â¾öµÄÁË¡£ÒªÍ¨¹ý½«×ֶζ¨ÒåΪÇø·Ö´óСдµÄÐÎʽ¡£ÔÚ

MySqlÖÐÒ»°ãÊÇÔÚVARCHARÖ®ºóÌí¼ÓBinary£¬Èç::

 

    username VARCHAR(40) binary

    

ÄÇôÔÚUliorm»òSQLAlchemyÖÐÈçºÎ×öÄØ£¿´úÂëÈçÏÂ::

 

    from sqlalchemy.dialects.mysql import VARCHAR

    

    class Human(Model):

        name = Field(str, verbose_name='ÐÕÃû', max_length=40, required=True)

        login_name = Field(str, verbose_name='µÇ¼Ãû', required=True, 

            max_length=40, unique=True, type_class=VARCHAR, 

            type_attrs=dict(binary=True))

    

¿ÉÒÔ¿´µ½ËüʹÓÃÁËmysqlµÄdialectµÄ×ֶζ¨Ò壬²¢½«Æä´«ÈëuliormµÄ×ֶζ¨ÒåÖУ¬ÆäÖвÎ

Êý ``type_class`` Ϊ×Ö¶ÎÀàÐÍ£¬ ``type_attrs`` Ϊ×Ö¶ÎÏàÓ¦µÄ²ÎÊý£¬ÕâÀïÉèÖà ``binary``

Ϊ ``True`` ¡£ÔÚSQLAlchemyÖеĶ¨ÒåʾÀýÈç::

 

    from sqlalchemy.dialects.mysql import VARCHAR

    

    Column('username', VARCHAR(40, binary=True))

    

ÕâÑùÔÚÊý¾Ý¿âÖУ¬¾ÍÊÇÇø·Ö´óСдµÄ£¬ÔÚ²éѯʱ²»ÔÙÐèҪʹÓÃfunc.binary()À´´¦ÀíÁË¡£

 

²»¹ýÕâÖÖ·½Ê½¼æÈÝÐÔ²»ºÃ£¬ËùÒÔ»¹ÓÐÒ»ÖÖ±äͨµÄ·½Ê½¾ÍÊÇдһ¸ösqlÎļþ£¬ÔÚÃüÁîÐÐ϶Ô

×ֶνøÐÐÐ޸ģ¬ÕâÑùModel¾Í²»ÐèÒªÐÞ¸ÄÁË¡£±ÈÈç::

 

    use <database>;

    ALTER TABLE human MODIFY COLUMN `login_name` VARCHAR(40) 

        BINARY CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL;

    


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

八月 25, 2011

limodou的學習記錄
limodou
is about »
» uliormµ÷Ó÷ÇORM sqlÓï¾äµÄ×¢ÒâÊÂÏî

Ò»¾ä»°¼òµ¥Ëµ£¬ÔÚÖ´ÐÐview´¦ÀíʱʹÓÃdo_À´Ö´ÐзÇORMµÄÓï¾ä£¬È磺

from uliweb.orm import do_

result = do_(select(User.c, User.c.username=='limodou'))

¸´ÔӵĽâÊÍ

uliormÊÇ»ùÓÚsqlalchemy¿ª·¢µÄ¡£ËùÒÔ¿ÉÒÔÖ±½ÓʹÓÃsqlalchemyµÄºËÐÄsql¹¦ÄÜ£¬±ÈÈç³£¼ûµÄ£ºselect, update, insert, update¡£ÆäÖÐselect¿ÉÒÔµ¥¶Àµ÷Ó᣶øupdate, insert, updateÒ»°ãÊǺÍÒ»¸öTable¶ÔÏóÁ¬½ÓʹÓ᣶øʹÓÃuliormÄãÒ»°ãÒªÏÈ´´½¨Ò»¸öModel£¬È»ºóÕâ¸öModel¾Í»áÓÐÒ»¸ötableÊôÐÔ£¬Ëü¾ÍÊÇÕæÕýµÄTable¶ÔÏó£¬ËùÒÔֻҪʹÓÃModel.table¾Í¿ÉÒÔµ÷ÓÃTableÏà¹ØµÄ·½·¨ÁË¡£ÄÇôTableÖл¹ÓÐ.cÊôÐÔ£¬ËüÊÇËùÓÐ×ֶεÄÒ»¸öÀà×ÖµäÊôÐÔ¡£Äã¿ÉÒÔʹÓÃModel.table.c»òÖ±½ÓʹÓÃModel.c£¬ËüÃÇÊÇÒ»ÑùµÄ¡£

Òò´ËÎÒÃÇÒѾ­ÖªµÀÁË£¬ÈçºÎÕÒµ½ÏàÓ¦µÄTableºÍ×ֶμ¯ºÏ£¬ÕâÑùÎÒÃǾͿÉÒÔÖ´ÐÐsqlalchemyÌṩµÄ¸÷ÖÖ·½·¨¡£±ÈÈçÏȶ¨ÒåÒ»¸öUser±í£º

class User(Model):
    username = Field(str, max_length=80, verbose_name='Óû§Ãû³Æ', index=True, unique=True, required=True)

    email = Field(str, max_length=80, verbose_name='ÓÊÏä')

ÉÏÃ涨ÒåÁËÁ½¸ö×ֶΡ£ÄÇôÎÒÃDz»ÓÃuliormÌṩµÄ·½·¨£¬¶øÊÇʹÓÃsqlalchemyÌṩµÄsqlÓï¾äÀ´²Ù×÷һϣº

select(User.c, User.c.username=='limodou').execute() #²éѯ

User.table.insert().values(username='new user', email='newuser@abc.com').execute() #²åÈë

User.table.update().values(username='test').where(User.c.username=='new user').execute() #¸üÐÂ

User.table.delete(User.c.username=='new user').execute() #ɾ³ý

×¢Òâµ½ºóÃæµÄ'.execute'£¬ÕâÑù»áʹÓÃÊý¾Ý¿âÒýÇæ×Ô¶¯´´½¨µÄÁ¬½Ó¡£È»ºóÔÚ½á¹û´¦ÀíÍê±Ïºó×Ô¶¯¹Ø±Õ¡£Èç¹û½á¹û»¹Ã»Óд¦ÀíÍ꣬¿ÉÒÔÖ±½Óµ÷ÓÃresult.close()À´¹Ø±Õ¡£ÉÏÊöµÄÃèÊö¿ÉÒÔÔÚsqlalchemyµÄÎĵµ¡¶Working with Engines and Connections¡·ÖÐÕÒµ½¡£¶øÕâÀï×Ô¶¯´´½¨µÄÁ¬½Ó£¬ÆäʵȱʡÊÇÁ¬½Ó³ØµÄ´¦Àí¡£¹Ø±ÕÒ²Ö»ÊÇ·µ»Øµ½Á¬½Ó³ØÖС£µ«ÊÇÕâÑùÒ»À´£¬ÓпÉÄÜÎÞ·¨±£Ö¤¶àÌõsqlÓï¾äʹÓÃͬһ¸öÁ¬½Ó£¬²¢ÇÒ´¦ÓÚÒ»¸öÊÂÎñ֮ϡ£ËùÒÔ´øÊÂÎñµÄ´¦ÀíÒªÏÈ´´½¨Á¬½Ó£¬È»ºóÔÚÁ¬½ÓÉϵ÷ÓÃbegin()À´¿ªÆôÒ»¸öÊÂÎñ£¬È»ºóËùÓеIJÙ×÷¶¼ÔÚÕâ¸öÁ¬½ÓÉÏ£¬È»ºó¸ù¾ÝÊÂÎñµÄÌá½»»ò»Ø¹öÀ´µ÷ÓÃÏàÓ¦µÄcommit()»òrollback()¡£

ͬʱsqlalchemyÔÚ´´½¨ÒýÇæʱ»¹ÌṩÁËÒ»¸östrategyµÄ²ÎÊý£¬¶øuliorm¾ÍÊÇʹÓÃÁËËü£¬È磺

db=create_engine('mysql://localhost/test',strategy='threadlocal')

ÕâÑù£¬ËüµÄ×÷ÓþÍÊǵ±ÄãÖ´ÐÐ.execute()(ÔÚsqlalchemyÖнС°Connectionless¡±£¬¼´·ÇÏÔʾÁ¬½Ó´¦Àí)ʱ×Ô¶¯´´½¨Ï̼߳¶µÄÁ¬½Ó¡£ÕâÑùµÄºÃ´¦ÊDZ£Ö¤²»Í¬µÄsqlÓï¾ä¹²ÀëÒ»¸öÁ¬½Ó£¬´Ó¶øʹµÃÊÂÎñµÄ´¦Àí±È½Ï¼òµ¥¡£µ«ÊÇuliormÒ²ÊÇÔÚÕâ¸öµØ·½³öÁËÎÊÌâ¡£ËùÒÔ¾­¹ýÖع¹£¬uliormµ¥¶ÀÌṩÁËBegin(), Commit(), Rollback()À´±£³Ö×ÔÒÑά»¤µÄÏ̼߳¶µÄÁ¬½Ó¡£µ«ÊÇconnectionlessÔÚuliormÖл¹ÊÇ¿ÉÒÔʹÓã¬Ò²Òò´Ë»áÔì³ÉËüÃÇʹÓõÄÁ¬½ÓÓпÉÄܲ»ÊÇͬһ¸ö£¬ËùÒÔΪÁ˱£Ö¤ÔÚÒ»¸öÇëÇóµÄ´¦Àí¹ý³ÌÖÐʹÓÃͬһ¸öÁ¬½Ó£¬ÄãҪʹÓÃuliormÌṩµÄdo_()º¯ÊýÀ´Ö´ÐзÇORM²Ù×÷¡£È磺

do_(select(User.c, User.c.username=='limodou'))

Æäʵ¾ÍÊÇ°ÑsqlÓï¾ä×îºóµÄ.execute()È¥µô£¬ÓÃdo_()°üº¬ÆðÀ´¾ÍÐÐÁË¡£Ëü»á×Ô¶¯²éÕÒµ±Ç°Ïß³ÌÖÐÒѾ­´æÔÚµÄÁ¬½Ó¶ÔÏó£¬Èç¹ûûÓÐÔòʹÓÃÏß³ÌÁ¬½Ó¶ÔÏó£¨ÊÊÓÃÓÚÅúÁ¿´¦Àí³ÌÐò£©¡£ÄÇôÕâ¸öÏ̶߳ÔÏóÓ¦ÈçºÎ´´½¨ÄØ£¿ËüÊÇͨ¹ýBegin()À´´´½¨µÄ¡£¶øBegin()»áÔÚÿ¸öÇëÇó½øÀ´Ö®ºó£¬ÔÚÖ´ÐÐÄãµÄviewº¯Êý֮ǰ±»µ÷Ó㬴Ӷø±£Ö¤ÒѾ­ÓÐÒ»¸ö¿ÉÓõÄÏß³ÌÁ¬½Ó¡£²¢ÇÒÔÚ·µ»ØÏìÓ¦ºÍÅ׳öÒ쳣ʱ£¬ËüÒ²»á±»ÕýÈ·»ØÊÕ¡£

µ±È»£¬Èç¹ûÄã²»ÏëʹÓÃȱʡµÄÏß³ÌÁ¬½Ó£¬¶øÊÇ×ÔÒÑÀ´´´½¨ÐµÄÁ¬½Ó£¬Ä㻹ÊÇ¿ÉÒÔͨ¹ý£º

db = get_connection() #»ñµÃȱʡµÄengine¶ÔÏó

conn = db.connect() #»ñµÃеÄÁ¬½Ó

À´´´½¨ÐµÄÁ¬½Ó¡£×¢Ò⣬Õ⻹ÊÇÁ¬½Ó³ØµÄ´¦Àí¡£sqlalchemyÔÚȱʡÇé¿öÏ»á×Ô¶¯´´½¨5¸öÁ¬½ÓÊýµÄÁ¬½Ó³Ø¡£

Èç¹ûÄ㻹ÏëʹÓÃÏß³ÌÁ¬½Ó£¬µ«ÊÇͬʱÏë×ÔÒÑ¿ØÖÆÊÂÎñ£¬ÄÇô¿ÉÒÔÔÚÄãµÄviewÖÐÏÔʾµ÷ÓÃBegin(), Commit(), Rollback()À´¸´Óõ±Ç°µÄÏß³ÌÁ¬½Ó£¬²¢½øÐÐÊÂÎñ¿ØÖÆ¡£ÕâÀïBegin()»áÏȲéÕÒÊDz»ÊÇÒѾ­´æÔÚÒ»¸öÏß³ÌÁ¬½Ó£¬Èç¹û²»´æÔÚ£¬Ôò»áÏÈ´´½¨£¬Èç¹û´æÔÚÔò¸´Óá£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

八月 24, 2011

limodou的學習記錄
limodou
is about »
» UliormÁ¬½Ó´¦ÀíÖع¹

Õâ¸ö¸Ð¾õÓ°Ïì±È½Ï´ó£¬Ö÷ÒªÊÇÓ°ÏìÁ¬½Ó³Ø´¦Àí£¬²»¹ýËüÊÇÔڵײãµÄ´¦Àí£¬¶Ôapiµ÷ÓÃûÓÐÓ°Ïì¡£

 

ΪʲôҪ¸Ä£¬ÕâÊǺÍÎÒ·¢ÏÖµÄMysql server has gone away(¹ØÓÚÕâ¸öÎÊÌâÒѾ­¼Ç¼ÔÚÁË http://hi.baidu.com/limodou/blog/item/0ba35bafd4214ae0fbed508e.html)Óйء£Ô­À´ÈÏΪ´«ÈëÁËpool_recycle¾Í¿ÉÒÔÁË£¬µ«ºóÀ´·¢ÏÖ»¹ÊDz»ÐС£×îºó¶¨ÒåÊÇÒòΪÁ¬½ÓûÓлعé³É¹¦¡£Õâ¸öÒª´ÓÔ­À´uliormµÄʵÏÖ˵Æð¡£Ò»°ãµÄsqlalchemyµÄ´¦Àí¿ÉÄÜÊÇÕâÑù£º

 

db = create_engine(xxx, pool_recycle=7200)

conn = db.connect()

trans = conn.begin()

try:

    try:

        conn.execute(yyyy)

        trans.commit()

    except:

        trasns.rollback()

finally:

    conn.close()

 

ÕâÑù£¬ÏÈ´´½¨ÒýÇ棬Ȼºó´´½¨Á¬½Ó£¬Ã¿´´½¨Ò»¸öÁ¬½Ó¶¼»á´Ó³Ø×ÓÖÐÈ¡Ò»¸öÁ¬½Ó£¬È»ºóÔÚÕâ¸öÁ¬½ÓÉÏÖ´ÐÐÊÂÎñÖ®ÀàµÄ´¦Àí¡£´¦ÀíÍê±ÏºóÓ¦¹Ø±ÕÁ¬½Ó£¬ÕâÑù¾ÍʵÏֵĻØÊÕ¡£Èç¹ûÁ¬½Ó³Ø»ØÊÕʱ¼äµ½´ï£¬Ôòsqlalchemy»á×Ô¶¯Öؽ¨Á¬½Ó³Ø¡£

 

µ«ÊÇÎÒµÄÓ÷¨ÊÇΪÁË·½±ã£¬ÎÒʹÓÃÁËdbµÄĬÈÏÁ¬½Ó£¬²¢ÇÒÊÇ»ùÓÚÏ̵߳ģ¬Òò´ËuliormµÄ´¦ÀíģʽÊÇ£º

 

db = create_engine(xxx, pool_recycle=7200)

conn = db.contextual_connect()

db.begin()

try:

    try:

        db.execute(yyyy)

        db.commit()

    except:

        db.rollback()

finally:

    conn.close()

 

¶ødb.contextual_connect()ÓпÉÄÜ»ØÊÕÓÐÎÊÌâ¡£ÒòΪÎÒÖع¹ÁËÕâ¿éµÄ´¦Àí£¬¸ÄΪ£º

 

ÔÚuliormÌṩµÄBegin(), Commit(), Rollback()ÖнøÐиÄÔ죬ÒòΪËüÃÇ»áÔÚmiddleware_transactionÖб»µ÷Ó㬱£Ö¤ÔÚÇëÇó´¦ÀíÇ°¿ªÊ¼ÊÂÎñ£¬ÔÚ·µ»ØºóÌá½»£¬ÔÚÓÐÒ쳣ʱ»Ø¹ö¡£ËùÒÔÒ»µ©ÄãʹÓÃÁËÕâ¸ö²å¼þ£¬Ã¿¸öviewµÄ´¦Àí¾Í»á×Ô¶¯±£Ö¤ÊÂÎñµÄÒ»ÖÂÐÔ£¬µ«Êǵ±³ÌÐòÖÐÓÐÌØÊâÐèÒª£¬¿ÉÒÔÊÖ¶¯´¦ÀíÊÂÎñ¡£

 

ÔÚµ÷ÓÃBegin()ʱ»á´´½¨Á¬½Ó£¬Í¬Ê±½«Õâ¸öÁ¬½Ó´æÈëthreading.local()µÄ±äÁ¿ÖУ¬±£Ö¤Ïß³ÌΨһ¡£ºóÐøµÄÊÂÎñ´¦ÀíÒ²ÊÇ»ùÓÚÕâ¸öд´½¨µÄÁ¬½ÓµÄ¡£Í¨¹ýÕâÖÖ·½·¨¾Í½â¾öÁËÁ¬½Ó»ØÊÕµÄÎÊÌâ¡£ÔÚÎÒµÄÈÕÖ¾ÖУ¬Èç¹ûÁ¬½Ó»ØÊÕÁË£¬¿ÉÒÔ¿´µ½£º

 

2011-08-24 15:23:39,832 INFO sqlalchemy.pool.QueuePool.0x...a350 Connection <_mysql.connection open to 'localhost' at 266f898> exceeded timeout; recycling

 

ÕâÑùµÄÐÅÏ¢¡£ÄãÈç¹ûÏë¿´¿ÉÒÔÔÚsettings.iniÖÐÌí¼Ó

 

[ORM]

CONNECTION_ARGS = {'pool_recycle':7200, 'echo_pool':True}

 

ΪÁ˲âÊÔ·½±ã£¬ ¿ÉÒÔ°ÑÉÏÃæµÄ'pool_recycle'ʱ¼äŪ¶ÌЩ£¬±ÈÈç10ÃëÖÓ¡£

 

Èç¹ûÓÐÎÊÌâÇë·´À¡¸øÎÒ¡£


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

八月 23, 2011

limodou的學習記錄
limodou
is about »
» uliwebºÍplugsÑÝʾÍøÕ¾Ô´Âë

Ëü¾ÍÊDz¼ÊðÔÚdotcloudÉϵÄÔ´´úÂ룬ĿǰÎÒÊÇÔÚgithubÉÏ´´½¨µÄ²Ö¿â£¬¿ÉÒÔͨ¹ý£º https://github.com/limodou/uliwebzone À´·ÃÎÊ¡£dotclouldµÄµØַΪ£º http://www.uliweb.dotcloud.com

ÄãÒ²¿ÉÒÔÔÚ±¾µØÔËÐУ¬°²×°µÄ»°ÐèÒª£º

1. uliweb ¿ÉÒÔͨ¹ýpython setup.py develop·½Ê½°²×°£¬±È½Ï·½±ãÓëuliwebͬ²½´úÂë¡£ÏîÄ¿µØÖ·£º http://code.google.com/p/uliweb/

2. plugs ¿ÉÒÔͨ¹ýpython setup.py develop·½Ê½°²×°¡£ÏîÄ¿µØÖ·£º http://code.google.com/p/plugs/

ÉÏÃæÁ½¸öÄ¿Ç°¶¼ÔÚcode.google.comÉÏ£¨×î½ü»áͬ²½µ½githubÉÏ£©¡£

3. PIL ÓÃÓÚͼÏñ´¦Àí

°²×°ºó¾ÍÊÇÖ´Ðгõʼ»¯¹¤×÷£º

½øÐÐÏîÄ¿ÃüÁîÐУº

uliweb syncdb (´´½¨Êý¾Ý¿â)

uliweb dbinit uliweb.contrib.rbac »ò uliweb dbinit (½øÐÐȨÏÞ±íµÄ³õʼ»¯´¦Àí)

»ù±¾ÉϾÍÕâЩÁË¡£¿ÉÒÔÔËÐп´ÁË£º

uliweb runserver


Àà±ð£ºUliweb ²é¿´ÆÀÂÛ

biggo.com.tw

A Django site.