event timeline
This commit is contained in:
commit
fc1a929428
53 changed files with 806 additions and 0 deletions
21
app/widgets.py
Normal file
21
app/widgets.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import logging
|
||||
import json
|
||||
|
||||
from django.forms import widgets
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class PrettyJSONWidget(widgets.Textarea):
|
||||
|
||||
def format_value(self, value):
|
||||
try:
|
||||
value = json.dumps(json.loads(value), indent=2, sort_keys=True, ensure_ascii=False)
|
||||
# these lines will try to adjust size of TextArea to fit to content
|
||||
row_lengths = [len(r) for r in value.split('\n')]
|
||||
self.attrs['rows'] = min(max(len(row_lengths) + 2, 10), 30)
|
||||
self.attrs['cols'] = min(max(max(row_lengths) + 2, 40), 120)
|
||||
return value
|
||||
except Exception as e:
|
||||
logger.warning("Error while formatting JSON: {}".format(e))
|
||||
return super(PrettyJSONWidget, self).format_value(value)
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue