Example #1
0
    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
Example #2
0
    def to_json(self, all_fields=False):

        json_object = dict(
            _id=self._id,
            _rev=self._rev,
            email=self.email,
            last_name=self.last_name,
            first_name=self.first_name,
            username=self.username,
            is_superuser=self.is_superuser,
            is_active=self.is_active,
            is_staff=self.is_staff,
            date_joined=Utility.format_datetime(self.date_joined),
            last_login=Utility.format_datetime(self.last_login),
            groups=list(self.get_group_permissions(self.groups)),
            user_permissions=list(self.get_all_permissions(self.user_permissions)),
            phone=self.phone,
            work_phone=self.work_phone,
            gender=self.gender,
            home_phone=self.home_phone,
            department=self.get_department_or_object(all_fields),
        )

        if all_fields:
            json_object.update(dict(
                password=self.password,
                image=self.image
            ))

        return json_object
Example #3
0
    def to_json(self, all_fields=False):

        json_object = dict(
            _id=self._id,
            _rev=self._rev,
            name=self.name,
            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
Example #4
0
    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)
Example #5
0
    def to_json(self, all_fields=False):

        json_object = dict(
            _id=self._id,
            _rev=self._rev,
            visitor=self.visitor.to_json(all_fields),
            host=self.host.to_json(all_fields),
            representing=self.representing,
            purpose=self.purpose,
            start_date=self.start_date.isoformat(),
            end_date=self.end_date.isoformat(),
            start_time=self.start_time.isoformat(),
            end_time=self.end_time.isoformat(),
            escort_required=self.escort_required,
            is_approved=self.is_approved,
            is_expired=self.is_expired,
            is_removed=self.is_removed,
            teams=self.get_team_members(),
            entrance=self.entrance,
            created=self.created.isoformat(),
            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())

        return json_object
Example #6
0
    def to_json(self, all_fields=False):
        json_object = dict(
            _id=self._id,
            _rev=self._rev,
            name=self.name,
            floor=self.floor,
            description=self.description,
            created=Utility.format_datetime(self.created),
            modifeid=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())

        return json_object
Example #7
0
 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 ''
Example #8
0
    def to_json(self, all_fields=False):

        json_object = dict(
                _id=self._id,
                _rev=self._rev,
                appointment=self.appointment,
                checked_in=Utility.format_datetime(self.checked_in),
                checked_out=Utility.format_datetime(self.checked_out),
                label_code=self.label_code,
                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
Example #9
0
    def to_json(self, all_fields=False):

        json_object = dict(
            _id=self._id,
            _rev=self._rev,
            appointment=self.get_appointment(all_fields),
            license=self.license,
            model=self.model,
            type=self.type,
            color=self.color,
            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
Example #10
0
    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
Example #11
0
    def to_json(self, all_fields=False):

        json_object = dict(
                _id=self._id,
                _rev=self._rev,
                model=self.model,
                type=self.type,
                row_id=self.row_id,
                rev=self.rev,
                snapshot=self.snapshot,
                reviewed=self.reviewed,
                created=Utility.format_datetime(self.created)
        )

        if all_fields:
            json_object.update(dict())

        return json_object