lib: cleanup unused widgets

This commit is contained in:
Jens Langhammer 2020-07-01 22:27:58 +02:00
parent 6634cc2edf
commit 13900bc603
2 changed files with 25 additions and 36 deletions

View file

@ -0,0 +1,25 @@
"""passbook user view tests"""
from guardian.shortcuts import get_anonymous_user
from django.test import TestCase
from django.utils.timezone import now
from passbook.core.tasks import clean_tokens
from passbook.core.models import Token
class TestTasks(TestCase):
"""Test Tasks"""
def test_token_cleanup(self):
"""Test Token cleanup task"""
Token.objects.create(
expires=now(),
user=get_anonymous_user()
)
self.assertEqual(
Token.objects.all().count(), 1
)
clean_tokens()
self.assertEqual(
Token.objects.all().count(), 0
)

View file

@ -1,36 +0,0 @@
"""Dynamic array widget"""
from django import forms
class DynamicArrayWidget(forms.TextInput):
"""Dynamic array widget"""
template_name = "lib/arrayfield.html"
def get_context(self, name, value, attrs):
value = value or [""]
context = super().get_context(name, value, attrs)
final_attrs = context["widget"]["attrs"]
id_ = context["widget"]["attrs"].get("id")
subwidgets = []
for index, item in enumerate(context["widget"]["value"]):
widget_attrs = final_attrs.copy()
if id_:
widget_attrs["id"] = "{id_}_{index}".format(id_=id_, index=index)
widget = forms.TextInput()
widget.is_required = self.is_required
subwidgets.append(widget.get_context(name, item, widget_attrs)["widget"])
context["widget"]["subwidgets"] = subwidgets
return context
def value_from_datadict(self, data, files, name):
try:
getter = data.getlist
return [value for value in getter(name) if value]
except AttributeError:
return data.get(name)
def format_value(self, value):
return value or []