Skip to content

Commit 2f51919

Browse files
author
Mikhail Pyrev
committed
Add Batch Django models
1 parent 319d5e9 commit 2f51919

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

capitalist/capitalist.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,11 @@ def get_document_fee(
8787
if wiretag:
8888
data['wiretag'] = wiretag
8989
return self.secure_request('get_document_fee', data)
90+
91+
def get_batch_info(self, batch_id, page_size=1, start_offset=0):
92+
data = {
93+
'batch_id': batch_id,
94+
'page_size': page_size,
95+
'start_offset': start_offset,
96+
}
97+
return self.secure_request('get_batch_info', data)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Generated by Django 2.1.7 on 2019-03-28 15:08
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
import django.utils.timezone
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('contenttypes', '0002_remove_content_type_name'),
12+
('django_capitalist', '0001_initial'),
13+
]
14+
15+
operations = [
16+
migrations.CreateModel(
17+
name='Batch',
18+
fields=[
19+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20+
('batch_id', models.CharField(max_length=50, unique=True, verbose_name='batch ID')),
21+
('created_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='created at')),
22+
('updated_at', models.DateTimeField(auto_now=True, verbose_name='updated at')),
23+
('object_id', models.PositiveIntegerField(blank=True, null=True)),
24+
('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
25+
],
26+
options={
27+
'verbose_name': 'batch',
28+
'verbose_name_plural': 'batches',
29+
},
30+
),
31+
migrations.CreateModel(
32+
name='BatchRecord',
33+
fields=[
34+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
35+
('state', models.CharField(choices=[('NEW', 'New'), ('READY', 'Ready'), ('INPROCESS', 'In process'), ('DECLINED', 'Declined'), ('PROCESSED', 'Processed')], default='NEW', max_length=20, verbose_name='status')),
36+
('data', models.TextField(verbose_name='record data (CSV)')),
37+
('internal_id', models.CharField(max_length=255, verbose_name='internal ID')),
38+
('created_at', models.DateTimeField(default=django.utils.timezone.now, verbose_name='created at')),
39+
('updated_at', models.DateTimeField(auto_now=True, verbose_name='updated at')),
40+
('object_id', models.PositiveIntegerField(blank=True, null=True)),
41+
('batch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='django_capitalist.Batch', verbose_name='batch')),
42+
('content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
43+
],
44+
options={
45+
'verbose_name': 'batch record',
46+
'verbose_name_plural': 'batch records',
47+
},
48+
),
49+
migrations.AlterUniqueTogether(
50+
name='batchrecord',
51+
unique_together={('batch', 'internal_id')},
52+
),
53+
]

capitalist/contrib/django/django_capitalist/models.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from django.contrib.contenttypes.fields import GenericForeignKey
2+
from django.contrib.contenttypes.models import ContentType
13
from django.db import models
4+
from django.utils import timezone
25
from django.utils.translation import gettext_lazy as _
36

47

@@ -32,3 +35,56 @@ class Meta:
3235

3336
def __str__(self):
3437
return '{} ({})'.format(self.name, self.number)
38+
39+
40+
class Batch(models.Model):
41+
batch_id = models.CharField(_('batch ID'), max_length=50, unique=True)
42+
created_at = models.DateTimeField(_('created at'), default=timezone.now)
43+
updated_at = models.DateTimeField(_('updated at'), auto_now=True)
44+
45+
# Not required. Just for your convenience.
46+
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True)
47+
object_id = models.PositiveIntegerField(blank=True, null=True)
48+
related_object = GenericForeignKey('content_type', 'object_id')
49+
50+
class Meta:
51+
verbose_name = _('batch')
52+
verbose_name_plural = _('batches')
53+
54+
def __str__(self):
55+
return 'Batch {}'.format(self.batch_id)
56+
57+
58+
class BatchRecord(models.Model):
59+
NEW = 'NEW'
60+
READY = 'READY'
61+
INPROCESS = 'INPROCESS'
62+
DECLINED = 'DECLINED'
63+
PROCESSED = 'PROCESSED'
64+
65+
STATE_CHOICES = (
66+
(NEW, _('New')),
67+
(READY, _('Ready')),
68+
(INPROCESS, _('In process')),
69+
(DECLINED, _('Declined')),
70+
(PROCESSED, _('Processed')),
71+
)
72+
73+
batch = models.ForeignKey(Batch, models.CASCADE, verbose_name=_('batch'))
74+
state = models.CharField(_('status'), max_length=20, choices=STATE_CHOICES, default=NEW)
75+
data = models.TextField(_('record data (CSV)'))
76+
internal_id = models.CharField(_('internal ID'), max_length=255)
77+
created_at = models.DateTimeField(_('created at'), default=timezone.now)
78+
updated_at = models.DateTimeField(_('updated at'), auto_now=True)
79+
80+
# Not required. Just for your convenience.
81+
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE, blank=True, null=True)
82+
object_id = models.PositiveIntegerField(blank=True, null=True)
83+
related_object = GenericForeignKey('content_type', 'object_id')
84+
85+
class Meta:
86+
verbose_name = _('batch record')
87+
verbose_name_plural = _('batch records')
88+
unique_together = [
89+
['batch', 'internal_id'],
90+
]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
# For a discussion on single-sourcing the version across setup.py and the
4444
# project code, see
4545
# https://packaging.python.org/en/latest/single_source_version.html
46-
version='1.0.0', # Required
46+
version='1.1.0', # Required
4747

4848
# This is a one-line description or tagline of what your project does. This
4949
# corresponds to the "Summary" metadata field:

0 commit comments

Comments
 (0)