from django import template
from django.utils.safestring import mark_safe

from site_content.models import SiteBlock, SitePage, SitePosition, SitePagePositionBlock
import simplejson

register = template.Library()


@register.simple_tag
def get_block(code):
    try:
        block = SiteBlock.objects.get(code=code)
        retval = block.data
        
    except SiteBlock.DoesNotExist:
        retval = ''
    
    return mark_safe(retval)


@register.inclusion_tag('site_content/siteposition_siteblock.html')
def get_position_blocks(position):
    try:
        siteposition = SitePosition.objects.get(code=position)
    
    except SitePosition.DoesNotExist:
        siteposition = SitePosition()
        
    return {'siteposition': siteposition}


@register.inclusion_tag('site_content/siteposition_sitepageblocks.html')
def get_page_position_blocks(page, position):
    blocks = SitePagePositionBlock.objects.filter(sitepage__id=page, siteposition__code=position).order_by('weight')
    position = SitePosition.objects.get(code=position)
    return {'blocks': blocks, 'position': position}
@@ -160,26 +160,8 @@
 lock
-%0Aimport simplejson
 %0A%0Are
@@ -1061,16 +1061,17 @@
 tion': position%7D
+%0A

remove unused simplejson import in page_block