-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating Todo completed and skipped_datetime to status field (#744)
* Migration todos model to use status field * migrating to todo status field * Fix model comment * Fix loading todos on adding template * Fix comment Co-authored-by: Adam Marcus <marcua@marcua.net> * Remove batch logic in migrate script * Fix comment * Use elseif * Fix logger strings * Fix linting * Increases test coverage * Fix test * Fix tests * Test notify_single_todo_update * Fix test * Fix linting * Fix test * Fix linting * Fix test * Increase coverage * Increases test coverage * Fix test * Fix tests * Fix rebase conflicts * Fix rebase conflicts * Update migration number Co-authored-by: Aditya Bharadwaj <aditya@b12.io> Co-authored-by: Adam Marcus <marcua@marcua.net>
- Loading branch information
1 parent
f022ab6
commit 521fb00
Showing
17 changed files
with
884 additions
and
722 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from orchestra.models import Todo | ||
|
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = ('Migrates completion and skipped_datetime' | ||
' values to status field in Todo model.') | ||
|
||
def bulk_update_todo_status(self, queryset, status): | ||
num_rows = queryset.count() | ||
logger.info('Started updating %s todos with status = %s', | ||
num_rows, status) | ||
queryset.only('id', 'status').update(status=status) | ||
logger.info('Finished updating %s todos with status = %s', | ||
num_rows, status) | ||
|
||
def handle(self, *args, **options): | ||
# declined todos | ||
self.bulk_update_todo_status( | ||
queryset=Todo.objects.filter( | ||
skipped_datetime__isnull=False), | ||
status=Todo.Status.DECLINED.value | ||
) | ||
# completed todos | ||
self.bulk_update_todo_status( | ||
queryset=Todo.objects.filter( | ||
skipped_datetime__isnull=True, | ||
completed=True), | ||
status=Todo.Status.COMPLETED.value | ||
) | ||
# pending todos | ||
self.bulk_update_todo_status( | ||
queryset=Todo.objects.filter( | ||
skipped_datetime__isnull=True, | ||
completed=False), | ||
status=Todo.Status.PENDING.value | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Generated by Django 2.2.13 on 2021-02-11 21:57 | ||
|
||
from django.db import migrations, models | ||
import orchestra.models.core.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('orchestra', '0092_autostaff_updates'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='todo', | ||
name='status', | ||
field=models.IntegerField(choices=[(0, 'pending'), (1, 'completed'), (2, 'declined')], default=0), | ||
), | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.