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

Added widget support for django-suit #150

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions django_hstore/templates/hstore_suit_widget.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% load i18n %}
<script type="text/html" id="hstore-row-template-{{ field_name }}" class="hstore-row-template-inline">
<div class="form-row field-data">
<div>
<input type="text" placeholder="{% trans 'key' %}" value="<%= key %>" style="width:100px;">
&nbsp; <strong>:</strong> &nbsp;&nbsp;
<input style="width:200px;"
value="<%= _.escape(value) %>"
type="text"
placeholder="{% trans 'value' %}">
&nbsp;&nbsp;
<a href="#" class="remove-row icon" title="{% trans 'remove row' %}">
<i class="icon-remove-sign"></i>
</a>
</div>
<hr style="margin: 2px 0px;"/>
</div>
</script>

<script type="text/html" id="hstore-ui-template-{{ field_name }}"{% if '__prefix__' in field_name %} class="hstore-ui-template-inline"{% endif %}>
<div class="control-group form-row field-name hstore" id="hstore-{{ field_name }}">
<div>
<div class="control-label">
<label class="required" for="id_name"><%= label %></label>
<a href="#" class="hstore-toggle-txtarea icon" id="change_id_account" title="{% trans 'toggle textarea' %}">
<i class="icon-pencil"></i>{% trans 'toggle textarea' %}
</a>
</div>
<% if(help && help != '') { %>
<div class="form-row">
<p class="help" style="margin:0;padding:0"><%= help %></p>
</div>
<% } %>

<div class="controls">
<div class="hstore-rows">
<% if(errors){ %>
<div class="form-row field-data">
<div>
<ul class="errorlist">
<%= errors %>
</ul>
</div>
</div>
<% } %>
<% for(key in data){ %>
<%= _.template(django.jQuery('.hstore-row-template-inline').eq(0).html(), { 'key': key, 'value': data[key] }) %>
<% } %>
</div>

<div class="form-row field-data hstore-textarea" style="display:none">
<div>
<label for="<%= id %>" class="required">{% trans 'Raw textarea' %}:</label>
<textarea class="vLargeTextField" cols="40" id="<%= id %>" name="<%= name %>" rows="10"><%= value %></textarea>
</div>
</div>

<div class="form-row">
<a href="#" class="hs-add-row icon" title="{% trans 'Add another row' %}">
<i class="icon-plus-sign"></i>{% trans "Add row" %}
</a>
</div>
</div>
</div>
</div>

</script>

<script>django.jQuery(function() { initDjangoHStoreWidget('{{ field_name }}') });</script>
15 changes: 15 additions & 0 deletions django_hstore/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,18 @@ class GrappelliAdminHStoreWidget(BaseAdminHStoreWidget):
AdminHStoreWidget = GrappelliAdminHStoreWidget
else:
AdminHStoreWidget = DefaultAdminHStoreWidget


class SuitAdminHStoreWidget(BaseAdminHStoreWidget):
"""
Widget that displays the HStore contents
in the django-admin with a nice interactive UI
designed for django-suit
"""
admin_style = 'suit'


if 'suit' in settings.INSTALLED_APPS:
AdminHStoreWidget = SuitAdminHStoreWidget
else:
AdminHStoreWidget = DefaultAdminHStoreWidget