Skip to content
This repository has been archived by the owner on Mar 15, 2018. It is now read-only.

Commit

Permalink
Revert "Upgrade to Django 1.6."
Browse files Browse the repository at this point in the history
This reverts commit da1fa86.
  • Loading branch information
Allen Short committed Mar 22, 2014
1 parent 401e139 commit 62d75b2
Show file tree
Hide file tree
Showing 62 changed files with 214 additions and 184 deletions.
3 changes: 3 additions & 0 deletions apps/addons/forms.py
Expand Up @@ -296,6 +296,9 @@ def __init__(self, *args, **kw):
cats = dict(self.addon.app_categories).get(app, [])
self.initial.append({'categories': [c.id for c in cats]})

# Reconstruct the forms according to the initial data.
self._construct_forms()

for app, form in zip(apps, self.forms):
key = app.id if app else None
form.request = self.request
Expand Down
6 changes: 3 additions & 3 deletions apps/addons/models.py
Expand Up @@ -890,7 +890,7 @@ def compatible_version(self, app_id, app_version=None, platform=None,
version_id = 0

log.debug(u'Caching compat version %s => %s' % (cache_key, version_id))
cache.set(cache_key, version_id, None)
cache.set(cache_key, version_id, 0)

return version

Expand Down Expand Up @@ -1356,7 +1356,7 @@ def tags_partitioned_by_developer(self):
"""Returns a tuple of developer tags and user tags for this addon."""
tags = self.tags.not_blacklisted()
if self.is_persona:
return [], tags
return models.query.EmptyQuerySet(), tags
user_tags = tags.exclude(addon_tags__user__in=self.listed_authors)
dev_tags = tags.exclude(id__in=[t.id for t in user_tags])
return dev_tags, user_tags
Expand Down Expand Up @@ -1713,7 +1713,7 @@ def check_ownership(self, request, require_owner, require_author,


class AddonDeviceType(amo.models.ModelBase):
addon = models.ForeignKey(Addon, db_constraint=False)
addon = models.ForeignKey(Addon)
device_type = models.PositiveIntegerField(
default=amo.DEVICE_DESKTOP, choices=do_dictsort(amo.DEVICE_TYPES),
db_index=True)
Expand Down
29 changes: 8 additions & 21 deletions apps/addons/query.py
Expand Up @@ -77,12 +77,11 @@ def get_from_clause(self):
qn2 = self.connection.ops.quote_name
index_map = self.query.index_map
first = True
from_params = []
for alias in self.query.tables:
if not self.query.alias_refcount[alias]:
continue
try:
name, alias, join_type, lhs, join_cols, _, join_field = self.query.alias_map[alias]
name, alias, join_type, lhs, lhs_col, col, nullable = self.query.alias_map[alias]
except KeyError:
# Extra tables can end up in self.tables, but not in the
# alias_map if they aren't in a join. That's OK. We skip them.
Expand All @@ -94,25 +93,13 @@ def get_from_clause(self):
else:
use_index = ''
if join_type and not first:
extra_cond = join_field.get_extra_restriction(
self.query.where_class, alias, lhs)
if extra_cond:
extra_sql, extra_params = extra_cond.as_sql(
qn, self.connection)
extra_sql = 'AND (%s)' % extra_sql
from_params.extend(extra_params)
else:
extra_sql = ""
result.append('%s %s%s %s ON ('
% (join_type, qn(name), alias_str, use_index))
for index, (lhs_col, rhs_col) in enumerate(join_cols):
if index != 0:
result.append(' AND ')
result.append('%s.%s = %s.%s' %
(qn(lhs), qn2(lhs_col), qn(alias), qn2(rhs_col)))
result.append('%s)' % extra_sql)
# If you really need a LEFT OUTER JOIN, file a bug.
join_type = 'INNER JOIN'
result.append('%s %s%s %s ON (%s.%s = %s.%s)'
% (join_type, qn(name), alias_str, use_index, qn(lhs),
qn2(lhs_col), qn(alias), qn2(col)))
else:
connector = connector = '' if first else ', '
connector = not first and ', ' or ''
result.append('%s%s%s %s' % (connector, qn(name), alias_str, use_index))
### jbalogh out. ###
first = False
Expand All @@ -125,4 +112,4 @@ def get_from_clause(self):
connector = not first and ', ' or ''
result.append('%s%s' % (connector, qn(alias)))
first = False
return result, from_params
return result, []
19 changes: 8 additions & 11 deletions apps/addons/tests/test_models.py
Expand Up @@ -2200,32 +2200,29 @@ def setUp(self):

def test_extract(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
assert self.addon.reload().get_localepicker()
filename=self.xpi_path('langpack-localepicker'))
assert self.addon.get_localepicker()
assert 'title=Select a language' in self.addon.get_localepicker()

def test_extract_no_file(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack'), status=amo.STATUS_PUBLIC)
eq_(self.addon.reload().get_localepicker(), '')
filename=self.xpi_path('langpack'))
eq_(self.addon.get_localepicker(), '')

def test_extract_no_files(self):
eq_(self.addon.get_localepicker(), '')

def test_extract_not_language_pack(self):
File.objects.create(platform=self.platform_mob, version=self.version,
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
assert self.addon.reload().get_localepicker()
filename=self.xpi_path('langpack-localepicker'))
assert self.addon.get_localepicker()
self.addon.update(type=amo.ADDON_EXTENSION)
eq_(self.addon.get_localepicker(), '')

def test_extract_not_platform_mobile(self):
File.objects.create(platform=self.platform_all, version=self.version,
filename=self.xpi_path('langpack-localepicker'),
status=amo.STATUS_PUBLIC)
eq_(self.addon.reload().get_localepicker(), '')
filename=self.xpi_path('langpack-localepicker'))
eq_(self.addon.get_localepicker(), '')


class TestMarketplace(amo.tests.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion apps/amo/forms.py
Expand Up @@ -37,7 +37,7 @@ def _get_changed_data(self):
"""
Model = self._meta.model
if self._changed_data is None:
changed = copy(forms.ModelForm.changed_data.__get__(self))
changed = copy(super(AMOModelForm, self)._get_changed_data())
fieldnames = [f.name for f in Model._meta.fields]
fields = [(name, Model._meta.get_field(name))
for name in changed if name in fieldnames]
Expand Down
4 changes: 2 additions & 2 deletions apps/amo/models.py
Expand Up @@ -163,8 +163,8 @@ class ManagerBase(caching.base.CachingManager, UncachedManagerBase):
function.
"""

def get_queryset(self):
qs = super(ManagerBase, self).get_queryset()
def get_query_set(self):
qs = super(ManagerBase, self).get_query_set()
if getattr(_locals, 'skip_cache', False):
qs = qs.no_cache()
return self._with_translations(qs)
Expand Down
2 changes: 1 addition & 1 deletion apps/amo/templates/amo/robots.html
Expand Up @@ -16,7 +16,7 @@
{% for a in apps -%}

Disallow: /{{ l }}/{{ a.short }}{{ url('search.search', add_prefix=False) }}
Disallow: /{{ l }}/{{ a.short }}{{ url('password_reset_form', add_prefix=False) }}
Disallow: /{{ l }}/{{ a.short }}{{ url('users.pwreset', add_prefix=False) }}
{% endfor %}

{% endfor %}
2 changes: 1 addition & 1 deletion apps/amo/tests/test_helpers.py
Expand Up @@ -461,7 +461,7 @@ def test_absolutify():

def test_timesince():
month_ago = datetime.now() - timedelta(days=30)
eq_(helpers.timesince(month_ago), u'1 month ago')
eq_(helpers.timesince(month_ago), u'1 month ago')
eq_(helpers.timesince(None), u'')


Expand Down
3 changes: 3 additions & 0 deletions apps/amo/tests/test_readonly.py
Expand Up @@ -3,6 +3,7 @@
from django.utils import importlib

import MySQLdb as mysql
from lib.misc import safe_signals
from nose.tools import assert_raises, eq_
from pyquery import PyQuery as pq

Expand All @@ -29,6 +30,7 @@ class ReadOnlyModeTest(amo.tests.TestCase):
extra = ('amo.middleware.ReadOnlyMiddleware',)

def setUp(self):
safe_signals.Signal.send = safe_signals.unsafe_send
models.signals.pre_save.connect(self.db_error)
models.signals.pre_delete.connect(self.db_error)
self.old_settings = dict((k, quickcopy(getattr(settings, k)))
Expand All @@ -50,6 +52,7 @@ def tearDown(self):
pass
models.signals.pre_save.disconnect(self.db_error)
models.signals.pre_delete.disconnect(self.db_error)
safe_signals.Signal.send = safe_signals.safe_send

def db_error(self, *args, **kwargs):
raise mysql.OperationalError("You can't do this in read-only mode.")
Expand Down
3 changes: 1 addition & 2 deletions apps/amo/tests/test_send_mail.py
Expand Up @@ -26,7 +26,6 @@ def setUp(self):
self._email_blacklist = list(getattr(settings, 'EMAIL_BLACKLIST', []))

def tearDown(self):
translation.activate('en_US')
settings.EMAIL_BLACKLIST = self._email_blacklist

def test_send_string(self):
Expand Down Expand Up @@ -203,7 +202,7 @@ def test_send_html_mail_jinja(self):

def test_send_attachment(self):
path = os.path.join(ATTACHMENTS_DIR, 'bacon.txt')
attachments = [(os.path.basename(path), storage.open(path).read(),
attachments = [(os.path.basename(path), storage.open(path),
mimetypes.guess_type(path)[0])]
send_mail('test subject', 'test body', from_email='a@example.com',
recipient_list=['b@example.com'], attachments=attachments)
Expand Down
4 changes: 2 additions & 2 deletions apps/amo/utils.py
Expand Up @@ -671,12 +671,12 @@ def cache_ns_key(namespace, increment=False):
except ValueError:
log.info('Cache increment failed for key: %s. Resetting.' % ns_key)
ns_val = epoch(datetime.datetime.now())
cache.set(ns_key, ns_val, None)
cache.set(ns_key, ns_val, 0)
else:
ns_val = cache.get(ns_key)
if ns_val is None:
ns_val = epoch(datetime.datetime.now())
cache.set(ns_key, ns_val, None)
cache.set(ns_key, ns_val, 0)
return '%s:%s' % (ns_val, ns_key)


Expand Down
15 changes: 0 additions & 15 deletions apps/api/tests/test_urls.py

This file was deleted.

3 changes: 1 addition & 2 deletions apps/api/tests/test_views.py
Expand Up @@ -1282,8 +1282,7 @@ def test_search_no_localepicker(self):
def setup_localepicker(self, platform):
self.addon.update(type=amo.ADDON_LPAPP, status=amo.STATUS_PUBLIC)
version = self.addon.versions.all()[0]
File.objects.create(version=version, platform_id=platform,
status=amo.STATUS_PUBLIC)
File.objects.create(version=version, platform_id=platform)

def test_search_wrong_platform(self):
self.setup_localepicker(amo.PLATFORM_MAC.id)
Expand Down
12 changes: 8 additions & 4 deletions apps/browse/views.py
Expand Up @@ -294,13 +294,17 @@ class PersonasFilter(BaseFilter):
def _filter(self, field):
qs = Addon.objects
if field == 'created':
return qs.order_by('-created')
return (qs.order_by('-created')
.with_index(addons='created_type_idx'))
elif field == 'popular':
return qs.order_by('-persona__popularity')
return (qs.order_by('-persona__popularity')
.with_index(personas='personas_popularity_idx'))
elif field == 'rating':
return qs.order_by('-bayesian_rating')
return (qs.order_by('-bayesian_rating')
.with_index(addons='rating_type_idx'))
else:
return qs.order_by('-persona__movers')
return (qs.order_by('-persona__movers')
.with_index(personas='personas_movers_idx'))


def personas_listing(request, category_slug=None):
Expand Down
7 changes: 2 additions & 5 deletions apps/devhub/forms.py
Expand Up @@ -441,11 +441,7 @@ def __init__(self, *args, **kw):
self.initial = ([{} for _ in qs] +
[{'application': a.id} for a in apps])
self.extra = len(amo.APP_GUIDS) - len(self.forms)
# After these changes, the forms need to be rebuilt. `forms`
# is a cached property, so we delete the existing cache and
# ask for a new one to be built.
del self.forms
self.forms
self._construct_forms()

def clean(self):
if any(self.errors):
Expand Down Expand Up @@ -902,6 +898,7 @@ class PackagerCompatBaseFormSet(BaseFormSet):
def __init__(self, *args, **kw):
super(PackagerCompatBaseFormSet, self).__init__(*args, **kw)
self.initial = [{'application': a} for a in amo.APP_USAGE]
self._construct_forms()

def clean(self):
if any(self.errors):
Expand Down
2 changes: 1 addition & 1 deletion apps/devhub/models.py
Expand Up @@ -113,7 +113,7 @@ class AppLog(amo.models.ModelBase):
"""
This table is for indexing the activity log by app.
"""
addon = models.ForeignKey(Webapp, db_constraint=False)
addon = models.ForeignKey(Webapp)
activity_log = models.ForeignKey('ActivityLog')

class Meta:
Expand Down
1 change: 0 additions & 1 deletion apps/devhub/tests/test_forms.py
Expand Up @@ -498,7 +498,6 @@ def test_localize_name_description(self):
def test_reupload(self, save_persona_image_mock,
create_persona_preview_images_mock,
make_checksum_mock):
make_checksum_mock.return_value = 'checksumbeforeyouwrecksome'
data = self.get_dict(header_hash='y0l0', footer_hash='abab')
self.form = EditThemeForm(data, request=self.request,
instance=self.instance)
Expand Down
3 changes: 1 addition & 2 deletions apps/discovery/tests/test_views.py
Expand Up @@ -527,8 +527,7 @@ def test_eula_trickle(self):


class TestMonthlyPick(amo.tests.TestCase):
fixtures = ['base/users', 'base/apps', 'base/addon_3615',
'discovery/discoverymodules']
fixtures = ['base/apps', 'base/addon_3615', 'discovery/discoverymodules']

def setUp(self):
self.url = reverse('discovery.pane.promos', args=['Darwin', '10.0'])
Expand Down
2 changes: 1 addition & 1 deletion apps/editors/helpers.py
Expand Up @@ -641,7 +641,7 @@ class ReviewAddon(ReviewBase):
def __init__(self, *args, **kwargs):
super(ReviewAddon, self).__init__(*args, **kwargs)

self.is_upgrade = (self.addon.status == amo.STATUS_LITE_AND_NOMINATED
self.is_upgrade = (self.addon.status is amo.STATUS_LITE_AND_NOMINATED
and self.review_type == 'nominated')

def set_data(self, data):
Expand Down
8 changes: 4 additions & 4 deletions apps/editors/models.py
Expand Up @@ -453,7 +453,7 @@ def get_total(cls, user):
if val is None:
val = 0

cache.set(key, val, None)
cache.set(key, val, 0)
return val

@classmethod
Expand All @@ -469,7 +469,7 @@ def get_recent(cls, user, limit=5, addon_type=None):
val.filter(addon__type=addon_type)

val = list(val[:limit])
cache.set(key, val, None)
cache.set(key, val, 0)
return val

@classmethod
Expand All @@ -492,7 +492,7 @@ def get_breakdown(cls, user):
"""
with amo.models.skip_cache():
val = list(ReviewerScore.objects.raw(sql, [user.id]))
cache.set(key, val, None)
cache.set(key, val, 0)
return val

@classmethod
Expand Down Expand Up @@ -605,7 +605,7 @@ def get_leaderboards(cls, user, days=7, types=None, addon_type=None):
'leader_near': leader_near,
'user_rank': user_rank,
}
cache.set(key, val, None)
cache.set(key, val, 0)
return val

@classmethod
Expand Down
8 changes: 4 additions & 4 deletions apps/editors/tests/test_views_themes.py
Expand Up @@ -178,10 +178,10 @@ def test_commit(self, copy_mock, create_preview_mock,
eq_(themes[4].addon.reload().current_version.version,
str(float(old_version) + 1))
else:
eq_(themes[0].addon.reload().status, amo.STATUS_REVIEW_PENDING)
eq_(themes[1].addon.reload().status, amo.STATUS_REVIEW_PENDING)
eq_(themes[2].addon.reload().status, amo.STATUS_REJECTED)
eq_(themes[3].addon.reload().status, amo.STATUS_REJECTED)
eq_(themes[0].addon.status, amo.STATUS_REVIEW_PENDING)
eq_(themes[1].addon.status, amo.STATUS_REVIEW_PENDING)
eq_(themes[2].addon.status, amo.STATUS_REJECTED)
eq_(themes[3].addon.status, amo.STATUS_REJECTED)
eq_(themes[4].addon.reload().status, amo.STATUS_PUBLIC)
eq_(ActivityLog.objects.count(), 4 if self.rereview else 5)

Expand Down
2 changes: 1 addition & 1 deletion apps/files/tests/test_views.py
Expand Up @@ -381,7 +381,7 @@ def test_directory(self):
def test_unicode(self):
self.file_viewer.src = unicode_filenames
self.file_viewer.extract()
res = self.client.get(self.file_url(u'\u1109\u1161\u11a9'))
res = self.client.get(self.file_url(iri_to_uri(u'\u1109\u1161\u11a9')))
eq_(res.status_code, 200)

def test_serve_no_token(self):
Expand Down

0 comments on commit 62d75b2

Please sign in to comment.