Code Duplication    Length = 29-32 lines in 2 locations

frontend/ore/models/node_group.py 1 location

@@ 44-75 (lines=32) @@
41
    def to_json(self, use_value_dict=False):
42
        return json.dumps(self.to_dict(use_value_dict))
43
44
    def get_property(self, key, default=None):
45
        try:
46
            return self.properties.get(key=key).get_value()
47
        except ObjectDoesNotExist:
48
            node_kind = self.nodes.all()[0].kind
49
            logger.debug(
50
                "Assuming node kind %s for node group properties" %
51
                node_kind)
52
            try:
53
                prop = notations.by_kind[
54
                    self.graph.kind]['nodes'][node_kind]['properties'][key]
55
                if prop is None:
56
                    logger.warning(
57
                        'Notation configuration has empty default for node property ' +
58
                        key)
59
                    result = default
60
                else:
61
                    result = prop['default']
62
                logger.debug(
63
                    'Node has no property "%s", using default "%s"' %
64
                    (key, str(result)))
65
                return result
66
            except KeyError:
67
                logger.debug(
68
                    'No default given in notation, using given default "%s" instead' %
69
                    default)
70
                return default
71
        except MultipleObjectsReturned:
72
            logger.error(
73
                "ERROR: Property %s in node group %u exists in multiple instances" %
74
                (key, self.pk))
75
            raise MultipleObjectsReturned()
76
77
    def set_attr(self, key, value):
78
        """

frontend/ore/models/node.py 1 location

@@ 664-692 (lines=29) @@
661
        else:
662
            return True
663
664
    def get_property(self, key, default=None):
665
        try:
666
            return self.properties.get(key=key).get_value()
667
        except ObjectDoesNotExist:
668
            try:
669
                prop = notations.by_kind[
670
                    self.graph.kind]['nodes'][
671
                    self.kind]['properties'][key]
672
                if prop is None:
673
                    logger.warning(
674
                        'Notation configuration has empty default for node property ' +
675
                        key)
676
                    result = default
677
                else:
678
                    result = prop['default']
679
                logger.debug(
680
                    'Node has no property "%s", using default "%s"' %
681
                    (key, str(result)))
682
                return result
683
            except KeyError:
684
                logger.debug(
685
                    'No default given in notation, using given default "%s" instead' %
686
                    default)
687
                return default
688
        except MultipleObjectsReturned:
689
            logger.error(
690
                "ERROR: Property %s in node %u exists in multiple instances" %
691
                (key, self.pk))
692
            raise MultipleObjectsReturned()
693
694
    def set_attr(self, key, value):
695
        """