implementing new suggestions api

This commit is contained in:
Vinicius Moreira
2019-09-04 15:48:24 -03:00
parent 3275cb4d54
commit 82998d5a99
2 changed files with 10 additions and 4 deletions

View File

@@ -5,9 +5,9 @@ from typing import List, Set, Type
from bauh_api.abstract.controller import SoftwareManager, SearchResult, ApplicationContext
from bauh_api.abstract.disk import DiskCacheLoader
from bauh_api.abstract.handler import ProcessWatcher
from bauh_api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory
from bauh_api.abstract.model import SoftwarePackage, PackageUpdate, PackageHistory, PackageSuggestion
SUGGESTIONS_LIMIT = 6
SUGGESTIONS_LIMIT = 5
class GenericSoftwareManager(SoftwareManager):
@@ -254,9 +254,12 @@ class GenericSoftwareManager(SoftwareManager):
man_sugs = man.list_suggestions(limit)
if man_sugs:
if len(man_sugs) > limit:
man_sugs = man_sugs[0:limit]
suggestions.extend(man_sugs)
def list_suggestions(self, limit: int) -> List[SoftwarePackage]:
def list_suggestions(self, limit: int) -> List[PackageSuggestion]:
if self.managers:
suggestions, threads = [], []
for man in self.managers:
@@ -267,4 +270,7 @@ class GenericSoftwareManager(SoftwareManager):
for t in threads:
t.join()
if suggestions:
suggestions.sort(key=lambda s: s.priority.value, reverse=True)
return suggestions

View File

@@ -385,7 +385,7 @@ class FindSuggestions(AsyncAction):
def run(self):
sugs = self.man.list_suggestions(limit=-1)
self.notify_finished(sugs if sugs is not None else [])
self.notify_finished([s.package for s in sugs] if sugs is not None else [])
class ListWarnings(QThread):