Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ include CONTRIBUTING.rst
include HISTORY.rst
include LICENSE
include README.md
recursive-include prettyjson/locale *.mo *.po
recursive-include prettyjson *.html *.png *.gif *js *.css *jpg *jpeg *svg *py
2 changes: 1 addition & 1 deletion prettyjson/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '0.4.1'

from .widgets import PrettyJSONWidget
from .widgets import PrettyJSONWidget # noqa
Binary file added prettyjson/locale/en/LC_MESSAGES/django.mo
Binary file not shown.
30 changes: 30 additions & 0 deletions prettyjson/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# English translation for django-prettyjson.
# Copyright (C) 2024
# This file is distributed under the same license as the django-prettyjson package.
# Manuel Jesus Barrera <[email protected]>, 2024.
#
msgid ""
msgstr ""
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-02 12:29+0000\n"
"PO-Revision-Date: 2018-07-04 21:21+0200\n"
"Language: en\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: xls-to-po 1.0\n"

#: prettyjson/widgets.py:27
msgid "Show parsed"
msgstr ""

#: prettyjson/widgets.py:28
msgid "Show raw"
msgstr ""

#: prettyjson/widgets.py:29
msgid "Collapse"
msgstr ""

#: prettyjson/widgets.py:30
msgid "Expand"
msgstr ""
Binary file added prettyjson/locale/es/LC_MESSAGES/django.mo
Binary file not shown.
34 changes: 34 additions & 0 deletions prettyjson/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Spanish translation for django-prettyjson.
# Copyright (C) 2024
# This file is distributed under the same license as the django-prettyjson package.
# Manuel Jesus Barrera <[email protected]>, 2024.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-03-02 12:29+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: prettyjson/widgets.py:27
msgid "Show parsed"
msgstr "Mostrar procesado"

#: prettyjson/widgets.py:28
msgid "Show raw"
msgstr "Mostrar sin procesar"

#: prettyjson/widgets.py:29
msgid "Collapse"
msgstr "Colapsar"

#: prettyjson/widgets.py:30
msgid "Expand"
msgstr "Expandir"
13 changes: 1 addition & 12 deletions prettyjson/static/prettyjson/prettyjson.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 1 addition & 60 deletions prettyjson/static/prettyjson/prettyjson.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions prettyjson/templatetags/prettyjson.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def prettyjson(obj, name="", **kwargs):
data = obj
if isinstance(obj, six.string_types):
data = json.loads(obj)

widget = PrettyJSONWidget(attrs=kwargs)
return mark_safe(widget.render(name=name,
value=(json.dumps(data, ensure_ascii=False, cls=StandardJSONEncoder)),
attrs=widget.attrs))
return mark_safe(
widget.render(
name=name,
value=(json.dumps(data, ensure_ascii=False, cls=StandardJSONEncoder)),
attrs=widget.attrs
)
)
22 changes: 17 additions & 5 deletions prettyjson/widgets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import django

from django.conf import settings
from django.forms import widgets

if django.VERSION >= (2, 0, 0):
from django.utils.translation import gettext as _
else:
from django.utils.translation import ugettext as _


class PrettyJSONWidget(widgets.Textarea):

Expand All @@ -14,11 +21,16 @@ def render(self, name, value, attrs=None, **kwargs):
if (start_as not in self._allowed_attrs()):
start_as = self.DEFAULT_ATTR

return ('<div class="jsonwidget" data-initial="' + start_as + '"><p><button class="parseraw" '
'type="button">Show parsed</button> <button class="parsed" '
'type="button">Collapse all</button> <button class="parsed" '
'type="button">Expand all</button></p>' + html + '<div '
'class="parsed"></div></div>')
return (
'<div class="jsonwidget" data-initial="' + start_as + '"> '
'<p> '
'<button class="parseraw btn-parsed" type="button">' + _("Show parsed") + '</button> '
'<button class="parsed btn-raw" type="button">' + _("Show raw") + '</button> '
'<button class="parsed btn-collapse" type="button">' + _("Collapse") + '</button> '
'<button class="parsed btn-expand" type="button">' + _("Expand") + '</button> '
'</p>' + html + '<div class="parsed"></div> '
'</div>'
)

@staticmethod
def _allowed_attrs():
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ def get_version(*file_paths):
return version_match.group(1)
raise RuntimeError('Unable to find version string.')


version = get_version('prettyjson', '__init__.py')

if sys.argv[-1] == 'publish':
try:
import wheel
import wheel # noqa
except ImportError:
print('Wheel library missing. Please run "pip install wheel"')
sys.exit()
Expand Down