vero4ka PyTips Documentation - Read the Docs

bookmarkalikeInternet and Web Development

Dec 14, 2013 (3 years and 7 months ago)

73 views

vero4ka PyTips Documentation
Release 1.0
vero4ka
November 06,2013
Contents
1 Python 3
1.1 utf-8?...................................................3
2 Django 5
2.1 hoiceField ModelForm?.......................................5
2.2 Deserialize request............................................5
2.3 querysets?..............................................5
2.4.....................................................6
2.5 native DateTimeField..........................................6
3 South 7
3.1?....................................................7
3.2,?..................................................7
3.3?...................................................7
3.4?...................................................7
4 Python Excel 9
4.1 content-type Excel?..........................................9
5 Linux 11
5.1?...................................................11
5.2.....................................................11
6 ExtJs 13
6.1 url grid,store?...........................................13
7 Indices and tables 15
i
ii
vero4ka PyTips Documentation,Release 1.0
Contents:
Contents 1
vero4ka PyTips Documentation,Release 1.0
2 Contents
CHAPTER 1
Python
1.1 utf-8?
>>> x=r’\u0110\xe8n\u0111\u1ecf n\xfat giao th\xf4ng Ng\xe3 t\u01b0 L\xe1ng H\u1ea1’
>>> u=unicode(x,’unicode-escape’)
>>> print u
Ðèn
¯
d nút giao thông Ngã t Láng H
3
vero4ka PyTips Documentation,Release 1.0
4 Chapter 1.Python
CHAPTER 2
Django
2.1 hoiceField ModelForm?
from django.db import models
class Project(models.Model):
name = models.CharField(max_length=140)
parent = models.ForeignKey(’self’,blank=True,null=True)
class ProjectForm(ModelForm):
def __init__(self,
*
args,
**
kwargs):
super(ProjectForm,self).__init__(
*
args,
**
kwargs)
ordered = []
//...making ordered list...
self.fields[’parent’].choices = ordered
self.fields[’parent’].choices.insert(0,(’’,u’------’))
2.2 Deserialize request
data = self.deserialize(
request,
request.raw_post_data,
format=request.META.get(’CONTENT_TYPE’,’application/json’))
2.3 querysets?
from itertools import chain
result_list = list(chain(page_list,article_list,post_list))
5
vero4ka PyTips Documentation,Release 1.0
2.4
import datetime
from django.db import models
class News(models.Model):
pub_date = models.DateTimeField(u’ ’,blank=False,default=datetime.datetime.now)
2.5 native DateTimeField
:
remote:/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808:
RuntimeWarning:DateTimeField received a naive datetime (2012-08-14 10:18:39.892967)
while time zone support is active.
remote:RuntimeWarning)
python manage.py migrate.
:
from django.utils.timezone import utc
datetime=datetime.datetime.utcnow().replace(tzinfo = utc)
6 Chapter 2.Django
CHAPTER 3
South
3.1?
$./manage.py schemamigration appname --initial
$./manage.py migrate appname
3.2,?
$./manage.py migrate --fake
3.3?
$./manage.py schemamigration appname --auto
$./manage.py migrate appname
3.4?
$./manage.py datamigration appname copy_values
7
vero4ka PyTips Documentation,Release 1.0
8 Chapter 3.South
CHAPTER 4
Python Excel
4.1 content-type Excel?
BIFF.xls:application/vnd.ms-excel
Excel2007.xlsx:application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
9
vero4ka PyTips Documentation,Release 1.0
10 Chapter 4.Python Excel
CHAPTER 5
Linux
5.1?
ls | perl -ane ’s/\n|\r//g;next unless m/\s+/;$sf=$_;$sf=~s/(\s)/\\$1/g;$df=$_;$df=~s/\s+/_/g;print"mv $sf $df\n"’ | sh
5.2
There are several ways to make xrandr customizations permanent from session to session:a).xprofile,b) kdm/gdm,
c) xorg.conf.Each of these mechanisms will be discussed in turn.
Setting xrandr commands in.xprofile
A user’s ~/.xprofile file is executed on Xorg startup if it exists and is executable.You can copy and paste xrandr
command line strings into this file so they’re executed when you log in.For example:
$ xrandr --output VGA-0 --mode 800x600
There are two disadvantages to using.xprofile for xrandr settings.First,it occurs fairly late in the startup process,so
you’ll see some resolution resizing during the initial screen draw;in some cases panel windows may resize improperly
as a result.Second,as this is a per-user setting,it won’t affect the resolutions of other users,nor will it alter the
resolution on the login screen.
xrandr –output $choice –primary
username@username:~$ xrandr
Screen 0:minimum 320 x 200,current 3200 x 1080,maximum 8192 x 8192
VGA1 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 476mm x 268mm
1920x1080 60.0
*
+
1600x1200 60.0
1680x1050 60.0
1400x1050 60.0
1280x1024 75.0 60.0
1440x900 59.9
1280x960 60.0
1152x864 75.0
1024x768 75.1 70.1 60.0
832x624 74.6
800x600 72.2 75.0 60.3 56.2
11
vero4ka PyTips Documentation,Release 1.0
640x480 72.8 75.0 66.7 60.0
720x400 70.1
HDMI1 connected 1280x1024+1920+56 (normal left inverted right x axis y axis) 338mm x 270mm
1280x1024 60.0 + 75.0
*
1024x768 75.1 60.0
800x600 75.0 60.3
640x480 75.0 60.0
720x400 70.1
DP1 disconnected (normal left inverted right x axis y axis)
username@username:~$ xrandr --output VGA1 --primary
12 Chapter 5.Linux
CHAPTER 6
ExtJs
6.1 url grid,store?
grid = Ext.getCmp(’MyGrid’);
var url = grid.getStore().getProxy().api.read;
var params = grid.getStore().getProxy().extraParams;
params[’new_param’] = ’value’;
var newUrl = url + ’?’ + Ext.Object.toQueryString (params);
window.open(newUrl,’_blank’);
13
vero4ka PyTips Documentation,Release 1.0
14 Chapter 6.ExtJs
CHAPTER 7
Indices and tables
• genindex
• modindex
• search
15