Updated to be compatible with Django 1.4.5, added tox settings for automated testing with Python 2.6/2.7 and Django 1.4/1.5.

This commit is contained in:
Chris Church
2013-06-22 16:27:09 -04:00
parent 939cbf31ef
commit d822287609
8 changed files with 104 additions and 8 deletions

View File

@@ -12,12 +12,13 @@ from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.timezone import now
from django.utils.translation import ugettext_lazy as _
from django.utils.html import format_html
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from ansibleworks.main.compat import format_html
from ansibleworks.main.models import *
from ansibleworks.main.forms import *
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
class UserAdmin(UserAdmin):
fieldsets = (

View File

@@ -0,0 +1,23 @@
'''
Compability library for support of both Django 1.4.x and Django 1.5.x.
'''
try:
from django.utils.html import format_html
except ImportError:
from django.utils.html import conditional_escape
from django.utils.safestring import mark_safe
def format_html(format_string, *args, **kwargs):
args_safe = map(conditional_escape, args)
kwargs_safe = dict([(k, conditional_escape(v)) for (k, v) in
kwargs.items()])
return mark_safe(format_string.format(*args_safe, **kwargs_safe))
try:
from django.utils.log import RequireDebugTrue
except ImportError:
import logging
from django.conf import settings
class RequireDebugTrue(logging.Filter):
def filter(self, record):
return settings.DEBUG

View File

@@ -131,6 +131,17 @@ class PrimordialModel(models.Model):
def __unicode__(self):
return unicode("%s-%s"% (self.name, self.id))
def save(self, *args, **kwargs):
# For compatibility with Django 1.4.x, attempt to handle any calls to
# save that pass update_fields.
try:
super(PrimordialModel, self).save(*args, **kwargs)
except TypeError:
if 'update_fields' not in kwargs:
raise
kwargs.pop('update_fields')
super(PrimordialModel, self).save(*args, **kwargs)
def mark_inactive(self, save=True):
'''Use instead of delete to rename and mark inactive.'''
if self.active:
@@ -845,10 +856,13 @@ class Job(CommonModel):
self.status = 'pending'
self.save(update_fields=['status'])
task_result = RunJob().delay(self.pk, **opts)
# Reload job from database so we don't clobber results from RunJob
# (mainly from tests when using Djanog 1.4.x).
job = Job.objects.get(pk=self.pk)
# The TaskMeta instance in the database isn't created until the worker
# starts processing the task, so we can only store the task ID here.
self.celery_task_id = task_result.task_id
self.save(update_fields=['celery_task_id'])
job.celery_task_id = task_result.task_id
job.save(update_fields=['celery_task_id'])
return True
@property

View File

@@ -252,7 +252,7 @@ LOGGING = {
'()': 'django.utils.log.RequireDebugFalse',
},
'require_debug_true': {
'()': 'django.utils.log.RequireDebugTrue',
'()': 'ansibleworks.main.compat.RequireDebugTrue',
},
},
'formatters': {