Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the size of Markdown fields in the admin, plus one other minor error #48

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

rspeed
Copy link

@rspeed rspeed commented Apr 20, 2015

The main issue I fixed is that in the admin the Markdown textareas were very narrow, and there was no way to fix it from an application (without monkey patching). The issue was due to the fact that MarkdownField explicitly sets its form_class to MarkdownFormField, which clobbers any attempt to override the widget. Based on the comment in the source, this was apparently done in an attempt to prevent django.contrib.admin.ModelAdmin from overriding the default widget. The correct way to do that is what has already been implemented in this project – using formfield_overrides in a subclass of ModelAdmin. So, since the problem is already solved in the correct way, I'm pretty sure I'm more or less just reverting it to an earlier behavior.

The other issue this pull request fixes is an issue when using a Markdown field on the frontend results in a JS error when JS files are included at the bottom of the body (which is a best practice). The closures in editor_init.html explicitly reference the variable jQuery in the global scope, but since jquery isn't included until later, the variable doesn't yet exist. My fix actually simplifies the code quite a bit by identifying the markdown elements using a "widget" custom data attribute, then running markItUp using a selector in jquery.init.js. Since we still need extra_settings I changed it to simply set it as a global variable named extra_markitup_settings, since it'll have the same value for each field.

I also removed the __init__ method from MarkdownWidget, since all it wasn't actually doing anything that wouldn't happen if it didn't exist.

…. Overriding the widget after initalizing forces it to be the not-admin version in *all* cases.

Fixes issue when using a Markdown field on the frontend results in a JS error when JS files are included at the bottom of the body (which is a best practice).
Removed unused __init__ method from MarkdownWidget.
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.92%) to 56.31% when pulling 4692382 on rspeed:develop into 0c8081b on klen:develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants