Skip to content

Commit

Permalink
model verbose name fix, widget html refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
eriktelepovsky committed Jan 28, 2015
1 parent c91d8e5 commit b8c4ed8
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 69 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
# The short X.Y version.
version = '1.1'
# The full version, including alpha/beta/rc tags.
release = '1.1.0'
release = '1.1.1'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion permissions_widget/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION='1.1.0'
VERSION='1.1.1'
9 changes: 4 additions & 5 deletions permissions_widget/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
PermissionSelectMultipleWidget
The actual permissions widget.
"""
from string import lower
from django import forms
from django import template
from django.template.loader import get_template
Expand Down Expand Up @@ -44,14 +45,12 @@ def render(self, name, value, attrs=None, choices=()):
setattr(permission, "value", permission.pk)

model_class = permission.content_type.model_class()
model = model_class
if model is not None:
model = model._meta.verbose_name
model_verbose_name = model_class._meta.verbose_name if model_class else None

if app in EXCLUDE_APPS:
continue

if u'%s.%s' % (app, model) in EXCLUDE_MODELS:
if u'%s.%s' % (app, lower(model_class.__name__)) in EXCLUDE_MODELS:
continue

permission_types.setdefault(permission_type, [])
Expand All @@ -60,7 +59,7 @@ def render(self, name, value, attrs=None, choices=()):
if last_model != model_class or last_app != app:
if row:
table.append(row)
row = dict(model=model, model_class=model_class, app=app, permissions={})
row = dict(model=model_verbose_name, model_class=model_class, app=app, permissions={})

# place permission
row['permissions'][permission_type] = {
Expand Down
129 changes: 67 additions & 62 deletions permissions_widget/templates/permissions_widget/widget.html
Original file line number Diff line number Diff line change
@@ -1,72 +1,77 @@
{% load permissions_widget_tags %}
{% load permissions_widget_tags i18n %}

<table class="table">
<tr>
<th colspan="{{ permission_types|length|add:"1" }}"><h2>Standard permissions</h2></th>
</tr>
<tr>
<td></td>
{% for permission_type in permission_types %}
<th>
{{ permission_type|capfirst }}
</th>
{% endfor %}
</tr>

{% for row in table %}
{% ifchanged row.app %}
<thead>
<tr>
<th colspan="{{ permission_types|length|add:"1" }}">
{{ row.app|capfirst }}
</th>
<th colspan="{{ permission_types|length|add:"1" }}"><h2>Standard permissions</h2></th>
</tr>
{% endifchanged %}
{% ifchanged row.model %}
<tr>
<td>
{{ row.model|capfirst }}
</td>
{% for permission_type in permission_types %}
{% with row.permissions|get_item:permission_type as permission %}
<td>
{% if permission %}
<input name="{{ name }}" title="{{ permission.name }}" {% if permission.value in value %}checked="checked"{% endif %} value="{{ permission.value }}" type="checkbox" />
{% endif %}
</td>
{% endwith %}
{% endfor %}
</tr>
{% endifchanged %}
{% endfor %}

{% if permission_types_custom %}
<tr>
<th colspan="{{ permission_types|length|add:"1" }}"><h2>Custom permissions</h2></th>
<th>{% trans 'App & Model' %}</th>
{% for permission_type in permission_types %}
<th>
{{ permission_type|capfirst }}
</th>
{% endfor %}
</tr>
{% endif %}
{% for row in table %}
{% ifchanged row.model %}
{% with permission_types_custom|get_for_model:row as permissions %}
{% if permissions %}
<tr>
<th colspan="{{ permission_types|length|add:"1" }}">
{{ row.app|capfirst }} |
{{ row.model|capfirst }}
</th>
</tr>
{% for permission in permissions %}
</thead>
<tbody>
{% for row in table %}
{% ifchanged row.app %}
<tr>
<th colspan="{{ permission_types|length|add:"1" }}">
{{ row.app|capfirst }}
</th>
</tr>
{% endifchanged %}

{% ifchanged row.model %}
<tr>
<td>
{{ row.model|capfirst }}
</td>
{% for permission_type in permission_types %}
{% with row.permissions|get_item:permission_type as permission %}
<td>
{% if permission %}
<input name="{{ name }}" title="{{ permission.name }}" {% if permission.value in value %}checked="checked"{% endif %} value="{{ permission.value }}" type="checkbox" />
{% endif %}
</td>
{% endwith %}
{% endfor %}
</tr>
{% endifchanged %}
{% endfor %}

{% if permission_types_custom %}
<tr>
<td>
{{ permission.name }}
</td>
<td>
<input name="{{ name }}" title="{{ permission.name }}" {% if permission.value in value %}checked="checked"{% endif %} value="{{ permission.value }}" type="checkbox" />
</td>
<td colspan="{{ permission_types|length|add:"-1" }}">&nbsp;</td>
<th colspan="{{ permission_types|length|add:"1" }}"><h2>Custom permissions</h2></th>
</tr>
{% endfor %}
{% endif %}
{% endwith %}
{% endifchanged %}
{% endfor %}

{% for row in table %}
{% ifchanged row.model %}
{% with permission_types_custom|get_for_model:row as permissions %}
{% if permissions %}
<tr>
<th colspan="{{ permission_types|length|add:"1" }}">
{{ row.app|capfirst }} |
{{ row.model|capfirst }}
</th>
</tr>
{% for permission in permissions %}
<tr>
<td>
{{ permission.name }}
</td>
<td>
<input name="{{ name }}" title="{{ permission.name }}" {% if permission.value in value %}checked="checked"{% endif %} value="{{ permission.value }}" type="checkbox" />
</td>
<td colspan="{{ permission_types|length|add:"-1" }}">&nbsp;</td>
</tr>
{% endfor %}
{% endif %}
{% endwith %}
{% endifchanged %}
{% endfor %}
</tbody>
</table>

0 comments on commit b8c4ed8

Please sign in to comment.