1 | # coding: utf8 |
||
2 | |||
3 | """ |
||
4 | This software is licensed under the Apache 2 license, quoted below. |
||
5 | |||
6 | Copyright 2014 Crystalnix Limited |
||
7 | |||
8 | Licensed under the Apache License, Version 2.0 (the "License"); you may not |
||
9 | use this file except in compliance with the License. You may obtain a copy of |
||
10 | the License at |
||
11 | |||
12 | http://www.apache.org/licenses/LICENSE-2.0 |
||
13 | |||
14 | Unless required by applicable law or agreed to in writing, software |
||
15 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
||
16 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
||
17 | License for the specific language governing permissions and limitations under |
||
18 | the License. |
||
19 | """ |
||
20 | |||
21 | from django.views.generic import ListView, DetailView, RedirectView |
||
22 | from django.http import Http404 |
||
23 | |||
24 | from omaha.models import Application, Version |
||
25 | from sparkle.models import SparkleVersion |
||
26 | |||
27 | |||
28 | class AppListView(ListView): |
||
29 | model = Application |
||
30 | template_name = 'downloads/application_list.html' |
||
31 | |||
32 | |||
33 | class VersionListView(DetailView): |
||
34 | model = Application |
||
35 | template_name = 'downloads/version_list.html' |
||
36 | context_object_name = 'app' |
||
37 | |||
38 | def get_object(self, queryset=None): |
||
39 | return Application.objects.get(name=self.kwargs.get('name')) |
||
40 | |||
41 | def get_context_data(self, **kwargs): |
||
42 | context = super(VersionListView, self).get_context_data(**kwargs) |
||
43 | app = self.get_object() |
||
44 | context['omaha_version_list'] = Version.objects.filter_by_enabled(app=app).order_by('-version') |
||
45 | context['sparkle_version_list'] = SparkleVersion.objects.filter(app=app) |
||
46 | return context |
||
47 | |||
48 | |||
49 | View Code Duplication | class OmahaLatestVersionRedirectView(RedirectView): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
50 | permanent = False |
||
51 | model = Version |
||
52 | |||
53 | def get_redirect_url(self, *args, **kwargs): |
||
54 | app = self.kwargs['app'] |
||
55 | channel = self.kwargs['channel'] |
||
56 | platform = self.kwargs['platform'] |
||
57 | try: |
||
58 | version = self.model.objects.filter_by_enabled(app__name=app, |
||
59 | channel__name=channel, |
||
60 | platform__name=platform).latest('version') |
||
61 | except self.model.DoesNotExist: |
||
62 | raise Http404 |
||
63 | return version.file.url |
||
64 | |||
65 | |||
66 | View Code Duplication | class SparkleLatestVersionRedirectView(RedirectView): |
|
0 ignored issues
–
show
|
|||
67 | permanent = False |
||
68 | model = SparkleVersion |
||
69 | |||
70 | def get_redirect_url(self, *args, **kwargs): |
||
71 | app = self.kwargs['app'] |
||
72 | channel = self.kwargs['channel'] |
||
73 | try: |
||
74 | version = self.model.objects.filter_by_enabled(app__name=app, |
||
75 | channel__name=channel).latest('created') |
||
76 | except self.model.DoesNotExist: |
||
77 | raise Http404 |
||
78 | return version.file.url |
||
79 |