Skip to content

Commit 2345cae

Browse files
committed
Merge pull request #6 from dabapps/python-3
Python 3 support
2 parents a262204 + 65e15bb commit 2345cae

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: python
22
python:
33
- '2.7'
4+
- '3.4'
45
install:
56
- pip install -r requirements.txt
67
script: python manage.py test

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Asynchronous tasks are run via a *job queue*. This system is designed to support
99

1010
This is not yet production-ready, and the API is liable to change. Use at your own risk.
1111

12+
**NOTE**: Between version 0.0.1 and 0.0.2, the project was upgraded to support
13+
Python 3. This required switching to Django's built-in UUIDField, which was added in Django 1.8. The simplest way to upgrade it to drop the existing
14+
`django_dbq_job` table, delete the migration from `django_migrations`, and then
15+
re-run `manage.py migrate`.
16+
1217
## Getting Started
1318

1419
### Describe your job

django_dbq/migrations/0001_initial.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from django.db import models, migrations
55
import jsonfield.fields
6-
import uuidfield.fields
6+
import uuid
77

88

99
class Migration(migrations.Migration):
@@ -15,18 +15,17 @@ class Migration(migrations.Migration):
1515
migrations.CreateModel(
1616
name='Job',
1717
fields=[
18-
('id', uuidfield.fields.UUIDField(primary_key=True, serialize=False, editable=False, max_length=32, blank=True, unique=True, db_index=True)),
19-
('created', models.DateTimeField(auto_now_add=True, db_index=True)),
18+
('id', models.UUIDField(serialize=False, editable=False, default=uuid.uuid4, primary_key=True)),
19+
('created', models.DateTimeField(db_index=True, auto_now_add=True)),
2020
('modified', models.DateTimeField(auto_now=True)),
2121
('name', models.CharField(max_length=100)),
22-
('state', models.CharField(default=b'NEW', max_length=20, db_index=True, choices=[(b'NEW', b'NEW'), (b'READY', b'READY'), (b'PROCESSING', b'PROCESSING'), (b'FAILED', b'FAILED'), (b'COMPLETE', b'COMPLETE')])),
22+
('state', models.CharField(db_index=True, max_length=20, default='NEW', choices=[('NEW', 'NEW'), ('READY', 'READY'), ('PROCESSING', 'PROCESSING'), ('FAILED', 'FAILED'), ('COMPLETE', 'COMPLETE')])),
2323
('next_task', models.CharField(max_length=100, blank=True)),
2424
('workspace', jsonfield.fields.JSONField(null=True)),
25-
('queue_name', models.CharField(default=b'default', max_length=20, db_index=True)),
25+
('queue_name', models.CharField(db_index=True, max_length=20, default='default')),
2626
],
2727
options={
2828
'ordering': ['-created'],
2929
},
30-
bases=(models.Model,),
3130
),
3231
]

django_dbq/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from jsonfield import JSONField
55
from model_utils import Choices
66
import logging
7-
import uuidfield
7+
import uuid
88

99

1010
logger = logging.getLogger(__name__)
@@ -43,7 +43,7 @@ class Job(models.Model):
4343

4444
STATES = Choices("NEW", "READY", "PROCESSING", "FAILED", "COMPLETE")
4545

46-
id = uuidfield.UUIDField(primary_key=True, auto=True, db_index=True)
46+
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
4747
created = models.DateTimeField(auto_now_add=True, db_index=True)
4848
modified = models.DateTimeField(auto_now=True)
4949
name = models.CharField(max_length=100)
@@ -58,7 +58,9 @@ class Meta:
5858
objects = JobManager()
5959

6060
def save(self, *args, **kwargs):
61-
if not self.pk:
61+
is_new = not Job.objects.filter(pk=self.pk).exists()
62+
63+
if is_new:
6264
self.next_task = get_next_task_name(self.name)
6365
self.workspace = self.workspace or {}
6466

django_dbq/tests.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
from django.test.utils import override_settings
66
from django_dbq.management.commands.worker import process_job
77
from django_dbq.models import Job
8-
from StringIO import StringIO
8+
try:
9+
from StringIO import StringIO
10+
except ImportError:
11+
from io import StringIO
912

1013

1114
def test_task(job=None):

requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
django-model-utils==1.5.0
2-
django-uuidfield==0.4.0
3-
jsonfield==0.9.20
4-
Django>=1.7
2+
jsonfield==1.0.3
3+
Django>=1.8
54
simplesignals==0.3.0

0 commit comments

Comments
 (0)