src/core/models/term.py
author ymh <ymh.work@gmail.com>
Wed, 05 Feb 2014 13:32:41 +0100
changeset 341 9b7682bc6f0c
parent 334 169b7cfd1f58
permissions -rw-r--r--
correct field selection on autocomplete
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 -*-
334
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     2
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     3
# Copyright Institut de Recherche et d'Innovation © 2014
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     4
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     5
# contact@iri.centrepompidou.fr
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     6
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     7
# Ce code a été développé pour un premier usage dans JocondeLab, projet du 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     8
# ministère de la culture et de la communication visant à expérimenter la
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
     9
# recherche sémantique dans la base Joconde
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    10
# (http://jocondelab.iri-research.org/).
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    11
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    12
# Ce logiciel est régi par la licence CeCILL-C soumise au droit français et
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    13
# respectant les principes de diffusion des logiciels libres. Vous pouvez
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    14
# utiliser, modifier et/ou redistribuer ce programme sous les conditions
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    15
# de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    16
# sur le site "http://www.cecill.info".
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    17
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    18
# En contrepartie de l'accessibilité au code source et des droits de copie,
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    19
# de modification et de redistribution accordés par cette licence, il n'est
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    20
# offert aux utilisateurs qu'une garantie limitée.  Pour les mêmes raisons,
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    21
# seule une responsabilité restreinte pèse sur l'auteur du programme,  le
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    22
# titulaire des droits patrimoniaux et les concédants successifs.
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    23
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    24
# A cet égard  l'attention de l'utilisateur est attirée sur les risques
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    25
# associés au chargement,  à l'utilisation,  à la modification et/ou au
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    26
# développement et à la reproduction du logiciel par l'utilisateur étant 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    27
# donné sa spécificité de logiciel libre, qui peut le rendre complexe à 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    28
# manipuler et qui le réserve donc à des développeurs et des professionnels
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    29
# avertis possédant  des  connaissances  informatiques approfondies.  Les
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    30
# utilisateurs sont donc invités à charger  et  tester  l'adéquation  du
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    31
# logiciel à leurs besoins dans des conditions permettant d'assurer la
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    32
# sécurité de leurs systèmes et ou de leurs données et, plus généralement, 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    33
# à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    34
#
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    35
# Le fait que vous puissiez accéder à cet en-tête signifie que vous avez 
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    36
# pris connaissance de la licence CeCILL-C, et que vous en avez accepté les
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    37
# termes.
169b7cfd1f58 Add headers to py files
ymh <ymh.work@gmail.com>
parents: 146
diff changeset
    38
#
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
'''
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
Created on Jun 8, 2013
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
@author: ymh
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
'''
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
91
3bbf7371378a Model reorganization for user + migration.
ymh <ymh.work@gmail.com>
parents: 83
diff changeset
    45
from core import settings
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
from django.db import models
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
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
    48
from mptt.models import MPTTModel, TreeForeignKey
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
import datetime
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
import logging
91
3bbf7371378a Model reorganization for user + migration.
ymh <ymh.work@gmail.com>
parents: 83
diff changeset
    51
