1# -*- coding: utf-8 -*-
3# Copyright 2018 The Distro Tracker Developers
4# See the COPYRIGHT file at the top-level directory of this distribution and
5# at https://deb.li/DTAuthors
6#
7# This file is part of Distro Tracker. It is subject to the license terms
8# in the LICENSE file found in the top-level directory of this
9# distribution and at https://deb.li/DTLicense. No part of Distro Tracker,
10# including this file, may be copied, modified, propagated, or distributed
11# except according to the terms contained in the LICENSE file.
12"""Debian specific fields for package tables."""
14from django.db.models import Prefetch
16from distro_tracker.core.models import (
17 PackageData,
18)
19from distro_tracker.core.package_tables import (
20 BaseTableField,
21)
24class UpstreamTableField(BaseTableField):
25 """
26 This table field displays information regarding the upstream version.
27 It displays the package's upstream version with a link to the source code
28 """
29 column_name = 'Upstream'
30 slug = 'debian_upstream'
31 template_name = 'debian/package-table-fields/upstream.html'
32 prefetch_related_lookups = [
33 Prefetch(
34 'data',
35 queryset=PackageData.objects.filter(key='upstream-watch-status'),
36 to_attr='watch_status'
37 ),
38 ]
40 def context(self, package):
41 try:
42 watch_data = package.watch_status[0]
43 return watch_data.value
44 except IndexError:
45 # There is no upstream watch data for the package
46 return