# Path: sandbox/views.py
# class BasicSampleFormView(FormView):
#     template_name = 'form.html'
#     form_class = SampleForm
# 
#     def get_success_url(self):
#         return reverse('home')
# 
# class ModesSampleFormView(BasicSampleFormView):
#     template_name = 'modes.html'
# 
#     def get_context_data(self, **kwargs):
#         context = super(ModesSampleFormView, self).get_context_data(**kwargs)
#         context.update({
#             'codemirror_mode': self.codemirror_mode,
#         })
#         return context
# 
#     def get_initial(self):
#         """
#         Try to find a demo source for given mode if any, if finded use it to
#         fill the demo textarea.
#         """
#         initial = {}
# 
#         if self.kwargs.get('mode', None):
#             filename = "{}.txt".format(self.kwargs['mode'])
#             filepath = os.path.join(settings.BASE_DIR, 'demo_datas', filename)
#             if os.path.exists(filepath):
#                 with io.open(filepath, 'r', encoding='utf-8') as fp:
#                     initial['foo'] = fp.read()
# 
#         return initial
# 
#     def get(self, request, *args, **kwargs):
#         self.codemirror_mode = kwargs.get('mode', None)
#         return super(ModesSampleFormView, self).get(request, *args, **kwargs)
# 
#     def post(self, request, *args, **kwargs):
#         self.codemirror_mode = kwargs.get('mode', None)
#         return super(ModesSampleFormView, self).post(request, *args, **kwargs)


from django.conf import settings
from django.conf.urls import url
from django.views.generic.base import TemplateView
from sandbox.views import BasicSampleFormView, ModesSampleFormView
"""
Sandbox URL Configuration
"""




urlpatterns = [
    # Dummy homepage to list demo views
    url(r'^$', TemplateView.as_view(
        template_name="homepage.html"
    ), name='home'),

    # Sample with codemirror in the raw way
    url(r'^raw/$', TemplateView.as_view(
        template_name="raw.html"
    ), name='raw'),

    # Basic form sample
    url(r'^form/$', BasicSampleFormView.as_view(
        template_name="form.html"
    ), name='form'),

    # Mode index list
    url(r'^modes/$', ModesSampleFormView.as_view(
        template_name="modes.html"
    ), name='mode-index'),

    # Basic form sample with specific mode

# Path: sandbox/views.py
# class BasicSampleFormView(FormView):
#     template_name = 'form.html'
#     form_class = SampleForm
# 
#     def get_success_url(self):
#         return reverse('home')
# 
# class ModesSampleFormView(BasicSampleFormView):
#     template_name = 'modes.html'
# 
#     def get_context_data(self, **kwargs):
#         context = super(ModesSampleFormView, self).get_context_data(**kwargs)
#         context.update({
#             'codemirror_mode': self.codemirror_mode,
#         })
#         return context
# 
#     def get_initial(self):
#         """
#         Try to find a demo source for given mode if any, if finded use it to
#         fill the demo textarea.
#         """
#         initial = {}
# 
#         if self.kwargs.get('mode', None):
#             filename = "{}.txt".format(self.kwargs['mode'])
#             filepath = os.path.join(settings.BASE_DIR, 'demo_datas', filename)
#             if os.path.exists(filepath):
#                 with io.open(filepath, 'r', encoding='utf-8') as fp:
#                     initial['foo'] = fp.read()
# 
#         return initial
# 
#     def get(self, request, *args, **kwargs):
#         self.codemirror_mode = kwargs.get('mode', None)
#         return super(ModesSampleFormView, self).get(request, *args, **kwargs)
# 
#     def post(self, request, *args, **kwargs):
#         self.codemirror_mode = kwargs.get('mode', None)
#         return super(ModesSampleFormView, self).post(request, *args, **kwargs)


# Path: sandbox/urls.py
from django.conf import settings
from django.conf.urls import url
from django.views.generic.base import TemplateView
from sandbox.views import BasicSampleFormView, ModesSampleFormView

"""
Sandbox URL Configuration
"""




urlpatterns = [
    # Dummy homepage to list demo views
    url(r'^$', TemplateView.as_view(
        template_name="homepage.html"
    ), name='home'),

    # Sample with codemirror in the raw way
    url(r'^raw/$', TemplateView.as_view(
        template_name="raw.html"
    ), name='raw'),

    # Basic form sample
    url(r'^form/$', BasicSampleFormView.as_view(
        template_name="form.html"
    ), name='form'),

    # Mode index list
    url(r'^modes/$', ModesSampleFormView.as_view(
        template_name="modes.html"
    ), name='mode-index'),

    # Basic form sample with specific mode

    url(r'^modes/(?P<mode>[-\w]+)/$', ModesSampleFormView.as_view(