1# Copyright 2014 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"""Django views for the distro_tracker.derivative application.""" 

11 

12from django.shortcuts import get_list_or_404, get_object_or_404, render 

13 

14from distro_tracker.core.models import Repository, RepositoryRelation 

15 

16from .utils import CATEGORIES_VERSION_COMPARISON, compare_repositories 

17 

18 

19def index(request): 

20 """Default view.""" 

21 list_derivatives = get_list_or_404(RepositoryRelation, name='derivative') 

22 return render(request, 'derivative/index.html', 

23 {'list_derivatives': list_derivatives}) 

24 

25 

26def comparison(request, distribution): 

27 """View comparing a distribution with its parent distribution.""" 

28 repository = get_object_or_404(Repository, shorthand=distribution) 

29 relation = get_object_or_404(repository.relations, name='derivative') 

30 pkglist = compare_repositories(repository, relation.target_repository) 

31 context = { 

32 'pkglist': pkglist, 

33 'categories': CATEGORIES_VERSION_COMPARISON, 

34 'repository': repository, 

35 'target_repository': relation.target_repository, 

36 } 

37 return render(request, 'derivative/comparison.html', context)