-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove custom DurationField, replace with IntegerField
the custom field derives from models.IntegerField so replace with that. Next we're going to make use of Django's own models.DurationField.
- Loading branch information
Showing
11 changed files
with
16 additions
and
115 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
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 |
---|---|---|
@@ -1,45 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
import datetime | ||
|
||
try: | ||
# may not be running under MySQL | ||
from MySQLdb.constants import FIELD_TYPE | ||
from django.db.backends.mysql.base import django_conversions | ||
django_conversions.update({FIELD_TYPE.TIME: None}) | ||
except ImportError: | ||
pass | ||
|
||
from django.db.models.fields import IntegerField | ||
|
||
from tcms.core.forms.fields import DurationField as DurationFormField | ||
|
||
|
||
class DurationField(IntegerField): | ||
def from_db_value(self, value, expression, connection): | ||
return self.to_python(value) | ||
|
||
def to_python(self, value): | ||
if isinstance(value, int): | ||
return datetime.timedelta(seconds=value) | ||
elif isinstance(value, datetime.timedelta): | ||
return value | ||
else: | ||
raise TypeError('Unable to convert %s to timedelta.' % value) | ||
|
||
def get_db_prep_value(self, value, connection, prepared): | ||
"""convert datetime.timedelta to seconds. | ||
1 day equal to 86400 seconds | ||
""" | ||
if isinstance(value, datetime.timedelta): | ||
return value.seconds + (86400 * value.days) | ||
else: | ||
value = super(DurationField, self).get_db_prep_value(value, | ||
connection, | ||
prepared) | ||
return value | ||
|
||
def formfield(self, form_class=DurationFormField, **kwargs): | ||
defaults = {'help_text': 'Enter duration in the format: DDHHMM'} | ||
defaults.update(kwargs) | ||
return form_class(**defaults) |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
15 changes: 6 additions & 9 deletions
15
tcms/testruns/migrations/0003_testrun_estimated_time_remove_max_length.py
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 |
---|---|---|
@@ -1,18 +1,15 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.db import migrations | ||
import tcms.core.models.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
""" | ||
As part of migrating to Django's own DurationField | ||
we don't need this anymore. | ||
""" | ||
dependencies = [ | ||
('testruns', '0002_add_initial_data'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='testrun', | ||
name='estimated_time', | ||
field=tcms.core.models.fields.DurationField(default=0), | ||
), | ||
] | ||
# deliberately left empty | ||
operations = [] |
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
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