Code Monkey home page Code Monkey logo

django-ace's Introduction

django-ace

Usage

from django import forms
from django_ace import AceWidget

class EditorForm(forms.Form):
    text = forms.CharField(widget=AceWidget)

Syntax highlighting and static analysis can be enabled by specifying the language:

class EditorForm(forms.Form):
    text = forms.CharField(widget=AceWidget(mode='css'))

Themes are also supported:

class EditorForm(forms.Form):
    text = forms.CharField(widget=AceWidget(mode='css', theme='twilight'))

All options, and their default values, are:

class EditorForm(forms.Form):
    text = forms.CharField(widget=AceWidget(
        mode=None,  # try for example "python"
        theme=None,  # try for example "twilight"
        wordwrap=False,
        width="500px",
        height="300px",
        minlines=None,
        maxlines=None,
        showprintmargin=True,
        showinvisibles=False,
        usesofttabs=True,
        tabsize=None,
        fontsize=None,
        toolbar=True,
        readonly=False,
        showgutter=True,  # To hide/show line numbers
        behaviours=True,  # To disable auto-append of quote when quotes are entered
    ))

Install

  1. Install using pip:

    pip install django_ace
  2. Update INSTALLED_APPS:

    INSTALLED_APPS = (
        # ...
        'django_ace',
    )

Example Project

There's an example project included in the source, to try it do:

cd example/
virtualenv .env
. .env/bin/activate
pip install -e ..
./manage.py makemigrations app
./manage.py migrate
./manage.py runserver

Then browser to http://localhost:8000.

Change log

v1.32.4

  • Expose useworker, contributed by @mounirmesselmeni.

v1.32.3

  • Update ACE editor to version v1.32.3.

v1.32.0

  • Update ACE editor to version v1.32.0.
  • Expose extensions, contributed by @okaycj.

v1.31.1

  • Update ACE editor to version v1.31.1.

v1.26.0

  • Update ACE editor to version v1.26.0.

v1.24.1

  • Update ACE editor to version v1.24.1.

v1.23.4

  • Update ACE editor to version v1.23.4.

v1.22.1

  • Update ACE editor to version v1.22.1.

v1.19.0

  • Update ACE editor to version v1.19.0.

v1.15.4

  • Added CSS to work with new admin in Django 4.2. Now you can use width="100%" without breaking the layout.

v1.15.3

  • Update ACE editor to version v1.15.3.

v1.14.0

  • Update ACE editor to version v1.14.0.
  • Follow ACE version numbers.

v1.0.13

  • Update ACE editor to version v1.11.2.

v1.0.12

  • Update ACE editor to version v1.5.0.

v1.0.11

  • Support Grappelli inlines.

v1.0.10

  • FIX JavaScript error when using JavaScriptCatalog.

v1.0.9

  • New widget option showgutters to hide line numbers.
  • New widget option behaviours to avoid auto-insert of quotes.

v1.0.8

  • New widget option readonly.
  • Update ACE editor to version v1.4.12.

v1.0.7

  • New widget option toolbar.
  • Update ACE editor to version v1.4.8.

v1.0.6

  • New widget option fontsize.
  • Update ACE editor to version v1.4.7.

v1.0.5

  • New widget option tabsize.
  • Upgrade ACE editor to version v1.4.2.

v1.0.4

  • Update Django compatibility to >1.11,<=2.1
  • New widget options minLines, maxLines, showinvisibles, usesofttabs.
  • Upgrade ACE editor to version v1.4.0.
  • Updated example for Django 1.11
  • PEP8 improvements

v1.0.2

  • Upgrade ACE editor to version 1.1.8
  • Add support for showprintmargin

v1.0.1

  • Add support for Django 1.7 by removing deprecated imports.

v1.0.0

  • Initial release.

django-ace's People

Contributors

anhtran avatar bradleyayers avatar chrisclark avatar chrisfranson avatar darbula avatar fdemmer avatar julienpalard avatar katylava avatar kezabelle avatar kitsunde avatar mounirmesselmeni avatar mturilin avatar okaycj avatar openxe avatar pricco avatar savar avatar svniemeijer 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  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  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  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-ace's Issues

Rendering Data Inside of the Form

Currently, it looks like this widget only functions as a form option with a submission. Is there a way to just render the editor with code inside of it, instead of having it as a place where the user would type and submit?

Effectively, I want a website where this editor has existing code, and the user can edit or play around with it, but not submit it.

WARNING django.request: Not Found: worker-html.js

Currently getting some errors when utilizing django-ace in an iframe.

