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


Python utility.Utility类代码示例

本文整理汇总了Python中utility.utility.Utility的典型用法代码示例。如果您正苦于以下问题:Python Utility类的具体用法?Python Utility怎么用?Python Utility使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Utility类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: to_json

    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,代码行数:33,代码来源:models.py

示例2: post_or_put

 def post_or_put(self, request, *args, **kwargs):
     request.data['_id'] = self.kwargs['_id']
     request.data['created_by'] = Utility.return_id(UserProfile, request.data.get('created_by'), '_id')
     request.data['modified_by'] = Utility.return_id(UserProfile, request.data.get('modified_by'), '_id')
     try:
         model.objects.get(_id=self.kwargs['_id'])
         return self.update(request, *args, **kwargs)
     except model.DoesNotExist:
         return self.create(request, *args, **kwargs)
开发者ID:cogfix,项目名称:vilogged-api,代码行数:9,代码来源:views.py

示例3: nest_row

def nest_row(row, id=None):
    if id is not None:
        row['_id'] = id
    appointment = Utility.get_nested(Appointments, AppointmentSerializer, row['appointment'])

    if len(appointment) > 0:
        appointment['host'] = Utility.get_nested(UserProfile, UserSerializer, appointment['host'])
        appointment['visitor'] = Utility.get_nested(Visitors, VisitorSerializer, appointment['visitor'])
        del appointment['visitor']['image']
        del appointment['host']['image']
        appointment['log'] = row
        row = appointment
    return row
开发者ID:cogfix,项目名称:vilogged-api,代码行数:13,代码来源:views.py

示例4: post

    def post(self, request):

        config = ConfigManager().get_config()
        user = None

        username = request.data.get('username', None)
        password = request.data.get('password', None)

        if config.get('authType', 'api') == 'api':
            user = authenticate(username=username, password=password)

        if config.get('authType', 'api') == 'ldap':
            user = LDAPManager().ldap_login(username, password)

        if user is not None:
            if user.is_active:
                token = Token.objects.get(user=user)
                serializer = UserSerializer(user)
                data = serializer.data
                del data['password']
                data['department'] = Utility.get_nested(Department, DepartmentSerializer, data['department'])

                return Response({'user': data, 'token': token.key})
            else:
                return Response({'detail': 'User not active'}, status=status.HTTP_400_BAD_REQUEST)

        return Response({'detail': 'invalid credentials provided'}, status=status.HTTP_401_UNAUTHORIZED)
开发者ID:musakunte,项目名称:vilogged-api,代码行数:27,代码来源:views.py

示例5: save_snapshot

    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,代码行数:35,代码来源:models.py

示例6: get

 def get(self, request, *args, **kwargs):
     user = Utility.get_data_or_none(UserProfile, request, **kwargs)
     if user is None:
         return Response({'detail': 'Not Found'}, status=status.HTTP_404_NOT_FOUND)
     else:
         profile = user.to_json(True)
         del profile['password']
         return Response(profile)
开发者ID:cogfix,项目名称:vilogged-api,代码行数:8,代码来源:views.py

示例7: get_value

 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,代码行数:10,代码来源:models.py

示例8: get

 def get(self, request, *args, **kwargs):
     user = Utility.get_data_or_none(UserProfile, request, **kwargs)
     if user is None:
         return Response({'detail': 'Not Found'}, status=status.HTTP_404_NOT_FOUND)
     else:
         serializer = UserSerializer(user)
         data = serializer.data
         del data['password']
         row = nest_row(data)
         return Response(row)
开发者ID:musakunte,项目名称:vilogged-api,代码行数:10,代码来源:views.py

示例9: to_json

    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,代码行数:20,代码来源:models.py

示例10: extra_filters

def extra_filters(request, list):
    built_filter = Utility.build_filter(FILTER_FIELDS, request.query_params, model)
    query = dict()
    order_by = request.query_params.get('order_by', '-created').replace('.', '__')
    for key in built_filter:
        query['{}__iexact'.format(key)] = built_filter[key]
    try:
        list = model.objects.filter(**query).order_by(order_by)
    except Exception as e:
        print (e)
    return list
开发者ID:cogfix,项目名称:vilogged-api,代码行数:11,代码来源:views.py

示例11: nest_row

def nest_row(row, id=None):
    if id is not None:
        row['_id'] = id
    row['visitor'] = Utility.get_nested(Visitors, VisitorSerializer, row['visitor'])
    row['host'] = Utility.get_nested(UserProfile, UserSerializer, row['host'])
    row['entrance'] = Utility.get_nested(Entrance, EntranceSerializer, row['entrance'])
    if type(row['visitor']) is dict and len(row['visitor']) > 0:
        row['visitor']['company'] = Utility.get_nested(Company, CompanySerializer, row['visitor']['company'])
        row['visitor']['group'] = Utility.get_nested(VisitorGroup, VisitorGroupSerializer, row['visitor']['group'])

    if type(row['host']) is dict and len(row['host']) > 0:
        row['host']['department'] = Utility.get_nested(Department, DepartmentSerializer, row['host']['department'])

    return row
开发者ID:musakunte,项目名称:vilogged-api,代码行数:14,代码来源:views.py


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