Skip to content

Commit

Permalink
Fix #69: Replace NoArgsCommand with BaseCommand (django 1.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
r4fek committed Aug 5, 2016
1 parent 85af713 commit 3ae61c1
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion django_cassandra_engine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Do not forget to change version number in mkdocs.yml also!
__version__ = (0, 10, 1)
__version__ = (0, 11, 0)
__author__ = "Rafał Furmański"
__contact__ = "[email protected]"
__homepage__ = "http://github.com/r4fek/django-cassandra-engine"
Expand Down
36 changes: 23 additions & 13 deletions django_cassandra_engine/management/commands/sync_cassandra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
from optparse import make_option
import django
if django.VERSION[0:2] >= (1, 10):
from django.core.management.base import BaseCommand, CommandError
else:
from django.core.management.base import (
NoArgsCommand as BaseCommand,
CommandError)

from django.core.management.base import NoArgsCommand, CommandError
from django.db import connections
from django.conf import settings

Expand All @@ -20,7 +25,9 @@ def emit_post_migrate_signal(verbosity, interactive, db):
if app_config.models_module is None:
continue
if verbosity >= 2:
print("Running post-migrate handlers for application %s" % app_config.label)
print("Running post-migrate handlers for application %s" %
app_config.label)

post_migrate.send(
sender=app_config,
app_config=app_config,
Expand All @@ -29,14 +36,18 @@ def emit_post_migrate_signal(verbosity, interactive, db):
using=db)


class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--database', action='store', dest='database',
default=None, help='Nominates a database to synchronize.'),
)

class Command(BaseCommand):
help = 'Sync Cassandra database(s)'

def add_arguments(self, parser):
parser.add_argument(
'--database',
action='store',
dest='database',
default=None,
help='Nominates a database to synchronize.',
)

@staticmethod
def _import_management():
"""
Expand Down Expand Up @@ -92,8 +103,7 @@ def sync(self, alias):
self.stdout.write('Syncing %s.%s' % (app_name, model.__name__))
sync_table(model)

def handle_noargs(self, **options):

def handle(self, *args, **options):
self._import_management()

database = options.get('database')
Expand All @@ -111,6 +121,6 @@ def handle_noargs(self, **options):
raise CommandError(
'Please add django_cassandra_engine backend to DATABASES!')

# Send the post_migrate signal, so individual apps can do whatever they need
# to do at this point.
# Send the post_migrate signal, so individual apps can do whatever
# they need to do at this point.
emit_post_migrate_signal(1, False, cassandra_alias)
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Django Cassandra Engine - CHANGELOG

## Version 1.11.0 (05.08.2016)

* Fix #69: Replace NoArgsCommand with BaseCommand to accommodate 1.10 upgrade (by @BenBrostoff)

## Version 0.10.1 (22.07.2016)

* Update `cassandra-driver` to 3.5.0
Expand Down
2 changes: 1 addition & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repo_url: https://github.com/r4fek/django-cassandra-engine

# Options
extra:
version: 0.10.1
version: 0.11.0
logo: images/dj_cassandra.png
author:
github: r4fek
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cassandra-driver==3.5.0
Django<1.10
cassandra-driver==3.6.0
Django<1.11
six>=1.6
5 changes: 0 additions & 5 deletions testproject/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ def run_tests(foo, settings='settings', extra=(), test_builtin=False):
apps = [
name for name in apps if not name.startswith('django.contrib.')]

# pre-1.6 test runners don't understand full module names
if django.VERSION < (1, 6):
apps = [app.replace('django.contrib.', '') for app in apps]
apps = [name for name in apps if not name.startswith('testproject.')]

os.chdir(test_dir)
print('\n============================\n'
'Running tests with settings: {}\n'
Expand Down
12 changes: 7 additions & 5 deletions testproject/urls.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
from testproject.app import views


urlpatterns = [
# Examples:
url(r'^$', 'app.views.home', name='home'),
url(r'^$', views.home, name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^admin/', include(admin.site.urls)),
)
]
7 changes: 6 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = django{17,18,19}
envlist = django{17,18,19,110}

[base]
deps = nose
Expand All @@ -25,3 +25,8 @@ deps =
deps =
django>=1.9, <1.10
{[base]deps}

[testenv:django110]
deps =
django>=1.9, <1.11
{[base]deps}

2 comments on commit 3ae61c1

@grillazz
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice update. Tested and it is working ok with --database switch.

@r4fek
Copy link
Owner Author

@r4fek r4fek commented on 3ae61c1 Aug 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you guys enjoyed it, thanks!

Please sign in to comment.