1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from __future__
import unicode_literals
, absolute_import
24 'application/json': 'icon-file-css',
25 'text/css': 'icon-file-css',
26 'text/calendar': 'icon-calendar',
28 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': 'icon-file-word',
29 'application/msword': 'icon-file-word',
31 'application/pdf': 'icon-file-pdf',
33 'application/vnd.ms-excel': 'icon-file-excel',
34 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'icon-file-excel',
36 'application/vnd.ms-powerpoint': 'icon-file-presentation',
37 'application/vnd.openxmlformats-officedocument.presentationml.presentation': 'icon-file-presentation',
39 'application/x-7z-compressed': 'icon-file-zip',
40 'application/x-ace-compressed': 'icon-file-zip',
41 'application/x-rar-compressed': 'icon-file-zip',
42 'application/x-tar': 'icon-file-zip',
43 'application/zip': 'icon-file-zip',
45 'application/xml': 'icon-file-xml',
46 'text/xml': 'icon-file-xml',
47 'text/n3': 'icon-file-xml',
48 'text/html': 'icon-file-xml',
49 'text/sgml': 'icon-file-xml',
51 'text/csv': 'icon-file-spreadsheet',
52 'text/tab-separated-values': 'icon-file-spreadsheet',
57 ('^application/x-bzip', 'icon-file-zip'), # matches bzip and bzip2
59 ('^audio/', 'icon-file-music'),
61 ('^image/', 'icon-file-image'),
63 ('^text/', 'icon-file-text'),
65 ('^video/', 'icon-file-video'),
67 ('application/vnd\.oasis\.opendocument\.', 'icon-file-openoffice'),
69 ('.+/.+\+xml$', 'icon-file-xml'),
71 ('.+/.+\+json$', 'icon-file-css')
73 _regex_mapping
= [(re
.compile(regex
), icon
) for regex
, icon
in _regex_mapping
]
76 def icon_from_mimetype(mimetype
, default_icon
='icon-file-filled'):
77 """Gets the most suitable icon for a MIME type."""
78 mimetype
= mimetype
.lower()
80 return _exact_mapping
[mimetype
]
82 for pattern
, icon
in _regex_mapping
:
83 if pattern
.search(mimetype
):
88 def register_custom_mimetypes():
89 """Registers additional extension/mimetype mappings.
91 This is used for mimetypes/extensions that are not in the official
92 mapping but useful, e.g. because indico has special handling for
95 mimetypes
.add_type(b
'text/markdown', b
'.md')