src/core/models/term.py
author veltr
Wed, 18 Sep 2013 18:31:29 +0200
changeset 110 597fa9d09973
parent 91 3bbf7371378a
child 146 b5ce341745e3
permissions -rw-r--r--
Added Term List View
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
# -*- coding: utf-8 -*-
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
'''
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
Created on Jun 8, 2013
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
@author: ymh
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
'''
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
91
3bbf7371378a Model reorganization for user + migration.
ymh <ymh.work@gmail.com>
parents: 83
diff changeset
     8
from core import settings
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
from django.db import models
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
from django.utils.translation import ugettext as _
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
    11
from mptt.models import MPTTModel, TreeForeignKey
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
import datetime
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
import logging
91
3bbf7371378a Model reorganization for user + migration.
ymh <ymh.work@gmail.com>
parents: 83
diff changeset
    14
from core.models import User
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
logger = logging.getLogger(__name__)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
TERM_URL_STATUS_CHOICES = (
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
    (0, "null_result"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
    (1, "redirection"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    (2, "homonyme"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    (3, "match"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    (4, "unsematized"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
TERM_URL_STATUS_CHOICES_TRANS = (
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
    (0, _("null_result")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
    (1, _("redirection")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
    (2, _("homonyme")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
    (3, _("match")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
    (4, _("unsematized")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
)
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
TERM_URL_STATUS_DICT = {
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    "null_result":0,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
    "redirection":1,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
    "homonyme":2,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
    "match":3,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
    "unsemantized":4,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
}
35
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    42
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    43
TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES = (
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    44
    (0, "--"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    45
    (1, "EE"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    46
    (2, "EI"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    47
    (3, "BM"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    48
    (4, "NM")
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    49
)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    50
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    51
TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS = (
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    52
    (0, _("--")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    53
    (1, _("EE")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    54
    (2, _("EI")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    55
    (3, _("BM")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    56
    (4, _("NM"))
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    57
)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    58
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    59
TERM_WK_LINK_SEMANTIC_LEVEL_DICT = {
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    60
    "--" : 0,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    61
    "EE" : 1,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    62
    "EI" : 2,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    63
    "BM" : 3,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    64
    "NM" : 4
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    65
}
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    66
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    67
   
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
class Thesaurus(models.Model):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
    label = models.CharField(max_length=128, unique=True, blank=False, null=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
    title = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=False)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
    description = models.TextField(blank=True, null=True)    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
    uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
        app_label = 'core'
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
        ordering = ['label']
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
        
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
    def __unicode__(self):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
        return self.label
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
    82
class Term(MPTTModel):
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
    label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
    lang = models.CharField(max_length=128, unique=False, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
    uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
    normalized_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True, editable=False)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
    wp_label = models.CharField(max_length=1024, unique=False, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
    wp_alternative_label = models.CharField(max_length=1024, unique=False, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
    thesaurus = models.ForeignKey(Thesaurus, blank=False, null=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
    created_at = models.DateTimeField(auto_now_add=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
    wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
    wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
    wikipedia_revision_id = models.BigIntegerField(unique=False, blank=True, null=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
    alternative_wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
    alternative_wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True)
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    96
    url_status = models.IntegerField(choices=TERM_URL_STATUS_CHOICES_TRANS, blank=True, null=True, default=None, db_index=True)
35
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    97
    link_semantic_level = models.IntegerField(choices=TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS, blank=True, null=True, default=None, db_index=True)
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
    dbpedia_uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
    validation_date = models.DateTimeField(null=True, blank=True, serialize=False)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
    validated = models.BooleanField(default=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
    validator = models.ForeignKey(User, null=True, blank=True, serialize=False)
48
f4fadc1b9d70 cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents: 35
diff changeset
   102
    wikipedia_edition = models.BooleanField(default=False, blank=False, null=False)
f4fadc1b9d70 cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents: 35
diff changeset
   103
    
f4fadc1b9d70 cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents: 35
diff changeset
   104
    nb_notice = models.IntegerField(blank=False, null=False, default=0, db_index=True, editable=False)
55
bcbd95da9be2 add preview of notices + add missing img for wp
ymh <ymh.work@gmail.com>
parents: 48
diff changeset
   105
    notices = models.ManyToManyField('core.Notice', related_name="terms+", through="core.NoticeTerm")
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   107
    parent = TreeForeignKey('self', null=True, blank=True, related_name='children')
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   108
    
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    @property
83
4cdef872c351 Amélioration du parcours et de la sélection dans les arbres de thésaurus
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   110
    def children_with_descendants(self):
4cdef872c351 Amélioration du parcours et de la sélection dans les arbres de thésaurus
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   111
        return self.children.extra(where=['(rght-lft) > 1'])
4cdef872c351 Amélioration du parcours et de la sélection dans les arbres de thésaurus
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   112
    
4cdef872c351 Amélioration du parcours et de la sélection dans les arbres de thésaurus
ymh <ymh.work@gmail.com>
parents: 67
diff changeset
   113
    @property
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
    def alternative_labels_str(self):
26
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   115
        return " | ".join([l.label for l in self.alternative_labels.all() if l.label != self.label])
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   116
    
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   117
    @property
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   118
    def alternative_labels_list(self):
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   119
        return [l.label for l in self.alternative_labels.all() if l.label != self.label]
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
    @property
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   122
    def wikipedia_language_version(self):
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   123
        if not self.wikipedia_url:
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   124
            return None
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   125
        for lang, urls in settings.WIKIPEDIA_URLS.iteritems():  # @UndefinedVariable
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   126
            if self.wikipedia_url.startswith(urls['base_url']):
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   127
                return lang
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   128
        return None
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   129
    
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   130
    @property
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
    def wikipedia_revision_permalink(self):
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   132
        tmpl_str = settings.WIKIPEDIA_URLS.get(self.wikipedia_language_version, {}).get('permalink_tmpl',None)  # @UndefinedVariable
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   133
        if tmpl_str:            
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   134
            return tmpl_str % (unicode(self.wikipedia_revision_id))
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   135
        else:
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   136
            return None
24
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   137
    
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   138
    @property
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   139
    def url_status_text(self):
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   140
        return TERM_URL_STATUS_CHOICES[self.url_status][1]
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
    @property
24
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   143
    def url_status_text_trans(self):
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   144
        return TERM_URL_STATUS_CHOICES_TRANS[self.url_status][1]
62
33fd91a414cc selection dialog for thesaurus tree
ymh <ymh.work@gmail.com>
parents: 61
diff changeset
   145
        
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
    def validate(self, user):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
        if not self.validated:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
            self.validation_date = datetime.datetime.utcnow()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
            self.validated = True
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
            self.validator = user
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
            self.save()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
    def unvalidate(self):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
        if self.validated:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
            self.validated = False
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
            self.validator = None
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
            self.validation_date = None
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
            self.save()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
    
110
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   160
    def __unicode__(self):
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   161
        return self.label
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   162
    
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
        app_label = 'core'
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   165
        
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   166
    class MPTTMeta:
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   167
        order_insertion_by = ['normalized_label']
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
class TermLabel(models.Model):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
    label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
    lang = models.CharField(max_length=128, unique=False, blank=True, null=True, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
    term = models.ForeignKey(Term, blank=False, null=False, db_index=True, related_name="alternative_labels")
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
        app_label = 'core'