2011-11-20 22:12:54 +04:00
|
|
|
from django.shortcuts import get_object_or_404, redirect
|
2011-07-30 04:50:33 +04:00
|
|
|
|
2011-09-20 21:45:35 +04:00
|
|
|
import jingo
|
2011-10-29 03:20:22 +04:00
|
|
|
from mobility.decorators import mobile_template
|
2011-09-20 21:45:35 +04:00
|
|
|
from tower import ugettext_lazy as _lazy
|
|
|
|
|
|
|
|
import amo
|
2011-10-26 01:20:09 +04:00
|
|
|
from amo.decorators import json_view, login_required, post_required
|
2011-11-20 22:12:54 +04:00
|
|
|
from amo.helpers import loc
|
2011-09-20 21:45:35 +04:00
|
|
|
from amo.utils import paginate
|
2011-10-26 01:20:09 +04:00
|
|
|
from addons.decorators import addon_view
|
2011-07-30 04:50:33 +04:00
|
|
|
import addons.views
|
2011-12-01 02:32:48 +04:00
|
|
|
from webapps.models import Installed
|
2011-09-20 21:45:35 +04:00
|
|
|
import search.views
|
2011-07-30 04:50:33 +04:00
|
|
|
|
2011-10-26 01:20:09 +04:00
|
|
|
from addons.models import Category
|
2011-10-16 15:00:37 +04:00
|
|
|
from browse.views import category_landing, CategoryLandingFilter
|
2011-10-14 03:31:27 +04:00
|
|
|
from sharing.views import share as share_redirect
|
2011-07-30 04:50:33 +04:00
|
|
|
from .models import Webapp
|
|
|
|
|
2011-09-20 21:45:35 +04:00
|
|
|
TYPE = amo.ADDON_WEBAPP
|
|
|
|
|
|
|
|
|
|
|
|
def es_app_list(request):
|
|
|
|
ctx = search.views.app_search_query(request)
|
|
|
|
return jingo.render(request, 'webapps/listing.html', ctx)
|
|
|
|
|
|
|
|
|
2011-11-20 22:12:54 +04:00
|
|
|
# TODO(cvan): Make a mobile apps homepage when we know what we want.
|
|
|
|
#@mobile_template('webapps/{mobile/}home.html')
|
2011-09-20 21:45:35 +04:00
|
|
|
def app_home(request):
|
2011-11-20 22:12:54 +04:00
|
|
|
if request.MOBILE:
|
|
|
|
return redirect('apps.list')
|
|
|
|
|
|
|
|
src = 'cb-btn-home'
|
|
|
|
dl_src = 'cb-dl-home'
|
|
|
|
|
|
|
|
ctx = {
|
|
|
|
'section': amo.ADDON_SLUGS[TYPE],
|
|
|
|
'addon_type': TYPE,
|
2011-11-22 03:22:08 +04:00
|
|
|
'free': Webapp.objects.top_free()[:18],
|
|
|
|
'paid': Webapp.objects.top_paid()[:18],
|
2011-11-20 22:12:54 +04:00
|
|
|
'src': src,
|
|
|
|
'dl_src': dl_src,
|
|
|
|
}
|
|
|
|
return jingo.render(request, 'webapps/home.html', ctx)
|
2011-09-20 21:45:35 +04:00
|
|
|
|
|
|
|
|
|
|
|
class AppCategoryLandingFilter(CategoryLandingFilter):
|
|
|
|
|
2011-10-16 15:00:37 +04:00
|
|
|
opts = (('downloads', _lazy(u'Most Popular')),
|
2011-12-02 04:34:13 +04:00
|
|
|
('rating', _lazy(u'Highest Rated')),
|
2011-10-16 15:00:37 +04:00
|
|
|
('featured', _lazy(u'Featured')))
|
|
|
|
|
|
|
|
|
|
|
|
class AppFilter(addons.views.BaseFilter):
|
|
|
|
opts = (('downloads', _lazy(u'Weekly Downloads')),
|
2011-11-20 22:12:54 +04:00
|
|
|
('free', loc(u'Top Free')),
|
|
|
|
('paid', loc(u'Top Paid')),
|
2011-12-02 04:34:13 +04:00
|
|
|
('rating', _lazy(u'Highest Rated')))
|
2011-11-20 22:12:54 +04:00
|
|
|
extras = (('created', _lazy(u'Newest')),
|
|
|
|
('name', _lazy(u'Name')),
|
2011-12-06 05:41:17 +04:00
|
|
|
('price', loc(u'Price')))
|
2011-10-16 15:00:37 +04:00
|
|
|
|
|
|
|
|
|
|
|
def app_listing(request):
|
|
|
|
qs = Webapp.objects.listed()
|
|
|
|
filter = AppFilter(request, qs, 'sort', default='downloads', model=Webapp)
|
|
|
|
return filter.qs, filter
|
2011-09-20 21:45:35 +04:00
|
|
|
|
|
|
|
|
2011-10-29 03:20:22 +04:00
|
|
|
@mobile_template('browse/{mobile/}extensions.html')
|
|
|
|
def app_list(request, category=None, template=None):
|
2011-09-20 21:45:35 +04:00
|
|
|
if category is not None:
|
|
|
|
q = Category.objects.filter(type=TYPE)
|
|
|
|
category = get_object_or_404(q, slug=category)
|
|
|
|
|
|
|
|
sort = request.GET.get('sort')
|
2011-12-06 05:41:17 +04:00
|
|
|
# TODO: Uncomment this when we have apps category landing pages.
|
|
|
|
#if not sort and not request.MOBILE and category and category.count > 4:
|
|
|
|
# return category_landing(request, category, TYPE,
|
|
|
|
# AppCategoryLandingFilter)
|
2011-09-20 21:45:35 +04:00
|
|
|
|
2011-10-16 15:00:37 +04:00
|
|
|
addons, filter = app_listing(request)
|
2011-09-20 21:45:35 +04:00
|
|
|
sorting = filter.field
|
|
|
|
src = 'cb-btn-%s' % sorting
|
|
|
|
dl_src = 'cb-dl-%s' % sorting
|
|
|
|
|
|
|
|
if category:
|
|
|
|
addons = addons.filter(categories__id=category.id)
|
|
|
|
|
|
|
|
addons = paginate(request, addons, count=addons.count())
|
|
|
|
ctx = {'section': amo.ADDON_SLUGS[TYPE], 'addon_type': TYPE,
|
|
|
|
'category': category, 'addons': addons, 'filter': filter,
|
|
|
|
'sorting': sorting, 'sort_opts': filter.opts, 'src': src,
|
2011-11-20 22:12:54 +04:00
|
|
|
'dl_src': dl_src}
|
2011-10-29 03:20:22 +04:00
|
|
|
return jingo.render(request, template, ctx)
|
2011-09-20 21:45:35 +04:00
|
|
|
|
2011-07-30 04:50:33 +04:00
|
|
|
|
2011-10-14 03:31:27 +04:00
|
|
|
def share(request, app_slug):
|
|
|
|
webapp = get_object_or_404(Webapp, app_slug=app_slug)
|
|
|
|
return share_redirect(request, webapp, webapp.name, webapp.summary)
|
2011-10-26 01:20:09 +04:00
|
|
|
|
|
|
|
|
|
|
|
@json_view
|
|
|
|
@addon_view
|
|
|
|
@login_required
|
|
|
|
@post_required
|
|
|
|
def record(request, addon):
|
2011-11-03 22:02:17 +04:00
|
|
|
if addon.is_webapp():
|
2011-12-01 02:32:48 +04:00
|
|
|
installed, c = Installed.objects.safer_get_or_create(addon=addon,
|
|
|
|
user=request.amo_user)
|
2011-11-03 22:02:17 +04:00
|
|
|
return {'addon': addon.pk,
|
|
|
|
'receipt': installed.receipt if installed else ''}
|