Skip to content

Commit

Permalink
[#8540] wiki pages' recent sort by mod_date; simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
brondsem committed Mar 28, 2024
1 parent f797888 commit 114c7be
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
6 changes: 1 addition & 5 deletions ForgeWiki/forgewiki/templates/wiki/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@
{% else %}
<td></td>
{% endif %}
{% if 'updated' in page %}
<td>{{abbr_date(page['updated'])}}</td>
{% else %}
<td></td>
{% endif %}
<td>{{abbr_date(page['mod_date'])}}</td>
</tr>
{% endfor %}
</tbody>
Expand Down
16 changes: 4 additions & 12 deletions ForgeWiki/forgewiki/wiki_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,24 +477,16 @@ def browse_pages(self, sort='alpha', show_deleted=False, page=0, limit=None, **k
q = WM.Page.query.find(criteria)
if sort == 'alpha':
q = q.sort('title')
elif sort == 'recent':
q = q.sort('mod_date', -1)
count = q.count()
q = q.skip(start).limit(int(limit))
for page in q:
recent_edit = page.history().first()
p = dict(title=page.title, url=page.url(), deleted=page.deleted)
p = dict(title=page.title, url=page.url(), deleted=page.deleted, mod_date=page.mod_date)
if recent_edit:
p['updated'] = recent_edit.timestamp
p['user_label'] = recent_edit.author.display_name
p['user_name'] = recent_edit.author.username
pages.append(p)
else:
if sort == 'recent':
uv_pages.append(p)
else:
pages.append(p)
if sort == 'recent':
pages.sort(reverse=True, key=lambda x: (x['updated']))
pages = pages + uv_pages
pages.append(p)
h1_text = f"{c.project.name} {c.app.config.options.mount_label} - Browse Pages"
return dict(
pages=pages, can_delete=can_delete, show_deleted=show_deleted,
Expand Down

0 comments on commit 114c7be

Please sign in to comment.