getting file size for all dict files to be downloaded. coming to be 400mb or so.
[worddb.git] / words / models.py
blob09e5bd150fc714b1e7ae4aeb33564edad26ff823
1 # imports # {{{
2 from django.db import models
3 from django.contrib.auth.models import User
4 from django.conf import settings
5 # }}}
7 # choices # {{{
8 LanguageChoices = (
9 # somebody has to build a list of languages and codes from:
10 # http://www.loc.gov/standards/iso639-2/php/code_list.php
11 ('en-us', 'English US'),
12 ('hi', u'\u0939\u093f\u0928\u094d\u0926\u0940 (Hindi)'),
13 ('spainish', "Spanish"),
14 # ...
16 POLChoices = (
17 ('noun', 'Noun'),
18 ('verb', 'Verb'),
19 ('adj', 'Adjective'),
21 ChangeTypes = (
22 ('added-word', 'Word added to the database'),
23 ('form-added', 'New form added to the word'),
24 ('form-removed', 'Existing form removed'),
25 ('language-changed', 'Language changed to a new language'),
26 ('etymology-created', 'Etymology created'),
27 ('etymology-updated', 'Etymology updated'),
28 ('synonym-added', 'Synonym added'),
29 ('synonym-removed', 'Synonym removed'),
30 ('thesaurus-added', 'Thesaurus added'),
31 ('thesaurus-removed', 'Thesaurus removed'),
32 ('antonym-added', 'Antonym added'),
33 ('antonym-removed', 'Antonym removed'),
34 ('translation-added', 'Translation added'),
35 ('translation-removed', 'Translation removed'),
36 ('rhyme-added', 'Rhyme added'),
37 ('rhyme-removed', 'Rhyme removed'),
38 ('meaning-added', 'Meaning added'),
39 # id_1 contains id of meaning, data is new data.
40 ('meaning-removed', 'Meaning removed'),
41 ('meaning-updated', 'Meaning updated'), # -- do --
42 ('pronunciation-added', 'Pronunciation added'),
43 ('pronunciation-removed', 'Pronunciation removed'),
44 ('pronunciation-edited', 'Pronunciation edited'),
45 ('usage-added', 'Usage added'),
46 ('usage-removed', 'Usage removed'),
47 ('usage-edited', 'Usage edited'),
49 # }}}
51 # Word # {{{
52 # WordManager # {{{
53 class WordManager(models.Manager):
54 def get_word(self, word_identified):
55 """
56 can take either word id or word text to return the word
57 """
58 try:
59 return Word.objects.get(word=word)
60 except Word.DoesNotExist:
61 return Word.objects.get(pk=word)
62 #}}}
64 class Word(models.Model):
65 word = models.CharField(max_length=100)
66 language = models.CharField(max_length=20, choices=LanguageChoices)
68 forms = models.TextField()
70 synonyms = models.ManyToManyField("self", symmetrical=True, blank=True)
71 thesaurus = models.ManyToManyField("self", symmetrical=True, blank=True)
72 antonyms = models.ManyToManyField("self", symmetrical=True, blank=True)
73 translations = models.ManyToManyField(
74 "self", symmetrical=True, blank=True
76 rhymes = models.ManyToManyField("self", symmetrical=True, blank=True)
77 relateds = models.ManyToManyField("self", symmetrical=True, blank=True)
79 created_on = models.DateTimeField(auto_now_add=True)
81 not_a_word = models.BooleanField(default=False)
82 not_a_word_marked_on = models.DateTimeField(null=True, blank=True)
84 objects = WordManager()
85 def __unicode__(self):
86 return u"%s, %s" % (self.word, self.get_language_display())
88 def get_form_data(self):
89 """
90 returns a list of dicts
91 dict: form, list: list of pronunciations, Queryset basically
92 """
93 return [
95 'form': form,
96 'pronunciations': Pronunciation.objects.filter(
97 spelling=form, is_deleted=False
100 for form in self.forms.split(
101 settings.WORD_FORM_DELIMITER
102 ) if form
105 @property
106 def visible_meanings(self):
107 return Meaning.visible_objects.filter(word=self)
109 def get_absolute_url(self): return "/%s/#w%s" % (self.word, self.id)
110 # }}}
112 # VisibleObjectManager # {{{
113 class VisibleObjectManager(models.Manager):
114 def get_query_set(self):
115 return super(VisibleObjectManager, self).get_query_set().filter(
116 is_deleted=False
118 # }}}
120 # Meaning # {{{
121 class Meaning(models.Model):
122 word = models.ForeignKey(Word)
123 meaning = models.TextField()
124 usage = models.TextField(blank=True)
125 language = models.CharField(max_length=20, choices=LanguageChoices)
126 # pol == part of language, or is there a better term for this
127 # noun/verb/adjective etc.
128 pol = models.CharField(max_length=20, choices=POLChoices)
130 created_on = models.DateTimeField(auto_now_add=True)
132 is_deleted = models.BooleanField(default=False)
133 deleted_on = models.DateTimeField(null=True, blank=True)
135 objects = models.Manager()
136 visible_objects = VisibleObjectManager()
138 def __unicode__(self):
139 return u"%s, %s: %s" % (self.word, self.pol, self.meaning)
141 class Meta:
142 ordering = ("language", "pol", )
143 # }}}
145 # Pronunciation # {{{
146 class Pronunciation(models.Model):
147 spelling = models.CharField(max_length=100)
148 # http://en.wikipedia.org/wiki/IPA_chart_for_English
149 pronunciation_key = models.CharField(max_length=100, blank=True)
151 # pronunciation_file = models.FileField?
152 created_on = models.DateTimeField(auto_now_add=True)
154 is_deleted = models.BooleanField(default=False)
155 deleted_on = models.DateTimeField(null=True, blank=True)
157 def __unicode__(self):
158 return u"%s: %s" % (self.spelling, self.pronunciation_key)
159 # }}}
161 # Etymology # {{{
162 class Etymology(models.Model):
163 word = models.ForeignKey(Word)
164 text = models.TextField()
165 language = models.CharField(max_length=20, choices=LanguageChoices)
167 class Meta:
168 ordering = ("language", )
169 unique_together = ('word', 'language')
171 def __unicode__(self):
172 return u"%s(%s): %s" % (
173 self.word, self.get_language_display(), self.text[:40]
175 # }}}
177 # Short # {{{
178 class Short(models.Model):
179 word = models.ForeignKey(Word)
180 text = models.CharField(max_length=50)
181 language = models.CharField(max_length=20, choices=LanguageChoices)
183 class Meta:
184 ordering = ("language", )
185 unique_together = ('word', 'language')
187 def __unicode__(self):
188 return u"%s(%s): %s" % (
189 self.word, self.get_language_display(), self.text
191 # }}}
193 # ChangeSheet # {{{
194 class ChangeSheet(models.Model):
195 word = models.ForeignKey(Word) # or to WordForm?
196 type = models.CharField(max_length=50, choices=ChangeTypes)
198 id_1 = models.IntegerField(null=True, blank=True)
199 data = models.TextField(blank=True)
201 user = models.ForeignKey(User) # who made this change
202 created_on = models.DateTimeField(auto_now_add=True)
204 def __unicode__(self):
205 return u"%s changed by %s: %s" % (
206 self.word, self.user, self.get_type_display()
208 # }}}