Merge "Make datetime strings consistent for future parsing"
This commit is contained in:
commit
16be61428f
|
@ -19,6 +19,7 @@ from django.utils import timezone
|
|||
|
||||
from adjutant.common.quota import QuotaManager
|
||||
from adjutant.common import user_store
|
||||
from adjutant.common.utils import str_datetime
|
||||
from adjutant.actions.models import Action
|
||||
|
||||
|
||||
|
@ -331,7 +332,7 @@ class UserMixin(ResourceMixin):
|
|||
user = id_manager.create_user(
|
||||
name=self.username, password=password,
|
||||
email=self.email, domain=self.domain_id,
|
||||
created_on=str(timezone.now()))
|
||||
created_on=str_datetime(timezone.now()))
|
||||
except Exception as e:
|
||||
# TODO: Narrow the Exceptions caught to a relevant set.
|
||||
self.add_note(
|
||||
|
@ -410,7 +411,7 @@ class ProjectMixin(ResourceMixin):
|
|||
description = getattr(self, "description", "")
|
||||
try:
|
||||
project = id_manager.create_project(
|
||||
self.project_name, created_on=str(timezone.now()),
|
||||
self.project_name, created_on=str_datetime(timezone.now()),
|
||||
parent=self.parent_id, domain=self.domain_id,
|
||||
description=description)
|
||||
except Exception as e:
|
||||
|
|
|
@ -17,6 +17,7 @@ from uuid import uuid4
|
|||
from django.utils import timezone
|
||||
|
||||
from adjutant.common import user_store
|
||||
from adjutant.common.utils import str_datetime
|
||||
from adjutant.actions.v1.base import (
|
||||
BaseAction, UserNameAction, UserMixin, ProjectMixin)
|
||||
|
||||
|
@ -261,7 +262,7 @@ class NewProjectWithUserAction(UserNameAction, ProjectMixin, UserMixin):
|
|||
user = id_manager.create_user(
|
||||
name=self.username, password=password,
|
||||
email=self.email, domain=self.domain_id,
|
||||
created_on=str(timezone.now()))
|
||||
created_on=str_datetime(timezone.now()))
|
||||
self.set_cache('user_id', user.id)
|
||||
else:
|
||||
user = id_manager.get_user(user_id)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
# Copyright (C) 2018 Catalyst IT Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# Date formats to use when storing time data we expect to parse.
|
||||
DATE_FORMAT = "%Y-%m-%dT%H:%M:%S"
|
||||
DATE_FORMAT_MS = "%Y-%m-%dT%H:%M:%S.%f"
|
|
@ -0,0 +1,24 @@
|
|||
# Copyright (C) 2018 Catalyst IT Ltd
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from adjutant.common import constants
|
||||
|
||||
|
||||
def str_datetime(datetime_obj, include_ms=False):
|
||||
if include_ms:
|
||||
return datetime.strftime(datetime_obj, constants.DATE_FORMAT_MS)
|
||||
else:
|
||||
return datetime.strftime(datetime_obj, constants.DATE_FORMAT)
|
Loading…
Reference in New Issue