<commit_before>from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib import admin
from reversion import VersionAdmin
from wq.identify.models import IdentifiedModel, IdentifiedModelAdmin

class AnnotatedModel(models.Model):
    annotations = generic.GenericRelation('Annotation')
    class Meta:
        abstract = True

class AnnotationType(IdentifiedModel):
    description = models.TextField()
    models      = models.ManyToManyField(ContentType)
    def fallback_identifier(self):
        return self.description

class Annotation(models.Model):
    type   = models.ForeignKey(AnnotationType)
    value  = models.CharField(max_length=255) # FIXME:numbers?

    # Link can contain a pointer to any model
    # FIXME: restrict to models allowed for given type
    content_type   = models.ForeignKey(ContentType)
    object_id      = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()

    def __unicode__(self):
      return ('%(object)s -> %(annot)s: %(value)s'
              % {
                  'object': self.content_object,
                  'annot':  self.type,
                  'value':  self.value
                })


class AnnotationTypeAdmin(IdentifiedModelAdmin, VersionAdmin):
    pass

class AnnotationInline(generic.GenericTabularInline):
    model = Annotation

class AnnotatedModelAdmin(VersionAdmin):
    inlines = [
        AnnotationInline,
    ]

admin.site.register(AnnotationType, AnnotationTypeAdmin)
<commit_msg>fix reference in wq.annotate.models; rename example app to avoid ambiguity with example project<commit_after>from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.contrib import admin
from reversion.admin import VersionAdmin
from wq.identify.models import IdentifiedModel, IdentifiedModelAdmin

class AnnotatedModel(models.Model):
    annotations = generic.GenericRelation('Annotation')
    class Meta:
        abstract = True

class AnnotationType(IdentifiedModel):
    description = models.TextField()
    models      = models.ManyToManyField(ContentType)
    def fallback_identifier(self):
        return self.description

class Annotation(models.Model):
    type   = models.ForeignKey(AnnotationType)
    value  = models.CharField(max_length=255) # FIXME:numbers?

    # Link can contain a pointer to any model
    # FIXME: restrict to models allowed for given type
    content_type   = models.ForeignKey(ContentType)
    object_id      = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey()

    def __unicode__(self):
      return ('%(object)s -> %(annot)s: %(value)s'
              % {
                  'object': self.content_object,
                  'annot':  self.type,
                  'value':  self.value
                })


class AnnotationTypeAdmin(IdentifiedModelAdmin, VersionAdmin):
    pass

class AnnotationInline(generic.GenericTabularInline):
    model = Annotation

class AnnotatedModelAdmin(VersionAdmin):
    inlines = [
        AnnotationInline,
    ]

admin.site.register(AnnotationType, AnnotationTypeAdmin)

{'fraction_non_alphanumeric': 0.0804953560371517, 'fraction_numerical': 0.0018575851393188853, 'mean_word_length': 3.462707182320442, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3663940', 'n_tokens_mistral': 870, 'n_tokens_neox': 847, 'n_words': 208}