WARNING django.request: Not Found: /iframe/worker-html.js

Note: I don't think this is directly caused by django-ace being in an iframe, but I thought I'd mention it.

Additionally, django-ace seems to behave perfectly fine even with this error being present.

Here is my AceWidget

    head_html = CharField(
        widget=AceWidget(
            mode="html",
            theme="twilight",
            width="100%",
            toolbar=False,
            showprintmargin=False,
        ),
        label="Custom HTML (head)",
        required=False,
    )

JavaScript Error because of incorrect mime type for static file

Python 3.9.5
Django v3.2.4
django_ace v1.0.11

JavaScript error:

Refused to execute script from 'http://127.0.0.1:8000/static/django_ace/ace/worker-json.js' because its MIME type ('text/plain') is not executable.

Uncaught DOMException: Failed to execute 'importScripts' on 'WorkerGlobalScope': The script at 'http://127.0.0.1:8000/static/django_ace/ace/worker-json.js' failed to load.

Django admin inline module is not rendering form's widget

Hi!
I tried to use a widget called AceWidget, but I don't know why it's not rendering this widget when I put it into the inline module and it's rendering a textarea by default.

code example:

from django_ace import AceWidget
from django import forms
from django.forms import formset_factory, BaseInlineFormSet
from prettyjson import PrettyJSONWidget
from django.contrib import admin

class StatementForm(forms.ModelForm):
    class Meta:
        model = Statements
        fields = ['query', 'executed', 'logs']
        widgets = {
            'logs': PrettyJSONWidget(attrs={'initial': 'parsed'}),
            'query': AceWidget(mode='sql')
        }

StatementFormSet = formset_factory(StatementForm, formset=BaseInlineFormSet, can_order=True)

class StatementTabularInline(admin.StackedInline):
    model = Statements
    formset = StatementFormSet
    readonly_fields = ['executed', 'logs', ]

@admin.register(Ticket)
class TicketAdmin(admin.ModelAdmin):
    inlines = [StatementTabularInline]

if I put the widget into the form without a "StackedInline" directly, It works. but if I put the form into the whatever inline module related, It doesn't render the widget

result of the code above:

image

Getting strange text in the editor

I am getting this value in the editor:
ההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


I have the following code in JS:

var editor = ace.edit("editor");
editor.session.setMode("ace/mode/json")
        editor.setOptions({
            mode: "json",
            wrap: true,
        });

If I remove these lines, nothing is added in the editor. How can I solve this issue?

Unable to render Dynamic content in html

I'm trying to use SnippetForm as:

views.py

def landing(request,*args,**kwargs):
    global content
    return render(request, 'snippet.html',{'form':SnippetForm(initial={'text': content})})

def console(request,*args,**kwargs):
     content = some text based on function 
    return render(request,'console.html',{'form': content})

console.html

{{form}}

snippet.html

<div>
          <form action="" id="editor" method="post">
              {% csrf_token %}
              <div class="row">
                {{ form.as_p }}
              </div>
              <span>
                <input type="button" class="btn btn-info" name="editedContent" id="contentSubmit" value="Submit" />
                <!-- <input type="submit" class="btn btn-info" name="editedContent" id="contentSubmit"/> -->
                <input type="submit" class="btn btn-info" name="cancelContent" id="cancelOperation" value="Cancel" />
              </span>
          </form>
</div>

Using Ajax request to update form:

$("#fileSubmit").click(function(e){
   e.preventDefault();
   var csrftoken=getCookie('csrftoken')
   var appName = $('#appNames').val()
   var fileName = $('#fileNames').val()
   console.log(appName,fileName)
   var data={'csrfmiddlewaretoken':csrftoken,group:$('#groupNames').val(),'appName':appName,'fileName':fileName,type: 'console'};
   console.log(data)
  $.ajax({
    url : "{% url 'console1:console' %}",
    type : "POST",
    data : data,
    success : function(result){
      console.log("Result",result);
      // $('#console').html(result);
      document.getElementById('id_text').innerHTML = result;
      document.getElementsByTagName('label').innerHTML = "";
      displayConsole();
    },
    error : function(error){
      console.log(error.responseText);
    }
  });
});

But the content is now updating can i know how to do it.. Thank you!!

Django trims whitespaces in json mode

Django trims whitespaces in json mode, so i found fix. I added code:

        if (mode == "json") {
            editor.setValue(JSON.stringify(JSON.parse(editor.getSession().getValue()), null, 2));
        }

to django_ace/static/django_ace/widgets.js in apply_widget() (151 line). If this fix ok, i can create pull request.
Thanks.

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.