More API testing.
[wolnelektury.git] / src / catalogue / __init__.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 import logging
6 from django.conf import settings as settings
7 from django.utils.module_loading import import_string
8 from catalogue.utils import AppSettings
9
10
11 default_app_config = 'catalogue.apps.CatalogueConfig'
12
13
14 class Settings(AppSettings):
15     """Default settings for catalogue app."""
16     DEFAULT_LANGUAGE = u'pol'
17     # PDF needs TeXML + XeLaTeX, MOBI needs Calibre.
18     DONT_BUILD = {'pdf', 'mobi'}
19     FORMAT_ZIPS = {
20             'epub': 'wolnelektury_pl_epub',
21             'pdf': 'wolnelektury_pl_pdf',
22             'mobi': 'wolnelektury_pl_mobi',
23             'fb2': 'wolnelektury_pl_fb2',
24         }
25
26     REDAKCJA_URL = "http://redakcja.wolnelektury.pl"
27     GOOD_LICENSES = {r'CC BY \d\.\d', r'CC BY-SA \d\.\d'}
28     RELATED_RANDOM_PICTURE_CHANCE = .5
29     GET_MP3_LENGTH = 'catalogue.utils.get_mp3_length'
30
31     def _more_DONT_BUILD(self, value):
32         for format_ in ['cover', 'pdf', 'epub', 'mobi', 'fb2', 'txt']:
33             attname = 'NO_BUILD_%s' % format_.upper()
34             if hasattr(settings, attname):
35                 logging.warn("%s is deprecated, use CATALOGUE_DONT_BUILD instead", attname)
36                 if getattr(settings, attname):
37                     value.add(format_)
38                 else:
39                     value.remove(format_)
40         return value
41
42     def _more_FORMAT_ZIPS(self, value):
43         for format_ in ['epub', 'pdf', 'mobi', 'fb2']:
44             attname = 'ALL_%s_ZIP' % format_.upper()
45             if hasattr(settings, attname):
46                 logging.warn("%s is deprecated, use CATALOGUE_FORMAT_ZIPS[%s] instead", attname, format_)
47                 value[format_] = getattr(settings, attname)
48         return value
49
50     def _more_GET_MP3_LENGTH(self, value):
51         return import_string(value)
52
53
54 app_settings = Settings('CATALOGUE')