Beispiel #1
0
    def serialized(self):
        """
        The JSON-friendly serialized version of this specific object for
        API purposes.
        """
        resp = {}
        fields = set((o.name for o in inspect(self.__class__).columns))
        fields = set((a for a in fields if not a.startswith('_')
                      if a not in self.__do_not_serialize__))
        fields.update(set(self.__force_serialize__))
        for attr in fields:
            attr_val = getattr(self, attr)
            if isinstance(attr_val, Base):
                attr_val = attr_val.serialized

            resp[attr] = serialize_db_value(attr_val)
        return resp
Beispiel #2
0
    def serializer_func(self, user):
        """
        Given the currently logged user, returns the appropriate serialization.

        :param user: the current user.
        :type user: <User>

        :returns: the JSON-friendly representation of this connection for API
                  purposes.
        :rtype: dict
        """
        resp = self.serialized
        resp['user_id'] = serialize_db_value(
            self.user_from_id
            if self.user_to_id == user.id else self.user_to_id)

        return resp
Beispiel #3
0
    def serializer_func(self, user):
        """
        Given the currently logged user, returns the appropriate serialization.

        :param user: the current user.
        :type user: <User>

        :returns: the JSON-friendly representation of this reference for API
                  purposes.
        :rtype: dict
        """
        resp = self.serialized
        update_dict = (
            ('user_id', (self.user_from_id
                         if self.user_to_id == user.id else self.user_to_id)),
            ('reference_type', self.type_status))

        resp.update(dict((k, serialize_db_value(v))
                         for (k, v) in update_dict))
        return resp