Minor fixes.
authorRadek Czajka <rczajka@rczajka.pl>
Wed, 16 Oct 2019 10:47:12 +0000 (12:47 +0200)
committerRadek Czajka <rczajka@rczajka.pl>
Wed, 16 Oct 2019 10:47:12 +0000 (12:47 +0200)
requirements/requirements.txt
src/catalogue/utils.py
src/club/models.py
src/search/index.py

index 4a9f0cc..08c6882 100644 (file)
@@ -1,7 +1,7 @@
 -i https://py.mdrn.pl/simple/
 
 # django
-Django==2.2.5
+Django==2.2.6
 fnpdjango==0.4
 docutils
 
index 7f33741..d17ead0 100644 (file)
@@ -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
index 40a4138..62c1069 100644 (file)
@@ -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()
index e471cd6..2d84cb4 100644 (file)
@@ -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 = {}