Code Duplication    Length = 22-25 lines in 3 locations

frontend/ore/models/node.py 1 location

@@ 694-718 (lines=25) @@
691
                (key, self.pk))
692
            raise MultipleObjectsReturned()
693
694
    def set_attr(self, key, value):
695
        """
696
        Method: set_attr
697
698
        Use this method to set a node's attribute. It looks in the node object and its related properties for an
699
        attribute with the given name and changes it. If non exist, a new property is added saving this attribute.
700
701
        Parameters:
702
            {string} key - The name of the attribute.
703
            {attr} value - The new value that should be stored.
704
705
        TODO: Deprecate this method, set_attrs() should only be used to have an efficient modification signal handling.
706
        """
707
        # Catch attribute setting before object saving cases
708
        assert(self.pk)
709
        if hasattr(self, key):
710
            # Native node attribute, such as X or Y
711
            setattr(self, key, value)
712
            self.save()
713
        else:
714
            # Node property
715
            prop, created = self.properties.get_or_create(
716
                key=key, defaults={
717
                    'node': self})
718
            prop.save_value(value)
719
720
    def set_attrs(self, d):
721
        '''

frontend/ore/models/edge.py 1 location

@@ 90-111 (lines=22) @@
87
        """
88
        return json.dumps(self.to_dict(use_value_dict))
89
90
    def set_attr(self, key, value):
91
        """
92
        Method: set_attr
93
94
        Use this method to set a edge's attribute. It looks in the edge object and its related properties for an
95
        attribute with the given name and changes it. If non exist, a new property is added saving this attribute.
96
97
        Parameters:
98
            {string} key - The name of the attribute.
99
            {attr} value - The new value that should be stored.
100
101
        TODO: Deprecate this method, set_attrs() should only be used to have an efficient modification signal handling.
102
        """
103
        assert(self.pk)
104
        if hasattr(self, key):
105
            # Native Edge attribute, such as client_id
106
            setattr(self, key, value)
107
        else:
108
            prop, created = self.properties.get_or_create(
109
                key=key, defaults={
110
                    'edge': self})
111
            prop.save_value(value)
112
113
    def set_attrs(self, d):
114
        '''

frontend/ore/models/node_group.py 1 location

@@ 77-98 (lines=22) @@
74
                (key, self.pk))
75
            raise MultipleObjectsReturned()
76
77
    def set_attr(self, key, value):
78
        """
79
        Method: set_attr
80
81
        Use this method to set a group's attribute. It looks in the group object and its related properties for an
82
        attribute with the given name and changes it. If non exist, a new property is added saving this attribute.
83
84
        Parameters:
85
            {string} key - The name of the attribute.
86
            {attr} value - The new value that should be stored.
87
88
        TODO: Deprecate this method, set_attrs() should only be used to have an efficient modification signal handling.
89
        """
90
        assert(self.pk)
91
        if hasattr(self, key):
92
            # Native NodeGroup attribute, such as client_id
93
            setattr(self, key, value)
94
        else:
95
            prop, created = self.properties.get_or_create(
96
                key=key, defaults={
97
                    'node_group': self})
98
            prop.save_value(value)
99
100
    def set_attrs(self, d):
101
        '''