-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
72 lines (61 loc) · 2.78 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from django.db import models
from django.db.models import permalink
from django.utils.translation import ugettext_lazy as _
from django.utils.text import capfirst
from datetime import datetime
try:
from markdown import markdown
except ImportError:
class MarkdownNotFound(Exception):
def __str__(self):
return "Markdown is not installed!"
raise MarkdownNotFound
from prana.languages import LANGUAGES
class Word(models.Model):
"""
Word/Meaning class
"""
word = models.CharField(_("word"), max_length=80)
meaning = models.CharField(_("meaning"), max_length=100)
language = models.CharField(_("language"), max_length=2, choices=LANGUAGES, default='en')
comment = models.TextField(_("comment"), blank=True, help_text=_("Use Markdown sintax to add a comment to the word"))
html_comment = models.TextField(editable=False, blank=True)
date = models.DateTimeField(_("date"), editable=False, default=datetime.now)
class Meta:
ordering = ("-date",)
verbose_name = _("word")
verbose_name_plural = _("words")
def __unicode__(self):
return "%s (%s)" % (capfirst(self.word), self.get_language_display())
def save(self):
self.html_comment = markdown(self.comment)
super(Word, self).save()
@permalink
def get_absolute_url(self):
return ("prana-worddetail", (), {'object_id': self.id})
class Verb(models.Model):
"""
Verb class
"""
verb = models.CharField(_("verb"), max_length=80, help_text=_("Use here the infinitive tense, e.g.: To be"))
meaning = models.CharField(_("meaning"), max_length=80, blank=True, help_text=_("The infinitive tense in your language, e.g.: Ser o estar"))
language = models.CharField(_("language"), max_length=2, choices=LANGUAGES, default='en')
content = models.TextField(_("content"), blank=True, \
help_text=_("e.g.: I am [2x Space + Intro] You are [2x Space + Intro] He is... and so forth. Use Markdown sintax here."))
html_content = models.TextField(editable=False, blank=True)
comment = models.TextField(_("comment"), blank=True, help_text=_("Use Markdown sintax to add a comment to the word"))
html_comment = models.TextField(editable=False, blank=True)
date = models.DateTimeField(_("date"), editable=False, default=datetime.now)
class Meta:
ordering = ("-date",)
verbose_name = _("verb")
verbose_name_plural = _("verbs")
def __unicode__(self):
return "%s (%s)" % (capfirst(self.verb), self.get_language_display())
def save(self):
self.html_content = markdown(self.content)
self.html_comment = markdown(self.comment)
super(Verb, self).save()
@permalink
def get_absolute_url(self):
return ("prana-verbdetail", (), { 'object_id': self.id })