mobile collection listing (bug 627509)

This commit is contained in:
Jeff Balogh 2011-02-01 10:55:40 -08:00
Родитель 9c063e40e3
Коммит e54a83f61c
8 изменённых файлов: 81 добавлений и 16 удалений

Просмотреть файл

@ -74,6 +74,7 @@ def url(viewname, *args, **kwargs):
kwargs=kwargs,
add_prefix=add_prefix))
@register.function
def services_url(viewname, *args, **kwargs):
"""Helper for ``url`` with host=SERVICES_URL."""
@ -292,7 +293,7 @@ def license_link(license):
if not license.builtin:
return _('Custom License')
t = env.get_template('amo/license_link.html').render({'license':license})
t = env.get_template('amo/license_link.html').render({'license': license})
return jinja2.Markup(t)
@ -327,3 +328,8 @@ def recaptcha(context, form):
d = dict(context.items())
d.update(form=form)
return d
@register.inclusion_tag('amo/mobile/sort_by.html')
def mobile_sort_by(base_url, options, selected):
return locals()

Просмотреть файл

@ -0,0 +1,10 @@
<div id="sort-menu">
<span>{{ _('Sort by:') }}</span>
<select>
{% for value, title in options %}
<option data-url="{{ base_url|urlparams(sort=value) }}"
{% if value == selected %}selected{% endif %}>
{{ title }}</option>
{% endfor %}
</select>
</div>

Просмотреть файл

@ -152,3 +152,8 @@ def collection_widgets(context, collection, condensed=False):
})
t = env.get_template('bandwagon/collection_widgets.html').render(**c)
return jinja2.Markup(t)
@register.inclusion_tag('bandwagon/mobile/listing_items.html')
def collection_listing_items_mobile(collections):
return locals()

Просмотреть файл

@ -0,0 +1,24 @@
{% extends "mobile/base.html" %}
{% block title %}{{ page_title(_('Collections')) }}{% endblock %}
{% block page %}
<hgroup>
<h2>{{ _('COLLECTIONS') }}</h2>
<h3>{{ _('Groups of related add-ons that anyone can create.') }}</h3>
</hgroup>
<div class="menu">
{% with base_url = url('collections.list') %}
{{ mobile_sort_by(base_url, filter.opts, filter.field) }}
{% endwith %}
</div>
<div class="collection-listing">
<ul class="listview">
{{ collection_listing_items_mobile(collections.object_list) }}
</ul>
</div>
{{ collections|mobile_paginator }}
{% endblock %}

Просмотреть файл

@ -0,0 +1,18 @@
{% cache collections %}
{% for collection in collections %}
<li class="item">
<a href="{{ collection.get_url_path() }}">
<img class="icon" width="32" height="32" src="{{ collection.icon_url }}">
<h3>{{ collection.name }}</h3>
<details>
<span class="desc">{{ collection.description|strip_html()|truncate(250) }}</span>
{% trans cnt=collection.subscribers, num=collection.subscribers|numberfmt %}
<span>{{ num }}</span> follower
{% pluralize %}
<span>{{ num }}</span> followers
{% endtrans %}
</details>
</a>
</li>
{% endfor %}
{% endcache %}

Просмотреть файл

@ -13,6 +13,7 @@ import test_utils
import amo
from addons.models import Addon
from addons.tests.test_views import TestMobile
from amo.urlresolvers import reverse
from amo.utils import urlparams
from bandwagon import forms
@ -826,3 +827,11 @@ class TestFeeds(test_utils.TestCase):
eq_(r.status_code, 301)
loc = r['Location']
assert loc.endswith(self.feed_url), loc
class TestMobileCollections(TestMobile):
def test_collections(self):
r = self.client.get(reverse('collections.list'))
eq_(r.status_code, 200)
self.assertTemplateUsed(r, 'bandwagon/mobile/collection_listing.html')

Просмотреть файл

@ -13,7 +13,8 @@ from tower import ugettext_lazy as _lazy, ugettext as _
from amo import messages
import amo.utils
import sharing.views
from amo.decorators import login_required, post_required, json_view, write
from amo.decorators import (login_required, post_required, json_view, write,
mobile_template)
from amo.urlresolvers import reverse
from access import acl
from addons.models import Addon
@ -102,11 +103,12 @@ def render(request, template, data={}, extra={}):
return jingo.render(request, template, data, **extra)
def collection_listing(request, base=None, extra={}):
@mobile_template('bandwagon/{mobile/}collection_listing.html')
def collection_listing(request, base=None, extra={}, template=None):
filter = get_filter(request, base)
collections = amo.utils.paginate(request, filter.qs)
votes = get_votes(request, collections.object_list)
return render(request, 'bandwagon/collection_listing.html',
return render(request, template,
dict(collections=collections, filter=filter,
collection_votes=votes, **extra))

Просмотреть файл

@ -9,9 +9,9 @@
{% endblock %}
{% if category %}
{% set url_base = url('browse.extensions', category.slug) %}
{% set base_url = url('browse.extensions', category.slug) %}
{% else %}
{% set url_base = url('browse.extensions') %}
{% set base_url = url('browse.extensions') %}
{% endif %}
{% block page %}
@ -21,16 +21,7 @@
<h2>{{ _('Extensions') }}</h2>
{% endif %}
<div class="menu">
<div id="sort-menu">
<span>{{ _('Sort by:') }}</span>
<select>
{% for value, title in sort_opts %}
<option data-url="{{ url_base|urlparams(sort=value) }}"
{% if value == sorting %}selected{% endif %}>
{{ title }}</option>
{% endfor %}
</select>
</div>
{{ mobile_sort_by(base_url, sort_opts, sorting) }}
</div>
<div class="addon-listing">