<commit_before>from django.db import models
from mediaman.thumbs import ImageWithThumbsField
from cat.models import MuseumObject
from south.modelsinspector import add_introspection_rules
import os.path
from filebrowser.fields import FileBrowseField
from easy_thumbnails.fields import ThumbnailerImageField
from django.contrib.auth.models import User
from django.db.models.signals import post_delete
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.storage import FileSystemStorage

add_introspection_rules(
    [
        (
            (ImageWithThumbsField, ),
            [],
            {
                "verbose_name": ["verbose_name", {"default": None}],
                "name":         ["name",         {"default": None}],
                "width_field":  ["width_field",  {"default": None}],
                "height_field": ["height_field", {"default": None}],
                "sizes":        ["sizes",        {"default": None}],
            },
        ),
    ],
    ["^mediaman.thumbs.ImageWithThumbsField", ])


class MediaFile(models.Model):
    md5sum = models.CharField(max_length=32, blank=True, editable=False)
    filesize = models.IntegerField(blank=True, null=True, editable=False)
    upload_date = models.DateTimeField(auto_now_add=True, editable=False)
    uploaded_by = models.ForeignKey(User, related_name="+",
            null=True, blank=True, editable=False)
    mime_type = models.CharField(max_length=150, blank=True, editable=False)
    original_filename = models.CharField(max_length=255, editable=False)
    original_path = models.CharField(max_length=255, blank=True, editable=False)
    original_filedate = models.DateTimeField(blank=True, null=True, editable=False)
    name = models.CharField(max_length=255, editable=False)

    class Meta:
        abstract = True



archival_storage = FileSystemStorage(
        location=settings.MEDIA_ROOT + '/archival')


class ArtefactRepresentation(MediaFile):
    image = ThumbnailerImageField(
        upload_to='mediareps/%Y/%m-%d/',
        storage=archival_storage,
        thumbnail_storage=default_storage)
    position = models.PositiveSmallIntegerField()
    artefact = models.ForeignKey(MuseumObject)

    class Meta:
        ordering = ['position']

    def __unicode__(self):
        return self.name


def remove_delete_image_file(sender, instance, **kwargs):
    instance.image.delete(save=False)

post_delete.connect(remove_delete_image_file, sender=ArtefactRepresentation)

#class ExternalArtefactRepresentation(models.Model):
#    url = models.URLField()
#    artefact = models.ForeignKey(MuseumObject)


class Document(MediaFile):
    document = models.FileField(upload_to='docs/')
#    document = FileBrowseField('Document', max_length=200, directory='docs/')

    def __unicode__(self):
        return self.name

<commit_msg>Upload documents to date based folder hierarchy<commit_after>from django.db import models
from mediaman.thumbs import ImageWithThumbsField
from cat.models import MuseumObject
from south.modelsinspector import add_introspection_rules
import os.path
from filebrowser.fields import FileBrowseField
from easy_thumbnails.fields import ThumbnailerImageField
from django.contrib.auth.models import User
from django.db.models.signals import post_delete
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.storage import FileSystemStorage

add_introspection_rules(
    [
        (
            (ImageWithThumbsField, ),
            [],
            {
                "verbose_name": ["verbose_name", {"default": None}],
                "name":         ["name",         {"default": None}],
                "width_field":  ["width_field",  {"default": None}],
                "height_field": ["height_field", {"default": None}],
                "sizes":        ["sizes",        {"default": None}],
            },
        ),
    ],
    ["^mediaman.thumbs.ImageWithThumbsField", ])


class MediaFile(models.Model):
    md5sum = models.CharField(max_length=32, blank=True, editable=False)
    filesize = models.IntegerField(blank=True, null=True, editable=False)
    upload_date = models.DateTimeField(auto_now_add=True, editable=False)
    uploaded_by = models.ForeignKey(User, related_name="+",
            null=True, blank=True, editable=False)
    mime_type = models.CharField(max_length=150, blank=True, editable=False)
    original_filename = models.CharField(max_length=255, editable=False)
    original_path = models.CharField(max_length=255, blank=True, editable=False)
    original_filedate = models.DateTimeField(blank=True, null=True, editable=False)
    name = models.CharField(max_length=255, editable=False)

    class Meta:
        abstract = True



archival_storage = FileSystemStorage(
        location=settings.MEDIA_ROOT + '/archival')


class ArtefactRepresentation(MediaFile):
    image = ThumbnailerImageField(
        upload_to='mediareps/%Y/%m-%d/',
        storage=archival_storage,
        thumbnail_storage=default_storage)
    position = models.PositiveSmallIntegerField()
    artefact = models.ForeignKey(MuseumObject)

    class Meta:
        ordering = ['position']

    def __unicode__(self):
        return self.name


def remove_delete_image_file(sender, instance, **kwargs):
    instance.image.delete(save=False)

post_delete.connect(remove_delete_image_file, sender=ArtefactRepresentation)

#class ExternalArtefactRepresentation(models.Model):
#    url = models.URLField()
#    artefact = models.ForeignKey(MuseumObject)


class Document(MediaFile):
    document = models.FileField(upload_to='docs/%Y/%m-%d/')
#    document = FileBrowseField('Document', max_length=200, directory='docs/')

    def __unicode__(self):
        return self.name


{'fraction_non_alphanumeric': 0.10890918490435982, 'fraction_numerical': 0.006203687747716698, 'mean_word_length': 3.7573770491803278, 'pattern_counts': {'":': 20, '<': 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': '4695157', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1681, 'n_words': 322}