本文整理汇总了Python中utility.utility.Utility.format_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.format_datetime方法的具体用法?Python Utility.format_datetime怎么用?Python Utility.format_datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utility.utility.Utility
的用法示例。
在下文中一共展示了Utility.format_datetime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_json
# 需要导入模块: from utility.utility import Utility [as 别名]
# 或者: from utility.utility.Utility import format_datetime [as 别名]
def to_json(self, all_fields=False):
json_object = dict(
_id=self._id,
_rev=self._rev,
first_name=self.first_name,
last_name=self.last_name,
email=self.email,
gender=self.gender,
phone=self.phone,
black_listed=self.black_listed,
occupation=self.occupation,
company=self.get_company(),
date_of_birth=Utility.format_datetime(self.date_of_birth),
nationality=self.nationality,
state_of_origin=self.state_of_origin,
lga_of_origin=self.lga_of_origin,
pass_code=self.pass_code,
type=self.get_type(),
created=Utility.format_datetime(self.created),
modified=Utility.format_datetime(self.modified),
created_by=Utility.return_instance_id(self.created_by),
modified_by=Utility.return_instance_id(self.modified_by)
)
if all_fields:
json_object.update(dict(
image=self.image,
fingerprint=self.fingerprint,
signature=self.signature,
))
return json_object
示例2: save_snapshot
# 需要导入模块: from utility.utility import Utility [as 别名]
# 或者: from utility.utility.Utility import format_datetime [as 别名]
def save_snapshot(sender, instance, **kwargs):
def get_value(data, field):
from django.db.models.fields.related import ForeignKey
if isinstance(field, ForeignKey) and data:
return getattr(data, '_id', 'no id')
elif data is not None:
return data
elif isinstance(field, (DateTimeField, DateField, TimeField)):
return Utility.format_datetime(data)
else:
return ''
if getattr(instance, '_id', None) is not None:
changed = dict()
current_record = sender.objects.filter(_id=instance._id)
if len(current_record) > 0:
current_record = current_record.first()
fields = instance._meta.get_fields()
for field in fields:
if field.name not in ['modified_by', 'created_by', '_rev', 'logentry', 'password']:
try:
current_value = getattr(current_record, field.name)
instance_value = getattr(instance, field.name)
if current_value != instance_value:
if instance(field, DateField):
current_value = Utility.format_datetime(current_value)
changed[field.name] = get_value(current_value, field)
except:
pass
if len(changed) > 0:
model = sender.__name__.lower()
try:
Changes.objects.create(model=model, type='updated', row_id=instance._id, snapshot=json.dumps(changed))
except Exception as e:
print (changed)
示例3: get_value
# 需要导入模块: from utility.utility import Utility [as 别名]
# 或者: from utility.utility.Utility import format_datetime [as 别名]
def get_value(data, field):
from django.db.models.fields.related import ForeignKey
if isinstance(field, ForeignKey) and data:
return getattr(data, '_id', 'no id')
elif data is not None:
return data
elif isinstance(field, (DateTimeField, DateField, TimeField)):
return Utility.format_datetime(data)
else:
return ''
示例4: to_json
# 需要导入模块: from utility.utility import Utility [as 别名]
# 或者: from utility.utility.Utility import format_datetime [as 别名]
def to_json(self, all_fields=False):
json_object = dict(
_id=self._id,
_rev=self._rev,
message_body=self.message_body,
destination=self.destination,
status=self.status,
type=self.type,
source=self.source,
created=Utility.format_datetime(self.created),
modified=Utility.format_datetime(self.modified),
created_by=Utility.get_instance_fields(self.created_by, ['_id', 'username']),
modified_by=Utility.get_instance_fields(self.modified_by, ['_id', 'username'])
)
if all_fields:
json_object.update(dict())
return json_object