Skip to content

Commit

Permalink
Django 1.7 and python 3.4 compatibility
Browse files Browse the repository at this point in the history
fix(admin) - Renamed queryset method to get_queryset given the previous naming convention is deprecated.

fix(models) - Replaced get_user_model with settings.AUTH_USER_MODEL as recommended in django 1.7.

fix(migrations) - Moved south migrations to south_migrations directory.

fix(tests) - Added sites field to AdBase objects on create to be retrieved by the ad manager.

fix - More django 1.7 - python 3.4 compatibility fixes.
  • Loading branch information
cypressbit committed Nov 27, 2014
1 parent c4c8a4e commit ecb390f
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 16 deletions.
8 changes: 4 additions & 4 deletions adzone/admin.py
Expand Up @@ -64,8 +64,8 @@ def download_clicks(self, request, queryset):
return response
download_clicks.short_description = "Download selected Ad Clicks"

def queryset(self, request):
qs = super(AdClickAdmin, self).queryset(request)
def get_queryset(self, request):
qs = super(AdClickAdmin, self).get_queryset(request)
return qs.select_related('ad').only('ad__title',
'click_date',
'source_ip')
Expand All @@ -78,8 +78,8 @@ class AdImpressionAdmin(admin.ModelAdmin):
date_hierarchy = 'impression_date'
actions = ['download_impressions']

def queryset(self, request):
qs = super(AdImpressionAdmin, self).queryset(request)
def get_queryset(self, request):
qs = super(AdImpressionAdmin, self).get_queryset(request)
return qs.select_related('ad').only('ad__title',
'impression_date',
'source_ip')
Expand Down
2 changes: 1 addition & 1 deletion adzone/context_processors.py
@@ -1,5 +1,5 @@
def get_source_ip(request):
if request.META.has_key('REMOTE_ADDR'):
if 'REMOTE_ADDR' in request.META:
return {'from_ip': request.META.get('REMOTE_ADDR')}
else:
return {}
2 changes: 1 addition & 1 deletion adzone/managers.py
Expand Up @@ -18,7 +18,7 @@ def get_random_ad(self, ad_zone, ad_category=None):
and ``ad_zone``.
If ``ad_category`` is None, the ad will be category independent.
"""
qs = self.get_query_set().filter(start_showing__lte=now(),
qs = self.get_queryset().filter(start_showing__lte=now(),
stop_showing__gte=now(),
zone__slug=ad_zone,
sites=Site.objects.get_current().pk
Expand Down
12 changes: 6 additions & 6 deletions adzone/models.py
Expand Up @@ -8,7 +8,7 @@
import datetime

from django.db import models
from django.contrib.auth import get_user_model
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from adzone.managers import AdManager
Expand All @@ -31,14 +31,14 @@ class Advertiser(models.Model):
company_name = models.CharField(
verbose_name=_(u'Company Name'), max_length=255)
website = models.URLField(verbose_name=_(u'Company Site'))
user = models.ForeignKey(get_user_model())
user = models.ForeignKey(settings.AUTH_USER_MODEL)

class Meta:
verbose_name = _(u'Ad Provider')
verbose_name_plural = _(u'Advertisers')
ordering = ('company_name',)

def __unicode__(self):
def __str__(self):
return self.company_name

def get_website_url(self):
Expand All @@ -56,7 +56,7 @@ class Meta:
verbose_name_plural = 'Categories'
ordering = ('title',)

def __unicode__(self):
def __str__(self):
return self.title


Expand All @@ -71,7 +71,7 @@ class Meta:
verbose_name_plural = 'Zones'
ordering = ('title',)

def __unicode__(self):
def __str__(self):
return self.title


Expand Down Expand Up @@ -108,7 +108,7 @@ class Meta:
verbose_name = _('Ad Base')
verbose_name_plural = _('Ad Bases')

def __unicode__(self):
def __str__(self):
return self.title

@models.permalink
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions adzone/templatetags/adzone_tags.py
Expand Up @@ -35,7 +35,7 @@ def random_zone_ad(context, ad_zone):
to_return['ad'] = ad

# Record a impression for the ad
if context.has_key('from_ip') and ad:
if 'from_ip' in context and ad:
from_ip = context.get('from_ip')
try:
impression = AdImpression(
Expand Down Expand Up @@ -63,7 +63,7 @@ def random_category_ad(context, ad_zone, ad_category):
to_return['ad'] = ad

# Record a impression for the ad
if context.has_key('from_ip') and ad:
if 'from_ip' in context and ad:
from_ip = context.get('from_ip')
try:
impression = AdImpression(
Expand Down
8 changes: 6 additions & 2 deletions adzone/tests.py
@@ -1,5 +1,6 @@
from django.test import TestCase
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.template import Template
from django.template.response import SimpleTemplateResponse
from django.utils import timezone
Expand Down Expand Up @@ -47,6 +48,7 @@ def create_advert():
category=category,
zone=zone,
)
ad.sites = [Site.objects.get_current()]
return ad


Expand Down Expand Up @@ -121,20 +123,22 @@ def setUp(self):
slug='category-2',
description='Category 2 description'
)
AdBase.objects.create(
ad1 = AdBase.objects.create(
title='Ad Title',
url='www.example.com',
advertiser=advertiser,
category=category,
zone=zone
)
AdBase.objects.create(
ad2 = AdBase.objects.create(
title='Ad 2 Title',
url='www.example2.com',
advertiser=advertiser,
category=category2,
zone=zone
)
ad1.sites = [Site.objects.get_current()]
ad2.sites = [Site.objects.get_current()]

def test_manager_exists(self):
AdManager
Expand Down

0 comments on commit ecb390f

Please sign in to comment.