Форум сайта python.su
<VirtualHost z.world.com:80>
DocumentRoot "/var/www/z
ServerName z.world.com:80
<Directory "/var/www/z">
AddDefaultCharset utf-8
Options FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from all
SetHandler mod_python
PythonHandler util.publisher
PythonDebug on
PythonPath "sys.path + ['/var/www/z']"
PythonOption basedir "/var/www/z"
PythonOption baseurl "/"
PythonAutoReload on
PythonOption mod_python.session.session_type "FileSession"
PythonOption mod_python.file_session.database_directory "/var/www/z/run/sessions"
</Directory>
</VirtualHost>
<VirtualHost z2.world.com:80>
ServerAdmin a@b.c
DocumentRoot /var/www/z2
ServerName z2.world.com:80
ErrorLog /var/www/log/error.log
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride All
</Directory>
#<Files app.py>
# SetHandler fastcgi-script
#</Files>
<Directory />
Options FollowSymLinks +ExecCGI
AllowOverride All
SetHandler fastcgi-script
PythonHandler util.publisher
DirectoryIndex util/publisher.py
PythonDebug on
PythonPath "sys.path + ['/var/www/z2']"
PythonOption basedir "/var/www/z2"
PythonOption baseurl "/"
PythonAutoReload on
PythonOption fastcgi-script.session.session_type "FileSession"
PythonOption fastcgi-script.file_session.database_directory "/var/www/z2/run/sessions"
</Directory>
</VirtualHost>
class Operation(models.Model):
check_time = models.DateTimeField("Дата проверки")
success = models.BooleanField("Результат проверки", default=True)
Operation.objects.extra({'check_date' :"date(check_time)"}).values('check_date').annotate(oper_count=Count('id'))
Operation.objects.extra({'check_date' :"date(check_time)"}).values('check_date').annotate(oper_count=Count('id')).filter(success=False)
class Model1(models.Model):
pass
class Model2(models.Model):
model1 = models.ForeignKey(Model1)
class Model3(models.Model):
model2 = models.ForeignKey(Model2)
def model1_delete_handler(sender, instance, **kwargs):
if instance.model2_set.all().count() != 0:
...
def model2_delete_handler(sender, instance, **kwargs):
if instance.model3_set.all().count() != 0:
...
signals.pre_delete.connect(model1_delete_handler, sender=Model1, dispatch_uid = 'model1_delete')
signals.pre_delete.connect(model2_delete_handler, sender=Model2, dispatch_uid = 'model2_delete')
from django.db.models import FileField as DjFileField
class FileField(DjFileField):
# блокирую сохранение
def pre_save(self, model_instance, add):
return getattr(model_instance, self.attname)
# генератор пути к файлу
def generate_filename(self, instance, filename):
return os.path.join(self.upload_to,
str(instance.id),
self.get_filename(filename))
class ItemImage(models.Model):
file = ImageField(upload_to="uploads")
def save(self, *args, **kwargs):
super(ItemImage, self).save(*args, **kwargs)
if self.file:
# генерирую имя и повторно сохраняю
self.file.name = self.file.field.generate_filename(self, self.file.name)
self.file.save(self.file.name, self.file, save=False)
ItemImage.objects.filter(id=self.id).update(file=self.file)
from PySide import QtCore, QtGui
from PySide.QtUiTools import QUiLoader
class MainWindow(QtGui.QMainWindow):
def __init__(self, *args):
loader = QUiLoader()
file = QFile('file.ui')
file.open(QFile.ReadOnly)
myWidget = loader.load(file, self)
file.close()
self.addWidget(myWidget)
def main():
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
class Task(Named):
proj = models.ForeignKey(Proj)
type = models.ForeignKey(TaskType)
tags = models.ManyToManyField(Tag, null=True, blank=True)
description = models.TextField(blank=True)
TASK_RELATINGS = (
(0, 'косвенно зависит'),
(1, 'включает в себя'),
(2, 'является частью'),
(3, 'является следствием'),
(4, 'является предшедственником'),
)
class TaskRelating(Named):
task_from = models.ForeignKey("Task", related_name="from_task")
task_to = models.ForeignKey("Task", related_name="to_task")
description = models.TextField(blank=True)
tags = models.ManyToManyField(Tag, null=True, blank=True)
type = models.IntegerField(choices=TASK_RELATINGS)
class Proj(Named):
authors = models.ManyToManyField(User)
tags = models.ManyToManyField(Tag, null=True, blank=True)
specifications = models.TextField(blank=True)
projects = Proj.objects.filter(authors=user)
for project in projects:
project.tasks = Task.objects.filter(proj=project)
class FlatSell(models.Model):
#...
class Image(models.Model):
#...
owner = models.ForeignKey(FlatSell, blank=True, null=True)
def upload(request, owner_id, form_class=PhotoUploadForm,
template_name="upload.html"):
# upload form for photos
#
photo_form = form_class()
if request.method == 'POST':
if request.POST["action"] == "upload":
photo_form = form_class(request.user, request.POST, request.FILES)
if photo_form.is_valid():
photo = photo_form.save(commit=False)
photo.ownerflat = owner_id
photo.save()
request.user.message_set.create(message=_("Successfully uploaded photo '%s'") % photo.title)
return HttpResponseRedirect(reverse('photo_details', args=(photo.id,)))
return render_to_response(template_name, {
"photo_form": photo_form,
}, context_instance=RequestContext(request))
LOGIN_URL = '/login/'
LOGOUT_URL ='/logout/'
PROJECT_ROOT = os.path.normpath(os.path.dirname(__file__))
{% block breadcrumbs %}<div class="breadcrumbs"><a href="/">{% trans 'Home' %}</a>{% if title %} › {{ title }}{% endif %}</div>{% endblock %}
from django.conf.urls.defaults import *
urlpatterns = patterns('',
('^pages/', include('django.contrib.flatpages.urls')),
)
from django.core.urlresolvers import reverse
reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/about-us/'})
# Gives: /pages/about-us/
<a href='{% url django.contrib.flatpages.views.flatpage url="/about-us/" %}'>About Us</a>
urlpatterns = patterns('',
('^pages/', include('django.contrib.flatpages.urls')),
)
class A():
def af(self):
def bf():
print 'bf'
bf()
a = A()
def cf(x,y):
print 'cf'
#
a.af.bf = cf
#
a.af()
>>> 'cf'
import smtplib
from email.MIMEText import MIMEText
from extract import MAILS
def send(to):
you = to
# текст письма
text = 'Здравствуйте!'
# заголовок письма
subj = 'САБЖ'
server = "smtp.km.ru"
name,pwd,me = "pythont","123456","pythont@km.ru"
user_name = name
user_passwd = pwd
msg = MIMEText(text, "", "utf-8")
msg['Subject'] = subj
msg['From'] = me
msg['To'] = you
s = smtplib.SMTP(server, port)
s.starttls()
s.login(user_name, user_passwd)
s.sendmail(me, you, msg.as_string())
s.quit()
send("youmail@yandex.ru")