diff --git a/gratipay/utils/listings.py b/gratipay/utils/listings.py new file mode 100644 index 0000000000..76879cf466 --- /dev/null +++ b/gratipay/utils/listings.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + + +class FakeProject(object): + + def __init__(self, website, package): + self.website = website + self.package = package + self.name = package.name + self.url_path = '/on/{}/{}/'.format(package.package_manager, package.name) + + def get_image_url(self, size): + assert size in ('large', 'small'), size + return self.website.asset('package-default-{}.png'.format(size)) + + +def with_unclaimed_packages_wrapped(website, projects_and_unclaimed_packages): + out = [] + for project, unclaimed_package in projects_and_unclaimed_packages: + if unclaimed_package: + assert project is None + project = FakeProject(website, unclaimed_package) + out.append(project) + return out diff --git a/gratipay/utils/tabs.py b/gratipay/utils/tabs.py new file mode 100644 index 0000000000..c6e135c8c3 --- /dev/null +++ b/gratipay/utils/tabs.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + +from collections import OrderedDict + + +def make(htmlfunc, var, current, *names): + """Helper to spit out a struct for rendering tabs (see templates/nav-tabs.html). + """ + tabs = OrderedDict() + tabs[names[0]] = {} + for name in names[1:]: + tabs[name] = {var: name} + for name, tab in tabs.iteritems(): + tab['link'] = '?{}={}'.format(var, tab[var]) if var in tab else '.' + tab['is_selected'] = (tab.get(var) == current) + tab['html'] = htmlfunc(name, tab) + return list(tabs.values()) diff --git a/scss/elements/buttons-knobs.scss b/scss/elements/buttons-knobs.scss index d31c63f8a8..843fd1ea78 100644 --- a/scss/elements/buttons-knobs.scss +++ b/scss/elements/buttons-knobs.scss @@ -58,7 +58,7 @@ button.selected:hover:not(:disabled), button.selected.drag, .important-button { - margin: 38px auto 30px; + margin: 30px auto 30px; text-align: center; button.large { @@ -81,5 +81,3 @@ button.selected:hover:not(:disabled), button.selected.drag, left: 5%; } } - - diff --git a/templates/nav-tabs.html b/templates/nav-tabs.html new file mode 100644 index 0000000000..127e6b2b20 --- /dev/null +++ b/templates/nav-tabs.html @@ -0,0 +1,11 @@ +{% macro nav_tabs(tabs) %} +
+{% endmacro %} diff --git a/www/index.html.spt b/www/index.html.spt index c366442b89..fab7b8abfe 100644 --- a/www/index.html.spt +++ b/www/index.html.spt @@ -1,5 +1,5 @@ from collections import OrderedDict -from gratipay.utils import get_featured_projects, icons +from gratipay.utils import get_featured_projects, icons, tabs import random [---] @@ -17,9 +17,9 @@ status_filter_active = (status_filter and status_filter in ['unreviewed', 'rejec page = request.qs.get('page', 1) try: - page = int(page) + page = int(page) except ValueError: - page = 1 + page = 1 if status_filter_active: status_value = { @@ -54,30 +54,21 @@ if status_filter_active: else: projects = get_featured_projects(website.db) - -tabs = OrderedDict() -tabs['featured'] = {} -tabs['approved'] = {'status_filter': 'approved'} -tabs['unreviewed'] = {'status_filter': 'unreviewed'} -tabs['rejected'] = {'status_filter': 'rejected'} - -for key, tab in tabs.iteritems(): - if tab.get('status_filter'): - tab['link'] = '?status=%s' % tab['status_filter'] - else: - tab['link'] = '.' - tab['is_selected'] = (tab.get('status_filter') == status_filter) - tab['title'] = i18ned_statuses[key] +def tab_html(key, tab): status = icons.REVIEW_MAP[key] - tab['html'] = ' {}'.format( status - , icons.STATUS_ICONS[status] - , tab['title'] - ) + return ' {}'.format( status + , icons.STATUS_ICONS[status] + , i18ned_statuses[key] + ) + +tabs = tabs.make(tab_html, 'status', status_filter, + 'featured', 'approved', 'unreviewed', 'rejected') title = _("Projects") suppress_sidebar = True page_id = "homepage" [---] +{% from "templates/nav-tabs.html" import nav_tabs with context %} {% extends "templates/base.html" %} {% block head_early %} {% if website.optimizely_id and request.headers.get('DNT') != '1' %} @@ -104,16 +95,7 @@ page_id = "homepage" - +{{ nav_tabs(tabs) }}