datatracker/ietf/liaisons/widgets.py
Jennifer Richards 9681d9f978
fix: revert POST for document search requests (#8263)
* Revert "fix: ensure csrf cookie for searches (#8260)"

This reverts commit 622ded5d2b.

* Revert "refactor: eliminate single-use helper (#8226)"

This reverts commit 6608c9d530.

* Revert "feat: POST for document search requests (#8206)"

This reverts commit b65a37b6e8.

* test: add back test fix

* refactor: eliminate single-use helper
2024-11-22 13:30:54 -06:00

48 lines
2.5 KiB
Python

# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
from django.urls import reverse as urlreverse
from django.forms.widgets import Widget
from django.utils.safestring import mark_safe
from django.utils.html import conditional_escape
from django_stubs_ext import QuerySetAny
class ButtonWidget(Widget):
def __init__(self, *args, **kwargs):
self.label = kwargs.pop('label', None)
self.show_on = kwargs.pop('show_on', None)
self.require = kwargs.pop('require', None)
self.required_label = kwargs.pop('required_label', None)
super(ButtonWidget, self).__init__(*args, **kwargs)
def render(self, name, value, **kwargs):
html = '<span class="d-none showAttachsOn">%s</span>' % conditional_escape(self.show_on)
html += '<span class="d-none attachEnabledLabel">%s</span>' % conditional_escape(self.label)
if self.require:
for i in self.require:
html += '<span class="d-none attachRequiredField">%s</span>' % conditional_escape(i)
required_str = 'Please fill in %s to attach a new file' % conditional_escape(self.required_label)
html += '<span class="d-none attachDisabledLabel">%s</span>' % conditional_escape(required_str)
html += '<button type="button" class="addAttachmentWidget btn btn-primary btn-sm">%s</button>' % conditional_escape(self.label)
return mark_safe(html)
class ShowAttachmentsWidget(Widget):
def render(self, name, value, **kwargs):
html = '<div id="id_%s">' % name
html += '<span class="d-none showAttachmentsEmpty form-control widget">No files attached</span>'
html += '<div class="attachedFiles form-control widget">'
if value and isinstance(value, QuerySetAny):
for attachment in value:
html += '<a class="initialAttach" href="%s">%s</a>&nbsp' % (conditional_escape(attachment.document.get_href()), conditional_escape(attachment.document.title))
html += '<a class="btn btn-primary btn-sm" href="{}">Edit</a>&nbsp'.format(urlreverse("ietf.liaisons.views.liaison_edit_attachment", kwargs={'object_id':attachment.statement.pk,'doc_id':attachment.document.pk}))
html += '<a class="btn btn-primary btn-sm" href="{}">Delete</a>&nbsp'.format(urlreverse("ietf.liaisons.views.liaison_delete_attachment", kwargs={'object_id':attachment.statement.pk,'attach_id':attachment.pk}))
html += '<br>'
else:
html += 'No files attached'
html += '</div></div>'
return mark_safe(html)