Fix outputted groups in JS

- Legacy-Id: 3840
This commit is contained in:
Ole Laursen 2012-01-20 16:18:03 +00:00
parent d16a5ea46a
commit 0f6053166e
2 changed files with 19 additions and 1 deletions

View file

@ -7,6 +7,7 @@ from django.utils.html import escape, fix_ampersands
from django.template.defaultfilters import linebreaksbr, wordwrap, stringfilter, urlize, truncatewords_html
from django.template import resolve_variable
from django.utils.safestring import mark_safe, SafeData
from django.utils import simplejson
try:
from email import utils as emailutils
except ImportError:
@ -449,6 +450,22 @@ def format_history_text(text):
return mark_safe(u'<div class="snipped">%s<div class="showAll">[show all]</div><div><div style="display:none" class="full">%s</div>' % (snipped, full))
return full
@register.filter
def user_roles_json(user):
roles = {}
if user.is_authenticated():
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
from redesign.group.models import Role
for r in Role.objects.filter(person__user=user).select_related(depth=1):
if r.name_id == "secr" and r.group.acronym == "secretariat":
roles["Secretariat"] = True
elif r.name_id == "ad" and r.group.type_id == "area" and r.group.state_id == "active":
roles["Area Director"] = roles["Area_Director"] = True
else:
for g in user.groups:
roles[g.name] = True
return mark_safe(simplejson.dumps(roles))
def _test():
import doctest
doctest.testmod()

View file

@ -34,6 +34,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% endcomment %}
{% load ietf_filters %}
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- v{{version_num}}, {{ revision_num }}, {{ revision_time }} -->
@ -46,7 +47,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{% block pagehead %}{% endblock %}
<script type="text/javascript">
IETF = {};
IETF.user_groups = { {% for group in user.groups.all %}"{{group}}":true{% if not forloop.last %}, {%endif%}{%endfor%} };
IETF.user_groups = {{ user|user_roles_json }};
</script>
{% ifnotequal server_mode "production" %}
<link rel="icon" href="/images/ietf-dev-icon.bmp" />