1
0
mirror of https://github.com/peeringdb/peeringdb.git synced 2024-05-11 05:55:09 +00:00

net count in advanced search and api/ix (#66)

This commit is contained in:
Stefan Pratter
2019-05-02 18:03:21 +00:00
parent e49d7c9b68
commit e19f0760bd
9 changed files with 110 additions and 17 deletions

View File

@@ -1166,6 +1166,40 @@ class InternetExchange(pdb_models.InternetExchangeBase):
return qset.filter(id__in=shared_exchanges)
@classmethod
def filter_net_count(cls, filt=None, value=None, qset=None):
"""
Filter ix queryset by network count value
Keyword Arguments:
- filt<str>: filter to apply: None, 'lt', 'gt', 'lte', 'gte'
- value<int>: value to filter by
- qset
Returns:
InternetExchange queryset
"""
if not qset:
qset = cls.objects.filter(status="ok")
value = int(value)
if filt == "lt":
exchanges = [ix.id for ix in qset if ix.network_count < value]
elif filt == "gt":
exchanges = [ix.id for ix in qset if ix.network_count > value]
elif filt == "gte":
exchanges = [ix.id for ix in qset if ix.network_count >= value]
elif filt == "lte":
exchanges = [ix.id for ix in qset if ix.network_count <= value]
else:
exchanges = [ix.id for ix in qset if ix.network_count == value]
return qset.filter(pk__in=exchanges)
@classmethod
def nsp_namespace_in_list(cls):
return str(cls.id)
@@ -1202,7 +1236,9 @@ class InternetExchange(pdb_models.InternetExchangeBase):
"""
Returns count of networks at this exchange
"""
return len(self.networks)
qset = NetworkIXLan.objects.filter(ixlan__ix_id=self.id, status="ok")
qset = qset.values("network_id").annotate(count=models.Count("network_id"))
return len(qset)
@property
def ixlan_set_active(self):