Django ship a default action “Delete selected <objects>”, how can we add a new action? It is easy to do that. All you need to do are in admin.py where the model admins are registered.
First write your action handler function like this
def tasks_finished( modeladmin, request, queryset ):
queryset.update( finished = True )
tasks_finished.short_description = "Mark these tasks as finished"
Then register the handler in your model admin site
class TaskAdmin( admin.ModelAdmin ):
list_display = [ "project", "title", "user", "works", "time", "finished" ]
list_filter = [ "finished", "user", "project" ]
inlines = [ WorkAdminInline ]
ordering = [ "project", "finished", "user", "title" ]
actions = [ tasks_finished ]
That is all you need to do.
After upgrade to django 1.2.1, I encountered csrf porblems. I did these things to fix it:
modify settings.py, add
try:
from django.middleware import csrf
MIDDLEWARE_CLASSES += (
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.csrf.CsrfResponseMiddleware',
)
except:
pass
below
MIDDLEWARE_CLASSES = (
......
)
add {% csrf_token %} in templates/admin/login.html ( Guess you must have override the login.html based on the old version ). The template tag csrf_token is default tag, you don’t need to load any extra tag libraries.
Don’t forget to restart your server.
Posted in Django
|
Tagged csrf, Django
|
Hello world, this post is added through PHProxy. Planing to add a web proxy function soon.
Posted in PHP
|
Tagged PHP, web proxy
|
Function:
function render_to_string( $file, $context = array() ){
if( ! file_exists( $file ) ){
return "";
}
ob_start();
include( $file );
$cnt = ob_get_clean();
return $cnt;
}
Example:
http://www.softwarematrix.cn/example/php.render_to_string/
You can download the test code from the example.
I like firebug, but the firefox/firebug goes unstable in my MAC OS. I have to use Safari. I’m a web application programmer, I get to debug my sites, and I need a debug bar like firebug. Thanks that Safari has its own develop tool. By default, it is hidden, Of course, not all who use safari a developper. I get to enable it:
Safari -> Preferences… -> Advanced -> Show Develop menu in menu bar
Once youe turn on the checkbox, there will be a menu appear in Safari menu bar named “Develop“, click submenu “Show Web Inspector“, something linke firebug will appear at the bottom of the browser. Wow, why it is so like Google Browser’s Develop Tool?
Click and hold the bookmark item, then drag it off the bar, release your mouse, and the bookmark gone from your bookmark bar. If you are deleting the bookmark folder, after you drag off it from the bar and release the mouse, a confirm box will appear. Just delete them, I dislike the function of bookmark, for google remember everything for me, and I just remember google.
You can hide the bookmark bar by menu operation: View -> Hide Bookmarks Bar
Now it completely gone, I like a clean browser.
Install inetutils from Cydia or
Huang-Jiang-Bins-iPhone-3:/var/mobile root# ping www.google.com
sh: ping: command not found
Huang-Jiang-Bins-iPhone-3:/var/mobile root# apt-get install inetutils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
inetutils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0B/212kB of archives.
After this operation, 889kB of additional disk space will be used.
Selecting previously deselected package inetutils.
(Reading database ... 5760 files and directories currently installed.)
Unpacking inetutils (from .../inetutils_1.6-8_iphoneos-arm.deb) ...
Setting up inetutils (1.6-8) ...
Huang-Jiang-Bins-iPhone-3:/var/mobile root# ping www.google.com
PING www-g-com-chn.l.google.com (66.249.89.104): 56 data bytes
64 bytes from 66.249.89.104: icmp_seq=0 ttl=50 time=202.328 ms
64 bytes from 66.249.89.104: icmp_seq=1 ttl=50 time=228.361 ms
64 bytes from 66.249.89.104: icmp_seq=2 ttl=50 time=145.664 ms
^C--- www-g-com-chn.l.google.com ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max/stddev = 145.664/192.118/228.361/34.524 ms
Just install adv-cmds from Cydia
Example:
Huang-Jiang-Bins-iPhone-3:/var/tmp root# ps -ef
UID PID PPID C STIME TTY TIME CMD
0 1 0 0 0:02.48 ?? 0:02.84 /sbin/launchd
65 12 1 0 0:00.68 ?? 0:01.41 /usr/sbin/mDNSResponder -launchd
0 13 1 0 0:01.35 ?? 0:02.26 /usr/sbin/notifyd
0 14 1 0 0:00.43 ?? 0:00.89 /usr/sbin/syslogd
0 15 1 0 0:11.33 ?? 0:21.59 /usr/libexec/configd
501 18 1 0 1:18.83 ?? 5:33.48 /System/Library/CoreServices/SpringBoard.app/SpringBoard
25 19 1 0 0:05.75 ?? 0:10.48 /System/Library/Frameworks/CoreTelephony.framework/Support/CommCenter
0 24 1 0 0:00.44 ?? 0:01.61 /usr/libexec/lockdownd
0 27 1 0 0:00.06 ?? 0:00.34 /usr/sbin/fairplayd.N88
501 35 1 0 0:04.72 ?? 0:25.91 /usr/sbin/mediaserverd
0 36 1 0 0:02.85 ?? 0:07.97 /usr/libexec/locationd
25 37 1 0 0:00.28 ?? 0:00.43 /usr/bin/awd_ice2
501 38 1 0 0:00.41 ?? 0:00.58 /usr/sbin/accessoryd
501 52 1 0 0:01.32 ?? 0:02.43 /usr/libexec/lsd
501 113 1 0 0:00.93 ?? 0:04.24 /Applications/MobilePhone.app/MobilePhone
501 114 1 0 0:00.87 ?? 0:02.90 /Applications/MobileMail.app/MobileMail
501 119 1 0 0:00.48 ?? 0:01.35 /usr/sbin/BTServer
501 131 1 0 0:00.29 ?? 0:00.85 /Applications/MobileSlideShow.app/MobileSlideShow
501 136 1 0 0:00.63 ?? 0:01.36 /Applications/MobileMusicPlayer.app/MobileMusicPlayer
0 227 1 0 0:04.88 ?? 0:06.93 /usr/sbin/sshd -i
0 665 1 0 0:00.20 ?? 0:00.43 /usr/sbin/sshd -i
501 228 227 0 0:00.14 ttys000 0:00.19 -sh
0 677 228 0 0:00.38 ttys000 0:00.54 sh
0 740 677 0 0:00.01 ttys000 0:00.01 ps -ef
501 666 665 0 0:00.02 ttys001 0:00.07 -sh
0 671 666 0 0:00.04 ttys001 0:00.07 sh
Posted in iPhone
|
Tagged adv-cmds, iPhone, ps
|
You can install OpenSSHd from Cydia. Search OpenSSH and install it. After that, you can connect to your iPhone via ssh, there are 2 users created for you, mobile and root. The default password is alpine, you should change that as soon as possible.
Example:
huangxh@agamemnon:~$ ssh mobile@10.6.175.246
mobile@10.6.175.246′s password: [alpine]
Huang-Jiang-Bins-iPhone-3:~ mobile$ passwd
Changing password for mobile.
Old password: [alpine]
New password: [your password]
Retype new password: [your password]
Huang-Jiang-Bins-iPhone-3:~ mobile$ su
Password: [alpine]
Huang-Jiang-Bins-iPhone-3:/var/mobile root# passwd
Changing password for root.
New password: [your password]
Retype new password: [your password]