# Path: smartsnippets/models.py
# class Variable(models.Model):
#     snippet_variable = models.ForeignKey(SmartSnippetVariable,
#                                          related_name='variables')
#     value = models.TextField()
#     snippet = models.ForeignKey(SmartSnippetPointer, related_name='variables')
# 
#     class Meta:
#         unique_together = (('snippet_variable', 'snippet'))
# 
#     @property
#     def formatted_value(self):
#         from widgets_pool import widget_pool
#         widget_instance = widget_pool.get_widget(self.widget)(self)
#         return widget_instance.formatted_value
# 
#     @property
#     def name(self):
#         return self.snippet_variable.name
# 
#     @property
#     def widget(self):
#         return self.snippet_variable.widget
# 
#     @property
#     def templates(self):
#         return self.snippet_variable.resources_dict.get('html', set())
# 
#     @property
#     def js(self):
#         return self.snippet_variable.resources_dict.get('js', set())
# 
#     @property
#     def css(self):
#         return self.snippet_variable.resources_dict.get('css', set())


from django.db import models
from cms.models import CMSPlugin, Page, Placeholder
from smartsnippets.models import Variable


class InheritPageContent(CMSPlugin):
    # from which page
    from_page = models.ForeignKey(Page)
    # from which section
    from_placeholder = models.CharField(max_length=255, db_index=True)

    class Meta:
        db_table = 'cmsplugin_inheritpagecontent'

    def get_placeholder(self):
        try:
            return self.from_page.placeholders.get(slot=self.from_placeholder)
        except Placeholder.DoesNotExist:
            return None


class OverwriteVariable(models.Model):
    # which variable I overwrite

# Path: smartsnippets/models.py
# class Variable(models.Model):
#     snippet_variable = models.ForeignKey(SmartSnippetVariable,
#                                          related_name='variables')
#     value = models.TextField()
#     snippet = models.ForeignKey(SmartSnippetPointer, related_name='variables')
# 
#     class Meta:
#         unique_together = (('snippet_variable', 'snippet'))
# 
#     @property
#     def formatted_value(self):
#         from widgets_pool import widget_pool
#         widget_instance = widget_pool.get_widget(self.widget)(self)
#         return widget_instance.formatted_value
# 
#     @property
#     def name(self):
#         return self.snippet_variable.name
# 
#     @property
#     def widget(self):
#         return self.snippet_variable.widget
# 
#     @property
#     def templates(self):
#         return self.snippet_variable.resources_dict.get('html', set())
# 
#     @property
#     def js(self):
#         return self.snippet_variable.resources_dict.get('js', set())
# 
#     @property
#     def css(self):
#         return self.snippet_variable.resources_dict.get('css', set())


# Path: smartsnippets_inherit/models.py
from django.db import models
from cms.models import CMSPlugin, Page, Placeholder
from smartsnippets.models import Variable



class InheritPageContent(CMSPlugin):
    # from which page
    from_page = models.ForeignKey(Page)
    # from which section
    from_placeholder = models.CharField(max_length=255, db_index=True)

    class Meta:
        db_table = 'cmsplugin_inheritpagecontent'

    def get_placeholder(self):
        try:
            return self.from_page.placeholders.get(slot=self.from_placeholder)
        except Placeholder.DoesNotExist:
            return None


class OverwriteVariable(models.Model):
    # which variable I overwrite

    variable = models.ForeignKey(Variable)