Skip to content

Commit

Permalink
create a new /explore/hopefuls page
Browse files Browse the repository at this point in the history
  • Loading branch information
Changaco committed Oct 12, 2023
1 parent 03bb903 commit e4a577f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
8 changes: 5 additions & 3 deletions templates/macros/profile-box.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
</div>
% endmacro

% macro profile_box_embedded(participant, summary, nmembers=None)
% macro profile_box_embedded(participant, summary, nmembers=None, numbers=True)
% call profile_box_embedded_wrapper(participant, participant.path(''))
{{ profile_box_embedded_participant(participant, summary, nmembers=nmembers) }}
{{ profile_box_embedded_participant(participant, summary, nmembers=nmembers, numbers=numbers) }}
% endcall
% endmacro

% macro profile_box_embedded_participant(participant, summary, nmembers=None)
% macro profile_box_embedded_participant(participant, summary, nmembers=None, numbers=True)
% set username = participant.username

<h4><a href="/{{ username }}/">{{ username }}</a></h4>

<p class="summary" lang="{{ summary.lang|default('') }}">{{ summary or '' }}</p>

% if numbers
<div class="numbers">
<dl>
<dt>{{ _("Patrons") }}</dt>
Expand All @@ -47,6 +48,7 @@ <h4><a href="/{{ username }}/">{{ username }}</a></h4>
</dl>
% endif
</div>
% endif
% endmacro

% macro profile_box_embedded_elsewhere(
Expand Down
74 changes: 74 additions & 0 deletions www/explore/hopefuls.spt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
[---]

per_page = 18
last_shown = request.qs.get_int('last_shown', default=None)
order = request.qs.get_choice('order', ('asc', 'desc'), default='desc')
op = '<' if order == 'desc' else '>'
participants = website.db.all("""
SELECT p
, ( SELECT (s.content, s.lang)::localized_string
FROM statements s
WHERE s.participant = p.id
AND s.type = 'summary'
ORDER BY s.lang = %s DESC, s.id
LIMIT 1
) AS summary
FROM participants p
WHERE p.kind IN ('individual', 'organization', 'group')
AND p.status = 'active'
AND (p.goal > 0 OR p.goal IS NULL)
AND p.hide_from_lists = 0
AND p.receiving = 0
AND p.payment_providers > 0
AND p.join_time < (current_timestamp - interval '72 hours')
AND coalesce(p.id {} %s, true)
ORDER BY p.id {}
LIMIT %s
""".format(op, order), (locale.language, last_shown, per_page + 1), max_age=0)
has_more = len(participants) > per_page
participants = participants[:per_page]

title = _("Explore")
subhead = _("Hopefuls")

[---] text/html
% from 'templates/macros/icons.html' import glyphicon with context
% from 'templates/macros/pagination.html' import simple_pager with context
% from 'templates/macros/profile-box.html' import profile_box_embedded with context

% extends "templates/layouts/explore.html"

% block content

% if participants
<p>{{ _("This page lists Liberapay users who are hoping to receive their first donations.") }}</p>
<p class="text-warning">{{ glyphicon('warning-sign') }} {{ _(
"Despite our efforts, some of the listed profiles may be spam or fraud."
) }}</p>
% if last_shown is None
<p class="text-info">{{ glyphicon('info-sign') }} {{ _(
"Profiles only start appearing in the list 72 hours after they're created."
) }}</p>
% endif

<div class="inline-boxes">
% for p, summary in participants
{{ profile_box_embedded(p, summary, numbers=False) }}
% endfor
</div>
% if has_more
<ul class="pager">
<li class="next"><a href="{{ request.qs.derive(last_shown=participants[-1][0].id) }}">{{ _(
"Next Page →"
) }}</a></li>
</ul>
% endif
% else
<p>{{ _("Nothing to show.") }}</p>
% endif

% if user.ANON
<p><a class="btn btn-success btn-lg" href="/sign-up">{{ _("Create your account") }}</a></p>
% endif

% endblock

0 comments on commit e4a577f

Please sign in to comment.