当前位置: 首页>>代码示例>>Python>>正文


Python Utility.format_datetime方法代码示例

本文整理汇总了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
开发者ID:cogfix,项目名称:vilogged-api,代码行数:35,代码来源:models.py

示例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)
开发者ID:cogfix,项目名称:vilogged-api,代码行数:37,代码来源:models.py

示例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 ''
开发者ID:cogfix,项目名称:vilogged-api,代码行数:12,代码来源:models.py

示例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
开发者ID:cogfix,项目名称:vilogged-api,代码行数:22,代码来源:models.py


注:本文中的utility.utility.Utility.format_datetime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。