Skip to main content

Django application that allows you to inline edition of some data from the database

Project description

Inplace Edit Form

Information

Inplace Edit Form is a Django application that allows you to inline edition of some data from the database

It is distributed under the terms of the GNU Lesser General Public License <http://www.gnu.org/licenses/lgpl.html>

Demo

Video Demo, of django-inplaceedit and Django-inlinetrans (Set full screen mode to view it correctly)

https://github.com/Yaco-Sistemas/django-inplaceedit/raw/master/video-frame.png

Requeriments

Installation

Install in your base.html

{% load inplace_edit %}

{% inplace_toolbar %}

or

{% inplace_static %}

In your settings.py

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',

    #.....................#

    'inplaceeditform',
)

And uncomment the request context processor:

TEMPLATE_CONTEXT_PROCESSORS = (
    #...#
    'django.core.context_processors.request',
    #...#
)

Optional:

INPLACEEDIT_EDIT_EMPTY_VALUE = 'Doble click to edit'
INPLACEEDIT_AUTO_SAVE = True
INPLACEEDIT_EVENT = "dblclick"
INPLACEEDIT_DISABLE_CLICK = True  # For inplace edit text into a link tag
INPLACEEDIT_EDIT_MESSAGE_TRANSLATION = 'Write a translation' # transmeta option
DEFAULT_INPLACE_EDIT_OPTIONS = {} # dictionnary of the optionals parameters that the templatetag can receive to change its behavior (see the Advanced usage section)
DEFAULT_INPLACE_EDIT_OPTIONS_ONE_BY_ONE = True # modify the behavior of the DEFAULT_INPLACE_EDIT_OPTIONS usage, if True then it use the default values not specified in your template, if False it uses these options only when the dictionnary is empty (when you do put any options in your template)

In your urls.py

urlpatterns = patterns('',

    #...#

    (r'^inplaceeditform/', include('inplaceeditform.urls')),

    #...#
)

If you use the date adaptor or datetime adaptor also:

js_info_dict = {
    'packages': ('django.conf',),
}

urlpatterns = patterns('',

    #...#

    (r'^inplaceeditform/', include('inplaceeditform.urls')),
    (r'^jsi18n$', 'django.views.i18n.javascript_catalog', js_info_dict),
)

Basic usage

{% inplace_edit  "OBJ.FIELD_NAME" %}
{% inplace_edit  "OBJ.FIELD_NAME|FILTER1|FILTER2|...|FILTERN" %}

Examples

{% load inplace_edit %}
   <html>
   <head>
   ...
   <script src="{{ STATIC_URL }}js/jquery.min.js" type="text/javascript"></script>
   {% inplace_toolbar %}
   </head>
   <body>
       ...
       <div id="content">
           ...
           {% inplace_edit "content.name" %}
           ...
           <div class="description">
               {% inplace_edit "content.date_initial|date:'d m Y'" %}
               {% inplace_edit "content.description|safe" %}
           </div>
           <div class="body">
               {% inplace_edit "content.body|safe|truncatewords_html:15" %}
           </div>
       </div>
       ...
   </body>
   </html>

How to use it

  • If you use inplace_static: Just pass the cursor above the field and double click (this is customizable), authenticated with a super user

  • If you use inplace_toolbar: Enable a edit inline and just pass the cursor above the field and double click (this is customizable), authenticated with a super user

Advanced usage

Inplaceedit has some optionals parameters that the templatetag can receive to change its behavior:
  • auto_height: Adapt the height’s widget to the tag container.

  • auto_width: Adapt the width’s widget to the tag container.

  • class_inplace: Add a class to edit inline form.

  • tag_name_cover: The value is covered for a span. But it’s possible to change it.

  • filters_to_show: The server filters the value before to save. List separate for “|”

  • loads: If you use some filter that need a load, you set this option. List separate for “:”

  • edit_empty_value: The text to display when the field is empty

Examples

{% inplace_edit "content.description|safe" auto_height=1, auto_width=1 %}
{% inplace_edit "content.title" class_inplace="titleFormEditInline" %}
{% inplace_edit "content.description|safe" filters_to_show="safe|truncatewords_html:30", tag_name_cover="div" %}
{% inplace_edit "content.description|my_filter" loads="my_template_tag" %}
{% inplace_edit "content.index" edit_empty_value="This is a editable content, now the value is none. Please double click to edit inplace" %}

Adaptor API

You can create a adaptor to work with inplace edit form, the behavior is fully customizable. To default inplaceedit has 8 adaptors. These use the api, overwriting some methods for them.

First step

In your settings:

ADAPTOR_INPLACEEDIT = {'myadaptor': 'app_name.fields.MyAdaptor'}

In app_name.fields.MyAdaptor:

class MyAdaptor(BaseAdaptorField):

    @property
    def name(self):
        return 'myadaptor'

