# Path: querybuilder/decorators.py
# def superuser_only(function):
#     def _inner(request, *args, **kwargs):
#         if not request.user.is_superuser:
#             raise PermissionDenied
# 
#         return function(request, *args, **kwargs)
#     return _inner


from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.core import serializers
from django.utils import simplejson
from django.template import RequestContext
from models import *
from forms import *
from querybuilder.models import *
from querybuilder.decorators import superuser_only
from encoders import json_table_encoder, json_graph_encoder
    from querybuilder.models import get_apps, get_models_in_app
import re
            main_data = formatted_data_list
        else:
            main_data = data_list
    else:
        column = get_object_or_404(DataColumn, id = column_id)
        main_data = column.get_data()

    if not encode:
        return main_data

    # Encode it in the appropriate format
    if element.get_type() == "graph":
        data = json_graph_encoder.encode(main_data)
    elif element.get_type() == "table":
        data = json_table_encoder.encode(main_data)
    else:
        data = simplejson.JSONEncoder.encode(main_data)

    return data

### Redirections ###

def redirect_to_design():
    return HttpResponseRedirect('/dashboard/design/')

def redirect_to_edit_element(element):
    return HttpResponseRedirect('/dashboard/design/edit_element/%d/' % element.id)

### Design-mode views ###


# Path: querybuilder/decorators.py
# def superuser_only(function):
#     def _inner(request, *args, **kwargs):
#         if not request.user.is_superuser:
#             raise PermissionDenied
# 
#         return function(request, *args, **kwargs)
#     return _inner


# Path: dashboard/views.py
from django.http import HttpResponse, HttpResponseRedirect, Http404
from django.shortcuts import render_to_response, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.core import serializers
from django.utils import simplejson
from django.template import RequestContext
from models import *
from forms import *
from querybuilder.models import *
from querybuilder.decorators import superuser_only
from encoders import json_table_encoder, json_graph_encoder
    from querybuilder.models import get_apps, get_models_in_app
import re

            main_data = formatted_data_list
        else:
            main_data = data_list
    else:
        column = get_object_or_404(DataColumn, id = column_id)
        main_data = column.get_data()

    if not encode:
        return main_data

    # Encode it in the appropriate format
    if element.get_type() == "graph":
        data = json_graph_encoder.encode(main_data)
    elif element.get_type() == "table":
        data = json_table_encoder.encode(main_data)
    else:
        data = simplejson.JSONEncoder.encode(main_data)

    return data

### Redirections ###

def redirect_to_design():
    return HttpResponseRedirect('/dashboard/design/')

def redirect_to_edit_element(element):
    return HttpResponseRedirect('/dashboard/design/edit_element/%d/' % element.id)

### Design-mode views ###


@superuser_only