當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。