How to use the janus.janus.DataMessage.from_message function in janus

To help you get started, we’ve selected a few janus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xamoom / xamoom-janus / janus / janus.py View on Github external
if not callable(getattr(self,attr))
                                    and type(object.__getattribute__(self,attr)) == Attribute
                                    and issubclass(object.__getattribute__(self,attr).value_type,DataMessage) == True
                                    and object.__getattribute__(self,attr).nested == True
                                    and object.__getattribute__(self,attr).mapping != None
                                    and object.__getattribute__(self,attr).name != 'id'
                                    and not attr.startswith("__")}

                for attr in nested:
                    if nested[attr].name in message['relationships']:
                        val = message['relationships'][nested[attr].name]['data']

                        if isinstance(val,(list,tuple)):
                            val_list = []
                            for v in val:
                                val_list.append(DataMessage.from_message(json.dumps({'data':v}),object.__getattribute__(self,attr).value_type))

                            setattr(self,attr,val_list)
                        else:
                            setattr(self,attr,DataMessage.from_message(json.dumps(val),object.__getattribute__(self,attr).value_type))

                        setattr(nested[attr],'updated',True) #mark this attribute as updated for later updating the backend object
                    else:
                        if nested[attr].required == True:
                            janus_logger.error('Missing required field ' + str(nested[attr].name) + ".")
                            raise Exception('Missing required field ' + str(nested[attr].name) + ".")

        if 'relationships' in message:
            #get relationships
            relations = {attr:object.__getattribute__(self,attr)
                            for attr in dir(self)
                                if not callable(getattr(self,attr))