Skip to content

Commit

Permalink
Migrating Todo completed and skipped_datetime to status field (#744)
Browse files Browse the repository at this point in the history
* 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
3 people committed Mar 22, 2021
1 parent f022ab6 commit 521fb00
Show file tree
Hide file tree
Showing 17 changed files with 884 additions and 722 deletions.
41 changes: 41 additions & 0 deletions orchestra/management/commands/migrate_todos_status.py
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
)
20 changes: 20 additions & 0 deletions orchestra/migrations/0093_todo_status_default.py
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),
),
]

8 changes: 5 additions & 3 deletions orchestra/models/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,15 +737,15 @@ class Todo(TodoMixin, BaseModel):
task (orchestra.models.Task):
The given task the Todo is attached to.
completed (boolean):
Whether the todo has been completed.
Whether the todo has been completed (DEPRECATED).
title (str):
A text description of the Todo.
start_by_datetime (datetime.datetime):
The time to start the todo. (inclusive)
due_datetime (datetime.datetime):
The time the todo is due
skipped_datetime (datetime.datetime):
The time the todo was skipped
The time the todo was skipped (DEPRECATED).
parent_todo (orchestra.models.Todo):
The parent todo item
template (orchestra.models.TodoListTemplate)
Expand Down Expand Up @@ -780,9 +780,11 @@ class Status(ChoicesEnum):
details = models.TextField(null=True, blank=True)
section = models.CharField(max_length=255, null=True, blank=True)
order = models.IntegerField(null=True, blank=True)
# DEPRECATED FIELD. Use status instead.
completed = models.BooleanField(default=False)
start_by_datetime = models.DateTimeField(null=True, blank=True)
due_datetime = models.DateTimeField(null=True, blank=True)
# DEPRECATED FIELD. Use status instead.
skipped_datetime = models.DateTimeField(null=True, blank=True)
parent_todo = models.ForeignKey(
'self', null=True, related_name='parent', on_delete=models.CASCADE)
Expand All @@ -791,7 +793,7 @@ class Status(ChoicesEnum):
on_delete=models.SET_NULL)
activity_log = JSONField(default={'actions': []})
status = models.IntegerField(
null=True, blank=True, choices=Status.choices())
default=Status.PENDING.value, choices=Status.choices())
additional_data = JSONField(default=dict)


Expand Down

0 comments on commit 521fb00

Please sign in to comment.