import logging
import os
import urllib2
import httplib
from django.conf import settings
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import simplejson
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from sorl.thumbnail import ImageField, get_thumbnail
# Create your models here.
# import the logging library


if hasattr(settings, 'COLLECTIONS_API_HOSTNAME'):
    COLLECTIONS_API_HOSTNAME = settings.COLLECTIONS_API_HOSTNAME
else:
    COLLECTIONS_API_HOSTNAME = 'www.vam.ac.uk'

if hasattr(settings, 'MEDIA_SERVER'):
   COLLECTIONS_API_MEDIA_SERVER = settings.COLLECTIONS_API_MEDIA_SERVER
else:
    COLLECTIONS_API_MEDIA_SERVER = 'media.vam.ac.uk'


# Get an instance of a logger
logger = logging.getLogger('labels')


class BaseScreen(models.Model):
    name = models.CharField(max_length=255, null=False)
    timeout_images = models.ManyToManyField("Image", blank=True)

    _thumbnail_url = None

    def __unicode__(self):
        return self.name

    def referrer(self):
        return self._meta.object_name.lower()

    @property
    def model_name(self):
        return self._meta.object_name.lower()

    def _Objects(self):
        return self.museumobjects.count()

    class Meta:
        abstract = True


class BaseLabel(models.Model):
    _thumbnail_url = None

    def digital_label(self):
        href = reverse('admin:%s_%s_change' % (self._meta.app_label, 'digitallabel'),
                       args=[self.digitallabel.pk])
        return mark_safe('<a href="%s">%s</a>' % (href, self.digitallabel))