X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/6d42bc478e3d1bd90eb294464748c21e4de0fc63..5ac6f14db010bbfbcf39190d0b639a47ab1c89d3:/src/catalogue/utils.py diff --git a/src/catalogue/utils.py b/src/catalogue/utils.py index 7f337418b..ca8ec0dc2 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 @@ -353,7 +303,7 @@ def delete_from_cache_by_language(cache, key_template): def gallery_path(slug): - return os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, slug) + return os.path.join(settings.MEDIA_ROOT, settings.IMAGE_DIR, slug) + '/' def gallery_url(slug): @@ -363,3 +313,9 @@ def gallery_url(slug): def get_mp3_length(path): from mutagen.mp3 import MP3 return int(MP3(path).info.length) + + +def set_file_permissions(self, fieldfile): + if fieldfile.instance.preview: + fieldfile.set_readable(False) +