# Path: contentious/api.py
# class ContentiousInterface(object):
#     def in_edit_mode(self, template_context):
#     def get_content_data(self, key, template_context):
#     def save_content_data(self, key, data, template_context):
#     def pre_render(self, tag_spec, meta):
# def get_api():
# 
# Path: contentious/compat.py
# def get_request_context(request):
#     context = RequestContext(request)
# 
#     if 'request' not in context:
#         context.update({'request': request})
# 
#     return context
# 
# Path: contentious/decorators.py
# def require_edit_mode(function):
#     """ View function decorator for requiring api.in_edit_mode to be True. """
#     def replacement(request, *args, **kwargs):
#         context = get_request_context(request)
#         if not api.in_edit_mode(context):
#             return HttpResponseForbidden()
#         return function(request, *args, **kwargs)
#     return replacement
# 
# Path: contentious/utils.py
# def json_response_from_exception(error):
#     """ Given an exception instance (preferably a ValidationError) return an
#         HTTP response with JSON giving the error(s).
#     """
#     try:
#         errors_dict = error.message_dict
#     except AttributeError:
#         try:
#             errors_dict = {'__all__': error.messages}
#         except AttributeError:
#             errors_dict = {'__all__': [unicode(error)]}
#     return HttpResponse(
#         safe_json_dump(errors_dict),
#         content_type="application/json;charset=utf-8",
#         status=400,
#     )


from django.core.exceptions import ValidationError
from django.http import HttpResponse
from django.views.decorators.http import require_POST
from contentious.api import api
from contentious.compat import get_request_context
from contentious.decorators import require_edit_mode
from contentious.utils import json_response_from_exception
#LIBRARIES

#CONTENTIOUS


@require_POST
@require_edit_mode
def save_content(request):
    """ View for creating/updating a piece of content. """
    #Make a copy of request.POST, but as a single-value (not multi-value dict)
    post = request.POST
    data = {k: post.get(k) for k in post.keys()}
    key = data.pop('key')
    data.pop('csrfmiddlewaretoken', None)
    try:

# Path: contentious/api.py
# class ContentiousInterface(object):
#     def in_edit_mode(self, template_context):
#     def get_content_data(self, key, template_context):
#     def save_content_data(self, key, data, template_context):
#     def pre_render(self, tag_spec, meta):
# def get_api():
# 
# Path: contentious/compat.py
# def get_request_context(request):
#     context = RequestContext(request)
# 
#     if 'request' not in context:
#         context.update({'request': request})
# 
#     return context
# 
# Path: contentious/decorators.py
# def require_edit_mode(function):
#     """ View function decorator for requiring api.in_edit_mode to be True. """
#     def replacement(request, *args, **kwargs):
#         context = get_request_context(request)
#         if not api.in_edit_mode(context):
#             return HttpResponseForbidden()
#         return function(request, *args, **kwargs)
#     return replacement
# 
# Path: contentious/utils.py
# def json_response_from_exception(error):
#     """ Given an exception instance (preferably a ValidationError) return an
#         HTTP response with JSON giving the error(s).
#     """
#     try:
#         errors_dict = error.message_dict
#     except AttributeError:
#         try:
#             errors_dict = {'__all__': error.messages}
#         except AttributeError:
#             errors_dict = {'__all__': [unicode(error)]}
#     return HttpResponse(
#         safe_json_dump(errors_dict),
#         content_type="application/json;charset=utf-8",
#         status=400,
#     )


# Path: contentious/views.py
from django.core.exceptions import ValidationError
from django.http import HttpResponse
from django.views.decorators.http import require_POST
from contentious.api import api
from contentious.compat import get_request_context
from contentious.decorators import require_edit_mode
from contentious.utils import json_response_from_exception

#LIBRARIES

#CONTENTIOUS


@require_POST
@require_edit_mode
def save_content(request):
    """ View for creating/updating a piece of content. """
    #Make a copy of request.POST, but as a single-value (not multi-value dict)
    post = request.POST
    data = {k: post.get(k) for k in post.keys()}
    key = data.pop('key')
    data.pop('csrfmiddlewaretoken', None)
    try:

        api.save_content_data(key, data, get_request_context(request))