feeds: create obj to keep FeedItems unique

master
pictuga 2018-10-31 21:47:19 +01:00
parent cfd758b6b5
commit 081d560bc4
1 changed files with 18 additions and 0 deletions

View File

@ -303,6 +303,24 @@ class FeedList(object):
def __len__(self): def __len__(self):
return len(self.getter()) return len(self.getter())
class Uniq(object):
_map = {}
_id = None
def __new__(cls, *args, **kwargs):
# check if an item was already created for it
# if so, reuse it
# if not, create a new one
tmp_id = cls._gen_id(*args, **kwargs)
if tmp_id is not None and tmp_id in cls._map:
return cls._map[tmp_id]
else:
obj = object.__new__(cls, *args, **kwargs)
obj.__init__(*args, **kwargs)
cls._map[obj._id] = obj
return obj
class FeedListDescriptor(object): class FeedListDescriptor(object):
""" """