<commit_before>import string
from types import IntType, LongType, StringType, UnicodeType

from django.core.exceptions import ObjectDoesNotExist
from django.template import Context, Library, loader, Node, Template, TemplateSyntaxError
from django.utils.translation import ugettext as _

from multimedia import settings
from multimedia.models import Media
from multimedia.utilities import parse_format
from tagging.models import Tag, TaggedItem
from tagging.utils import parse_tag_input


register = Library()


class ThumbnailNode(Node):
  def __init__(self, var_or_id, format=None, **extra):
    self.var_or_id = var_or_id
    self.format    = format
    self.extra     = extra

  def render(self, context):
    try:
      if self.var_or_id.isdigit():
        media = Media.objects.get(id=self.var_or_id)
      else:
        media = context[self.var_or_id]
    except ObjectDoesNotExist:
      return '<!-- failed to retrieve media with an id of "%d" -->' % self.var_or_id

    thumbnail = media.thumbnail(self.format)
    context = Context({'thumbnail':thumbnail, 'extra':self.extra})
    return loader.render_to_string(thumbnail.format['template'], context)


class ThumbnailForMediaNode(Node):
  def __init__(self,var_or_id,format,context_var):
    self.var_or_id   = var_or_id
    self.format      = format
    self.context_var = context_var
    
  def render(self, context):
    if self.var_or_id.isdigit():
      media = Media.objects.get(id=self.var_or_id)
    else:
      media = context[self.var_or_id]
    thumbnail = media.thumbnail(self.format)<commit_msg>use http://{{site}}/{{thumbnail.url}} iff site is defined<commit_after>import string
from types import IntType, LongType, StringType, UnicodeType

from django.contrib.sites.models import Site
from django.core.exceptions import ObjectDoesNotExist
from django.template import Context, Library, loader, Node, Template, TemplateSyntaxError
from django.utils.translation import ugettext as _

from multimedia import settings
from multimedia.models import Media
from multimedia.utilities import parse_format
from tagging.models import Tag, TaggedItem
from tagging.utils import parse_tag_input


register = Library()


class ThumbnailNode(Node):
  def __init__(self, var_or_id, format=None, **extra):
    self.var_or_id = var_or_id
    self.format    = format
    self.extra     = extra

  def render(self, context):
    try:
      if self.var_or_id.isdigit():
        media = Media.objects.get(id=self.var_or_id)
      else:
        media = context[self.var_or_id]
    except ObjectDoesNotExist:
      return '<!-- failed to retrieve media with an id of "%d" -->' % self.var_or_id

    thumbnail = media.thumbnail(self.format)
    context = Context({'thumbnail':thumbnail, 'extra':self.extra, 'site':Site.objects.get_current()})
    return loader.render_to_string(thumbnail.format['template'], context)


class ThumbnailForMediaNode(Node):
  def __init__(self,var_or_id,format,context_var):
    self.var_or_id   = var_or_id
    self.format      = format
    self.context_var = context_var
    
  def render(self, context):
    if self.var_or_id.isdigit():
      media = Media.objects.get(id=self.var_or_id)
    else:
      media = context[self.var_or_id]
    thumbnail = media.thumbnail(self.format)
{'fraction_non_alphanumeric': 0.09748620478234211, 'fraction_numerical': 0.0, 'mean_word_length': 4.066770186335404, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1678839', 'n_tokens_mistral': 1034, 'n_tokens_neox': 1007, 'n_words': 243}