Beispiel #1
0
 def get_default(self, obj):
     """
     Return default value
     :param obj: Object being processed
     :return: Objects default value
     """
     return attrib_str_to_value(obj.type_fk.raw_type, obj.default_str)
Beispiel #2
0
def get_graph_json(obj):
    """
    returns "graph" component of a graph JSON representation. This
    comprises of a list containing two dictionaries as per the following
    sample:
        "graph": [ {
                "attrs": [ { .. 1 or more graph attribute definitions .. } ]
            },
            {
                "data": [ { .. 0 or more graph attributes .. } ]
            }
    :param obj: Parent Graph object.
    :return: JSON representation of the "graph" component of the object
             made up of attributes and data that have been linked to this
             Graph object via FKs.
    """
    attrs_list = []
    for attr in GraphAttribDefGraph.objects.filter(graph_fk=obj.id):
        attr_data = GraphAttribJsonSerializer(attr).data
        # Remove "default" fields that do not have a value, as per
        # example legacy JSON
        if attr_data['default'] is None:
            attr_data.pop('default')
        attrs_list.append(attr_data)

    data_dict = {}
    for attr in GraphAttrib.objects.filter(graph_fk=obj.id):
        data_dict[attr.attrib_fk.label] = \
            attrib_str_to_value(attr.attrib_fk.type_fk.raw_type, attr.value_str)
    return [{"attrs": attrs_list}, {"data": [data_dict]}]
Beispiel #3
0
    def update_vertex_attrib(vertex, attrib_label, attrib_type,
                             attrib_value_str):
        """
        Common code to handle the propagation of to a VertexAttrib object (Create or Delete) up into the parent Vertex
        objects json field.

        :param vertex: Parent Vertex object to update
        :param attrib_label: Attribute label being updated
        :param attrib_type: The type of the attribute being updated
        :param attrib_value_str: String value of the attribute being updated
        """
        vertex_attribute_json = json.loads(str(vertex.attribute_json))
        vertex_attribute_json[attrib_label] = attrib_str_to_value(
            attrib_type, attrib_value_str)
        vertex.attribute_json = json.dumps(vertex_attribute_json)
        signals.post_save.disconnect(vertex_saved, sender=Vertex)
        vertex.save()
        signals.post_save.connect(vertex_saved, sender=Vertex)
Beispiel #4
0
    def update_graph_attrib(graph, attrib_label, attrib_type,
                            attrib_value_str):
        """
        Common code to handle the propagation of to a GraphAttrib object
        (Create or Delete) up into the parent Graph objects json field.

        :param graph: Parent Graph object to update
        :param attrib_label: Attribute label being updated
        :param attrib_type: The type of the attribute being updated
        :param attrib_value_str: String value of the attribute being updated
        """
        graph_attribute_json = json.loads(str(graph.attribute_json))
        graph_attribute_json[attrib_label] = attrib_str_to_value(
            attrib_type, attrib_value_str)
        graph.attribute_json = json.dumps(graph_attribute_json)
        signals.post_save.disconnect(graph_saved, sender=Graph)
        graph.save()
        signals.post_save.connect(graph_saved, sender=Graph)
Beispiel #5
0
    def update_transaction_attrib(transaction, attrib_label, attrib_type,
                                  attrib_value_str):
        """
        Common code to handle the propagation of to a TransactionAttrib object
        (Create or Delete) up into the parent Transaction objects json field.

        :param transaction: Parent Transaction object to update
        :param attrib_label: Attribute label being updated
        :param attrib_type: The type of the attribute being updated
        :param attrib_value_str: String value of the attribute being updated
        """
        transaction_attribute_json = json.loads(str(
            transaction.attribute_json))
        transaction_attribute_json[attrib_label] = attrib_str_to_value(
            attrib_type, attrib_value_str)
        transaction.attribute_json = json.dumps(transaction_attribute_json)
        signals.post_save.disconnect(transaction_saved, sender=Transaction)
        transaction.save()
        signals.post_save.connect(transaction_saved, sender=Transaction)