Giter VIP home page Giter VIP logo

django-simplemde's People

Contributors

alexcleduc avatar batisteo avatar braunsonm avatar cjdreiss avatar eraldo avatar onepill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-simplemde's Issues

MDE issues in Django Admin

Hi ๐Ÿ‘‹
I've two issues with the SimpleMDEField in my Django Admin.

The input field of the block is not displayed below the styling (bold, italic...) section, instead it's displayed by the side of it.
Screenshot 2023-11-27 at 16 16 55

And I use the SimpleMDEField in Inline classes, I've noticed that when I add multiple inline instances, the SimpleMDEField of the new instance is locked till I save the instance.

Is anyone else experiencing this issue? If so, I plan to investigate and open a PR. If anyone has found a solution or workaround, please share.

Anything that needs work?

Just wanted to say thanks for writing this :) Super handy

Feel free to open a few issues with help wanted and I might be able to get to some if you need the help!

dynamic changes to the editor

How to I get hold of the editor instance?

My javascript skills are lacking here. :|
If I change the init script to:
var editor = new SimpleMDE(options);
Then I can access things like editor.codemirror.

How do I get hold of the editor without changing the init script?
Is it somehow bound to the .simplemde-box?

For example: I can get to the options via $('.simplemde-box').data().simplemdeOptions.autosave
How can I get to the codemirror instance? Any ideas?

How do I get unique id's for autosave?

Within my SIMPLEMDE_OPTIONS in my settings file it is not possible to generate unique id's because it is read only once.

For now I overwrite the simplemde.init.js:

var simplemdeJQuery = null;

if (typeof jQuery !== 'undefined') {
  simplemdeJQuery = jQuery;
} else if (typeof django !== 'undefined') {
  //use jQuery come with django admin
  simplemdeJQuery = django.jQuery
} else {
  console.error('cant find jQuery, please make sure your have jQuery imported before this script');
}

if (!!simplemdeJQuery) {
  simplemdeJQuery(function() {
    simplemdeJQuery.each(simplemdeJQuery('.simplemde-box'), function(i, elem) {
      var options = JSON.parse(simplemdeJQuery(elem).attr('data-simplemde-options'));
      options['element'] = elem;
      var date = new Date();
      var id = date.getMilliseconds();
      options['autosave'] = options['autosave'] || {};
      options['autosave']['uniqueId'] = 'simplemde-autosave-' + id;
      new SimpleMDE(options);
    });
  });
}

That code is very hacky and only meant as a workaround.

Any ideas?

New release?

Last PyPI version was updated in March. This library no longer works in Django 2.1 due to my MR here: #18 not being pushed to PyPI.

PIP not importing most recent changes?

I'm running Django 4.0.6 and it appears that the code has been updated to the new force_str instead of force_text per GitHub, however PIP v 0.1.3 doesn't show these changes.

Running python3 manage.py check returns the following:

Traceback (most recent call last):
  File "/home/wcadev/.local/lib/python3.8/site-packages/simplemde/utils.py", line 5, in <module>
    from django.utils.encoding import force_text
ImportError: cannot import name 'force_text' from 'django.utils.encoding' (/home/wcadev/.local/lib/python3.8/site-packages/django/utils/encoding.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/home/wcadev/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line
    utility.execute()
  File "/home/wcadev/.local/lib/python3.8/site-packages/django/core/management/__init__.py", line 420, in execute
    django.setup()
  File "/home/wcadev/.local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/wcadev/.local/lib/python3.8/site-packages/django/apps/registry.py", line 116, in populate
    app_config.import_models()
  File "/home/wcadev/.local/lib/python3.8/site-packages/django/apps/config.py", line 304, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 848, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/wcadev/public_html/wcadmin/communication/models.py", line 4, in <module>
    from simplemde.fields import SimpleMDEField
  File "/home/wcadev/.local/lib/python3.8/site-packages/simplemde/fields.py", line 4, in <module>
    from .widgets import SimpleMDEEditor
  File "/home/wcadev/.local/lib/python3.8/site-packages/simplemde/widgets.py", line 13, in <module>
    from .utils import json_dumps
  File "/home/wcadev/.local/lib/python3.8/site-packages/simplemde/utils.py", line 7, in <module>
    from django.utils.encoding import force_unicode as force_text
ImportError: cannot import name 'force_unicode' from 'django.utils.encoding' (/home/wcadev/.local/lib/python3.8/site-packages/django/utils/encoding.py)

How to create a custom extension

Nice work! :D

I was just about to create a field for simpleMDE.
I am glad you have already done so.

I am curious if you have already thought of ways to add custom extensions.
At the moment I do not see a configuration for that in the widget's render function.
I order for me to use your field 'as is' it would be nice to include some kind of hook for mdx extensions.

Or do you have any other ideas/approaches/advice? What do you think?

PS: The option of being able to also add css styles would also be great.. but hey - a step at a time. ;)

Deprecation warnings

WARNING 2018-07-08 18:28:24,541 boundfield 12664 1824 \django\forms\boundfield.py:36: RemovedInDjango21Warning: Add the `renderer` argument to the render() method of <class 'simplemde.widgets.SimpleMDEEditor'>. It will be mandatory in Django 2.1.
  return self.as_widget()

Not showing editor in forms.

By default the field works nicely in the admin.
In a form it shows as a plain Textfield.

The browser console reports:
simplemde.init.js:1 Uncaught ReferenceError: django is not defined

Any ideas?

Does not allow content to be submitted when used in a form

I have a simple form like so:

from simplemde.widgets import SimpleMDEEditor
# from simplemde.fields import SimpleMDEEditor # Both have the same issue

class GenericForm(forms.Form):
    subject = forms.CharField(min_length=3, max_length=80, label='How can we help?',
                              help_text='Please describe what you need in brief (one sentence).')
    details = forms.CharField(widget=SimpleMDEEditor, label='Please add any details that might help us help you.')

    def __init__(self, user, *args, **kwargs):
        self.user = user
        super(GenericForm, self).__init__(*args, **kwargs)

This form works fine if I change the widget to forms.Textarea, but it does not work with the MDEEditor widget. The submit button of the form simply does nothing.

If anyone is able to point me in the right direction it would be appreciated!

Django admin label is floated and breaks into the editor toolbar

Hello,

I ran into this issue in another repo that I forked and fixed it there.
Django's label in the admin has a float right, and when the editor is put in the label is inside the toolbar.

I'll submit a PR with the fix, see details below.

screen shot 2018-03-14 at 2 00 47 pm

Removing the float left for just that field fixes the design.

screen shot 2018-03-14 at 2 23 14 pm

I fixed it by putting a style tag in the widget that has a selector based on the name of the field so it doesn't screw up the rest of the labels in admin.

def render(self, name, value, attrs=None):
    if 'class' not in attrs.keys():
        attrs['class'] = ''

    attrs['class'] += ' simplemde-box'

    attrs['data-simplemde-options'] = json_dumps(self.options)

    html = super(SimpleMDEEditor, self).render(name, value, attrs)

    # insert this style tag to fix the label from breaking into the toolbar
    html += "<style>.field-%s label { float: none; }</style>" % name

    return mark_safe(html)

Preview looks ugly in django admin

Django admin CSS styles are mixed with the SimpleMDE CSS and the preview looks ugly in django admin.
Especially lists doesn't have any bullets, and have large left margin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.