forked from python/pythondotorg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.py
49 lines (36 loc) · 1.33 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from django.conf import settings
from django.views.generic.base import RedirectView, TemplateView
from codesamples.models import CodeSample
from downloads.models import Release
class IndexView(TemplateView):
template_name = "python/index.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'code_samples': CodeSample.objects.published()[:5],
})
return context
class AuthenticatedView(TemplateView):
template_name = "includes/authenticated.html"
class DocumentationIndexView(TemplateView):
template_name = 'python/documentation.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'latest_python2': Release.objects.latest_python2(),
'latest_python3': Release.objects.latest_python3(),
})
return context
class MediaMigrationView(RedirectView):
prefix = None
permanent = True
query_string = False
def get_redirect_url(self, *args, **kwargs):
image_path = kwargs['url']
if self.prefix:
image_path = '/'.join([self.prefix, image_path])
return '/'.join([
settings.AWS_S3_ENDPOINT_URL,
settings.AWS_STORAGE_BUCKET_NAME,
image_path,
])