<commit_before># -*- coding: utf-8 -*-
import uuid
import os
from datetime import datetime

from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable
from opps.source.models import Source


def get_file_path(instance, filename):
    ext = filename.split('.')[-1]
    filename = "{0}-{1}.{2}".format(uuid.uuid4(), instance.slug, ext)
    d = datetime.now()
    folter = d.strftime("images/%Y/%m/%d/")
    return os.path.join(folter, filename)


class Image(Publishable):

    title = models.CharField(_(u"Title"), max_length=140)
    slug = models.SlugField(_(u"Slug"), max_length=150, blank=True)
    image = models.ImageField(upload_to=get_file_path)
    description = models.TextField(_(u"Description"), null=True, blank=True)

    source = models.ForeignKey(Source, null=True, blank=True)

    def __unicode__(self):
        return "{0}-{1}".format(self.id, self.slug)
<commit_msg>Add get absolute url on image models<commit_after># -*- coding: utf-8 -*-
import uuid
import os
from datetime import datetime

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone

from opps.core.models import Publishable
from opps.source.models import Source


def get_file_path(instance, filename):
    ext = filename.split('.')[-1]
    filename = "{0}-{1}.{2}".format(uuid.uuid4(), instance.slug, ext)
    d = datetime.now()
    folter = d.strftime("images/%Y/%m/%d/")
    return os.path.join(folter, filename)


class Image(Publishable):

    title = models.CharField(_(u"Title"), max_length=140)
    slug = models.SlugField(_(u"Slug"), max_length=150, blank=True)
    image = models.ImageField(upload_to=get_file_path)
    description = models.TextField(_(u"Description"), null=True, blank=True)

    source = models.ForeignKey(Source, null=True, blank=True)

    def __unicode__(self):
        return "{0}-{1}".format(self.id, self.slug)

    def get_absolute_url(self):
        if self.date_available<=timezone.now() and self.published==True:
            return self.image.url
        return u""

{'fraction_non_alphanumeric': 0.1413760603204524, 'fraction_numerical': 0.013195098963242224, 'mean_word_length': 4.103365384615385, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '2184334', 'n_tokens_mistral': 703, 'n_tokens_neox': 689, 'n_words': 156}