This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 679
/
views.py
159 lines (114 loc) · 4.74 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import time
import basket
from basket.base import BasketException
from django.conf import settings
from django.http import HttpResponseServerError
from django.shortcuts import render
import constance.config
from waffle.decorators import waffle_switch
from devmo import (SECTION_USAGE, SECTION_ADDONS, SECTION_APPS, SECTION_MOBILE,
SECTION_WEB, SECTION_MOZILLA)
from feeder.models import Bundle, Feed
from demos.models import Submission
from landing.forms import SubscriptionForm
def home(request):
"""Home page."""
demos = (Submission.objects.all_sorted('upandcoming')
.exclude(hidden=True))[:5]
tweets = []
for section in SECTION_USAGE:
tweets += Bundle.objects.recent_entries(section.twitter)[:2]
tweets.sort(key=lambda t: t.last_published, reverse=True)
updates = []
for s in SECTION_USAGE:
updates += Bundle.objects.recent_entries(s.updates)[:1]
return render(request, 'landing/home.html',
{'demos': demos, 'updates': updates, 'tweets': tweets})
def addons(request):
"""Add-ons landing page."""
extra = {
'discussions': Feed.objects.get(
shortname='amo-forums').entries.all()[:4],
'comments': Feed.objects.get(
shortname='amo-blog-comments').entries.all()[:4],
}
return common_landing(request, section=SECTION_ADDONS, extra=extra)
def mozilla(request):
"""Mozilla Applications landing page."""
return common_landing(request, section=SECTION_MOZILLA)
def search(request):
"""Google Custom Search results page."""
query = request.GET.get('q', '')
return render(request, 'landing/searchresults.html',
{'query': query})
def mobile(request):
"""Mobile landing page."""
return common_landing(request, section=SECTION_MOBILE)
def web(request):
"""Web landing page."""
return common_landing(request, section=SECTION_WEB)
def apps(request):
"""Web landing page."""
return common_landing(request, section=SECTION_APPS,
extra={'form': SubscriptionForm()})
def apps_newsletter(request):
if request.method == 'POST':
form = SubscriptionForm(request.locale, data=request.POST)
context = {'form': form}
if form.is_valid():
optin = 'N'
if request.locale == 'en-US':
optin = 'Y'
for i in range(constance.config.BASKET_RETRIES):
try:
result = basket.subscribe(email=form.cleaned_data['email'],
newsletters=settings.BASKET_APPS_NEWSLETTER,
country=form.cleaned_data['country'],
format=form.cleaned_data['format'],
lang=request.locale,
optin=optin)
if result.get('status') != 'error':
break
except BasketException:
if i == constance.config.BASKET_RETRIES:
return HttpResponseServerError()
else:
time.sleep(constance.config.BASKET_RETRY_WAIT * i)
del context['form']
else:
context = {'form': SubscriptionForm(request.locale)}
return render(request, 'landing/apps_newsletter.html', context)
def learn(request):
"""Learn landing page."""
return render(request, 'landing/learn.html')
def learn_html(request):
"""HTML landing page."""
return render(request, 'landing/learn_html.html')
@waffle_switch('html5_landing')
def learn_html5(request):
"""HTML5 landing page."""
demos = (Submission.objects.all_sorted()
.filter(featured=True, taggit_tags__name__in=['tech:html5']))[:6]
return render(request, 'landing/learn_html5.html', {'demos': demos})
def learn_css(request):
"""CSS landing page."""
return render(request, 'landing/learn_css.html')
def learn_javascript(request):
"""JavaScript landing page."""
return render(request, 'landing/learn_javascript.html')
def promote_buttons(request):
"""Bug 646192: MDN affiliate buttons"""
return render(request, 'landing/promote_buttons.html')
def forum_archive(request):
"""Forum Archive from phpbb-static landing page."""
return render(request, 'landing/forum_archive.html')
def common_landing(request, section=None, extra=None):
"""Common code for landing pages."""
if not section:
raise NotImplementedError
updates = Bundle.objects.recent_entries(section.updates)[:5]
tweets = Bundle.objects.recent_entries(section.twitter)[:8]
data = {'updates': updates, 'tweets': tweets}
if extra:
data.update(extra)
return render(request, 'landing/%s.html' % section.short, data)