# Path: shortener/links/models.py
# class Link(TimeStampedModel):
# 
#     original_url = models.CharField(_("URL to be shortened"), max_length=255, unique=True)
#     identifier = models.CharField(_("Identifier"),
#                                     max_length=100,
#                                     blank=True,
#                                     validators=[validate_five_characters],
#                                     db_index=True)
# 
#     def __unicode__(self):
#         return self.original_url
# 
#     @property
#     def count(self):
#         return self.linklog_set.count()
# 
#     def log(self, request):
#         self.linklog_set.create_from_request(
#             link=self,
#             request=request
#         )
# 
#     def get_identifier_url(self):
#         try:
#             return reverse("links:redirect", kwargs={'identifier': self.identifier})
#         except NoReverseMatch:
#             return 'NADA'
# 
#     @property
#     def tiny(self):
#         return base64.encode(self.pk)
# 
#     def get_tiny_url(self):
#         return reverse("links:redirect", kwargs={'identifier': self.tiny})
# 
#     def amazonify(self):
#         url = self.original_url
#         if url.startswith(
#             ("https://amazon.",
#                 "http://amazon.",
#                 "http://amzn.",
#                 "https://amzn.",
#                 "https://www.amazon.",
#                 "http://www.amazon.")
#             ):
#             url = amazonify(url, "mlinar-20")
#         return url


from django.conf import settings
from django.contrib import admin
from django.contrib.sites.models import Site
from django.utils.safestring import mark_safe
from .models import Link



class LinkAdmin(admin.ModelAdmin):

    verbose_name_plural = "links"
    list_display = ['original_url',  'identifier',  'count', 'created', 'modified', ]
    readonly_fields = ('test_url', 'created', 'modified', 'count')
    search_fields = ['original_url', 'identifier']

    def test_url(self, instance):
        site = Site.objects.get_current()

# Path: shortener/links/models.py
# class Link(TimeStampedModel):
# 
#     original_url = models.CharField(_("URL to be shortened"), max_length=255, unique=True)
#     identifier = models.CharField(_("Identifier"),
#                                     max_length=100,
#                                     blank=True,
#                                     validators=[validate_five_characters],
#                                     db_index=True)
# 
#     def __unicode__(self):
#         return self.original_url
# 
#     @property
#     def count(self):
#         return self.linklog_set.count()
# 
#     def log(self, request):
#         self.linklog_set.create_from_request(
#             link=self,
#             request=request
#         )
# 
#     def get_identifier_url(self):
#         try:
#             return reverse("links:redirect", kwargs={'identifier': self.identifier})
#         except NoReverseMatch:
#             return 'NADA'
# 
#     @property
#     def tiny(self):
#         return base64.encode(self.pk)
# 
#     def get_tiny_url(self):
#         return reverse("links:redirect", kwargs={'identifier': self.tiny})
# 
#     def amazonify(self):
#         url = self.original_url
#         if url.startswith(
#             ("https://amazon.",
#                 "http://amazon.",
#                 "http://amzn.",
#                 "https://amzn.",
#                 "https://www.amazon.",
#                 "http://www.amazon.")
#             ):
#             url = amazonify(url, "mlinar-20")
#         return url


# Path: shortener/links/admin.py
from django.conf import settings
from django.contrib import admin
from django.contrib.sites.models import Site
from django.utils.safestring import mark_safe
from .models import Link




class LinkAdmin(admin.ModelAdmin):

    verbose_name_plural = "links"
    list_display = ['original_url',  'identifier',  'count', 'created', 'modified', ]
    readonly_fields = ('test_url', 'created', 'modified', 'count')
    search_fields = ['original_url', 'identifier']

    def test_url(self, instance):
        site = Site.objects.get_current()

        response = """<a href="{0}{1}/{2}">{0}{1}/{2}</a>""".format(