Removed some Django 0.96-only code
- Legacy-Id: 1870
This commit is contained in:
parent
b8406b7680
commit
93126af05b
|
@ -1,108 +0,0 @@
|
|||
# Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
||||
# All rights reserved. Contact: Pasi Eronen <pasi.eronen@nokia.com>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions
|
||||
# are met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
#
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following
|
||||
# disclaimer in the documentation and/or other materials provided
|
||||
# with the distribution.
|
||||
#
|
||||
# * Neither the name of the Nokia Corporation and/or its
|
||||
# subsidiary(-ies) nor the names of its contributors may be used
|
||||
# to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from os.path import exists
|
||||
import os
|
||||
import re
|
||||
|
||||
def convert_py(file):
|
||||
print " Converting ", file
|
||||
inf = open(file)
|
||||
outf_name = file+'.tmp~'
|
||||
outf = open(outf_name, "w")
|
||||
fixes = {}
|
||||
for line in inf:
|
||||
if re.search("Field.*maxlength=\d", line):
|
||||
line = line.replace("maxlength=", "max_length=")
|
||||
fixes['changed maxlength to max_length'] = True
|
||||
if re.search("^\s*from django import newforms as forms\s*$", line):
|
||||
line = "from django import forms\n"
|
||||
fixes['changed newforms to forms'] = True
|
||||
if re.search("^\s*import django.newforms as forms\s*$", line):
|
||||
line = "from django import forms\n"
|
||||
fixes['changed newforms to forms'] = True
|
||||
if re.search("^\s*from django.core.validators import email_re\s*$", line):
|
||||
line = "from django.forms.fields import email_re\n"
|
||||
fixes['changed email_re import'] = True
|
||||
if re.search("ForeignKey.*raw_id_admin=True", line):
|
||||
line = re.sub(",\s*raw_id_admin=True", "", line)
|
||||
fixes['removed raw_id_admin'] = True
|
||||
if re.search("ForeignKey.*edit_inline=True", line):
|
||||
line = re.sub(",\s*edit_inline=True", "", line)
|
||||
fixes['removed edit_inline'] = True
|
||||
if re.search("ForeignKey.*edit_inline=models\.\w+", line):
|
||||
line = re.sub(",\s*edit_inline=models\.\w+", "", line)
|
||||
fixes['removed edit_inline'] = True
|
||||
if re.search("ForeignKey.*num_in_admin=\d+", line):
|
||||
line = re.sub(",\s*num_in_admin=\d+", "", line)
|
||||
fixes['removed num_in_admin'] = True
|
||||
if re.search("ForeignKey.*max_num_in_admin=\d+", line):
|
||||
line = re.sub(",\s*max_num_in_admin=\d+", "", line)
|
||||
fixes['removed max_num_in_admin'] = True
|
||||
if re.search("ManyToManyField.*filter_interface=models\.\w+", line):
|
||||
line = re.sub(",\s*filter_interface=models\.\w+", "", line)
|
||||
fixes['removed filter_interface'] = True
|
||||
if re.search("(Field|ForeignKey).*core=True", line):
|
||||
line = re.sub(",\s*core=True", "", line)
|
||||
fixes['removed core'] = True
|
||||
if re.search("\.clean_data", line):
|
||||
line = re.sub("\.clean_data", ".cleaned_data", line)
|
||||
fixes['cleaned_data'] = True
|
||||
outf.write(line)
|
||||
inf.close()
|
||||
fixes_list = fixes.keys()
|
||||
fixes_list.sort()
|
||||
something_fixed = len(fixes_list) > 0
|
||||
if something_fixed:
|
||||
outf.write("\n# changes done by convert-096.py:")
|
||||
outf.write("\n# ".join(fixes_list))
|
||||
outf.write("\n")
|
||||
outf.close()
|
||||
if something_fixed:
|
||||
os.rename(file, file+'.backup~')
|
||||
os.rename(outf_name, file)
|
||||
print " Fixes: "+", ".join(fixes_list)
|
||||
else:
|
||||
os.remove(outf_name)
|
||||
|
||||
if not exists("settings.py"):
|
||||
raise Exception("Please run this in directory containing settings.py")
|
||||
|
||||
for root, dirs, files in os.walk("."):
|
||||
if root.find(".svn") >= 0:
|
||||
continue
|
||||
print "Processing ", root
|
||||
for file in files:
|
||||
if file.endswith(".py") and not file.startswith("#"):
|
||||
convert_py(root+"/"+file)
|
||||
|
||||
|
|
@ -329,12 +329,6 @@ def stable_dictsort(value, arg):
|
|||
decorated.sort(lambda a, b: cmp(a[0], b[0]))
|
||||
return [item[1] for item in decorated]
|
||||
|
||||
# DJANGO_096: a dummy safe filter for Django 0.96
|
||||
if django.VERSION[0] == 0:
|
||||
@register.filter
|
||||
def safe(x):
|
||||
return x
|
||||
|
||||
def _test():
|
||||
import doctest
|
||||
doctest.testmod()
|
||||
|
|
|
@ -23,51 +23,22 @@ import django
|
|||
phone_re = re.compile(r'^\+?[0-9 ]*(\([0-9]+\))?[0-9 -]+( ?x ?[0-9]+)?$')
|
||||
phone_error_message = """Phone numbers may have a leading "+", and otherwise only contain numbers [0-9]; dash, period or space; parentheses, and an optional extension number indicated by 'x'."""
|
||||
|
||||
if django.VERSION[0] == 0:
|
||||
from django.forms import ModelForm
|
||||
|
||||
def ipr_detail_form_callback(field, **kwargs):
|
||||
if field.name == "licensing_option":
|
||||
return forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False, **kwargs)
|
||||
if field.name in ["is_pending", "applies_to_all"]:
|
||||
return forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False, **kwargs)
|
||||
if field.name in ("rfc_number", "id_document_tag"): #, 'legacy_url_0','legacy_url_1','legacy_title_1','legacy_url_2','legacy_title_2'):
|
||||
return None
|
||||
return field.formfield(**kwargs)
|
||||
|
||||
def ipr_contact_form_callback(field, **kwargs):
|
||||
if field.name in ('ipr', 'contact_type'):
|
||||
return None
|
||||
if field.name == "telephone":
|
||||
return forms.RegexField(phone_re, error_message=phone_error_message, **kwargs)
|
||||
if field.name == "fax":
|
||||
return forms.RegexField(phone_re, error_message=phone_error_message, required=False, **kwargs)
|
||||
return field.formfield(**kwargs)
|
||||
# TODO:
|
||||
# Add rfc existence validation for RFC field
|
||||
# Add draft existence validation for Drafts field
|
||||
|
||||
# Get base form classes for our models
|
||||
BaseIprForm = forms.form_for_model(models.IprDetail, formfield_callback=ipr_detail_form_callback)
|
||||
BaseContactForm = forms.form_for_model(models.IprContact, formfield_callback=ipr_contact_form_callback)
|
||||
|
||||
else:
|
||||
# Django 1.x
|
||||
|
||||
from django.forms import ModelForm
|
||||
class BaseIprForm(ModelForm):
|
||||
licensing_option = forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False)
|
||||
is_pending = forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
|
||||
applies_to_all = forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
|
||||
class Meta:
|
||||
model = models.IprDetail
|
||||
exclude = ('rfc_document', 'id_document_tag') # 'legacy_url_0','legacy_url_1','legacy_title_1','legacy_url_2','legacy_title_2')
|
||||
|
||||
class BaseContactForm(ModelForm):
|
||||
telephone = forms.RegexField(phone_re, error_message=phone_error_message)
|
||||
fax = forms.RegexField(phone_re, error_message=phone_error_message, required=False)
|
||||
class Meta:
|
||||
model = models.IprContact
|
||||
exclude = ('ipr', 'contact_type')
|
||||
class BaseIprForm(ModelForm):
|
||||
licensing_option = forms.IntegerField(widget=forms.RadioSelect(choices=models.LICENSE_CHOICES), required=False)
|
||||
is_pending = forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
|
||||
applies_to_all = forms.IntegerField(widget=forms.RadioSelect(choices=((1, "YES"), (2, "NO"))), required=False)
|
||||
class Meta:
|
||||
model = models.IprDetail
|
||||
exclude = ('rfc_document', 'id_document_tag') # 'legacy_url_0','legacy_url_1','legacy_title_1','legacy_url_2','legacy_title_2')
|
||||
|
||||
class BaseContactForm(ModelForm):
|
||||
telephone = forms.RegexField(phone_re, error_message=phone_error_message)
|
||||
fax = forms.RegexField(phone_re, error_message=phone_error_message, required=False)
|
||||
class Meta:
|
||||
model = models.IprContact
|
||||
exclude = ('ipr', 'contact_type')
|
||||
|
||||
# Some subclassing:
|
||||
|
||||
|
|
|
@ -179,9 +179,6 @@ def get_templates():
|
|||
|
||||
class TemplateCoverageTestCase(unittest.TestCase):
|
||||
def testTemplateCoverage(self):
|
||||
if django.VERSION[0] == 0:
|
||||
print "Not testing template coverage under Django 0.96"
|
||||
return
|
||||
if not test_runner.loaded_templates:
|
||||
print "Skipping template coverage test"
|
||||
return
|
||||
|
|
|
@ -63,12 +63,6 @@ urlpatterns = patterns('',
|
|||
(r'^accounts/(?P<dir>\w+)/', 'django.views.generic.simple.redirect_to', { 'url': '/account/%(dir)s/' }),
|
||||
)
|
||||
|
||||
# New admin site works differently, and needs work
|
||||
if django.VERSION[0] == 0:
|
||||
urlpatterns += patterns('',
|
||||
(r'^admin/', include('django.contrib.admin.urls')),
|
||||
)
|
||||
|
||||
if settings.SERVER_MODE in ('development', 'test'):
|
||||
urlpatterns += patterns('',
|
||||
(r'^(?P<path>(?:images|css|js)/.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
|
||||
|
|
|
@ -44,14 +44,6 @@ test_database_name = None
|
|||
old_destroy = None
|
||||
old_create = None
|
||||
|
||||
def safe_create_0(verbosity, *args, **kwargs):
|
||||
global test_database_name, old_create
|
||||
print "Creating test database..."
|
||||
x = old_create(0, *args, **kwargs)
|
||||
print "Saving test database name "+settings.DATABASE_NAME+"..."
|
||||
test_database_name = settings.DATABASE_NAME
|
||||
return x
|
||||
|
||||
def safe_create_1(self, verbosity, *args, **kwargs):
|
||||
global test_database_name, old_create
|
||||
print "Creating test database..."
|
||||
|
@ -68,21 +60,6 @@ def safe_destroy_0_1(*args, **kwargs):
|
|||
settings.DATABASE_NAME = test_database_name
|
||||
return old_destroy(*args, **kwargs)
|
||||
|
||||
# Test that test/r5106.patch has been applied. This is not written
|
||||
# as normal test case, because it needs to be run before Django's
|
||||
# test framework takes over. This test applies only to Django 0.96,
|
||||
# and can be removed once we transition to 1.x.
|
||||
def test_django_foreignkey_patch():
|
||||
print "Testing Django 0.96 ForeignKey patch..."
|
||||
try:
|
||||
import ietf
|
||||
t = django.core.management._get_sql_model_create(ietf.idtracker.models.GoalMilestone)
|
||||
except KeyError, f:
|
||||
if str(f.args) == "('ForeignKey',)":
|
||||
raise Exception("Django 0.96 patch in test/r5106.patch not installed?")
|
||||
else:
|
||||
raise
|
||||
|
||||
def test_send_smtp(msg, bcc=None):
|
||||
global mail_outbox
|
||||
mail_outbox.append(msg)
|
||||
|
@ -93,17 +70,6 @@ def template_coverage_loader(template_name, dirs):
|
|||
|
||||
template_coverage_loader.is_usable = True
|
||||
|
||||
def run_tests_0(*args, **kwargs):
|
||||
global old_destroy, old_create, test_database_name
|
||||
import django.test.utils
|
||||
m = sys.modules['django.test.utils']
|
||||
old_create = m.create_test_db
|
||||
m.create_test_db = safe_create_0
|
||||
old_destroy = m.destroy_test_db
|
||||
m.destroy_test_db = safe_destroy_0_1
|
||||
from django.test.simple import run_tests
|
||||
run_tests(*args, **kwargs)
|
||||
|
||||
def run_tests_1(test_labels, *args, **kwargs):
|
||||
global old_destroy, old_create, test_database_name
|
||||
from django.db import connection
|
||||
|
@ -125,9 +91,5 @@ def run_tests(*args, **kwargs):
|
|||
raise EnvironmentError("Refusing to run tests on core3")
|
||||
import ietf.utils.mail
|
||||
ietf.utils.mail.send_smtp = test_send_smtp
|
||||
if django.VERSION[0] == 0:
|
||||
test_django_foreignkey_patch()
|
||||
run_tests_0(*args, **kwargs)
|
||||
else:
|
||||
run_tests_1(*args, **kwargs)
|
||||
run_tests_1(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -60,18 +60,12 @@ class RealDatabaseTest:
|
|||
self._setDatabaseName(self._original_testdb)
|
||||
|
||||
def _getDatabaseName(self):
|
||||
if django.VERSION[0] == 0:
|
||||
return django.conf.settings.DATABASE_NAME
|
||||
else:
|
||||
return connection.settings_dict['DATABASE_NAME']
|
||||
return connection.settings_dict['DATABASE_NAME']
|
||||
|
||||
def _setDatabaseName(self, name):
|
||||
connection.close()
|
||||
if django.VERSION[0] == 0:
|
||||
django.conf.settings.DATABASE_NAME = name
|
||||
else:
|
||||
django.conf.settings.DATABASE_NAME = name
|
||||
connection.settings_dict['DATABASE_NAME'] = name
|
||||
django.conf.settings.DATABASE_NAME = name
|
||||
connection.settings_dict['DATABASE_NAME'] = name
|
||||
connection.cursor()
|
||||
|
||||
def read_testurls(filename):
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
Index: /django/trunk/django/core/management.py
|
||||
===================================================================
|
||||
--- /django/trunk/django/core/management.py (revision 5102)
|
||||
+++ /django/trunk/django/core/management.py (revision 5106)
|
||||
@@ -169,4 +169,6 @@
|
||||
if isinstance(f, (models.ForeignKey, models.OneToOneField)):
|
||||
rel_field = f.rel.get_related_field()
|
||||
+ while isinstance(rel_field, (models.ForeignKey, models.OneToOneField)):
|
||||
+ rel_field = rel_field.rel.get_related_field()
|
||||
data_type = get_rel_data_type(rel_field)
|
||||
else:
|
Loading…
Reference in a new issue