Python API

  • loads_to_post: It returns the value of the request (normally request.POST)

  • classes: Classes of tag cover. By default “inplaceedit” and “myadaptorinplaceedit”

  • get_config: Preprocessed of the configuration. By default, it does nothing.

  • get_form_class: It returns the form class.

  • get_form: It returns a instace of form class.

  • get_field: It returns a field of instance of form class.

  • render_value: It returns the render of the value. If you write {% inplace_edit “obj.name|filter1” %} it returns something like this {{ obj.name|filter1 }}.

  • render_value_edit: It returns the render value if you can edit. It returns by default the same of “render_value”, but if the value is None call to empty_value

  • empty_value: It returns an empty value for this adaptor. By default, ‘Dobleclick to edit’.

  • render_field: It returns the render of form, with a field.

  • render_media_field: It returns the media (scripts and css) of the field.

  • render_config: It returns the render of config.

  • can_edit: It returns a boolean that indicate if this user can edit inline this content or not.

  • get_value_editor: It returns a clean value to be saved in DB.

  • save: Save the value in DB.

  • get_auto_height: Returned if the field rendered with auto height

  • get_auto_width: Returned if the field rendered with auto width

  • treatment_height: Special treatment to widget’s height.

  • treatment_width: Special treatment to widget’s width.

If you want to use own options in your adaptor, you can do it. These options will be in self.config in the adaptor.
{% inplace_edit "obj.field_name" my_opt1="value1", my_opt2="value2" %}

JavaScript API

There are four hooks,

  • getValue: if the value is componing for various widgets, you can set the function getValue, to these DOM elements. Something like this:

    <script type="text/javascript">
        (function($){
            $(document).ready(function () {
                function myGetValue(form, field_id) {
                    return ""Something"";
                }
                $(".applyMyAdaptor").data("getValue", myGetValue);
        });
        })(jQuery);
    </script>
  • applyFinish: if you need/want to do some action after the value be saved. Something like this:

    <script type="text/javascript">
        (function($){
            $(document).ready(function () {
                function myApplyFinish() {
                    return ""Something"";
                }
                $(".applyMyAdaptor").data("applyFinish", myApplyFinish);
        });
        })(jQuery);
    </script>
  • cancelFinish: if you need/want to do some action after the cancel the edit. Something like this:

    <script type="text/javascript">
        (function($){
            $(document).ready(function () {
                function myCancelFinish() {
                    return ""Something"";
                }
                $(".cancelMyAdaptor").data("cancelFinish", myCancelFinish);
        });
        })(jQuery);
    </script>
  • extraConfig: if you need/want add something to the config in the ajax request to print the field

    <script type="text/javascript">
        (function($){
            $(document).ready(function () {
                function myExtraConfig(data) {
                    return data + ""Something"";
                }
                $(".configMyAdaptor").data("extraConfig", myExtraConfig);
        });
        })(jQuery);
    </script>

For example the adaptor datetime use these hooks.

Overwriting a default adaptor

To overwrite a adaptor add in your settings something like this:

ADAPTOR_INPLACEEDIT = {'text': 'app_name.fields.MyAdaptorText'}

For this case you overwrite the AdaptorText with MyAdaptorText.

Permission Adaptor API

By default you can inline edit a field if you are authenticated with a superuser. But it’s customizable:

Overwriting the default permission adaptor

This package have two inplementations:

  • SuperUserPermEditInline (by default): Only you can edit if you are super user

  • AdminDjangoPermEditInline: Yo can edit the content if you have a permission edit for that model. If you want enabled this, write in your settings:

ADAPTOR_INPLACEEDIT_EDIT = 'inplace_edit.perms.AdminDjangoPermEditInline'

You can create a specify adaptor. MyAdaptorEditInline is a class with a single class method, this method receives a adaptor field

# in your settings

ADAPTOR_INPLACEEDIT_EDIT = 'app_name.perms.MyAdaptorEditInline'


# in app_name.perms

class MyAdaptorEditInline(object):

    @classmethod
    def can_edit(cls, adaptor_field):
       return True # All user can edit

Example

class MyAdaptorEditInline(object):

    @classmethod
    def can_edit(cls, adaptor_field):
        user = adaptor_field.request.user
        obj = adaptor_field.obj
        can_edit = False
        if user.is_anonymous():
            pass
        elif user.is_superuser:
            can_edit = True
        else:
           can_edit = has_permission(obj, user, 'edit')
        return can_edit

Testing

This django application has been tested on severals browsers: Firefox, Google Chrome, Opera, Safari and Internet Explorer on versions 7 and 8, to check javascript actions.

Also, exists a django project to test inplaceeditform. This project can use as demo project, because inplaceeditform is totally adapted to it.

Transmeta

This egg is compatible with Transmeta But it is not a requirement

