Pinax源代码分析7 - Profiles

Pinax源代码分析7 Profiles

负责管理用户的档案

url

    (r'^profiles/', include('profiles.urls')),

逻辑与模板

url(r'^username_autocomplete/$', 'misc.views.username_autocomplete_friends', name='profile_username_autocomplete'),

misc app username_autocomplete_all 处理,依赖于basic_profilesavatar

from basic_profiles.models import Profile
from avatar.templatetags.avatar_tags import avatar

url(r'^$', 'profiles.views.profiles', name='profile_list'),

profiles view 会将所有用户的queryUser.objects.all())传递给模板 profiles/profiles.html

{% extends "profiles/base.html" %}

{% load pagination_tags %}
{% load avatar_tags %}
{% load humanize %}

{% block body %}
    {% autopaginate users %}
    {% regroup users by date_joined.date as users_by_date_joined %}
    {% for date in users_by_date_joined %}
        <h2 class="join_date">{{ date.grouper|naturalday:_("MONTH_DAY_FORMAT")|capfirst }}</h2>
        {% for user in date.list %}
                <div style="float: left;">{% avatar user 40 %}</div>
        {% endfor %}
    {% endfor %}
    {% paginate %}
{% endblock %}

模板扩展了profilesbase.html模板,base 负责提供子导航的内容。


pagination_tags
django_pagination pagination app 的自定义标签。profiles.html使用{% autopaginate users %}users进行分页, 使用{% paginate %}显示页码和页码范围等信息。
avatar_tags
django_avatar avator app 的自定义标签。使用{% avatar user 40 %}来获得显示用户头像的标签。
humanize
Django 自带的,在django.contrib 目录下。这里使用naturalday标签,如果日期是今天就会显示today,相似的有昨天和明天的判断。

暂时没有找到regroup标签是在哪里定义的。

url(r'^(?P<username>[/w/._-]+)/$', 'profiles.views.profile', name='profile_detail'),

profile view 会判断浏览者和被浏览者是不是一个人、好友、follow关系。并且依此来处理和显示档案相关的表单。

{% extends "profiles/base.html" %}

{% load app_plugins %}
            {% plugin_point "profiles.profile" user=other_user owner=other_user viewer=user %}
           
app_plugins
app_plugins app 定义的自定义标签,没太看明白 plugin_point 的用法。修改代码为:
            <br />---------------------------------------------------------
            {% plugin_point "profiles.profile" user=other_user owner=other_user viewer=user %}
            <br />---------------------------------------------------------

结果页面为:

 pinax app_plugin测试

看来这一行生成了不少东西。查阅app_plugins的官方http://code.google.com/p/django-app-plugins/可知,这个app主要实现的是一个反向的{% block %} 每个app在自己的模板目录里的foo.html文件中定义将要被包含的内容,其它模板调用{% plugin_point "foo" %}的时候就会被包含进去。例如pinax中,wiki的模板中有plugins/profiles/profile.html,而在profile.html模板中有如下一句:
  {% plugin_point "profiles.profile" user=other_user owner=other_user viewer=user %}
这就将wikiplugins/profiles/profile.html中的内容包含进来了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值