Форум сайта python.su
def reference_street(request):
word = request.GET.get('q', u'---')
try:
streets = ReferenceStreet.objects.filter(street__startswith=word)
except:
streets = u'None'
return HttpResponse(streets)
Django version 1.1 pre-alpha SVN-9832, using settings 'notary.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16/Feb/2009 15:09:30] "GET /bookreference/street/?q=w&limit=150×tamp=1234789769304 HTTP/1.1" 200 38
[16/Feb/2009 15:12:19] "GET /bookreference/street/?q=%D0%B7&limit=150×tamp=1234789939903 HTTP/1.1" 200 0
def index(self):
countries = si.meta.Session.query(si.Countries).first()
c.a_countries = FieldSet(countries, data=request.params)
if c.a_countries.validate():
c.a_countries.sync()
si.meta.Session.commit()
c.a_countries.configure(options=[c.a_countries.name.label(_(u'Наименование')).required(),
c.a_countries.code.label(_(u'Код')).required(),
c.a_countries.archive.label(_(u'Архив')),],
exclude = [c.a_countries.createdt],
readonly=False)
return render('/admin/layouts/geography.mako')
class Photo(models.Model):
description = models.CharField(max_length=100, blank=True)
photo = models.ImageField(upload_to='/home/r/project/django/mysite/' )
class PhotoForm(forms.ModelForm):
class Meta:
model = Photo
import urllib
import smtplib
def createhtmlmail (html, subject):
"""Create a mime-message that will render HTML in popular
MUAs, text in better ones"""
import MimeWriter
import mimetools
import cStringIO
out = cStringIO.StringIO() # output buffer for our message
htmlin = cStringIO.StringIO(html)
writer = MimeWriter.MimeWriter(out)
#
# set up some basic headers... we put subject here
# because smtplib.sendmail expects it to be in the
# message body
#
writer.addheader("Subject", subject)
writer.addheader("MIME-Version", "1.0")
#
# start the multipart section of the message
# multipart/alternative seems to work better
# on some MUAs than multipart/mixed
#
writer.startmultipartbody("alternative")
writer.flushheaders()
#
# start the html subpart of the message
#
subpart = writer.nextpart()
subpart.addheader("Content-Transfer-Encoding", "quoted-printable")
#
# returns us a file-ish object we can write to
#
pout = subpart.startbody("text/html", [("charset", 'cp-1251')])
mimetools.encode(htmlin, pout, 'quoted-printable')
htmlin.close()
#
# Now that we're done, close our writer and
# return the message body
#
writer.lastpart()
msg = out.getvalue()
out.close()
return msg
# Формирование файла weather.html
citycode = '27612'
_url = "http://www.gismeteo.ru/towns/" + citycode + ".htm"
skin = 'default'
u = urllib.urlopen(_url)
s = u.read()
p1 = s.find('var frc=\'') + 9
p2 = s.find('\'',p1)
s = s[p1:p2]
s = s.replace('align=center ', '')
s = s.replace('<span class=sml>', '')
s = s.replace('</span>', '')
s = s.replace('nowrap', 'nowrap="true"')
s = s.replace('<table', '<table class="tbl"')
s = s.replace('bgcolor=F0F0F0', 'class="cl1"')
s = s.replace('bgcolor=F0FFF0', 'class="cl2"')
s = s.replace('bgcolor=F0F0FF', 'class="cl3"')
s = s.replace('bgcolor=FFF0F0', 'class="cl4"')
s = s.replace('bgcolor=FFFFF0', 'class="cl5"')
s = s.replace('bgcolor=FFFFFF', 'class="cl6"')
b = 1
while b:
p1 = s.find('<img')
if p1 == -1:
b = 0
else:
p2 = s.find('>',p1)
if p2 == -1:
b = 0
else:
_oldstr = s[p1:p2+1]
_newstr = ''
pp1 = _oldstr.find('title="')
if pp1 > -1:
pp2 = _oldstr.find('"',pp1+7)
if pp2 > -1:
_newstr = _oldstr[pp1+7:pp2]
s = s.replace(_oldstr, _newstr)
f = open('weather.html', 'w')
f.write('<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">\n</head>\n<body>\n')
f.write(s+'\n')
f.write('</body>\n</html>')
f.close()
#Отправка почты
html = open("weather.html").read()
subject = "Погода сегодня!"
message = createhtmlmail(html, subject)
server = smtplib.SMTP("111.111.111.111")
server.sendmail('my@mail.ru', ['you@mail.ru'], message)
server.quit()
exit = QtGui.QAction(QtGui.QIcon('icons/exit.png'), 'Exit', self)
exit.setShortcut('Ctrl+Q')
exit.setStatusTip('Exit application')
self.connect(exit, QtCore.SIGNAL('triggered()'), QtCore.SLOT('close()'))
QtGui.QStatusBar()
menubar = QtGui.QMenuBar()
file = menubar.addMenu('&File')
file.addAction(exit)
import sys
from PyQt4 import QtWebKit, QtCore, QtGui, QtNetwork, Qt
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
self.setFixedWidth(800)
self.setFixedHeight(652)
self.browser = QtWebKit.QWebView(self)
self.browser.setFixedWidth(800)
self.browser.setFixedHeight(652)
self.connect(self.browser.page().networkAccessManager(), QtCore.SIGNAL("finished(QNetworkReply*)"), self.finished)
self.browser.load(QtCore.QUrl("http://ya.ru"))
def finished(self, networkReply):
## Выводим URL
print networkReply.url().toString()
## Вывод содержимого запроса.
print networkReply.readAll()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())