Skip to content
This repository was archived by the owner on Nov 4, 2024. It is now read-only.

Commit cd9bf8e

Browse files
authored
api: return fake uptake results (#55)
We are turning off sentry, so uptake will no longer be added to the database.
1 parent 7ca4ecd commit cd9bf8e

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

apps/api/views.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,31 +64,27 @@ def uptake(request):
6464
return xml.error('product and/or os are required GET parameters.',
6565
errno=101)
6666

67+
product_names = None
6768
if product:
6869
if fuzzy:
6970
products = Product.objects.filter(name__icontains=product)
7071
else:
7172
products = Product.objects.filter(name__exact=product)
72-
pids = [p.id for p in products]
73-
if not pids:
73+
product_names = [p.name for p in products]
74+
if not product_names:
7475
return xml.error('No products found', errno=102)
75-
else:
76-
pids = None
7776

77+
os_names = None
7878
if os:
7979
if fuzzy:
8080
oses = OS.objects.filter(name__icontains=os)
8181
else:
8282
oses = OS.objects.filter(name__exact=os)
83-
osids = [o.id for o in oses]
84-
if not osids:
83+
os_names = [o.name for o in oses]
84+
if not os_names:
8585
return xml.error('No OSes found', errno=102)
86-
else:
87-
osids = None
88-
89-
uptake = Location.get_mirror_uptake(products=pids, oses=osids)
9086

91-
xml.prepare_uptake(uptake)
87+
xml.prepare_uptake_fake(products=product_names, oses=os_names)
9288
return xml.render()
9389

9490

@@ -504,6 +500,32 @@ def prepare_locations(self, product, locations):
504500
locnode.appendChild(self.doc.createTextNode(location.path))
505501
prodnode.appendChild(locnode)
506502

503+
def prepare_uptake_fake(self, products, oses):
504+
root = self.doc.createElement('mirror_uptake')
505+
self.doc.appendChild(root)
506+
507+
for product in products:
508+
for os_name in oses:
509+
item = self.doc.createElement('item')
510+
511+
elem = self.doc.createElement('product')
512+
elem.appendChild(self.doc.createTextNode(str(product)))
513+
item.appendChild(elem)
514+
515+
elem = self.doc.createElement('os')
516+
elem.appendChild(self.doc.createTextNode(str(os_name)))
517+
item.appendChild(elem)
518+
519+
elem = self.doc.createElement('available')
520+
elem.appendChild(self.doc.createTextNode(str(2000000)))
521+
item.appendChild(elem)
522+
523+
elem = self.doc.createElement('total')
524+
elem.appendChild(self.doc.createTextNode(str(2000000)))
525+
item.appendChild(elem)
526+
527+
root.appendChild(item)
528+
507529
def prepare_uptake(self, uptake):
508530
"""Product uptake"""
509531
content_map = {'product': 'location__product__name',

0 commit comments

Comments
 (0)