# Path: smartsnippets/widgets_pool.py
# class WidgetPool(object):
#     def __init__(self):
#     def discover_widgets(self):
#     def register_settings(self, namespace, settings_dict):
#     def unregister_settings(self, namespace, settings_keys=None):
#     def register_widget(self, widget):
#     def unregister_widget(self, widget):
#     def get_widget(self, name):
#     def get_all_widgets(self, has_model=False, snippet=None):
#     def get_settings(self, namespace, name=None):
# 
# Path: smartsnippets/widgets_base.py
# class SmartSnippetWidgetBase(object):
#     name = 'Base Widget'
#     model = SmartSnippetVariable
#     template = None
# 
#     def __init__(self, variable, **kwargs):
#         self.variable = variable
# 
#     @property
#     def formatted_value(self):
#         return self.variable.value
# 
#     def get_extra_data(self, request):
#         return {}
# 
#     def render(self, request, context=None):
#         if self.template is None:
#             raise NotImplementedError(
#                 "render needs to be implemented or set a default template")
# 
#         default_data = {'field': self.variable}
#         select_template = list(self.variable.templates) + [self.template]
#         return render_to_string(
#             select_template,
#             dict(self.get_extra_data(request).items() + default_data.items()),
#             context_instance=(context or RequestContext(request))
#         )
# 
# Path: smartsnippets/models.py
# class DropDownVariable(SmartSnippetVariable):
#     choices = models.CharField(
#         max_length=512,
#         help_text=_(
#             'Enter a comma separated list of choices that will be '
#             'available in the dropdown variable when adding and '
#             'configuring the custom component on a page.'))
# 
#     @property
#     def choices_list(self):
#         return ([choice.strip() for choice in self.choices.split(',') if choice.strip()]
#                 if self.choices else [])
# 
#     def save(self, *args, **kwargs):
#         self.widget = 'DropDownField'
#         super(DropDownVariable, self).save(*args, **kwargs)


from smartsnippets.widgets_pool import widget_pool
from smartsnippets.widgets_base import SmartSnippetWidgetBase
from .models import DropDownVariable
import collections
import json
    name = 'DropDown Field'
    model = DropDownVariable
    template = 'smartsnippets/widgets/dropdownfield/widget.html'

class SwitcherField(SmartSnippetWidgetBase):
    name = 'Switcher Field'
    template = 'smartsnippets/widgets/switcherfield/widget.html'


class URLField(SmartSnippetWidgetBase):
    name = 'URL Field'
    template = 'smartsnippets/widgets/urlfield/widget.html'


class JSONField(TextField):
    name = 'JSON Field'

    @property
    def formatted_value(self):
        try:
            return json.loads(
                self.variable.value or '{}',
                object_pairs_hook=collections.OrderedDict
            )
        except ValueError:
            pass
        return {}




# Path: smartsnippets/widgets_pool.py
# class WidgetPool(object):
#     def __init__(self):
#     def discover_widgets(self):
#     def register_settings(self, namespace, settings_dict):
#     def unregister_settings(self, namespace, settings_keys=None):
#     def register_widget(self, widget):
#     def unregister_widget(self, widget):
#     def get_widget(self, name):
#     def get_all_widgets(self, has_model=False, snippet=None):
#     def get_settings(self, namespace, name=None):
# 
# Path: smartsnippets/widgets_base.py
# class SmartSnippetWidgetBase(object):
#     name = 'Base Widget'
#     model = SmartSnippetVariable
#     template = None
# 
#     def __init__(self, variable, **kwargs):
#         self.variable = variable
# 
#     @property
#     def formatted_value(self):
#         return self.variable.value
# 
#     def get_extra_data(self, request):
#         return {}
# 
#     def render(self, request, context=None):
#         if self.template is None:
#             raise NotImplementedError(
#                 "render needs to be implemented or set a default template")
# 
#         default_data = {'field': self.variable}
#         select_template = list(self.variable.templates) + [self.template]
#         return render_to_string(
#             select_template,
#             dict(self.get_extra_data(request).items() + default_data.items()),
#             context_instance=(context or RequestContext(request))
#         )
# 
# Path: smartsnippets/models.py
# class DropDownVariable(SmartSnippetVariable):
#     choices = models.CharField(
#         max_length=512,
#         help_text=_(
#             'Enter a comma separated list of choices that will be '
#             'available in the dropdown variable when adding and '
#             'configuring the custom component on a page.'))
# 
#     @property
#     def choices_list(self):
#         return ([choice.strip() for choice in self.choices.split(',') if choice.strip()]
#                 if self.choices else [])
# 
#     def save(self, *args, **kwargs):
#         self.widget = 'DropDownField'
#         super(DropDownVariable, self).save(*args, **kwargs)


# Path: smartsnippets/widgets.py
from smartsnippets.widgets_pool import widget_pool
from smartsnippets.widgets_base import SmartSnippetWidgetBase
from .models import DropDownVariable
import collections
import json

    name = 'DropDown Field'
    model = DropDownVariable
    template = 'smartsnippets/widgets/dropdownfield/widget.html'

class SwitcherField(SmartSnippetWidgetBase):
    name = 'Switcher Field'
    template = 'smartsnippets/widgets/switcherfield/widget.html'


class URLField(SmartSnippetWidgetBase):
    name = 'URL Field'
    template = 'smartsnippets/widgets/urlfield/widget.html'


class JSONField(TextField):
    name = 'JSON Field'

    @property
    def formatted_value(self):
        try:
            return json.loads(
                self.variable.value or '{}',
                object_pairs_hook=collections.OrderedDict
            )
        except ValueError:
            pass
        return {}




widget_pool.register_widget(TextField)