Skip to content

Commit

Permalink
removed form media
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Jan 29, 2014
1 parent bfde43a commit 871de42
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Put this form inside a
{{ form.as_p }}
</form>

.. note:: The decorator adds ``jquery`` and ``parsley.min.js`` to form media
.. note:: Make sure `jquery.js` and `parsley.js` are included in the template.

Admin
-----
Expand All @@ -113,7 +113,7 @@ To add parsley validations to admin, use the ``ParsleyAdminMixin`` with your ``M
class StudentAdmin(ParsleyAdminMixin, admin.ModelAdmin):
pass
.. note:: The mixin adds an additional script: ``parsley.django-admin.js`` to the admin media.
.. note:: Use the `parsley.django-admin.js` helper from parsley static to auto-validate admin forms.

Advanced Usage
--------------
Expand Down
8 changes: 7 additions & 1 deletion example/core/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@


class MyUserAdmin(ParsleyAdminMixin, UserAdmin):
pass

class Media:
js = (
"//code.jquery.com/jquery-latest.min.js",
"parsley/js/parsley.min.js",
"parsley/js/parsley.django-admin.js"
)


admin.site.unregister(User)
Expand Down
1 change: 1 addition & 0 deletions example/core/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
</style>
<script src="http://code.jquery.com/jquery-1.10.1.min.js" ></script>
<script src="{{ STATIC_URL }}parsley/js/parsley.js" ></script>
<script type='text/javascript' src='{{ STATIC_URL }}core/js/bootstrap-tab.min.js'></script>
{{ form.media }}

Expand Down
11 changes: 0 additions & 11 deletions parsley/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,4 @@ def new_init(self, *args, **kwargs):
attrs["{prefix}-%s".format(prefix=prefix) % key] = value
klass.__init__ = new_init

js_media = (
"//code.jquery.com/jquery-latest.min.js",
"parsley/js/parsley.min.js",
)
try:
klass.Media.js += js_media
except AttributeError:
class Media:
js = js_media
klass.Media = Media

return klass
8 changes: 0 additions & 8 deletions parsley/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,3 @@ class ParsleyAdminMixin(object):
def get_form(self, *args, **kwargs):
form = super(ParsleyAdminMixin, self).get_form(*args, **kwargs)
return parsleyfy(form)

class Media:
extend = False
js = (
"//code.jquery.com/jquery-latest.min.js",
"parsley/js/parsley.min.js",
"parsley/js/parsley.django-admin.js",
)
37 changes: 0 additions & 37 deletions parsley/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,43 +205,6 @@ def test_missing_field(self):
ExtraDataMissingFieldForm() # No error should be raised


class TestAdminMixin(ParsleyTestCase):
def test_media(self):
student_admin = StudentAdmin(Student, admin.site)
js = student_admin.media.render_js()
self.assertIn(
'<script type="text/javascript" src="/static/parsley/js/parsley.min.js"></script>',
js
)
self.assertIn(
'<script type="text/javascript" src="/static/parsley/js/parsley.django-admin.js"></script>',
js
)


class TestFormMedia(ParsleyTestCase):

def test_form_media(self):
form = FormWithoutMedia()
js = form.media.render_js()
self.assertIn(
'<script type="text/javascript" src="/static/parsley/js/parsley.min.js"></script>',
js
)

def test_existing_form_media(self):
form = FormWithMedia()
js = form.media.render_js()
self.assertIn(
'<script type="text/javascript" src="/static/jquery.min.js"></script>',
js
)
self.assertIn(
'<script type="text/javascript" src="/static/parsley/js/parsley.min.js"></script>',
js
)


class TestMultiValueField(ParsleyTestCase):
def test_parsley_attributes(self):
form = MultiWidgetForm()
Expand Down

0 comments on commit 871de42

Please sign in to comment.