Django Inplace Edit Extra Field

If you want to get more download Django Inplace Edit Extra Field

Development

You can get the last bleeding edge version of inplaceedit by doing a checkout of its git repository:

git clone git://github.com/Yaco-Sistemas/django-inplaceedit.git

Releases

0.88 (2012-10-05)

  • Add to default parameter to inplace_css

  • Translate to the string: “You have unsaved changes!”

  • Fix a problem with the treatment of the sizes

  • INPLACEEDIT_EDIT_EMPTY_VALUE settings

  • Thanks to:

0.87 (2012-09-05)

  • Add callback to onbeforeunload

  • Refactor the jquery.inplaceeditform.js

  • Now is not required the ADMIN_MEDIA_PREFIX in the settings, but this is backward compatible

  • New options to the settings: DEFAULT_INPLACE_EDIT_OPTIONS and DEFAULT_INPLACE_EDIT_OPTIONS_ONE_BY_ONE

  • Thanks to:

0.86 (2012-08-21)

  • Toolbar to edit inplace

  • Auto save option

  • New JS hook (extraConfig)

  • Now you can choose the event to edit inplace, by default is doble click

  • Now when you edit inline the input (or select) get the focus

  • Now while there is a ajax request cannot do other ajax request to the same element

  • Update the way to get the CSFRToken

  • JSLint to jquery.inplaceeditform.js (There were some errors still)

  • Refactor and remove little errors

  • Refactor the css files

0.85 (2012-08-09)

  • A strange error with buildout

  • I’m sorry but I removed the package by mistake

0.84 (2012-08-09)

  • Move the repository to github

0.83 (2012-05-22)

  • Now django-inplaceedit managing static files (backward compatible)

0.82 (2012-03-19)

  • Fix a error when a field contained “_id”

0.81 (2012-01-25)

  • A little error in AdminDjangoPermEditInline

0.80 (2012-01-24)

  • More robust when a user can edit a content

  • SuperUserPermEditInline, before was a logic, and you can not inherit.

  • AdminDjangoPermEditInline, a logic very useful. Thanks to Raimon

0.79 (2012-01-11)

  • Messages configurables and translatables in the settings

0.78 (2012-01-9)

  • Messages configurables in the settings

0.77 (2011-12-14)

  • Fixes a error in bolean adaptor

0.76 (2011-12-08)

  • More robust

0.75 (2011-11-24)

  • The resources dont’t have dependencie of MEDIA_URL (in CSS file)

0.74 (2011-10-03)

  • Usability: edit inline works when you submit the form

0.73 (2011-09-22)

  • Image/File field compatibility with Django 1.1 (overwriting inplaceeditform/adaptor_file/inc.csrf_token.html) (Django 1.2 or above recommended)

0.72 (2011-09-16)

  • Compatibility with jQuery 1.2 (jQuery 1.5 or above recommended)

  • Compatibility with Django 1.1 (Django 1.2 or above recommended)

0.71 (2011-09-5)

  • Fixed error in 0.69 rendering text fields whose font size is not integer.

0.70 (2011-08-31)

  • Catalonia translations, by Raimon Esteve

0.69 (2011-08-18)

  • Compatible with the CSRF protection (CsrfViewMiddleware)

  • Improvement in the rendering of the widgets (better calculate the height and width)

  • More versatile the api

0.68 (2011-08-16)

  • Update the README

0.67 (2011-06-23)

  • Spanish translations

0.66 (2011-06-21)

  • Support to old browsers. Some browser have not a JSON library

0.65 (2011-06-7)

  • Improved the inplace edit widget in images.

0.64 (2011-06-6)

  • Inplace edit of imagefield and filefield works in IE (new), FF, Chrome (alpha)

0.63 (2011-05-24)

  • Inplace edit of imagefield and filefield (alpha)

  • More versatile the api

0.62 (2011-03-18)

  • Fixes the warning when the error is for other field

  • More versatile the api

0.60 (2011-02-18)

  • Created a test project

  • Inplace editof booleanfield

  • Fixes some details of datetimefield and datefield

  • Can’t save datetime values on several browser

  • The icons did not see

  • autoheight and autowidth

  • Improve the inplace edit with choices field

  • Made less intrusive inplace edit form, now it’s putting two spaces)

0.55 (2011-02-11)

  • A new egg from django-inplaceedit-version1

  • The js should be a plugin jQuery

  • The generated html should be bit intrusive

  • API to create adaptators

  • Option to auto_height, and auto_width

  • Error/ succes messages

  • Two functions of render_value, with you can edit, and other when you cannot edit

  • A function with empty value

  • The files media should not be added if this is adding

  • The inplaceedit should can edit some like this:

{% inplace_edit "obj.field_x.field_y" %}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-inplaceedit-0.88.tar.gz (47.0 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page