[bug 634345] Upgrade Django to 1.2.5, fix backwards incompatible changes, and flag some AJAX POSTs for update.

* Update to vendor lib required for django and django-taggit.
* Add a note on the auto_delete_files decorator explaining why it's necessary.
This commit is contained in:
Paul Craciunoiu 2011-02-24 15:16:38 -08:00 коммит произвёл Ricky Rosario
Родитель 1d20fa7270
Коммит fa13814389
10 изменённых файлов: 44 добавлений и 5 удалений

Просмотреть файл

@ -6,6 +6,7 @@ from django.db import models
from sumo.models import ModelBase, LocaleField
from sumo.urlresolvers import reverse
from sumo.utils import auto_delete_files
class Media(ModelBase):
@ -27,6 +28,7 @@ class Media(ModelBase):
return '[%s] %s' % (self.locale, self.title)
@auto_delete_files
class Image(Media):
creator = models.ForeignKey(User, related_name='gallery_images')
file = models.ImageField(upload_to=settings.GALLERY_IMAGE_PATH,
@ -43,6 +45,7 @@ class Image(Media):
return self.thumbnail.url if self.thumbnail else self.file.url
@auto_delete_files
class Video(Media):
creator = models.ForeignKey(User, related_name='gallery_videos')
webm = models.FileField(upload_to=settings.GALLERY_VIDEO_PATH, null=True,

Просмотреть файл

@ -52,7 +52,7 @@ class TaggedQuestionsFeed(QuestionsFeed):
def items(self, tag):
qs = Question.objects.filter(creator__is_active=True, status=CONFIRMED,
tags__in=[tag.name])
tags__name__in=[tag.name])
return qs.order_by('-updated')[:constants.QUESTIONS_PER_PAGE]

Просмотреть файл

@ -94,7 +94,7 @@ def questions(request):
tags = Tag.objects.filter(slug__in=tag_slugs)
if tags:
for t in tags:
question_qs = question_qs.filter(tags__in=[t.name])
question_qs = question_qs.filter(tags__name__in=[t.name])
if len(tags) == 1:
feed_urls += ((reverse('questions.tagged_feed',
args=[tags[0].slug]),

Просмотреть файл

@ -1,4 +1,6 @@
from django.core import paginator
from django.db import models
from django.db.models.signals import pre_delete
from django.utils.http import urlencode
@ -50,3 +52,30 @@ def smart_int(string, fallback=0):
return int(float(string))
except (ValueError, TypeError):
return fallback
def delete_files_for_obj(sender, **kwargs):
"""Signal receiver of a model class and instance. Deletes its files."""
obj = kwargs.pop('instance')
for field_name in sender._meta.get_all_field_names():
# Skip related models' attrs.
if not hasattr(obj, field_name):
continue
# Get the class and value of the field.
field_class = sender._meta.get_field(field_name)
field_value = getattr(obj, field_name)
# Check if it's a FileField instance and the field is set.
if isinstance(field_class, models.FileField) and field_value:
field_value.delete()
def auto_delete_files(cls):
"""Deletes all FileFields when model instances are deleted.
Meant to be used on model classes.
Django disabled auto-deletion of files when deleting a model in
ticket #6456, to prevent dataloss.
"""
pre_delete.connect(delete_files_for_obj, sender=cls)
return cls

Просмотреть файл

@ -6,8 +6,10 @@ from django.db import models
from sumo.helpers import reverse
from sumo.models import ModelBase
from sumo.utils import auto_delete_files
@auto_delete_files
class ImageAttachment(ModelBase):
"""An image attached to an object using a generic foreign key"""
file = models.ImageField(upload_to=settings.IMAGE_UPLOAD_PATH,

Просмотреть файл

@ -17,11 +17,13 @@ from tower import ugettext_lazy as _lazy
from countries import COUNTRIES
from sumo.models import ModelBase
from sumo.urlresolvers import reverse
from sumo.utils import auto_delete_files
SHA1_RE = re.compile('^[a-f0-9]{40}$')
@auto_delete_files
class Profile(ModelBase):
"""Profile model for django users, get it with user.get_profile()."""

Просмотреть файл

@ -174,7 +174,7 @@ def list_documents(request, category=None, tag=None):
if tag:
tagobj = get_object_or_404(Tag, slug=tag)
docs = docs.filter(tags__in=[tagobj.name])
docs = docs.filter(tags__name__in=[tagobj.name])
docs = paginate(request, docs, per_page=DOCUMENTS_PER_PAGE)
return jingo.render(request, 'wiki/list_documents.html',

Просмотреть файл

@ -210,6 +210,7 @@
this.kbox = $(this.$el).data('kbox');
this.$el.find('#submit').bind('click', {reply: this}, function(e) {
// TODO(csrf): send CSRF token
var reply = e.data.reply,
data = {
'content': reply.content,

Просмотреть файл

@ -88,7 +88,7 @@
// Starting small for discoverability.
close: tender
});
// keyup isn't triggered by pasting into the field. FWIW,
// Google Suggest also punts on this.
$input.keyup(tender);
@ -132,6 +132,7 @@
if (async) {
$tag.addClass("in-progress"); // Dim for immediate feedback.
// TODO(csrf): send CSRF token
$.ajax({
type: "POST",
url: $remover.closest("form.remove-tag-form").data("action-async"),
@ -189,6 +190,7 @@
$tag = putTagOnscreen(tagName);
if ($tag && async) {
// TODO(csrf): send CSRF token
$.ajax({
type: "POST",
url: $container.data("action-async"),

2
vendor

@ -1 +1 @@
Subproject commit d20ec406fc3363c4a52c725a6e99f6691ded6eec
Subproject commit 923355fdbd0beaaef2f3f45d2a0b72f95213a818