from django.forms import ModelForm
from django.forms.util import ErrorList
class MyModelForm(ModelForm):
def __init__(self, data=None, files=None, auto_id='id_%s', prefix=None,
initial=None, error_class=ErrorList, label_suffix=':',
empty_permitted=False, instance=None):
opts = self._meta
if instance is None:
if opts.model is None:
raise ValueError('ModelForm has no model class specified.')
instance = opts.model()
instance.save()
super(MyModelForm, self).__init__(data, files, auto_id, prefix,
initial, error_class, label_suffix,
empty_permitted, instance)
class DrawExample(QtGui.QWidget):
def __init__(self):
super(DrawExample, self).__init__()
self.points = []
self.init_ui()
self.timer = self.startTimer(0)
def init_ui(self):
self.setGeometry(300, 300, WIDTH, HEIGHT)
self.setWindowTitle('Draw')
self.show()
def timerEvent(self, e):
if e.timerId() != self.timer: return
if len(self.points) >= 10000:
self.killTimer(self.timer)
return
for i in xrange(100):
self.points.append((
random.randint(1, WIDTH-3),
random.randint(1, HEIGHT-3),
QtGui.QColor(
random.randint(1, 255),
random.randint(1, 255),
random.randint(1, 255)
),
))
self.update()
def paintEvent(self, e):
qp = QtGui.QPainter()
qp.begin(self)
for point in self.points:
qp.setPen(point[2])
qp.drawEllipse(point[0]-3, point[1]-3, 6, 6)
qp.end()
1 dnat
ip route add default via 192.168.0.1 table dnat
iptables -t mangle -A PREROUTING -p TCP --dport 80 -m conntrack --ctstate NEW -j CONNMARK --set-mark 1
iptables -t mangle -A OUTPUT -p TCP --sport 80 -j CONNMARK --restore-mark
ip rule add fwmark 1 table dnat