# Path: easymode/utils/languagecode.py
# def strip_language_code(url):
#     """
#     Strip the language code from the beginning of string
# 
#     >>> strip_language_code('http://example.com/en/example.html')
#     'http://example.com/example.html'
#     
#     :param url: An url.
#     :rtype: The ``url`` but the language code is removed.
#     """
#     return STRIP_LANGUAGE_CODE_REGEX.sub('/',url, 1)


from django import forms
from django.conf import settings
from django.core import urlresolvers
from django.forms import widgets
from django.template.loader import render_to_string
from django.utils.encoding import force_unicode
from django.utils.html import mark_safe
from django.utils.translation import ugettext
from easymode.utils.languagecode import strip_language_code
"""
Contains widgets that can be used for admin models
with related items.
"""


__all__ = ('RenderLink', 'LinkWidget')

class RenderLink(forms.Widget):
    """
    Renders a link to an admin page based on the primary key
    value of the model.
    """
    input_type = None
    
    def _has_changed(self, initial, data):
        return False
    def id_for_label(self, id_):
        return "hmm geen idee"
        
    def render(self, name, value, attrs=None):
        
        modelname = self.attrs['modelname']
        app_label = self.attrs['app_label']
        label = self.attrs['label']
        url_pattern = '%s:%s_%s_change' % ('admin', app_label, modelname)
        

# Path: easymode/utils/languagecode.py
# def strip_language_code(url):
#     """
#     Strip the language code from the beginning of string
# 
#     >>> strip_language_code('http://example.com/en/example.html')
#     'http://example.com/example.html'
#     
#     :param url: An url.
#     :rtype: The ``url`` but the language code is removed.
#     """
#     return STRIP_LANGUAGE_CODE_REGEX.sub('/',url, 1)


# Path: easymode/tree/admin/widgets/foreignkey.py
from django import forms
from django.conf import settings
from django.core import urlresolvers
from django.forms import widgets
from django.template.loader import render_to_string
from django.utils.encoding import force_unicode
from django.utils.html import mark_safe
from django.utils.translation import ugettext
from easymode.utils.languagecode import strip_language_code

"""
Contains widgets that can be used for admin models
with related items.
"""


__all__ = ('RenderLink', 'LinkWidget')

class RenderLink(forms.Widget):
    """
    Renders a link to an admin page based on the primary key
    value of the model.
    """
    input_type = None
    
    def _has_changed(self, initial, data):
        return False
    def id_for_label(self, id_):
        return "hmm geen idee"
        
    def render(self, name, value, attrs=None):
        
        modelname = self.attrs['modelname']
        app_label = self.attrs['app_label']
        label = self.attrs['label']
        url_pattern = '%s:%s_%s_change' % ('admin', app_label, modelname)
        

        url = strip_language_code(urlresolvers.reverse(url_pattern, args=[value]))