在 05-12-24,风尘无限<[EMAIL PROTECTED]> 写道:
>
> 对于非英语的Django用户/爱好者,对每一个"app"也加入一个"verbose_name"或"verbose_name_plural",以便于WEB
> PAGE的友好好浏览是必要的。
>
> 我的实现方式:
> 一、修改adminapplist.py为:
> ####################################################
> from django.core import template
>
> class AdminApplistNode(template.Node):
>     def __init__(self, varname):
>         self.varname = varname
>
>     def render(self, context):
>         from django.core import meta
>         from django.utils.text import capfirst
>         app_list = []
>         user = context['user']
>
>         for app in meta.get_installed_model_modules():
>             app_label = ''
>             app_name = app.__name__[app.__name__.rindex('.')+1:]
>
>             if hasattr(app, 'verbose_name'):
>                 app_label = app.verbose_name
>             else:
>                 app_label = app_name;
>             has_module_perms = user.has_module_perms(app_label)
>
>             if has_module_perms:
>                 model_list = []
>                 for m in app._MODELS:
>                     if m._meta.admin:
>                         module_name = m._meta.module_name
>                         perms = {
>                             'add': user.has_perm("%s.%s" % (app_label,
> m._meta.get_add_permission())),
>                             'change': user.has_perm("%s.%s" %
> (app_label, m._meta.get_change_permission())),
>                             'delete': user.has_perm("%s.%s" %
> (app_label, m._meta.get_delete_permission())),
>                         }
>
>                         # Check whether user has any perm for this
> module.
>                         # If so, add the module to the model_list.
>                         if True in perms.values():
>                             model_list.append({
>                                 'name':
> capfirst(m._meta.verbose_name_plural),
>                                 'admin_url': '%s/%s/' % (app_name,
> m._meta.module_name),
>                                 'perms': perms,
>                             })
>
>                 if model_list:
>                     app_list.append({
>                         'name': app_name.title(),
>                         'title': app_label.title(),
>                         'has_module_perms': has_module_perms,
>                         'models': model_list,
>                     })
>         context[self.varname] = app_list
>         return ''
>
> def get_admin_app_list(parser, token):
>     """
>     {% get_admin_app_list as app_list %}
>     """
>     tokens = token.contents.split()
>     if len(tokens) < 3:
>         raise template.TemplateSyntaxError, "'%s' tag requires two
> arguments" % tokens[0]
>     if tokens[1] != 'as':
>         raise template.TemplateSyntaxError, "First argument to '%s' tag
> must be 'as'" % tokens[0]
>     return AdminApplistNode(tokens[2])
>
> template.register_tag('get_admin_app_list', get_admin_app_list)
> ###################################################################
> 二、修改template index.hmtl的内容:
> {% for app in app_list %}
>         <div class="module">
>         <h2>{{ app.name }}</h2>
>         <table>
>         {% for model in app.models %}
> 为:
> {% for app in app_list %}
>         <div class="module">
>         <h2>{{ app.title }}</h2>
>         <table>
>         {% for model in app.models %}
> ###################################################################
> ###################################################################
> 三、这样在每一个app的module定义PY文件中加入如下属性就可以在管理界面中看到了:
> ###################################################################
> verbose_name = u'保险业务信息管理'.encode('gb2312')
> ###################################################################
>
>
兄弟,这是老外的邮件列表啊,怎么不用英文呢?老外有几个看得懂呢?

Hi, guy, why did you write it in Chinese, why not in English?

--
I like python!
My Blog: http://www.donews.net/limodou
NewEdit Maillist: http://groups.google.com/group/NewEdit

Reply via email to