1# Copyright 2013 The Distro Tracker Developers
2# See the COPYRIGHT file at the top-level directory of this distribution and
3# at https://deb.li/DTAuthors
4#
5# This file is part of Distro Tracker. It is subject to the license terms
6# in the LICENSE file found in the top-level directory of this
7# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
8# including this file, may be copied, modified, propagated, or distributed
9# except according to the terms contained in the LICENSE file.
10"""
11Implements the classes necessary to place the links to extracted source
12files in the :class:`distro_tracker.core.panels.VersionedLinks` panel.
13"""
14from distro_tracker.core.models import ExtractedSourceFile
15from distro_tracker.core.panels import VersionedLinks
16from distro_tracker.core.templatetags.distro_tracker_extras import octicon
19class SourceFilesLinkProvider(VersionedLinks.LinkProvider):
20 """
21 Provides the links to extracted source files which are placed in the
22 :class:`distro_tracker.core.panels.VersionedLinks` panel.
23 """
24 icons = [
25 octicon('tasklist', 'changelog'),
26 octicon('law', 'copyright'),
27 octicon('tools', 'rules'),
28 octicon('package', 'control'),
29 ]
31 _file_names = [
32 'changelog',
33 'copyright',
34 'rules',
35 'control',
36 ]
38 def get_link_for_icon(self, package, index):
39 file_name = self._file_names[index]
40 try:
41 extracted = package.extracted_source_files.get(name=file_name)
42 except ExtractedSourceFile.DoesNotExist:
43 return
45 return extracted.extracted_file.url