<commit_before>import os

from django.core.files.storage import get_storage_class
from django.db import models

from instance import Instance
from utils.image_tools import get_dimensions, resize


def upload_to(instance, filename):
    return os.path.join(
        instance.instance.user.username,
        'attachments',
        os.path.split(filename)[1])


class Attachment(models.Model):
    instance = models.ForeignKey(Instance, related_name="attachments")
    media_file = models.FileField(upload_to=upload_to)
    mimetype = models.CharField(
        max_length=20, null=False, blank=True, default='')

    class Meta:
        app_label = 'odk_logger'<commit_msg>get full filepath of an attachment<commit_after>import os

from django.core.files.storage import get_storage_class
from django.db import models

from instance import Instance
from utils.image_tools import get_dimensions, resize


def upload_to(instance, filename):
    return os.path.join(
        instance.instance.user.username,
        'attachments',
        os.path.split(filename)[1])


class Attachment(models.Model):
    instance = models.ForeignKey(Instance, related_name="attachments")
    media_file = models.FileField(upload_to=upload_to)
    mimetype = models.CharField(
        max_length=20, null=False, blank=True, default='')

    class Meta:
        app_label = 'odk_logger'

    @property
    def full_filepath(self):
        if self.media_file:
            default_storage = get_storage_class()()
            try:
                return default_storage.path(self.media_file.name)
            except NotImplementedError:
                # read file from s3
                name, ext = os.path.splitext(self.media_file.name)
                tmp = NamedTemporaryFile(suffix=ext, delete=False)
                f = default_storage.open(self.media_file.name)
                tmp.write(f.read())
                tmp.close()
                return tmp.name
        return None
{'fraction_non_alphanumeric': 0.09044455799693409, 'fraction_numerical': 0.0035769034236075624, 'mean_word_length': 2.877227722772277, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1859218', 'n_tokens_mistral': 574, 'n_tokens_neox': 557, 'n_words': 122}