src/hdabo/models.py
author ymh <ymh.work@gmail.com>
Thu, 02 Apr 2015 22:52:54 +0200
changeset 613 4bb38d03e430
parent 545 c752fdee555b
child 693 09e00f38d177
permissions -rw-r--r--
upgrade django to 1.8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
     1
# -*- coding: utf-8 -*-
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
     2
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
     3
import datetime
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
     4
66
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
     5
from django.conf import settings
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
     6
from django.contrib.auth.models import AbstractUser
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
     7
from django.db import models
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
     8
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
     9
from hdabo import utils
72
ba8ebabbaece -correct css and display
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
    10
from hdabo.utils import Property, normalize
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    11
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    12
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
    13
# User Class, due to migration to django 1.6.5
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
    14
class User(AbstractUser):
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
    15
    class Meta:
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
    16
        db_table = 'auth_user'
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
    17
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    18
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    19
class SortedModelManager(models.Manager):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    20
    use_for_related_fields = True
545
c752fdee555b Migration to django 1.7
ymh <ymh.work@gmail.com>
parents: 443
diff changeset
    21
    def get_queryset(self):
c752fdee555b Migration to django 1.7
ymh <ymh.work@gmail.com>
parents: 443
diff changeset
    22
        qs = super(SortedModelManager, self).get_queryset()
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    23
        if getattr(self, 'through', None) is not None and getattr(self.through, 'Meta', None) is not None and getattr(self.through.Meta, 'ordering', None) is not None:
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    24
            qs = qs.order_by(*[self.through._meta.db_table + "." + f for f in self.through.Meta.ordering])
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    25
        return qs
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    26
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    27
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    28
class Organisation(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    29
    hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    30
    name = models.CharField(max_length=512, unique=False, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    31
    location = models.CharField(max_length=512, unique=False, blank=True, null=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    32
    website = models.CharField(max_length=2048, unique=False, blank=True, null=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    33
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    34
class Author(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    35
    hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    36
    lastname = models.CharField(max_length=512, unique=False, blank=True, null=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    37
    firstname = models.CharField(max_length=512, unique=False, blank=True, null=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    38
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    39
class TimePeriod(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    40
    TIME_PERIOD_CHOICES = (
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    41
        (1, u'Primaire'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    42
        (2, u'Collège'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    43
        (3, u'Lycée'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    44
    )
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    45
    TIME_PERIOD_DICT = {
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    46
        u'Primaire': 1,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    47
        u'Collège': 2,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    48
        u'Lycée': 3,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    49
    }
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    50
    label = models.CharField(max_length=512, unique=False, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    51
    school_period = models.IntegerField(choices=TIME_PERIOD_CHOICES)
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    52
    natural_key = models.CharField(max_length=512, unique=True, blank=False, null=False)
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    53
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    54
    objects = SortedModelManager()
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    55
    
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    56
    class Meta:
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    57
        unique_together = ("label", "school_period")
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    58
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    59
    def __unicode__(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    60
        return unicode(self.label)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    61
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    62
class Domain(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    63
    DOMAIN_PERIOD_CHOICES = (
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    64
        (0, u'Global'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    65
        (1, u'Primaire'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    66
        (2, u'Collège'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    67
        (3, u'Lycée'),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    68
    )
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    69
    DOMAIN_PERIOD_DICT = {
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    70
        u'Global': 0,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    71
        u'Primaire': 1,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    72
        u'Collège': 2,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    73
        u'Lycée': 3,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    74
    }
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    75
    label = models.CharField(max_length=512, unique=False, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    76
    school_period = models.IntegerField(choices=DOMAIN_PERIOD_CHOICES)
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    77
    natural_key = models.CharField(max_length=512, unique=True, blank=False, null=False)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    78
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    79
    objects = SortedModelManager()
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
    80
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    81
    class Meta:
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    82
        unique_together = ("label", "school_period")
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    83
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    84
    def __unicode__(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    85
        return unicode(self.label)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    86
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    87
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    88
class DocumentFormat(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    89
    label = models.CharField(max_length=512, unique=True, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    90
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    91
    def __unicode__(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    92
        return unicode(self.label)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    93
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    94
class TagCategory(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    95
    label = models.CharField(max_length=512, unique=True, blank=False, null=False)
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
    96
    natural_key = models.CharField(max_length=512, unique=False, blank=False, null=False, db_index=True)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    97
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    98
    def __unicode__(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
    99
        return unicode(self.label)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   100
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   101
    class Meta:
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   102
        verbose_name_plural = "TagCategories"
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   103
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   104
class Tag(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   105
    TAG_URL_STATUS_CHOICES = (
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   106
        (0, "null_result"),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   107
        (1, "redirection"),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   108
        (2, "homonyme"),
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   109
        (3, "match"),
108
4b73a767a6c0 backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents: 104
diff changeset
   110
        (4, "unsematized"),
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   111
    )
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   112
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   113
    TAG_URL_STATUS_DICT = {
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   114
        "null_result":0,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   115
        "redirection":1,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   116
        "homonyme":2,
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   117
        "match":3,
108
4b73a767a6c0 backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents: 104
diff changeset
   118
        "unsemantized":4,
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   119
    }
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   120
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   121
    label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True)
108
4b73a767a6c0 backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents: 104
diff changeset
   122
    alternative_label = models.CharField(max_length=1024, unique=False, blank=True, null=True)
72
ba8ebabbaece -correct css and display
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   123
    normalized_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, db_index=True, editable=False)
108
4b73a767a6c0 backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents: 104
diff changeset
   124
    created_at = models.DateTimeField(auto_now_add=True)
69
3b4a2c79524e desactivation lien W dans la fiche
ymh <ymh.work@gmail.com>
parents: 66
diff changeset
   125
    original_label = models.CharField(max_length=1024, unique=False, blank=False, null=False, editable=False)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   126
    alias = models.CharField(max_length=1024, unique=False, blank=True, null=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   127
    category = models.ForeignKey(TagCategory, null=True, blank=True)
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
   128
    wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents: 114
diff changeset
   129
    wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True)
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
   130
    alternative_wikipedia_url = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
119
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents: 114
diff changeset
   131
    alternative_wikipedia_pageid = models.BigIntegerField(unique=False, blank=True, null=True, db_index=True)
e3ebe3545f72 first implementation of django version.
ymh <ymh.work@gmail.com>
parents: 114
diff changeset
   132
    url_status = models.IntegerField(choices=TAG_URL_STATUS_CHOICES, blank=True, null=True, default=None, db_index=True)
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
   133
    dbpedia_uri = models.URLField(max_length=2048, blank=True, null=True, db_index=True)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   134
    popularity = models.IntegerField(blank=False, null=False, default=0, db_index=True)
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   135
    #natural_key = models.CharField(max_length=7168, blank=True, null=True, db_index=True)
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   136
    #TODO: find a proper key. natural key is not really a key.
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   137
    natural_key = models.CharField(max_length=7168, blank=False, null=False, db_index=True)
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   138
    
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   139
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   140
    def __init__(self, *args, **kwargs):
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   141
        models.Model.__init__(self, *args, **kwargs)
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   142
        self.force_natural_key = False
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   143
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   144
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   145
    def url_status_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   146
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   147
            return self.TAG_URL_STATUS_CHOICES[self.url_status][1]
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   148
        
72
ba8ebabbaece -correct css and display
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   149
        return locals()
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   150
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   151
    def calculate_natural_key(self):
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   152
        parts = [
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   153
            utils.sanitize(self.label if hasattr(self,'label') else ''),
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   154
            utils.sanitize(self.normalized_label if hasattr(self,'normalized_label') else ''),
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   155
            utils.sanitize(self.original_label if hasattr(self,'original_label') else ''),
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   156
            self.wikipedia_url.split("/")[-1].rstrip('/') if hasattr(self,'wikipedia_url') and self.wikipedia_url else ""
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   157
        ]
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   158
        return ('_'.join(parts))[:7168]
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   159
72
ba8ebabbaece -correct css and display
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   160
    
ba8ebabbaece -correct css and display
ymh <ymh.work@gmail.com>
parents: 69
diff changeset
   161
    def save(self, *args, **kwargs):
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   162
        if self.label and not self.normalized_label:
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   163
            self._normalized_label = normalize(self.label)
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   164
        if not self.force_natural_key:
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   165
            self.natural_key = self.calculate_natural_key()
85
2ff78b3ac007 Correction bug #18
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   166
        super(Tag, self).save(*args, **kwargs) 
2ff78b3ac007 Correction bug #18
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   167
            
2ff78b3ac007 Correction bug #18
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   168
    class Meta:
2ff78b3ac007 Correction bug #18
ymh <ymh.work@gmail.com>
parents: 72
diff changeset
   169
        unique_together = (('label', 'original_label', 'url_status'),)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   170
        
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   171
class Location(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   172
    name = models.CharField(max_length=512, unique=False, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   173
    insee = models.CharField(max_length=5, unique=True, blank=False, null=False)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   174
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   175
    def __unicode__(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   176
        return unicode("%s : %s" % (self.name, self.insee))
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   177
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   178
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   179
def generate_m2m_setter(m2m_field_name):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   180
    
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   181
    def set_m2m_field(self, lst):
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   182
        
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   183
        m2m_manager = getattr(self, m2m_field_name)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   184
        m2m_manager.clear()
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   185
        
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   186
        through_klass = set_m2m_field.cache.get('through_klass', None)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   187
        if through_klass is None:
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   188
            field = getattr(self.__class__, m2m_field_name)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   189
            through_klass = field.through
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   190
            set_m2m_field.cache['through_klass'] = through_klass
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   191
            for f in through_klass._meta.fields:
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   192
                if isinstance(f, models.ForeignKey) and f.name != "datasheet":
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   193
                    set_m2m_field.cache['target_obj_field_name'] = f.name
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   194
                    break
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   195
        target_obj_field_name = set_m2m_field.cache['target_obj_field_name']
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   196
443
27f71b0a772d next version of import_rdf
ymh <ymh.work@gmail.com>
parents: 275
diff changeset
   197
        for i, obj in enumerate(lst):
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   198
            kwargs = {
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   199
                'datasheet': self,
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   200
                'sort_value' : i,
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   201
                target_obj_field_name: obj
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   202
            }
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   203
            new_rel = through_klass(**kwargs)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   204
            new_rel.save()
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   205
    set_m2m_field.cache = {}
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   206
            
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   207
    return set_m2m_field
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   208
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   209
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   210
class Datasheet(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   211
    hda_id = models.CharField(max_length=512, unique=True, blank=False, null=False)
197
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   212
    author = models.ForeignKey(Author, null=True, blank=True, serialize=False)
200
23b2b36e5118 Merge with 72aa63f8365dbcc4606aa066ecbdd91aabdbf7a9
ymh <ymh.work@gmail.com>
parents: 199 197
diff changeset
   213
    organisation = models.ForeignKey(Organisation, serialize=False, null=True)
197
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   214
    title = models.CharField(max_length=2048, unique=False, blank=False, null=False, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   215
    description = models.TextField(blank=True, null=True, serialize=False)
266
825ff4d6a8ac reorganise folders and update venv dependancies (django, etc...)
cavaliet
parents: 200
diff changeset
   216
    url = models.URLField(max_length=2048, blank=True, null=True, serialize=False)
197
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   217
    domains = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Global']}, related_name="datasheets", through="Datasheet_domains", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   218
    primary_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Primaire']}, related_name="primary_periods_datasheets", through="Datasheet_primary_periods", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   219
    college_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Collège']}, related_name="college_periods_datasheets", through="Datasheet_college_periods", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   220
    highschool_periods = models.ManyToManyField(TimePeriod, limit_choices_to={'school_period':TimePeriod.TIME_PERIOD_DICT[u'Lycée']}, related_name="highschool_periods_datasheets", through="Datasheet_highschool_periods", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   221
    primary_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Primaire']}, related_name="primary_themes_datasheets", through="Datasheet_primary_themes", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   222
    college_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Collège']}, related_name="college_themes_datasheets", through="Datasheet_college_themes", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   223
    highschool_themes = models.ManyToManyField(Domain, limit_choices_to={'school_period':Domain.DOMAIN_PERIOD_DICT[u'Lycée']}, related_name="highschool_themes_datasheets", through="Datasheet_highschool_themes", serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   224
    town = models.ForeignKey(Location, null=True, blank=True, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   225
    format = models.ForeignKey(DocumentFormat, null=True, blank=True, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   226
    original_creation_date = models.DateField(serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   227
    original_modification_date = models.DateField(serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   228
    modification_datetime = models.DateTimeField(auto_now=True, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   229
    validation_date = models.DateTimeField(null=True, blank=True, serialize=False)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   230
    validated = models.BooleanField(default=False, db_index=True)
197
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   231
    validator = models.ForeignKey(User, null=True, blank=True, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   232
    manual_order = models.BooleanField(default=False, db_index=True, serialize=False)
72aa63f8365d update datasheet model for serializasation and dumpdata.
cavaliet
parents: 181
diff changeset
   233
    tags = models.ManyToManyField(Tag, through='TaggedSheet', serialize=False)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   234
    
181
27d111cf9c19 update DataSheet with natural_key
cavaliet
parents: 119
diff changeset
   235
    def natural_key(self):
27d111cf9c19 update DataSheet with natural_key
cavaliet
parents: 119
diff changeset
   236
        return self.hda_id
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   237
        
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   238
    def validate(self, user):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   239
        self.validation_date = datetime.datetime.now()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   240
        self.validated = True
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   241
        self.validator = user
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   242
        self.save()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   243
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   244
    def unvalidate(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   245
        self.validation_date = datetime.datetime.min
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   246
        self.validated = False
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   247
        self.validator = None
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   248
        self.save()
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   249
        
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   250
        
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   251
    set_domains = generate_m2m_setter("domains")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   252
    
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   253
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   254
    def domains_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   255
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   256
            return [d.label for d in self.domains.all()]
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   257
        
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   258
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   259
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   260
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   261
    def domains_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   262
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   263
            return "; ".join(self.domains_list)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   264
        
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   265
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   266
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   267
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   268
    set_primary_periods = generate_m2m_setter("primary_periods")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   269
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   270
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   271
    def primary_periods_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   272
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   273
            return [d.label for d in self.primary_periods.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   274
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   275
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   276
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   277
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   278
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   279
    def primary_periods_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   280
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   281
            return "; ".join(self.primary_periods_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   282
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   283
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   284
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   285
    set_college_periods = generate_m2m_setter("college_periods")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   286
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   287
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   288
    def college_periods_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   289
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   290
            return [d.label for d in self.college_periods.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   291
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   292
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   293
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   294
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   295
    def college_periods_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   296
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   297
            return "; ".join(self.college_periods_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   298
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   299
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   300
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   301
    set_highschool_periods = generate_m2m_setter("highschool_periods")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   302
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   303
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   304
    def highschool_periods_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   305
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   306
            return [d.label for d in self.highschool_periods.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   307
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   308
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   309
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   310
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   311
    def highschool_periods_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   312
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   313
            return "; ".join(self.highschool_periods_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   314
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   315
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   316
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   317
    set_primary_themes = generate_m2m_setter("primary_themes")
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   318
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   319
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   320
    def primary_themes_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   321
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   322
            return [d.label for d in self.primary_themes.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   323
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   324
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   325
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   326
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   327
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   328
    def primary_themes_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   329
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   330
            return "; ".join(self.primary_themes_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   331
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   332
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   333
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   334
    set_college_themes = generate_m2m_setter("college_themes")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   335
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   336
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   337
    def college_themes_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   338
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   339
            return [d.label for d in self.college_themes.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   340
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   341
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   342
    
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   343
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   344
    def college_themes_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   345
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   346
            return "; ".join(self.college_themes_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   347
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   348
        return locals() 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   349
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   350
    set_highschool_themes = generate_m2m_setter("highschool_themes")
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   351
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   352
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   353
    def highschool_themes_list(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   354
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   355
            return [d.label for d in self.highschool_themes.all()] 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   356
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   357
        return locals()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   358
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   359
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   360
    def highschool_themes_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   361
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   362
            return "; ".join(self.highschool_themes_list) 
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   363
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   364
        return locals()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   365
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   366
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   367
    def town_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   368
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   369
            return self.town.name if self.town else ""
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   370
        
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   371
        return locals()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   372
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   373
    @Property
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   374
    def tags_text(): #@NoSelf
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   375
        def fget(self):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   376
            return "; ".join([t.label for t in self.tags.all()])
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   377
        
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   378
        return locals()
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   379
96
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   380
    @models.permalink
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   381
    def get_absolute_url(self):
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   382
        return ('display_datasheet', (), {
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   383
                    'ds_id': self.hda_id
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   384
                })
e8a32d48da1b add search page, cf #19
ymh <ymh.work@gmail.com>
parents: 85
diff changeset
   385
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   386
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   387
class TaggedSheet(models.Model):
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   388
    datasheet = models.ForeignKey(Datasheet)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   389
    tag = models.ForeignKey(Tag)
108
4b73a767a6c0 backport changes made on model for hdabo_sf
ymh <ymh.work@gmail.com>
parents: 104
diff changeset
   390
    created_at = models.DateTimeField(auto_now_add=True)
47
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   391
    original_order = models.IntegerField(null=False, blank=False, default=0)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   392
    order = models.IntegerField(null=False, blank=False, default=0, db_index=True)
08b008c5a07d - add popularity
ymh <ymh.work@gmail.com>
parents: 44
diff changeset
   393
    index_note = models.FloatField(null=False, blank=False, default=0.0, db_index=True)
66
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   394
    wikipedia_revision_id = models.BigIntegerField(unique=False, blank=True, null=True)
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   395
    
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   396
    @Property
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   397
    def wikipedia_verion_permalink(): #@NoSelf
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   398
        def fget(self):
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   399
            return settings.WIKIPEDIA_VERSION_PERMALINK_TEMPLATE % (unicode(self.wikipedia_revision_id))
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   400
        
289ded098316 add revision link cf bug #12
ymh <ymh.work@gmail.com>
parents: 47
diff changeset
   401
        return locals()
104
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   402
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   403
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   404
class SortedDatasheetLink(models.Model):    
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   405
    datasheet = models.ForeignKey(Datasheet, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   406
    sort_value = models.IntegerField(null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   407
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   408
    class Meta:
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   409
        abstract = True
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   410
        ordering = ['sort_value']
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   411
        
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   412
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   413
class Datasheet_domains(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   414
    domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   415
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   416
class Datasheet_highschool_periods(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   417
    timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   418
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   419
class Datasheet_highschool_themes(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   420
    domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   421
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   422
class Datasheet_college_periods(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   423
    timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   424
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   425
class Datasheet_college_themes(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   426
    domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   427
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   428
class Datasheet_primary_periods(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   429
    timeperiod = models.ForeignKey(TimePeriod, db_index=True, null=False, blank=False)
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   430
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   431
class Datasheet_primary_themes(SortedDatasheetLink):
28a2c02ef6c8 Remove sorted m2m fields and prepare for south
ymh <ymh.work@gmail.com>
parents: 96
diff changeset
   432
    domain = models.ForeignKey(Domain, db_index=True, null=False, blank=False)
275
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   433
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   434
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   435
# Evolution pour Hda 2 : folders of datasheets
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   436
class Folder(models.Model):
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   437
    url = models.URLField(max_length=2048, unique=True, blank=False, null=False)
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   438
    title = models.CharField(max_length=2048, blank=True, null=True)
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   439
    description = models.TextField(blank=True, null=True)
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   440
    datasheets = models.ManyToManyField(Datasheet)
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   441
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   442
b2eb3e9e6956 first step of folder administration
cavaliet
parents: 272
diff changeset
   443