From: Radek Czajka Date: Wed, 16 Oct 2019 10:47:12 +0000 (+0200) Subject: Minor fixes. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/ec4c9d6d4e2ce8c31123c48fb140b1d75e762155 Minor fixes. --- diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 4a9f0ccb4..08c6882b0 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,7 +1,7 @@ -i https://py.mdrn.pl/simple/ # django -Django==2.2.5 +Django==2.2.6 fnpdjango==0.4 docutils diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 7f337418b..d17ead0e6 100644 --- a/src/catalogue/utils.py +++ b/src/catalogue/utils.py @@ -185,56 +185,6 @@ class MultiQuerySet(object): continue -class SortedMultiQuerySet(MultiQuerySet): - def __init__(self, *args, **kwargs): - self.order_by = kwargs.pop('order_by', None) - self.sortfn = kwargs.pop('sortfn', None) - if self.order_by is not None: - self.sortfn = lambda a, b: cmp((getattr(a, f) for f in self.order_by), - (getattr(b, f) for f in self.order_by)) - super(SortedMultiQuerySet, self).__init__(*args, **kwargs) - - def __getitem__(self, item): - sort_heads = [0] * len(self.querysets) - try: - (offset, stop, step) = item.indices(self.count()) - except AttributeError: - # it's not a slice - make it one - return self[item:item + 1][0] - items = [] - total_len = stop - offset - skipped = 0 - i_s = range(len(sort_heads)) - - while len(items) < total_len: - candidate = None - candidate_i = None - for i in i_s: - def get_next(): - return self.querysets[i][sort_heads[i]] - try: - if candidate is None: - candidate = get_next() - candidate_i = i - else: - competitor = get_next() - if self.sortfn(candidate, competitor) > 0: - candidate = competitor - candidate_i = i - except IndexError: - continue # continue next sort_head - # we have no more elements: - if candidate is None: - break - sort_heads[candidate_i] += 1 - if skipped < offset: - skipped += 1 - continue # continue next item - items.append(candidate) - - return items - - def truncate_html_words(s, num, end_text='...'): """Truncates HTML to a certain number of words (not counting tags and comments). Closes opened tags if they were correctly closed in the given diff --git a/src/club/models.py b/src/club/models.py index 40a413849..62c1069f2 100644 --- a/src/club/models.py +++ b/src/club/models.py @@ -205,11 +205,12 @@ class PayUOrder(payu_models.Order): def status_updated(self): if self.status == 'COMPLETED': since = self.schedule.expires_at - if since is None or since < self.received_at: - since = self.received_at + n = now() + if since is None or since < n: + since = n new_exp = self.schedule.plan.get_next_installment(since) if self.schedule.payed_at is None: - self.schedule.payed_at = self.received_at + self.schedule.payed_at = n if self.schedule.expires_at is None or self.schedule.expires_at < new_exp: self.schedule.expires_at = new_exp self.schedule.save() diff --git a/src/search/index.py b/src/search/index.py index e471cd642..2d84cb4d7 100644 --- a/src/search/index.py +++ b/src/search/index.py @@ -665,20 +665,18 @@ class SearchResult(object): lambda f: f[self.POSITION][self.POSITION_INDEX] <= s[self.POSITION][self.POSITION_INDEX] < f[self.POSITION][self.POSITION_INDEX] + f[self.POSITION][self.POSITION_SPAN], frags))), sect) - def remove_duplicates(lst, keyfn, compare): + def remove_duplicates(lst, keyfn, larger): els = {} for e in lst: eif = keyfn(e) if eif in els: - if compare(els[eif], e) >= 1: + if larger(els[eif], e): continue els[eif] = e return els.values() # remove fragments with duplicated fid's and duplicated snippets - frags = remove_duplicates(frags, lambda f: f[self.FRAGMENT], lambda a, b: cmp(a[self.SCORE], b[self.SCORE])) - # frags = remove_duplicates(frags, lambda f: f[OTHER]['snippet_pos'] and f[OTHER]['snippet_pos'] or f[FRAGMENT], - # lambda a, b: cmp(a[SCORE], b[SCORE])) + frags = remove_duplicates(frags, lambda f: f[self.FRAGMENT], lambda a, b: a[self.SCORE] > b[self.SCORE]) # remove duplicate sections sections = {}