misc: prefill tenant choices

This commit is contained in:
Christophe Siraut 2020-10-30 17:50:56 +01:00
parent f8db9f3cfe
commit 740a2836e6
3 changed files with 10 additions and 1 deletions

View File

@ -16,3 +16,4 @@ class EntriesForm(forms.Form):
super().__init__(*args, **kwargs)
self.fields['host'].choices = set([(e, e) for e in Entry.objects.hosts()])
self.fields['_systemd_unit'].choices = [(e, e) for e in Entry.objects.units()]
self.fields['tenant'].choices = [(e, e) for e in Entry.objects.tenants()]

View File

@ -50,6 +50,14 @@ class EntryManager(models.Manager):
cache.set('units', value, 600 * random.random())
return value
def tenants(self):
value = cache.get('tenants')
if value is None:
value = sorted([v for v in self.model.objects.all().annotate(unit=KeyTextTransform('TENANT', 'data')).values_list('unit', flat=True).distinct() if v], key=lambda x: x.lower())
cache.set('tenants', value, 600 * random.random())
return value
class Entry(models.Model):
timestamp = models.DateTimeField(db_index=True)

View File

@ -23,7 +23,7 @@
<form action="." style="display:inline;">
{{ form.as_table }}
<input type="submit" value="Filter" />
<br/><input type="submit" value="Filter" />
</form>
<table>