from core.models import User
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
logger = logging.getLogger(__name__)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
TERM_URL_STATUS_CHOICES = (
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
    (0, "null_result"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
    (1, "redirection"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
    (2, "homonyme"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
    (3, "match"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
    (4, "unsematized"),
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
TERM_URL_STATUS_CHOICES_TRANS = (
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
    (0, _("null_result")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
    (1, _("redirection")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
    (2, _("homonyme")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
    (3, _("match")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
    (4, _("unsematized")),
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
)
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
TERM_URL_STATUS_DICT = {
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
    "null_result":0,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
    "redirection":1,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
    "homonyme":2,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
    "match":3,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
    "unsemantized":4,
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
}
35
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    79
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    80
TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES = (
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    81
    (0, "--"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    82
    (1, "EE"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    83
    (2, "EI"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    84
    (3, "BM"),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    85
    (4, "NM")
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    86
)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    87
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    88
TERM_WK_LINK_SEMANTIC_LEVEL_CHOICES_TRANS = (
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    89
    (0, _("--")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    90
    (1, _("EE")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    91
    (2, _("EI")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    92
    (3, _("BM")),
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    93
    (4, _("NM"))
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    94
)
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    95
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    96
TERM_WK_LINK_SEMANTIC_LEVEL_DICT = {
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    97
    "--" : 0,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    98
    "EE" : 1,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
    99
    "EI" : 2,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   100
    "BM" : 3,
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   101
    "NM" : 4
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   102
}
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   103
859862939996 add qualifier on the wikipedia link
ymh <ymh.work@gmail.com>
parents: 26
diff changeset
   104
   
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
class Thesaurus(models.Model):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
    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
   107
    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
   108
    description = models.TextField(blank=True, null=True)    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
    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
   110
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
        app_label = 'core'
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
        ordering = ['label']
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
        
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
    def __unicode__(self):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
        return self.label
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   119
class Term(MPTTModel):
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
    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
   121
    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
   122
    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
   123
    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
   124
    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
   125
    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
   126
    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
   127
    created_at = models.DateTimeField(auto_now_add=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
    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
   129
    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
   130
    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
   131
    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
   132
    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
   133
    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
   134
    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
   135
    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
   136
    validation_date = models.DateTimeField(null=True, blank=True, serialize=False)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
    validated = models.BooleanField(default=False, db_index=True)
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
    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
   139
    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
   140
    
f4fadc1b9d70 cache the nb_notice query to improve perf.
ymh <ymh.work@gmail.com>
parents: 35
diff changeset
   141
    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
   142
    notices = models.ManyToManyField('core.Notice', related_name="terms+", through="core.NoticeTerm")
146
b5ce341745e3 Added nb_illustrated_notice and changed queries for keywords
veltr
parents: 110
diff changeset
   143
    nb_illustrated_notice = models.IntegerField(blank=False, null=False, default=0, db_index=True, editable=False)
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
    
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   145
    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
   146
    
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
    @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
   148
    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
   149
        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
   150
    
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
   151
    @property
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
    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
   153
        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
   154
    
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   155
    @property
758b9289aa9a add check box to indicate that a wk page should be created
ymh <ymh.work@gmail.com>
parents: 24
diff changeset
   156
    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
   157
        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
   158
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
    @property
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   160
    def wikipedia_language_version(self):
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   161
        if not self.wikipedia_url:
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   162
            return None
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   163
        for lang, urls in settings.WIKIPEDIA_URLS.iteritems():  # @UndefinedVariable
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   164
            if self.wikipedia_url.startswith(urls['base_url']):
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   165
                return lang
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   166
        return None
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   167
    
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   168
    @property
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
    def wikipedia_revision_permalink(self):
67
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   170
        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
   171
        if tmpl_str:            
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   172
            return tmpl_str % (unicode(self.wikipedia_revision_id))
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   173
        else:
5d9223bb3aab Add other wikipedia.
ymh <ymh.work@gmail.com>
parents: 62
diff changeset
   174
            return None
24
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   175
    
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   176
    @property
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   177
    def url_status_text(self):
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   178
        return TERM_URL_STATUS_CHOICES[self.url_status][1]
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
    @property
24
1d20eaea6169 small change of status link unsemantized.
ymh <ymh.work@gmail.com>
parents: 15
diff changeset
   181
    def url_status_text_trans(self):
15
8440c36660e5 add translation,
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   182
        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
   183
        
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
    def validate(self, user):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
        if not self.validated:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
            self.validation_date = datetime.datetime.utcnow()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
            self.validated = True
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
            self.validator = user
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
            self.save()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
    def unvalidate(self):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
        if self.validated:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
            self.validated = False
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
            self.validator = None
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
            self.validation_date = None
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
            self.save()
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
    
110
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   198
    def __unicode__(self):
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   199
        return self.label
597fa9d09973 Added Term List View
veltr
parents: 91
diff changeset
   200
    
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
        app_label = 'core'
61
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   203
        
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   204
    class MPTTMeta:
0048668779c0 change model for thesaurus tree. show level and ancestor
ymh <ymh.work@gmail.com>
parents: 55
diff changeset
   205
        order_insertion_by = ['normalized_label']
0
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
class TermLabel(models.Model):
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
    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
   209
    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
   210
    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
   211
    
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
    class Meta:
4095911a7830 Jocondelab first commit before design
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
        app_label = 'core'