# Path: smartsnippets/resources_processor.py
# def get_resources(resources_data):
#     """
#         Parses resources_data to get all resources defined with
#     the following format:
#         snippet-field/custom.html, static: admin/style.css,
#             http://somesite/absolute-url.js
#     and returns a dictionary with resources extensions and the links defined.
#     """
#     if not resources_data:
#         return {}
#     resources_data = resources_data or ''
#     resources = defaultdict(list)
#     for resource in resources_data.split(','):
#         processed_link = _process(resource)
#         if not processed_link:
#             continue
#         links = resources[processed_link[0]]
#         res_link = processed_link[1]
#         # check if already added. Note: using list and not set just to
#         #   make sure the ordering is kept
#         if res_link not in links:
#             links.append(processed_link[1])
#     return resources
# 
# Path: smartsnippets/settings.py
# def _has_data_defined(widget_data):
# USE_BOOTSTRAP_ACE = getattr(
#     settings, 'SMARTSNIPPETS_USE_BOOTSTRAP_ACE', False)


import re
import logging
from django.core.cache import cache
from django.db import models
from django.core.exceptions import ValidationError
from django.template import Template, TemplateSyntaxError, \
    TemplateDoesNotExist, loader, VariableDoesNotExist
from django.template.loader import render_to_string
from django.db.models import signals
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from cms.models import CMSPlugin
from sekizai.helpers import (
    Watcher as sekizai_context_watcher,
    get_varname as sekizai_cache_key,
)
from .resources_processor import get_resources
from .settings import (
    snippet_caching_time, caching_enabled, allow_inheritance,
    inherit_variable_pattern)
        from widgets_pool import widget_pool
    resources = models.TextField(_('Admin resources'), null=True, blank=True)

    def __init__(self, *args, **kwargs):
        super(SmartSnippetVariable, self).__init__(*args, **kwargs)
        self._resource_dict = None

    @property
    def resources_dict(self):
        if self._resource_dict is None:
            self._resource_dict = get_resources(self.resources)
        return self._resource_dict

    class Meta:
        unique_together = (('snippet', 'name'))
        order_with_respect_to = 'snippet'
        verbose_name = "Standard variable"

    def save(self, *args, **kwargs):
        self.name = clean_variable_name(self.name)
        super(SmartSnippetVariable, self).save(*args, **kwargs)
        # auto-generate missing variables for all snippet plugins
        plugin_ids = SmartSnippetPointer.objects \
            .filter(snippet=self.snippet) \
            .exclude(variables__snippet_variable=self) \
            .values_list('id', flat=True)
        # in order to improve performance do a bulk create
        Variable.objects.bulk_create([
            Variable(snippet_id=plugin_id, snippet_variable=self)
            for plugin_id in plugin_ids
        ])

# Path: smartsnippets/resources_processor.py
# def get_resources(resources_data):
#     """
#         Parses resources_data to get all resources defined with
#     the following format:
#         snippet-field/custom.html, static: admin/style.css,
#             http://somesite/absolute-url.js
#     and returns a dictionary with resources extensions and the links defined.
#     """
#     if not resources_data:
#         return {}
#     resources_data = resources_data or ''
#     resources = defaultdict(list)
#     for resource in resources_data.split(','):
#         processed_link = _process(resource)
#         if not processed_link:
#             continue
#         links = resources[processed_link[0]]
#         res_link = processed_link[1]
#         # check if already added. Note: using list and not set just to
#         #   make sure the ordering is kept
#         if res_link not in links:
#             links.append(processed_link[1])
#     return resources
# 
# Path: smartsnippets/settings.py
# def _has_data_defined(widget_data):
# USE_BOOTSTRAP_ACE = getattr(
#     settings, 'SMARTSNIPPETS_USE_BOOTSTRAP_ACE', False)


# Path: smartsnippets/models.py
import re
import logging
from django.core.cache import cache
from django.db import models
from django.core.exceptions import ValidationError
from django.template import Template, TemplateSyntaxError, \
    TemplateDoesNotExist, loader, VariableDoesNotExist
from django.template.loader import render_to_string
from django.db.models import signals
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from cms.models import CMSPlugin
from sekizai.helpers import (
    Watcher as sekizai_context_watcher,
    get_varname as sekizai_cache_key,
)
from .resources_processor import get_resources
from .settings import (
    snippet_caching_time, caching_enabled, allow_inheritance,
    inherit_variable_pattern)
        from widgets_pool import widget_pool

    resources = models.TextField(_('Admin resources'), null=True, blank=True)

    def __init__(self, *args, **kwargs):
        super(SmartSnippetVariable, self).__init__(*args, **kwargs)
        self._resource_dict = None

    @property
    def resources_dict(self):
        if self._resource_dict is None:
            self._resource_dict = get_resources(self.resources)
        return self._resource_dict

    class Meta:
        unique_together = (('snippet', 'name'))
        order_with_respect_to = 'snippet'
        verbose_name = "Standard variable"

    def save(self, *args, **kwargs):
        self.name = clean_variable_name(self.name)
        super(SmartSnippetVariable, self).save(*args, **kwargs)
        # auto-generate missing variables for all snippet plugins
        plugin_ids = SmartSnippetPointer.objects \
            .filter(snippet=self.snippet) \
            .exclude(variables__snippet_variable=self) \
            .values_list('id', flat=True)
        # in order to improve performance do a bulk create
        Variable.objects.bulk_create([
            Variable(snippet_id=plugin_id, snippet_variable=self)
            for plugin_id in plugin_ids
        ])

        if not caching_enabled: