File indexing completed on 2026-12-02 10:29:07
0001 """Help pages: What's new (docs/WHATS_NEW.md)."""
0002 from django.http import Http404
0003 from django.shortcuts import render
0004
0005 from ai.assessments import render_assessment_markdown
0006 from monitor_app.authority import may_act
0007 from monitor_app.inclusive_filter import Facet, InclusiveFilter
0008
0009 from . import whats_new as wn
0010
0011
0012 def _username(request):
0013 user = getattr(request, 'user', None)
0014 return user.username if user and user.is_authenticated else ''
0015
0016
0017 def _render_fields(row):
0018 """HTML of an item's Markdown fields, sanitized."""
0019 row['details_html'] = render_assessment_markdown(row.get('details', ''))
0020 row['refs_html'] = render_assessment_markdown(row.get('refs', ''))
0021 row['importance_label'] = wn.IMPORTANCE_LABELS.get(row.get('importance'), '')
0022 row['importance_rank'] = (wn.IMPORTANCE.index(row['importance'])
0023 if row.get('importance') in wn.IMPORTANCE
0024 else len(wn.IMPORTANCE))
0025 return row
0026
0027
0028 def _facets(rows):
0029 tags = sorted({t for r in rows for t in r['tags']})
0030 return [Facet('tag', 'Tags',
0031 lambda r: r['tags'] + ([r['importance']] if r['importance'] else []),
0032 display=lambda v: wn.IMPORTANCE_LABELS.get(v, v),
0033 order=list(wn.IMPORTANCE) + tags)]
0034
0035
0036 def whats_new(request):
0037 """The What's new list, newest shipped first; the filter shows the
0038 items carrying every selection."""
0039 username = _username(request)
0040 rows = [_render_fields(r) for r in wn.list_items(username=username)]
0041 facets = _facets(rows)
0042 flt = InclusiveFilter(request.GET, noun='items', match='all')
0043 flt.annotate(rows, facets)
0044 return render(request, 'help/whats_new.html', {
0045 'rows': rows,
0046 'inclusive_filter': flt.context(rows, facets, request),
0047 'open_all': request.GET.get('open') == 'all',
0048 'username': username,
0049 'may_add': bool(username) and may_act(username),
0050 'importance_levels': wn.IMPORTANCE,
0051 'tags_in_use': wn.tags_in_use(),
0052 'contacts': wn.contacts(),
0053 })
0054
0055
0056 def whats_new_item(request, slug):
0057 username = _username(request)
0058 try:
0059 item = wn.get_item(slug, username=username)
0060 except wn.WhatsNewError:
0061 raise Http404(f"no What's new item {slug}")
0062 _render_fields(item)
0063 for c in item['comments']:
0064 c['html'] = render_assessment_markdown(c['text'])
0065 item['tags_text'] = ' '.join(item['tags'])
0066 item['builds_on_text'] = ' '.join(item['builds_on'])
0067 return render(request, 'help/whats_new_item.html', {
0068 'item': item, 'username': username,
0069 'importance_levels': wn.IMPORTANCE,
0070 'tags_in_use': wn.tags_in_use(),
0071 'contacts': wn.contacts(),
0072 })
0073
0074
0075 def whats_new_version(request, slug, version_num):
0076 try:
0077 version = wn.get_version(slug, version_num)
0078 entry = wn.get_entry(slug)
0079 except wn.WhatsNewError:
0080 raise Http404(f'no version {version_num} of {slug}')
0081 _render_fields(version)
0082 return render(request, 'help/whats_new_version.html', {
0083 'version': version, 'current_title': entry.title if entry else slug,
0084 'username': _username(request),
0085 })
0086
0087
0088 def whats_new_new(request):
0089 return render(request, 'help/whats_new_new.html', {
0090 'username': _username(request),
0091 'importance_levels': wn.IMPORTANCE,
0092 'tags_in_use': wn.tags_in_use(),
0093 'contacts': wn.contacts(),
0094 'today': wn._today().isoformat(),
0095 })