February 2009 Archives

django m2m自包含

| No Comments | No TrackBacks
设计一个group,可以包含user也可以包含group。user和group都可以被多个group包含。
class Group(models.Model):
    users = models.ManyToManyField(User)
    groups = models.ManyToManyField('self')
update: ManyToMany对象有一个symmetrical的参数,当为True时的意思是对象间有互相拥有的关系,是双向的,反之为False时就是单向的。

大裤叉配楼火灾

| No Comments | No TrackBacks
引自《阿房宫赋》:
楚人一炬,可怜焦土!

对待平等

| 2 Comments | No TrackBacks

云风的一篇平等讲述了他们团队对平等的一些理解。herock又对平等产生了许些质疑。我从电影King Arthur里觉的人与人之间的平等是重要的,也是人与人之间互相尊敬的一个基础。其实真正的平等并不存在,herock重在说明这一情况(唯物)。而云风则更注重人对人的平等,且不论平等是否存在(唯心)。

摘电影里的一句话

Every man must be equal.

我当时取名Gawain(圆桌骑士之一)即是受这部电影的影响。

按Command(⌘)和L是移动焦点到地址栏,然后再按Command(⌘)和分号(; semicolon)就是修改当前地址的各个部分了,多按几次修改的部分就不同

django login

| No Comments | No TrackBacks

最近写一个django项目的时候犯懒,把admin的login form给简单的扒出来用了用,感觉还不错。

先把display_login_form给扒出来

def display_login_form(request, error_message='', extra_context=None):
    request.session.set_test_cookie()
    context = {
        'title': 'Log in',
        'app_path': request.get_full_path(),
        'error_message': error_message,
        'root_path': '',
    }
    context.update(extra_context or {})
    return render_to_response('admin/login.html', context,
        context_instance=template.RequestContext(request)
    )

然后自己再写一个login

def login(request):
    if request.POST:
        username = request.POST['username']
        password = request.POST['password']
        user = auth.authenticate(username=username, password=password)
        if user is not None and user.is_active:
            auth.login(request, user)
            return http.HttpResponseRedirect(request.get_full_path())
        else:
            return display_login_form(request,"Login error!")
    else:
        return display_login_form(request)

需要认证的地方就这样写

def login_test(request):
    if not request.user.is_authenticated():
        return login(request)
    else:
        return http.HttpResponse("Welcome %s" % request.user)
update: 上面那个方法还是不够懒,细读了一下文档,可以这样写。
  • settings.py
  • LOGIN_URL = '/login/'
    LOGIN_REDIRECT_URL = '/'
    
  • urls.py
  •     (r'^login/','django.contrib.auth.views.login',{'template_name': 'admin/login.html'}),
        (r'^logout/','superman.lib.views.logout'),
    

易用的touchpad

| 2 Comments | No TrackBacks

有个朋友最近入手一台二手iBook(Late 2004)。试用了一下,发现Touchpad不支持双个手指滚动的功能,立时感到易用性下降许多。

我用的是Mid 2005版,有双个手指滚动的功能,很方便。以前有一个单键的Apple Pro Mouse,但是很不好用,后来索性把鼠标拨了不用了,直接用Touchpad。键盘使用的频率要比鼠标高的多,要用到鼠标,手掌就会离开托手的位置,之后再回到托手的位置,Touchpad虽然精度不高但是手掌不用离开托手(我是懒人)。如果仅是如此还是不够,要拖动滚动条的时候还是麻烦,Touchpad远不如鼠标的滚轮方便,但是Apple近乎完美的解决了这个问题,就是用两个手指滚动,这远比其他厂商采用的右侧滚动区(HP等)或第三键滚动(IBM)方便的多。

虽然现在的MacBook都有了Multi-Touch,其易用性也已经不可同日而语了,但我觉的最重要的还是两个手指(two finger)滚动(两个手指还可以当右键使two finger+单击)。

About this Archive

This page is an archive of entries from February 2009 listed from newest to oldest.

January 2009 is the previous archive.

March 2009 is the next archive.

Find recent content on the main index or look in the archives to find all content.